You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
According to the docs from Ordering.enso, hash contract means that for any objects x, y, z:
Hash consistency:
If x == y then hash(x) == hash(y)
If hash(x) != hash(y) then x != y
Consistency: if x == y then x == y for all the subsequent invocations.
Symmetry: if x == y then y == x
Transitivity: if x < y and y < z then x < z
if x > y then y < x
On the latest develop (1f8511d) we do not check any of these properties at runtime. We should check these properties at runtime, at least from time to time.
The following diff shows a naive approach, how to check hash consistency naively:
diff --git a/distribution/lib/Standard/Base/0.0.0-dev/src/Any.enso b/distribution/lib/Standard/Base/0.0.0-dev/src/Any.enso
index 4752b8b80..59ac58063 100644
--- a/distribution/lib/Standard/Base/0.0.0-dev/src/Any.enso+++ b/distribution/lib/Standard/Base/0.0.0-dev/src/Any.enso@@ -113,13 +113,16 @@ type Any
if Meta.is_same_object eq_self Incomparable then False else
similar_type = Meta.is_same_object eq_self eq_that
if similar_type.not then False else
- case eq_self.is_ordered of- True ->- # Comparable.equals_builtin is a hack how to directly access EqualsNode from the- # engine, so that we don't end up in an infinite recursion here (which would happen- # if we would compare with `eq_self == eq_that`).- Comparable.equals_builtin (eq_self.compare self that) Ordering.Equal- False -> eq_self.equals self that+ self_hash = eq_self.hash self+ that_hash = eq_that.hash that+ if Comparable.equals_builtin self_hash that_hash . not then False else+ case eq_self.is_ordered of+ True ->+ # Comparable.equals_builtin is a hack how to directly access EqualsNode from the+ # engine, so that we don't end up in an infinite recursion here (which would happen+ # if we would compare with `eq_self == eq_that`).+ Comparable.equals_builtin (eq_self.compare self that) Ordering.Equal+ False -> eq_self.equals self that
## ALIAS Inequality
Note that we do not want to check that in each invocation of Any.== because it could have major performance impact. For example, for an atom with a multilevel field hierarchy, checking equality is potentially faster than computing hash code.
According to the docs from
Ordering.enso
, hash contract means that for any objects x, y, z:On the latest
develop
(1f8511d) we do not check any of these properties at runtime. We should check these properties at runtime, at least from time to time.The following diff shows a naive approach, how to check hash consistency naively:
Note that we do not want to check that in each invocation of
Any.==
because it could have major performance impact. For example, for an atom with a multilevel field hierarchy, checking equality is potentially faster than computing hash code.Related discussion on the PR:
The text was updated successfully, but these errors were encountered: