Skip to content

[DO NOT MERGE] Illustrate issue with TreeTypeMap and miniphases #1770

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 2 commits into from

Conversation

smarter
Copy link
Member

@smarter smarter commented Dec 2, 2016

Ping @DarkDimius @odersky, I'm not sure how to proceed from here.

The first commit illustrates the issue:

When running TreeTypeMap in a miniphase, the tree we're transforming has
already been transformed by all the miniphases in the same group, but
the symbols we're looking at might be older than the trees, this means
that we can miss transforming some symbols as illustrated in details by
the added testcase which currently fails.

The second commit contains a hack to show that my diagnostic of the issue above is correct, but I don't know how to fix this properly:

With this commit, tests/pos/treetypemap-miniphase.scala now compiles,
but this is only a hack: there are other instances of TreeTypeMap in the
compiler and they would all need to be run with "atGroupEnd", this is
tricky since we are not always calling TreeTypeMap in a context where we
have access to the current TreeTransformer (for example when we create a
TreeTypeMap inside TypeMap to deal with annotations), ideas and
alternative fixes welcome.

When running TreeTypeMap in a miniphase, the tree we're transforming has
already been transformed by all the miniphases in the same group, but
the symbols we're looking at might be older than the trees, this means
that we can miss transforming some symbols as illustrated in details by
the added testcase which currently fails.
With this commit, tests/pos/treetypemap-miniphase.scala now compiles,
but this is only a hack: there are other instances of TreeTypeMap in the
compiler and they would all need to be run with "atGroupEnd", this is
tricky since we are not always calling TreeTypeMap in a context where we
have access to the current TreeTransformer (for example when we create a
TreeTypeMap inside TypeMap to deal with annotations), ideas and
alternative fixes welcome.
@DarkDimius
Copy link
Contributor

In short: we have already encountered this issue and we have introduced changeOwnerAfter that is supposed to be robust against this(which in turn introduced Denotation.transformAfter). See 979ee0f

If I remember correctly @odersky proposed to keep changeOwner though it is unsafe because it is faster.

@DarkDimius
Copy link
Contributor

DarkDimius commented Dec 3, 2016

Similarly: entered is generaly unsafe while enteredAfter is more robust.

@@ -80,7 +80,9 @@ class ElimByName extends MiniPhaseTransform with InfoTransformer { thisTransform
val inSuper = if (ctx.mode.is(Mode.InSuperCall)) InSuperCall else EmptyFlags
val meth = ctx.newSymbol(
ctx.owner, nme.ANON_FUN, Synthetic | Method | inSuper, MethodType(Nil, Nil, argType))
Closure(meth, _ => arg.changeOwner(ctx.owner, meth))
atGroupEnd { implicit ctx: Context =>
Closure(meth, _ => arg.changeOwner(ctx.owner, meth))
Copy link
Contributor

Choose a reason for hiding this comment

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

try changeOwnerAfter. It's supposed to fix the issue. No need for atGroupEnd.

@DarkDimius
Copy link
Contributor

The correct solution to this issue is to only change denotations\owners in InfoTransormer. Than neither of those functionalities would have been needed.

@odersky
Copy link
Contributor

odersky commented Dec 3, 2016

If I remember correctly @odersky proposed to keep changeOwner though it is unsafe because it is faster.

No, it's the opposite. changeOwnerAfter is faster. I kept changeOwner in elimByName to make sure it was debugged, because we need it in other cases where we duplicate a tree. elimByName exercises the functionality much more than anything else. But now that we have done that, I think it's time to switch to changeOwnerAfter in elimByName.

But there are other tree type maps, for instance in tailrec and extensionMethods. So we need to be careful with those.

@smarter
Copy link
Member Author

smarter commented Dec 3, 2016

The correct solution to this issue is to only change denotations\owners in InfoTransormer. Than neither of those functionalities would have been needed.

That's what I thought too, but that seems like a major refactoring since many phases change denotations while transforming trees.

@smarter
Copy link
Member Author

smarter commented Dec 3, 2016

But there are other tree type maps, for instance in tailrec and extensionMethods. So we need to be careful with those.

In particular, every TypeMap might instantiate a TreeTypeMap to map over an annotation and that can end up creating new symbols: https://github.com/lampepfl/dotty/blob/47d208448e614125446c7f294f8231c3fb7108d6/compiler/src/dotty/tools/dotc/core/Types.scala#L3493

smarter added a commit to dotty-staging/dotty that referenced this pull request Jan 11, 2017
Using changeOwnerAfter would be more appropriate but currently fails
with an assertion in LambdaLift
smarter added a commit to dotty-staging/dotty that referenced this pull request Jan 11, 2017
Using changeOwnerAfter would be more appropriate but currently fails
with an assertion in LambdaLift
smarter added a commit to dotty-staging/dotty that referenced this pull request Jan 11, 2017
Using changeOwnerAfter would be more appropriate but currently fails
with an assertion in LambdaLift
smarter added a commit to dotty-staging/dotty that referenced this pull request Jan 11, 2017
Using changeOwnerAfter would be more appropriate but currently fails
with an assertion in LambdaLift
@smarter smarter mentioned this pull request Jan 11, 2017
smarter added a commit to dotty-staging/dotty that referenced this pull request Jan 27, 2017
Using changeOwnerAfter would be more appropriate but currently fails
with an assertion in LambdaLift
smarter added a commit to dotty-staging/dotty that referenced this pull request Jan 27, 2017
Using changeOwnerAfter would be more appropriate but currently fails
with an assertion in LambdaLift
smarter added a commit to dotty-staging/dotty that referenced this pull request Jan 28, 2017
Using changeOwnerAfter would be more appropriate but currently fails
with an assertion in LambdaLift
@felixmulder
Copy link
Contributor

Closed in favor of opening an issue

@felixmulder felixmulder closed this Apr 4, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants