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

Don't follow BaseType of abstract binders in MT reduction #13780

Merged
merged 2 commits into from
Apr 4, 2022

Conversation

OlivierBlanvillain
Copy link
Contributor

Fix #11982 and the associated soundness problem. The issue with the behavior on master arises from the fact that type binder of match types might change as context gets more precise, which results in a single match type reducing in two different ways. This issue comes from the fact that subtyping looks into base types, and is thus able to match a type such as T <: Tuple2[Int, Int] against a pattern case Tuple2[a, b], even if the best solutions for a and b in the current context are not guaranteed to be the best solution in more precise contexts (such as at call site in the added test case).

@smarter smarter added this to the 3.2.0 milestone Dec 2, 2021
Fix scala#11982 and the associated soundness problem. The issue with the
behavior on master arises from the fact that type binder of match types
might change as context gets more precise, which results in a single
match type reducing in two different ways. This issue comes from the
fact that subtyping looks into base types, and is thus able to match a
type such as `T <: Tuple2[Int, Int]` against a pattern `case Tuple2[a,
b]`, even if the best solutions for `a` and `b` in the current context
are not guaranteed to be the best solution in more precise contexts
(such as at call site in the added test case).
@odersky odersky merged commit ad2553d into scala:main Apr 4, 2022
@odersky odersky deleted the fix-11982-2 branch April 4, 2022 13:37
smarter added a commit to dotty-staging/dotty that referenced this pull request Apr 20, 2022
Previously, when reducing `a.T` we checked if the type of `a` was a subtype of
`RefinedType(.., T, TypeAlias(...))`, now we extend this check to handle
refinements where the `info` is a `TypeBounds` where both bounds are equal.

This solves two big issues at once:
- We can restore tests/pos/13491.scala to its original form from before scala#13780.
  The check for abstract types introduced by scala#13780 for soundness reasons is no
  longer hit because the type selection is reduced before we get to that point.
  This is important because parboiled2 relies on this and is therefore currently
  broken on 3.1.3-RC1 and main (sirthias/parboiled2#365).
- This fixes scala#14904 (slow compilation issue affecting parboiled2) without
  caching skolems (as in the alternative fix scala#14909). Again, this is due to the
  type containing skolem being reducible to a simpler type and therefore cacheable.
smarter added a commit to dotty-staging/dotty that referenced this pull request Apr 20, 2022
Previously, when reducing `a.T` we checked if the type of `a` was a subtype of
`RefinedType(.., T, TypeAlias(...))`, now we extend this check to handle
refinements where the `info` is a `TypeBounds` where both bounds are equal.

This solves two big issues at once:
- We can restore tests/pos/13491.scala to its original form from before scala#13780.
  The check for abstract types introduced by scala#13780 for soundness reasons is no
  longer hit because the type selection is reduced before we get to that point.
  This is important because parboiled2 relies on this and is therefore currently
  broken on 3.1.3-RC1 and main (sirthias/parboiled2#365).
- This fixes scala#14903 (slow compilation issue affecting parboiled2) without
  caching skolems (as in the alternative fix scala#14909). Again, this is due to the
  type containing skolem being reducible to a simpler type and therefore cacheable.
michelou pushed a commit to michelou/dotty that referenced this pull request Apr 25, 2022
Previously, when reducing `a.T` we checked if the type of `a` was a subtype of
`RefinedType(.., T, TypeAlias(...))`, now we extend this check to handle
refinements where the `info` is a `TypeBounds` where both bounds are equal.

This solves two big issues at once:
- We can restore tests/pos/13491.scala to its original form from before scala#13780.
  The check for abstract types introduced by scala#13780 for soundness reasons is no
  longer hit because the type selection is reduced before we get to that point.
  This is important because parboiled2 relies on this and is therefore currently
  broken on 3.1.3-RC1 and main (sirthias/parboiled2#365).
- This fixes scala#14903 (slow compilation issue affecting parboiled2) without
  caching skolems (as in the alternative fix scala#14909). Again, this is due to the
  type containing skolem being reducible to a simpler type and therefore cacheable.
odersky added a commit to dotty-staging/dotty that referenced this pull request May 31, 2022
scala#13780 caused several regressions and I think it is too restrictive as a fix.
I am reverting it an re-opening the original scala#11982 issue.

It would be good to get to the bottom of what the soundness problem hinted at
in scala#11982 is, and what a fix should be. As it stands scala#11982 is not obviously
a soundness problem but a separate compilation problem.
odersky added a commit to dotty-staging/dotty that referenced this pull request May 31, 2022
scala#13780 caused several regressions and I think it is too restrictive as a fix.
I am reverting it an re-opening the original scala#11982 issue.

It would be good to get to the bottom of what the soundness problem hinted at
in scala#11982 is, and what a fix should be. As it stands scala#11982 is not obviously
a soundness problem but a separate compilation problem.
odersky added a commit to dotty-staging/dotty that referenced this pull request May 31, 2022
scala#13780 caused several regressions and I think it is too restrictive as a fix.
I am reverting it an re-opening the original scala#11982 issue.

It would be good to get to the bottom of what the soundness problem hinted at
in scala#11982 is, and what a fix should be. As it stands scala#11982 is not obviously
a soundness problem but a separate compilation problem.
odersky added a commit that referenced this pull request May 31, 2022
odersky added a commit to dotty-staging/dotty that referenced this pull request Jun 12, 2022
Take up scala#13780 again, but refine it so that abstract types are allowed in match type
reduction as long as they uniquely instantiate type parameters of the type pattern.

Fixes scala#11982
Kordyjan pushed a commit to dotty-staging/dotty that referenced this pull request Jun 22, 2022
Take up scala#13780 again, but refine it so that abstract types are allowed in match type
reduction as long as they uniquely instantiate type parameters of the type pattern.

Fixes scala#11982
bishabosha pushed a commit to dotty-staging/dotty that referenced this pull request Oct 18, 2022
scala#13780 caused several regressions and I think it is too restrictive as a fix.
I am reverting it an re-opening the original scala#11982 issue.

It would be good to get to the bottom of what the soundness problem hinted at
in scala#11982 is, and what a fix should be. As it stands scala#11982 is not obviously
a soundness problem but a separate compilation problem.
bishabosha pushed a commit to dotty-staging/dotty that referenced this pull request Oct 18, 2022
Take up scala#13780 again, but refine it so that abstract types are allowed in match type
reduction as long as they uniquely instantiate type parameters of the type pattern.

Fixes scala#11982
@Kordyjan Kordyjan modified the milestones: 3.2.0-RC1, 3.1.3 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.

Singleton inference failure when used in same file
4 participants