[code-reflection] RFR: Replace the use of Interpreter to create Quoted instance with specialized code [v4]
Paul Sandoz
psandoz at openjdk.org
Wed May 28 15:42:06 UTC 2025
On Wed, 28 May 2025 11:59:16 GMT, Maurizio Cimadamore <mcimadamore at openjdk.org> wrote:
>> To be clear: I think using `CoreOp::quoteOp` inside javac is a no-go. Javac has a lot of special code to allow to generate the model for a lambda "in isolation" -- this involves computing all the captures upfront, and then setting up a block with enough `Var` to satisfy the generation of the lambda body. References to captured symbols inside the lambda body are replaced with reference to such generated `Var`s -- this is roughly what `CoreOp::quoteOp` does -- but that method assumes we have an `Op` to begin with -- whereas javac is trying to generate that op as well, so I think what javac does looks ok.
>>
>> What seems more doable (and desirable IMHO) is to replace `QuotedHelper` with the other function -- `CoreOp::quotedOp` -- but to do this, `CoreOp::quotedOp` needs to relax some of its checks to tolerate (local) `Var` initialized with an (immediately preceding) constant op.
>
> (I have no objection to this PR going ahead as is -- what I find mildly strange is that we tied this PR with the addition of these two new API functions in `CoreOp`, even though we ultimately don't have a definite answer on how to reuse said functions from the original code in this PR).
> @PaulSandoz did you intend for the new methods to be the official way to deal with quoted models both in javac and elsewhere -- or was that just an API suggestion unrelated from the goal of this PR? (I'm a bit confused)
The main goal is to replace the use of the interpreter, but we really need to specify what is going on. To achieve that we can define two interrelated methods. The first, `Op -> FuncOp`, that extracts an operation out if its context and quotes it, and the second, FuncOp -> (Op, SequencesSet<Values>), that validates and returns the operation that is quoted and the values it captures [*] from which it is possible to create a `Quoted` instance that maps symbolic values to runtime values.
It was not entirely clear to me how generally reusable the first might by javac but the specification can still be referred to. The bytecode generator can probably reuse it.
[*] normally the function parameters wrapped in vars, but as you noted there might be embedded constants.
-------------
PR Review Comment: https://git.openjdk.org/babylon/pull/424#discussion_r2112216751
More information about the babylon-dev
mailing list