Skip to content

Fix #6635: Improve subtype tests for aliases and singleton types #8443

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

Merged
merged 3 commits into from
Mar 17, 2020

Conversation

odersky
Copy link
Contributor

@odersky odersky commented Mar 5, 2020

  1. backtrack in more cases when we fail after dealiasing
  2. fall back to atoms comparisons when comparing two singleton types

odersky added 2 commits March 5, 2020 14:58
 1. backtrack in more cases when we we fail after dealiasing
 2. fall back to atoms comparisons when comparing two singleton types

The widened criterion for (1) is still provisional. We need to come up
with a criterion that is sound and has a low risk of leading to
combinatorial explosion when comparing two long alias chains.
A better criterion for avoiding backtracking after comparing a dealiased type.
@odersky
Copy link
Contributor Author

odersky commented Mar 5, 2020

test performance please

@dottybot
Copy link
Member

dottybot commented Mar 5, 2020

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

@odersky odersky mentioned this pull request Mar 5, 2020
@dottybot
Copy link
Member

dottybot commented Mar 5, 2020

Performance test finished successfully:

Visit http://dotty-bench.epfl.ch/8443/ to see the changes.

Benchmarks is based on merging with master (91e5f35)

Cache canDopAlias calls in TypeRefs.

Performance tests pointed to a ~1% showdown before, which is really in the noise.
However, stats showed that the number of iterations in the exists call of
`canDropAlias` is significant (a bit more than total member operations).
With this optimization, the number of calls gets reduced to 1% of what it was.
@odersky
Copy link
Contributor Author

odersky commented Mar 5, 2020

test performance please

@dottybot
Copy link
Member

dottybot commented Mar 5, 2020

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

@Blaisorblade
Copy link
Contributor

Cool that Dotty can fix this! Needing backtracking is unfortunate but easy, and the alternative I had imagined (union-find) requires much more work, so that's cool...

@dottybot
Copy link
Member

dottybot commented Mar 5, 2020

Performance test finished successfully:

Visit http://dotty-bench.epfl.ch/8443/ to see the changes.

Benchmarks is based on merging with master (c5a3b5c)

@nicolasstucki nicolasstucki linked an issue Mar 6, 2020 that may be closed by this pull request
@odersky
Copy link
Contributor Author

odersky commented Mar 6, 2020

@Blaisorblade Yes, I fear that union-find would be difficult to make fast in these situations.

@anatoliykmetyuk anatoliykmetyuk added this to the 0.23.0-RC1 milestone Mar 9, 2020
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! Good to have this fixed.

}
isNewSubType(tp1.underlying.widenExpr) || comparePaths
case _ => false
comparePaths || isNewSubType(tp1.underlying.widenExpr)
Copy link
Contributor

Choose a reason for hiding this comment

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

Discussed this change in-person w/ Martin: changing the order of arguments here is solely a performance optimization, not an actual change to logic.

Copy link
Contributor

Choose a reason for hiding this comment

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

a || b == b || a, so yes.

Copy link
Contributor

Choose a reason for hiding this comment

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

@hepin1989 thank you for your astute observation! I was thinking about things such as the old RHS assuming the old LHS already handled some type shape, or that we do some evil tricks when loading code from Tasty and the check on new LHS is necessary so that the new RHS doesn't blow up, but I suppose it never hurts to be reminded of elementary laws of Boolean algebra.

Copy link
Contributor

Choose a reason for hiding this comment

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

Or otherwise, a || b and b || a differ when a and b are not pure :-)

@anatoliykmetyuk
Copy link
Contributor

anatoliykmetyuk commented Mar 13, 2020

@AleksanderBG what's the status on this? This one is the only blocker for the release.

@abgruszecki
Copy link
Contributor

@anatoliykmetyuk I thought that Martin also requested Olivier's review. If not, you can just merge this.

&& tp1.signature == tp2.signature
&& !(sym1.isClass && sym2.isClass) // class types don't subtype each other
) ||
thirdTryNamed(tp2)
Copy link
Contributor

Choose a reason for hiding this comment

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

introduce an explicit boolean return?

@anatoliykmetyuk
Copy link
Contributor

@anatoliykmetyuk I thought that Martin also requested Olivier's review. If not, you can just merge this.

/cc @OlivierBlanvillain

implicit val ctx: Context = this.ctx
tp2.info match {
val info2 = tp2.info
Copy link
Contributor

Choose a reason for hiding this comment

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

This binding doesn't seem necessary

@anatoliykmetyuk anatoliykmetyuk merged commit 174d5d0 into scala:master Mar 17, 2020
@anatoliykmetyuk anatoliykmetyuk deleted the fix-#6635 branch March 17, 2020 14:18
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.

b: a.type but a.A != b.A
7 participants