Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DRAFT: datalog style constant folding solver skeleton #1157

Closed
wants to merge 12 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions hugr-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ pub mod extension;
pub mod hugr;
pub mod macros;
pub mod ops;
pub mod partial_value;
pub mod std_extensions;
pub mod types;
pub mod utils;
Expand Down
45 changes: 44 additions & 1 deletion hugr-core/src/ops/constant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ impl AsRef<Value> for Const {
}
}

#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)]
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
#[serde(tag = "v")]
/// A value that can be stored as a static constant. Representing core types and
/// extension types.
Expand Down Expand Up @@ -136,6 +136,49 @@ pub enum Value {
},
}

impl PartialEq for Value {
fn eq(&self, other: &Self) -> bool {
let cmp_tuple_sum =
|tuple_values: &[Value], tag: usize, sum_values: &[Value], sum_type: &SumType| {
tag == 0 && sum_type.num_variants() == 1 && tuple_values == sum_values
};
match (self, other) {
(Self::Extension { e: e1 }, Self::Extension { e: e2 }) => e1 == e2,
(Self::Function { hugr: h1 }, Self::Function { hugr: h2 }) => h1 == h2,
(Self::Tuple { vs: v1 }, Self::Tuple { vs: v2 }) => v1 == v2,
(
Self::Sum {
tag: t1,
values: v1,
sum_type: s1,
},
Self::Sum {
tag: t2,
values: v2,
sum_type: s2,
},
) => t1 == t2 && v1 == v2 && s1 == s2,
(
Self::Tuple { vs },
Self::Sum {
tag,
values,
sum_type,
},
)
| (
Self::Sum {
tag,
values,
sum_type,
},
Self::Tuple { vs },
) => cmp_tuple_sum(vs, *tag, values, sum_type),
_ => false,
}
}
}

/// An opaque newtype around a [`Box<dyn CustomConst>`](CustomConst).
///
/// This type has special serialization behaviour in order to support
Expand Down
2 changes: 1 addition & 1 deletion hugr-core/src/ops/module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ impl OpTrait for AliasDefn {
}

/// A type alias declaration. Resolved at link time.
#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
#[derive(Debug, Clone, PartialEq, Eq, Hash, serde::Serialize, serde::Deserialize)]
#[cfg_attr(test, derive(proptest_derive::Arbitrary))]
pub struct AliasDecl {
/// Alias name
Expand Down
Loading
Loading