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
Never inspect twice the same macro application, fix (again) #1237 #1408
Conversation
The problem in 2.10.x is that macro expansions don't get duplicated like in 2.11.0, therefore the part of the expandee ends up being in an expansion creating the vicious cycle. In 2.11.0, the macro engine calls duplicate on all expansions, which creates new trees for every node of the expansion, preventing the cycles from occurring. |
I've restarted tests. |
Can one of the admins verify this patch? |
Restarted tests again. Hopefully, Travis will be more happy now. |
I set milestone to 0.13.6. I think this is important fix that should be included in the release. |
Hi @Duhemm! Could you rebase your PR on top of latest 0.13 branch? That should help with failing tests. |
This test shows that macros that simply return their argument produce a stack overflow during extraction of used names. Consider a macro `foo(c: Context)(a: c.Expr[Any]) = a`. An application of this macro such as `foo(someVal)` will lead to the expansion `someVal`. sbt will extract the `original` tree from it, and find `foo(someVal)`, and recurse infinitely on `someVal`.
In Scala 2.10.4, this macro can produce a stack overflow : def foo(a: Any): Any = macro impl def impl(c: Context)(a: c.Expr[Any]): c.Expr[Any] = a Here, an application such as `foo(someVal)` will produce the expansion `someVal`. As expected, `someVal` has `original` tree `foo(someVal)`, but if we inspect this tree, we will find that `someVal` has an original tree, but it shouldn't. Moreover, in Scala 2.11, some macros have their own application as `original` trees. See sbt#1237 for a description of these problems. This commit fixes these two problems. Fixes sbt#1237
Hi @gkossakowski ! It's done, I hope the tests will pass now ! |
|
Travis seems to be a bit too flaky. Restarting... |
Yay! Finally green! 💚 LGTM! |
Never inspect twice the same macro application, fix (again) #1237
In some cases, expanded macros report that their original tree and its expansion are the same, thus creating a cyclic chain. This chain may then produce a SOE during dependencies or used names extraction. This kind of problem was already reported in sbt#1237 and sbt#1408. Unfortunately, the fix that was applied to the dependencies extraction part was not sufficient. This commit ports the fix applied to the used names extraction part to the dependencies extraction part.
In some cases, expanded macros report that their original tree and its expansion are the same, thus creating a cyclic chain. This chain may then produce a SOE during dependencies or used names extraction. This kind of problem was already reported in sbt#1237 and sbt#1408. Unfortunately, the fix that was applied to the dependencies extraction part was not sufficient. This commit ports the fix applied to the used names extraction part to the dependencies extraction part.
In some cases, expanded macros report that their original tree and its expansion are the same, thus creating a cyclic chain. This chain may then produce a SOE during dependencies or used names extraction. This kind of problem was already reported in sbt#1237 and sbt#1408. Unfortunately, the fix that was applied to the dependencies extraction part was not sufficient. This commit ports the fix applied to the used names extraction part to the dependencies extraction part.
In some cases, expanded macros report that their original tree and its expansion are the same, thus creating a cyclic chain. This chain may then produce a SOE during dependencies or used names extraction. This kind of problem was already reported in sbt#1237 and sbt#1408. Unfortunately, the fix that was applied to the dependencies extraction part was not sufficient. This commit ports the fix applied to the used names extraction part to the dependencies extraction part. Mark test 'source-dependencies/macro' as passing Fixes sbt#1544
In some cases, expanded macros report that their original tree and its expansion are the same, thus creating a cyclic chain. This chain may then produce a SOE during dependencies or used names extraction. This kind of problem was already reported in sbt#1237 and sbt#1408. Unfortunately, the fix that was applied to the dependencies extraction part was not sufficient. Mark test 'source-dependencies/macro' as passing Fixes sbt#1544
In some cases, expanded macros report that their original tree and its expansion are the same, thus creating a cyclic chain. This chain may then produce a SOE during dependencies or used names extraction. This kind of problem was already reported in sbt/sbt#1237 and sbt/sbt#1408. Unfortunately, the fix that was applied to the dependencies extraction part was not sufficient. Mark test 'source-dependencies/macro' as passing Fixes #1544
In some cases, expanded macros report that their original tree and its expansion are the same, thus creating a cyclic chain. This chain may then produce a SOE during dependencies or used names extraction. This kind of problem was already reported in sbt/sbt#1237 and sbt/sbt#1408. Unfortunately, the fix that was applied to the dependencies extraction part was not sufficient. Mark test 'source-dependencies/macro' as passing Fixes scala#1544 Rewritten from sbt/zinc@92001e4
Consider the following macro :
In Scala 2.10.4 (I've not observed this with any other version of Scala), an application of this macro such as :
will expand to
someVal
. If we inspect this expansion, we will find thatsomeVal
is attached the original treefoo(someVal)
, as expected. However, if we inspect the components of this tree, we will find a cyclic chain ofMacroExpansionAttachment
: The same original tree is attached tosomeVal
, and so on, until the stack overflows.The solution used here consists to filter out the nodes that point to the current node in the
original
tree (I think that the diff may be clearer than my sentence).Thanks to @dwijnand for reporting the bug !
/cc @xeno-by
Fixes #1237 (again).