Skip to content

Fix #444: be more conservative on when Block and If types should be recomputed #5958

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 1 commit into from
Feb 21, 2019

Conversation

liufengyun
Copy link
Contributor

Fix #444: be more conservative on when Block and If types should be recomputed

It seems that @DarkDimius forgot to make a PR after the fix.

Copy link
Member

@dottybot dottybot left a comment

Choose a reason for hiding this comment

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

Hello, and thank you for opening this PR! 🎉

All contributors have signed the CLA, thank you! ❤️

Commit Messages

We want to keep history, but for that to actually be useful we have
some rules on how to format our commit messages (relevant xkcd).

Please stick to these guidelines for commit messages:

  1. Separate subject from body with a blank line
  2. When fixing an issue, start your commit message with Fix #<ISSUE-NBR>:
  3. Limit the subject line to 72 characters
  4. Capitalize the subject line
  5. Do not end the subject line with a period
  6. Use the imperative mood in the subject line ("Add" instead of "Added")
  7. Wrap the body at 80 characters
  8. Use the body to explain what and why vs. how

adapted from https://chris.beams.io/posts/git-commit

Have an awesome day! ☀️

@odersky odersky merged commit ab1da64 into scala:master Feb 21, 2019
@liufengyun liufengyun deleted the fix-if-block branch February 21, 2019 15:01
Copy link
Member

@smarter smarter left a comment

Choose a reason for hiding this comment

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

Looking at the original issue, I see Dmitry later had a different fix in master...dotty-staging:signatures-issues, but the one you picked also seems correct and simpler, so I'm inclined to go with it. However you should remove the transformBlock and transformIf from ElimErasedValueType which were added to workaround the bug, you should also add the vcblock and vcif test cases that triggered the block, you can find them in smarter@4ddaf55

We also need to run the performance tests to make sure we're not regressing.

@@ -572,15 +572,25 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
override def Block(tree: Tree)(stats: List[Tree], expr: Tree)(implicit ctx: Context): Block = {
val tree1 = untpdCpy.Block(tree)(stats, expr)
tree match {
case tree: Block if expr.tpe eq tree.expr.tpe => tree1.withTypeUnchecked(tree.tpe)
case tree: Block if (expr.tpe eq tree.expr.tpe) && (expr.tpe eq tree.tpe) =>
// the second guard is needed in case avoid somehow widened the type.
Copy link
Member

Choose a reason for hiding this comment

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

More detailed comment:

          // The last guard is a conservative check: if `tree.tpe` is different from `expr.tpe`, then
          // it was computed from widening `expr.tpe`, and tree transforms might cause `expr.tpe.widen`
          // to change even if `expr.tpe` itself didn't change, e.g:
          //     { val s = ...;  s }
          // If the type of `s` changed, then the type of the block might have changed, even though `expr.tpe`
          // will still be `TermRef(NoPrefix, s)`

case tree: If if (thenp.tpe eq tree.thenp.tpe) && (elsep.tpe eq tree.elsep.tpe) => tree1.withTypeUnchecked(tree.tpe)
case tree: If if (thenp.tpe eq tree.thenp.tpe) && (elsep.tpe eq tree.elsep.tpe) &&
((tree.tpe eq thenp.tpe) || (tree.tpe eq elsep.tpe)) =>
// last guard is needed in case previous if had computed a widened ORType that needs to be recomputed
Copy link
Member

Choose a reason for hiding this comment

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

New comment:

          // The last guard is a conservative check similar to the one done in `Block` above,
          // if `tree.tpe` is not identical to the type of one of its branch, it might have been
          // computed from the widened type of the branches, so the same reasoning than
          // in `Block` applies.

@smarter
Copy link
Member

smarter commented Feb 21, 2019

... I wish this wasn't merged so fast, my comments still stand.

@liufengyun
Copy link
Contributor Author

@smarter Thanks a lot, I'll address the comment in another PR.

liufengyun added a commit to dotty-staging/dotty that referenced this pull request Feb 21, 2019
smarter added a commit that referenced this pull request Feb 22, 2019
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.

TypedTreeCopier makes incorrect assumption when deciding if Block or If nodes need to be retyped
5 participants