[code-reflection] RFR: Simplify code generation for quotable lambdas not to require duplicate capture argument lists
Maurizio Cimadamore
mcimadamore at openjdk.org
Fri Oct 4 21:17:58 UTC 2024
On Fri, 4 Oct 2024 21:06:04 GMT, Maurizio Cimadamore <mcimadamore at openjdk.org> wrote:
>> src/jdk.compiler/share/classes/com/sun/tools/javac/comp/ReflectMethods.java line 556:
>>
>>> 554: // add "this" capture (if needed)
>>> 555: if (lambdaCaptureScanner.capturesThis) {
>>> 556: top.localToOp.put(currentClassSym, null); // @@@ just make translation happy
>>
>> I think we can avoid this. For a quotable lambda we know the number of block parameters (captures) before we obtain the captured expressions from `top.localToOp`.
>>
>> If `funcOp.parameters().size() == bodyScanner.stack.localToOp.size() + 1` then we know we need to first capture `this` expression. This is easier to do if we inline the call to `quotedCapturedArgs`.
>
> Note that this logic is only really needed for the Quoted case, not the Quotable one. If we inline this directly into the Quoted path (as you suggested) perhaps this will be simplified away.
That said - not sure. Isn't `funcOp` the function for the lambda? That should not feature any captured argument - just the parameter of the lambda as they appear in the source. I'm not sure we can deduce the need for `this` capture just by looking at that?
-------------
PR Review Comment: https://git.openjdk.org/babylon/pull/249#discussion_r1788346522
More information about the babylon-dev
mailing list