Preserve hard unions in more situations #12654
Merged
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.
There's multiple places where we take apart a union, apply some
transformation to its parts, then either return the original union if
nothing changed or recombine the transformed parts into a new union. The
problem is that to check if nothing changed we use referential equality
when
=:=
would be more correct, so we sometimes end up returning aunion equivalent to the original one except the new one is a soft union.
I've seen this lead to subtle type inference differences both when
experimenting with changes to constraint solving and when trying to
replace our Uniques hashmaps by weak hashmaps.
We could fix this by replacing these
eq
calls by=:=
but insteadthis commit takes the approach of preserving the softness of a union
even when its components are modified, see the test case.