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

Optimize isSameType for invariant applied types with the same structure #15556

Merged
merged 2 commits into from
Jun 30, 2022

Conversation

odersky
Copy link
Contributor

@odersky odersky commented Jun 30, 2022

Comparing two deeply applied types with the same structure uses recursive isSameType tests if the types are
invariant. Each of these gets translated to two isSubType tests which can lead to exponential blowup relative to the type's
nesting depth. This problem does not occur if the two types are eq. But two types might still be structurally equal modulo dealiasing.

We now cache isSameType successes after a certain nesting level to avoid recomputation.

Fixes #15525.

Reclassifies #15365 as a pos test

…ucture

Two deeply applied types with the same structure uses recursive isSameType tests. Each of these
translated to two isSubType tests which can lead to exponential blowup relative to the type's
nesting depth. This problem does not occur if the two types are `eq`. But two types
might still be structurally equal modulo dealiasing.

We now cache isSameType successes after a certain nesting level to avoid recomputation.

Fixes scala#15525.

Reclassifies scala#15365 as a pos test
Interestingly, swapping the order in which argument subtypes were tested in
`isSubArg` caused

 - one exhaustivity failure (patmat/i9631.scala)
 - one failed compile in the community build (libretto).
 - one reclassification of a neg test to a pos test (i15365.scala)

We should find out at some point why, when we have the time.
@odersky
Copy link
Contributor Author

odersky commented Jun 30, 2022

test performance please

@dottybot
Copy link
Member

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

@dottybot
Copy link
Member

Performance test finished successfully:

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

Benchmarks is based on merging with main (771a336)

@odersky odersky merged commit f157978 into scala:main Jun 30, 2022
@odersky odersky deleted the fix-15525 branch June 30, 2022 18:31
@Kordyjan Kordyjan added this to the 3.2.1 milestone Aug 1, 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.

Very slow compile time involving path-dependent types
4 participants