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

Fix healAmbiguous to compareAlternatives with disambiguate = true #21339

Merged
merged 6 commits into from
Aug 7, 2024

Conversation

EugeneFlesselle
Copy link
Contributor

@EugeneFlesselle EugeneFlesselle commented Aug 6, 2024

Based on #21328
Opened here to have it run the CI

odersky added 5 commits August 6, 2024 20:52
We now use a left-biased scheme, as follows.

From 3.6 on:

 - A given x: X is better than a given or implicit y: Y if y can be instantiated/widened to X.
 - An implicit x: X is better than a given or implicit y: Y if y can be instantiated to a supertype of X.
 - Use owner score for givens as a tie breaker if after all other tests we still have an ambiguity.

This is not transitive, so we need a separate scheme to work around that.

Other change:

 - Drop special handling of NotGiven in prioritization. The previous logic pretended to do so,
   but was ineffective.
We only have transitivity between givens or between implicits. To cope with that

 - We tank first all implicits, giving a best implicit search result.
 - Then we rank all givens startign with the implicit result. If there is
   a given that is better than the best implicit, the best given will be chosen.
   Otherwise we will stick with the best implicit.
Warnings from 3.6, change in 3.7. This is one version later than
originally planned.
Make the wording of a priority change warning message stable under different orders of eligibles.
We now always report the previously chosen alternative first and the new one second.

Note: We can still get ambiguities by fallging different pairs of alternatives depending on initial order.
@EugeneFlesselle EugeneFlesselle force-pushed the given-healAmbiguous branch 2 times, most recently from be388ca to dcf90e1 Compare August 6, 2024 21:42
On the final result, compared with all the ambiguous candidates we are trying
to recover from. We should still use `disambiguate = false` when filtering the
`pending` candidates for the purpose of warnings, as in the other cases.

Before the changes, it was possible for an ambiguous SearchFailure
to be healed by a candidate which was considered better (possibly only) under
a prioritization scheme different from the current one.

As an optimization, we can avoid redoing compareAlternatives in versions which
could have only used the new prioritization scheme to begin with.

Also restores behaviour avoiding false positive warnings.
Specifically, in cases where we could report a change in prioritization,
despite having not yet done `tryImplicit` on the alternative,
i.e. it was only compared as part of an early filtering

See scala#21045 for related changes
@Gedochao Gedochao added the backport:nominated If we agree to backport this PR, replace this tag with "backport:accepted", otherwise delete it. label Aug 7, 2024
@Gedochao Gedochao added this to the 3.5.0 milestone Aug 7, 2024
Copy link
Contributor

@odersky odersky left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks all good to me now

@odersky odersky marked this pull request as ready for review August 7, 2024 09:50
@odersky
Copy link
Contributor

odersky commented Aug 7, 2024

@EugeneFlesselle Please merge unless there's something else you want to add.

@EugeneFlesselle EugeneFlesselle merged commit 590b496 into scala:main Aug 7, 2024
56 checks passed
@EugeneFlesselle EugeneFlesselle deleted the given-healAmbiguous branch August 7, 2024 09:59
WojciechMazur added a commit that referenced this pull request Aug 8, 2024
@WojciechMazur WojciechMazur modified the milestones: 3.5.0, 3.5.1 Aug 12, 2024
@WojciechMazur WojciechMazur added backport:accepted This PR needs to be backported, once it's been backported replace this tag by "backport:done" backport:done This PR was successfully backported. and removed backport:nominated If we agree to backport this PR, replace this tag with "backport:accepted", otherwise delete it. backport:accepted This PR needs to be backported, once it's been backported replace this tag by "backport:done" labels Aug 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport:done This PR was successfully backported.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants