Skip to content

Commit 3745791

Browse files
committed
Revert equality to its original index-based semantics
1 parent c9cebb8 commit 3745791

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

saw-core/src/Verifier/SAW/Term/Functor.hs

+11-2
Original file line numberDiff line numberDiff line change
@@ -465,6 +465,15 @@ combine :: Int -> Int -> Int
465465
combine h1 h2 = (h1 * 0x01000193) `xor` h2
466466

467467
instance Eq Term where
468+
-- Note: we take some minor liberties with the contract of 'hashWithSalt' in
469+
-- this implementation of 'Eq'. The contract states that if two values are
470+
-- equal according to '==', then they must have the same hash. For terms
471+
-- constructed by/within SAW, this will hold, because SAW's handling of index
472+
-- generation and assignment ensures that equality of indices implies equality
473+
-- of terms and term hashes (see 'Verifier.SAW.SharedTerm.getTerm'). However,
474+
-- if terms are constructed outside this standard procedure or in a way that
475+
-- does not respect index uniqueness rules, 'hashWithSalt''s contract could be
476+
-- violated.
468477
(==) = alphaEquiv
469478

470479
alphaEquiv :: Term -> Term -> Bool
@@ -474,8 +483,8 @@ alphaEquiv = term
474483
term (Unshared tf1) (Unshared tf2) = termf tf1 tf2
475484
term (Unshared tf1) (STApp{stAppTermF = tf2}) = termf tf1 tf2
476485
term (STApp{stAppTermF = tf1}) (Unshared tf2) = termf tf1 tf2
477-
term (STApp{stAppIndex = i1, stAppHash = h1, stAppTermF = tf1})
478-
(STApp{stAppIndex = i2, stAppHash = h2, stAppTermF = tf2}) = (i1 == i2 && h1 == h2) || termf tf1 tf2
486+
term (STApp{stAppIndex = i1, stAppTermF = tf1})
487+
(STApp{stAppIndex = i2, stAppTermF = tf2}) = i1 == i2 || termf tf1 tf2
479488

480489
termf :: TermF Term -> TermF Term -> Bool
481490
termf (FTermF ftf1) (FTermF ftf2) = ftermf ftf1 ftf2

0 commit comments

Comments
 (0)