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

Bypass eligible caches for implicit search under GADT constraints #14072

Merged
merged 2 commits into from Dec 9, 2021

Conversation

odersky
Copy link
Contributor

@odersky odersky commented Dec 8, 2021

Under a non-empty GADT constraint, bypass caches when computing eligible implicits.
The GADT constraint might influence what implicits are available locally, so cached
results would be unreliable.

What this means for performance depends on how many implicit searches are performed
under non-empty GADT constraints. I measured for dotty itself. There, about 2% of givens
were checked in uncached mode because they were under a nonempty GADT constraint.
Rechecking those 2% might have been avoided if they had been cached already otherwise.

Fixes #13974

isEmpty is pointless since it is always false if we are inside  a polymorphic method.
isNarrowing computes whether the constraint actually has tigher bounds for a type variable
than the original bounds.
Under a non-empty GADT constraint, bypass caches when computing eligible implicits.
The GADT constraint might influence what implicits are available locally, so cached
results would be unreliable.

Fixes scala#13974
@odersky
Copy link
Contributor Author

odersky commented Dec 8, 2021

test performance please

@dottybot
Copy link
Member

dottybot commented Dec 8, 2021

performance test scheduled: 1 job(s) in queue, 0 running.

@dottybot
Copy link
Member

dottybot commented Dec 8, 2021

Performance test finished successfully:

Visit https://dotty-bench.epfl.ch/14072/ to see the changes.

Benchmarks is based on merging with master (d6fe4b4)

Copy link
Contributor

@abgruszecki abgruszecki left a comment

Choose a reason for hiding this comment

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

LGTM, we should merge.

@@ -304,7 +312,7 @@ final class ProperGadtConstraint private(

override def fresh = new ProperGadtConstraint
override def restore(other: GadtConstraint): Unit =
if (!other.isEmpty) sys.error("cannot restore a non-empty GADTMap")
assert(!other.isNarrowing, "cannot restore a non-empty GADTMap")
Copy link
Contributor

Choose a reason for hiding this comment

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

Was this changed intentionally? I don't think we should allow restoring a non-empty GadtConstraint into an empty one. GadtConstraint is also a scope, and EmptyGadtConstraint doesn't allow constraining anything, so such a call to restore would lead to errors down the road.

With that being said, this is more of a nitpick than anything else, I think we should merge this PR and then I'll tweak GadtConstraint to define EmptyGadtConstraint a bit more gracefully.

@abgruszecki
Copy link
Contributor

@odersky so what's the policy right now on merging PRs into master? I think this PR fits into a patch release, so I guess this means we can just merge it, right?

@odersky odersky merged commit 9913ee6 into scala:master Dec 9, 2021
@odersky odersky deleted the fix-13974 branch December 9, 2021 14:21
@nicolasstucki nicolasstucki mentioned this pull request Dec 10, 2021
@Kordyjan Kordyjan added this to the 3.1.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.

dotty doesn't seem to take the full context into account when resolving implicits
4 participants