Update Hashable Term
instance so alphaEquiv t1 t2
implies hash t1 == hash t2
#1869
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The
Hashable
class requires that if two elements are equal, then they have the same hash. I noticed that the currentHashable
instance forTerm
did not satisfy this in two ways:Lambda "x" t u
would have a different hash thanLambda "y" t u
, even though they are equal (since equality ofTerm
s isalphaEquiv
)STApp
vs.Unshared
:STApp { stAppTermF = t }
would have a different hash thanUnshared t
, even though they are equal (since, as above, equality ofTerm
s isalphaEquiv
, andalphaEquiv
does not differentiate between the two constructors if they have equalTermF
representations)This PR resolves both of these issues: the first by defining a manual
Hashable (TermF e)
instance, and the second by removing thecombine 0x00000000
andcombine 0x55555555
parts of theHashable Term
instance which differentiated theSTApp
andUnshared
constructors.I noticed that some of this was already discussed in #1830 – in particular Andrei left a comment with an optimization to
alphaEquiv
that can be made if the first change above was implemented. Since I did the latter, I included that optimization.