Repository navigation
GROOVY-12712: number for-await source variables per source unit - #3243
Conversation
daniellansun
left a comment
There was a problem hiding this comment.
Build-and-test is red with the two ParserNegativeSyntaxTest failures that were broken on master after GROOVY-12641 (GEP-19). Those fixtures have been fixed on current master (see #3247).
Please rebase onto the latest master and push so CI can re-run against that tip — that should clear this noise. If anything is still red after the rebase, we can dig into it then.
The parser desugars `for await (x in source)` into a block that declares the iterable in a variable named `$__forAwaitSource_<n>`. The number came from a static AtomicLong shared by every compilation in the JVM, so the same file compiled to different class bytes (the name is in the local variable table) depending on what was compiled before it, and two parses of one file in one JVM gave different ASTs. AstBuilder now counts the loops of its source unit and passes the ordinal to a new wrapForAwaitLoop(ForStatement, long); the one-argument overload keeps the global counter for callers outside the parser.
e20b8f8 to
3f8e070
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #3243 +/- ##
==================================================
- Coverage 74.3428% 74.3370% -0.0058%
+ Complexity 44310 44306 -4
==================================================
Files 1699 1699
Lines 150862 150863 +1
Branches 28756 28756
==================================================
- Hits 112155 112147 -8
- Misses 28435 28440 +5
- Partials 10272 10276 +4
🚀 New features to boost your workflow:
|
✅ All tests passed ✅🏷️ Commit: 3f8e070 Learn more about TestLens at testlens.app/docs. |
daniellansun
left a comment
There was a problem hiding this comment.
Thanks for rebasing onto current master (with #3247) and confirming the local async tests. Tip 3f8e07083d7e is green across LTS / Analyze, and the GROOVY-12712 change reads cleanly.
Numbering $__forAwaitSource_<n> from an AstBuilder-local counter (with the existing AtomicLong overload kept for API compatibility) is the right fix: the name that reaches the LVT no longer depends on JVM-wide compile order. The parser-driven ordinal plus testForAwaitSourceNamesDependOnTheSourceUnitOnly / testWrapForAwaitLoopWithIndexUsesThatIndex lock the contract well.
No further concerns from me on this tip.
The parser desugars
for await (x in source)into a block that declares the iterable in a variable named$__forAwaitSource_<n>(AsyncTransformHelper.wrapForAwaitLoop, called fromAstBuilder.visitForStmtAlt). The number came from astatic AtomicLongshared by every compilation in the JVM, so the same file compiled to different class bytes depending on what was compiled before it in the samegroovyc, build daemon or IDE session (the name reaches the local variable table), and two parses of one file in one JVM gave two different CONVERSION-phase ASTs. That breaks reproducible builds, confuses output-keyed build caches, and makes any tool that re-parses a file and compares ASTs (a formatter checking that it preserved the AST) report a difference for every file with afor awaitloop.AstBuildernow counts thefor awaitloops of its source unit and passes the ordinal to a newwrapForAwaitLoop(ForStatement, long)overload, so the name depends on the source alone. The one-argument overload keeps the global counter for callers outside the parser (it is public, andAsyncTransformHelperTestuses it).Tests:
AsyncTransformHelperTestgains a test for the indexed overload and one that parses a source with two loops twice through aCompilationUnitand asserts both parses declare$__forAwaitSource_1and$__forAwaitSource_2;AsyncAwaitTest(274 tests) andAsyncTransformHelperTestpass on JDK 21.Reproducer from the issue, on 6.0.0:
groovyc -d one Beta.groovygives$__forAwaitSource_1,groovyc -d two Alpha.groovy Beta.groovygives$__forAwaitSource_2for the sameBeta.groovy, andcmp one/Beta.class two/Beta.classdiffers. With this change both compilations declare$__forAwaitSource_1.Candidate for
GROOVY_6_0_Xas well.