Add PartialEq to BoundKind and Value

Implement PartialEq for BoundKind to allow for structural equality
checks during optimization. This enables the optimizer to terminate
early when a node no longer changes.

Also, implement PartialEq for Value to facilitate comparisons between
different Value variants.
This commit is contained in:
Michael Schimmel
2026-02-21 20:01:58 +01:00
parent 56b8e8389b
commit f980d9befc
4 changed files with 84 additions and 3 deletions
+24 -1
View File
@@ -59,7 +59,7 @@ pub trait Object: fmt::Debug {
pub type ValueList = Rc<Vec<Value>>;
/// Internal storage for Records to allow sharing schema (keys) between instances.
#[derive(Debug, Clone)]
#[derive(Debug, Clone, PartialEq)]
pub struct RecordData {
/// Names for slots.
pub keys: Rc<Vec<Keyword>>,
@@ -85,6 +85,29 @@ pub enum Value {
TailCallRequest(Box<(Rc<dyn Object>, Vec<Value>)>), // Internal: For TCO (Boxed to keep Value small)
}
impl PartialEq for Value {
fn eq(&self, other: &Self) -> bool {
match (self, other) {
(Value::Void, Value::Void) => true,
(Value::Bool(a), Value::Bool(b)) => a == b,
(Value::Int(a), Value::Int(b)) => a == b,
(Value::Float(a), Value::Float(b)) => a == b,
(Value::DateTime(a), Value::DateTime(b)) => a == b,
(Value::Text(a), Value::Text(b)) => a == b,
(Value::Keyword(a), Value::Keyword(b)) => a == b,
(Value::Tuple(a), Value::Tuple(b)) => a == b,
(Value::Record(a), Value::Record(b)) => a == b,
(Value::Function(a), Value::Function(b)) => Rc::ptr_eq(a, b),
(Value::Object(a), Value::Object(b)) => Rc::ptr_eq(a, b),
(Value::Cell(a), Value::Cell(b)) => Rc::ptr_eq(a, b),
(Value::TailCallRequest(a), Value::TailCallRequest(b)) => {
Rc::ptr_eq(&a.0, &b.0) && a.1 == b.1
}
_ => false,
}
}
}
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct Signature {
pub params: StaticType,