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

Fix #11178: remove unsound tweak for F-bounds in isInstanceOf check #11768

Merged
merged 6 commits into from
Mar 17, 2021

Conversation

liufengyun
Copy link
Contributor

Fix #11178: remove unsound tweak for F-bounds

This reverts #9789. We have made several improvements to F-bounds,
the unsound tweak is no longer needed.

@liufengyun liufengyun changed the title Fix #11178: remove unsound tweak for F-bounds Fix #11178: remove unsound tweak for F-bounds in isInstanceOf check Mar 16, 2021
This reverts scala#9789. We have made several improvements to F-bounds,
the unsound tweak is no longer needed.
@liufengyun liufengyun added this to the 3.0.0-RC2 milestone Mar 17, 2021
It is possible that a subtype of MdNode extends Seq.
It's unclear why the operation is needed.
P1 <:< X
withMode(Mode.GadtConstraintInference) {
TypeComparer.constrainPatternType(P1, X, widenParams = false)
debug.println(TypeComparer.explained(_.constrainPatternType(P1, X, widenParams = false)))
Copy link
Contributor

Choose a reason for hiding this comment

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

I think I understand the intent here, but it's a bit surprising that we don't widen the params, given that doing so is necessary for soundness. What would be a motivating example for not widening them here?

Copy link
Contributor Author

@liufengyun liufengyun Mar 17, 2021

Choose a reason for hiding this comment

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

The motivation for not widening is something specific to the algorithm: here for P1 = pre.F[Xs], all Xs are type variables. We want the Xs to be constrained.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I feel very happy the work on the GADT makes the checking so elegant that we remove a lot of ad-hoc tweaks. The fact that the algorithm is simpler and it found more bugs in the compiler gives more confidence.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

One example is the following:

  // tests/neg-custom-args/isInstanceOf/JavaSeqLiteral.scala
  trait Tree[-T]

  class JavaSeqLiteral[-T] extends Tree[T]

  trait Type

  class DummyTree extends JavaSeqLiteral[Any]

  def foo1(tree: Tree[Type]) =
    tree.isInstanceOf[JavaSeqLiteral[Type]]

In checking whether the test tree.isInstanceOf[JavaSeqLiteral[Type]] is realizable, we want to constrain JavaSeqLiteral[X] <: Tree[Type], such that we can infer X = Type and JavaSeqLiteral[X] <:< JavaSeqLiteral[Type].

If we perform widening, we will get X = Nothing, and we don't have JavaSeqLiteral[X] <:< JavaSeqLiteral[Type] any more.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok, I think what we're doing here is sound, but with small changes we could easily make it unsound. I'll need to add a comment explaining what's going on, and then we can merge the PR.

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, I'll add a comment explaining the code.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Comment added in aa296ba

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.

Ok, that looks good!

@liufengyun liufengyun merged commit a4fd829 into scala:master Mar 17, 2021
@liufengyun liufengyun deleted the fix-11178 branch March 17, 2021 21:02
@Kordyjan Kordyjan modified the milestones: 3.0.0-RC2, 3.0.0 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
Development

Successfully merging this pull request may close these issues.

No warning on typecase pattern involving a case class
3 participants