Skip to content

Commit

Permalink
docs: Clarify CustomConst::equal_consts (#1396)
Browse files Browse the repository at this point in the history
This is just explaining existing behaviour, but I think it's important
to explain that we are not expecting the equivalent of `Eq` on a
structure that could be just an `f64`....

This does constrain impls to be symmetric and transitive, but all
current ones are, and I couldn't think of any... (indeed, "either Eq or
always return false" would describe all current impls, and this is still
significantly more permissive than that.)
  • Loading branch information
acl-cqc authored Aug 6, 2024
1 parent 27db0f2 commit b7f0765
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion hugr-core/src/ops/constant/custom.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,14 @@ pub trait CustomConst:
/// Compare two constants for equality, using downcasting and comparing the definitions.
///
/// If the type implements `PartialEq`, use [`downcast_equal_consts`] to compare the values.
///
/// Note that this does not require any equivalent of [Eq]: it is permissible to return
/// `false` if in doubt, and in particular, there is no requirement for reflexivity
/// (i.e. `x.equal_consts(x)` can be `false`). However, we do expect both
/// symmetry (`x.equal_consts(y) == y.equal_consts(x)`) and transitivity
/// (if `x.equal_consts(y) && y.equal_consts(z)` then `x.equal_consts(z)`).
fn equal_consts(&self, _other: &dyn CustomConst) -> bool {
// false unless overloaded
// false unless overridden
false
}

Expand Down

0 comments on commit b7f0765

Please sign in to comment.