codeconsole opened a new pull request, #3243:
URL: https://github.com/apache/groovy/pull/3243

   The parser desugars `for await (x in source)` into a block that declares the 
iterable in a variable named `$__forAwaitSource_<n>` 
(`AsyncTransformHelper.wrapForAwaitLoop`, called from 
`AstBuilder.visitForStmtAlt`). The number came from a `static AtomicLong` 
shared by every compilation in the JVM, so the same file compiled to different 
class bytes depending on what was compiled before it in the same `groovyc`, 
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 a `for await` loop.
   
   `AstBuilder` now counts the `for await` loops of its source unit and passes 
the ordinal to a new `wrapForAwaitLoop(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, and 
`AsyncTransformHelperTest` uses it).
   
   Tests: `AsyncTransformHelperTest` gains a test for the indexed overload and 
one that parses a source with two loops twice through a `CompilationUnit` and 
asserts both parses declare `$__forAwaitSource_1` and `$__forAwaitSource_2`; 
`AsyncAwaitTest` (274 tests) and `AsyncTransformHelperTest` pass on JDK 21.
   
   Reproducer from the issue, on 6.0.0: `groovyc -d one Beta.groovy` gives 
`$__forAwaitSource_1`, `groovyc -d two Alpha.groovy Beta.groovy` gives 
`$__forAwaitSource_2` for the same `Beta.groovy`, and `cmp one/Beta.class 
two/Beta.class` differs. With this change both compilations declare 
`$__forAwaitSource_1`.
   
   Candidate for `GROOVY_6_0_X` as well.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to