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

Deskolemize PatternTypeConstrainer #12506

Merged
merged 4 commits into from
Jun 7, 2021

Conversation

abgruszecki
Copy link
Contributor

@abgruszecki abgruszecki commented May 17, 2021

Before this PR, constrainSimplePatternType did a bunch of manipulations on its arguments and then ran a subtype check. It wrapped one of the types in a SkolemType and replaced type arguments (if any) of the other one with wildcards. The point of those manipulations was to make TypeComparer take a specific path and compare appropriate subcomponents of constrainSimplePatternType's arguments. This turned out to be a problem overall. To improve the situation, we instead manually compare the appropriate subcomponents of constrainSimplePatternType's arguments - the changes can be seen as inlining pieces of code from TypeComparer.

Also, this PR adds restoring the GADT constraint to TypeComparer - this turned out to be more important now that constrainSimplePatternType now does multiple isSubType checks.

Fixes #11103, #12476.

@abgruszecki abgruszecki marked this pull request as ready for review May 19, 2021 11:46
@abgruszecki abgruszecki requested a review from odersky May 19, 2021 11:46
@abgruszecki abgruszecki linked an issue May 19, 2021 that may be closed by this pull request
@abgruszecki
Copy link
Contributor Author

abgruszecki commented May 27, 2021

test performance with #exhaustivity please

@abgruszecki
Copy link
Contributor Author

@liufengyun am I doing something wrong? Why won't the performance check run?

Before this commit, constrainSimplePatternType did a bunch of manipulations and
then ran a subtype check. It wrapped one of the types in a SkolemType and
replaces type arguments of the other one with wildcards. The point of those
manipulations was to make TypeComparer take a specific path and compare
appropriate subcomponents of constrainSimplePatternType's arguments. This turned
out to be a problem overall. To improve the situation, we instead manually
compare the appropriate subcomponents of constrainSimplePatternType - the
changes can be seen as inlining pieces of code from TypeComparer.

Also, this commit adds restoring the GADT constraint to TypeComparer - this
turned out to be more important now that constrainSimplePatternType now does
multiple isSubType checks.
@abgruszecki
Copy link
Contributor Author

I added additional explanations to the first commit. The tests passed before and should also pass now.

@liufengyun
Copy link
Contributor

liufengyun commented May 27, 2021

@abgruszecki You are not on the whitelist. I'm now adding you.

Edited: it should work now.

@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/12506/ to see the changes.

Benchmarks is based on merging with master (1f8e9b2)

@abgruszecki
Copy link
Contributor Author

test performance please

@dottybot
Copy link
Member

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

@dottybot
Copy link
Member

Performance test finished successfully:

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

Benchmarks is based on merging with master (e48a268)

@odersky odersky removed their assignment Jun 2, 2021
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.

I did not understand all the changes in PatternTypeConstrainer, but it looks reasonable.

def apply(tp: Type) = tp.dealias match
case tp: TypeRef if !tp.symbol.isClass =>
expandBounds(tp.info.bounds)
if alreadyExpanding contains tp then tp else
Copy link
Contributor

Choose a reason for hiding this comment

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

How is this connected to the rest of the changes? Did the rest trigger a SO here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, this is the source of the SO that happened after restoring GADT constraints on failed subtype checks.

@abgruszecki
Copy link
Contributor Author

There was a worrisome jump in performance benchmarks, I still want to take a look at that.

@abgruszecki
Copy link
Contributor Author

test performance please

@dottybot
Copy link
Member

dottybot commented Jun 2, 2021

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

@dottybot
Copy link
Member

dottybot commented Jun 2, 2021

Performance test finished successfully:

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

Benchmarks is based on merging with master (54929c2)

@abgruszecki
Copy link
Contributor Author

@smarter I modified the comments, can you mark it as accepted?

It seems that the second benchmark didn't show a performance decrease compared to current master, so I think we're good to go.

@abgruszecki abgruszecki merged commit dd3f2fb into scala:master Jun 7, 2021
@abgruszecki abgruszecki deleted the deskolemize-gadts branch June 7, 2021 10:33
@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
6 participants