Skip to content

Fix #12267: Constraints should not cross phases #12300

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

Closed
wants to merge 4 commits into from

Conversation

odersky
Copy link
Contributor

@odersky odersky commented Apr 30, 2021

Use these changes to compile the stdlib. You need to comment out AnyVal.scala and then
use the following command on community-projects/stdLib213:

scalac -Ydetailed-stats *.scala */*.scala */*/*.scala */*/*/*.scala

What I see is:

Calls to translucentSuperType 53152:

try norm KO -> 53086
try norm OK -> 66

The only computationally relevant part of this are calls to tryMatchAlias

try match alias -> 528

Those calls suceed in 66 cases

try norm OK -> 66

The successful normalizations all return types like this:

try norm OK F[T1] *: scala.Tuple.Map[(T2, T3, T4, T5, T6, T7, T8), F] -> 3

Now it could be that trying the normalizations is costly, or that the normalized types
cause exhaustivity checking to explode. Tht remains to be found out.

Use these changes to compile the stdlib. You need to comment out AnyVal.scala and then
use the following command on community-projects/stdLib213:

    sc -Ydetailed-stats *.scala */*.scala */*/*.scala */*/*/*.scala

What I see is:

Calls to `translucentSuperType` 53152:

    try norm KO -> 53086
    try norm OK -> 66

The only computationally relevant part of this are calls to tryMatchAlias

    try match alias -> 528

Those calls suceed in 66 cases

    try norm OK -> 66

The successful normalizations all return types like this:

    try norm OK F[T1] *: scala.Tuple.Map[(T2, T3, T4, T5, T6, T7, T8), F] -> 3

Now it could be that trying the normalizations is costly, or that the normalized types
cause exhaustivity checking to explode. Tht remains to be found out.
@odersky odersky marked this pull request as draft April 30, 2021 14:27
@scala scala deleted a comment from dottybot May 3, 2021
@scala scala deleted a comment from dottybot May 3, 2021
@scala scala deleted a comment from dottybot May 3, 2021
@scala scala deleted a comment from dottybot May 3, 2021
@scala scala deleted a comment from dottybot May 3, 2021
@scala scala deleted a comment from dottybot May 3, 2021
@scala scala deleted a comment from dottybot May 3, 2021
To enforce the invariant, we need to ensure that tvars are
instantiated at end of phases.
@scala scala deleted a comment from dottybot May 3, 2021
@scala scala deleted a comment from dottybot May 3, 2021
@scala scala deleted a comment from dottybot May 3, 2021
@liufengyun
Copy link
Contributor

retest performance with #stdlib please

@dottybot
Copy link
Member

dottybot commented May 3, 2021

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

@liufengyun liufengyun marked this pull request as ready for review May 3, 2021 20:32
@liufengyun liufengyun changed the title Peformance test for WIP Fix #12267: Constraints should not cross phases May 3, 2021
@dottybot
Copy link
Member

dottybot commented May 3, 2021

Performance test finished successfully:

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

Benchmarks is based on merging with master (98ecc10)

@odersky
Copy link
Contributor Author

odersky commented May 4, 2021

We might need something like that in the end, but it also hides errors. Before doing this, I wonder whether we could find sources of overflowing constraints and treat them in a more fine-grained manner that does not wait until the end of a phase to remove constraint entries.

@liufengyun
Copy link
Contributor

We might need something like that in the end, but it also hides errors. Before doing this, I wonder whether we could find sources of overflowing constraints and treat them in a more fine-grained manner that does not wait until the end of a phase to remove constraint entries.

Maybe change ctx.constraint.gc() to an assertion instead?

With the following code,

https://github.com/lampepfl/dotty/blob/144069973feb219caf66cb7741f50a75e88cc5e6/compiler/src/dotty/tools/dotc/core/ConstraintHandling.scala#L88-L99

We get constraints like the following in compiling tests/pos/t2619b.scala:

adding constraint B :> AbstractModule to
Constraint(
 uninstantiated variables: B
 constrained types: [B >: ModuleBF.type](prefix: List[B]): List[B]
 bounds:
     B >: ModuleBF.type | ModuleBE.type <: AbstractModule
 ordering:
)
added constraint B :> AbstractModule to
Constraint(
 uninstantiated variables:
 constrained types: [B >: ModuleBF.type](prefix: List[B]): List[B]
 bounds:
     B := AbstractModule
 ordering:
) = true

This will leave the tvar that binds to B uninitialized, thus depends on the constraint for pickling to work correctly.

@odersky
Copy link
Contributor Author

odersky commented May 5, 2021

I think we should do a gc() in the toplevel constraint and should assert that after that the constraint is empty. Right now that's not the case, it seems for several different reasons. I tracked one down to a shortcoming in mergeConstraints but that's not all it seems.

@odersky
Copy link
Contributor Author

odersky commented May 6, 2021

This is now superseded by #12333

@odersky odersky closed this May 6, 2021
@liufengyun liufengyun deleted the explore-perf branch May 31, 2021 14:29
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.

3 participants