Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Preserve hard unions in more situations #12654

Merged
merged 1 commit into from
Jun 2, 2021

Conversation

smarter
Copy link
Member

@smarter smarter commented May 31, 2021

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 a
union 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 instead
this commit takes the approach of preserving the softness of a union
even when its components are modified, see the test case.

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 a
union 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 instead
this commit takes the approach of preserving the softness of a union
even when its components are modified, see the test case.
@smarter smarter requested a review from odersky May 31, 2021 12:44
@odersky odersky merged commit 54929c2 into scala:master Jun 2, 2021
@odersky odersky deleted the soft-unions-2 branch June 2, 2021 16:11
@Kordyjan Kordyjan added this to the 3.0.2 milestone Aug 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants