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

Backport "Remove unnecessary and recursive Space decomposition" to LTS #20804

Merged
merged 4 commits into from
Jun 26, 2024

Conversation

WojciechMazur
Copy link
Contributor

Backports #19216 to the LTS branch.

PR submitted by the release tooling.
[skip ci]

dwijnand added 4 commits June 25, 2024 14:00
... makes it easier to disable one of them.

[Cherry-picked dbb97ca]
Space decomposition recently learnt to decompose prefixes.  Given a
nested definition like in i19031, aggressively trying to decompose while
intersecting can lead to recursive decompositions (building bigger and
bigger nested prefixes).  Turns out the decomposition isn't necessary.

[Cherry-picked 5439e98]
If refineUsingParent/instantiateToSubType is passed a HK then it's
not possible to instantiate a class to that type (at the moment and
perhaps ever).  So it's important we guard against that.

This came up while trying to see if Mark[?] and Foo[Int] (from
pos/i19031.ci-reg1.scala) are provably disjoint - which they should be
reported not to be.  Because they're not applied types of the same type
constructor we end up trying to prove that HK type Mark is disjoint from
HK type Foo.  Because we don't know how to instantiate Foo's subclasses
(e.g Bar2) such that it's a subtype of higher-kinded type "Mark", we end
up discarding all of Foo's subclasses, which implies that Foo & Mark is
uninhabited, thus they are provably disjoint - which is incorrect.

We originally didn't encounter this because we eagerly decomposed in
Space intersection, while now we've dispatched it to provablyDisjoint.

(edit) We allow for some kindness in provablyDisjoint.

[Cherry-picked 7e47294]
Minimising from the `case test.Generic =>` in ParallelTesting, the
anonymous pattern match is expanded, wrapping the match with
`applyOrElse`, which has a type parameter A1 as the scrutinee type, with
an upper bound of the original element type (out.Foo for us).  During
reachability analysis the pattern type, e.g. out.Bar3.type, is
intersected with the scrutinee type, A1 - giving out.Bar3.type & A1.
Then that we attempt to decompose that type.  Previously the abstract A1
in that type lead to 3 WildcardTypes, for the 3 subclasses, which are a
subtype of previous cases.

The fix that by generalising how we recognise the singleton types in the
scrutinee type, so instead of the ownership chain we use the parameter
type info, and we also match term parameters.  For extra correctness
we consider the failure to be a subtype of a mixin as a failure for
instantiating.

Also, make sure to handle and avoid recursion in traverseTp2.

[Cherry-picked 0931c43]
Base automatically changed from lts-19113 to lts-3.3 June 26, 2024 09:24
@WojciechMazur
Copy link
Contributor Author

No regressions detected in the community build up to lts-19356.

Reference

@WojciechMazur WojciechMazur merged commit 6764ad7 into lts-3.3 Jun 26, 2024
19 checks passed
@WojciechMazur WojciechMazur deleted the lts-19216 branch June 26, 2024 09:24
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.

2 participants