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

   ## GROOVY-10657: release subscript assignment RHS after putAt
   
   https://issues.apache.org/jira/browse/GROOVY-10657
   
   `obj[index] = rhs` is compiled as a `putAt` call, but class generation first 
stored the right-hand value in a `$rhs` temporary. `CompileStack.removeVar` 
only dropped that slot from the compiler's temporary list; it did not clear the 
local, so the value stayed strongly reachable until the enclosing method 
returned. A direct `putAt` call does not keep that temporary.
   
   `putAt` consumes the receiver, the index, and the value in that order. Plain 
subscript assignment already evaluates the receiver and the index into slots 
before the right-hand side, so when the assignment value is discarded the RHS 
is evaluated as the last argument and no `VariableSlotLoader` is created for 
it. When the assignment expression's value is used, or the RHS must run before 
the receiver (safe subscript, and synthetic assignments whose RHS re-reads the 
subscript), the temporary remains and a reference slot is cleared after the 
write. The expression value is still the RHS, not the value returned by `putAt`.
   
   Receiver and index reference temporaries are cleared the same way. 
`src/test/groovy/bugs/Groovy10657.groovy` assigns a large array through 
subscript syntax and checks that a `WeakReference` is cleared while the 
assigning frame is still live.
   
   ### Testing
   - `bugs.Groovy10657`
   - static compilation coverage in `StaticCompilationTest`
   


-- 
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