[code-reflection] RFR: Support storing the code that builds the code model [v18]

Maurizio Cimadamore mcimadamore at openjdk.org
Wed Mar 19 09:25:25 UTC 2025


On Sat, 15 Mar 2025 02:42:01 GMT, Mourad Abbay <mabbay at openjdk.org> wrote:

> We can turn opMethod into one with no param and load these fields inside its body.

That is what I was asking about -- while I agree what we have seems more flexible, we don't seem to use this flexibility anywhere -- as the method that turns a `Quotable` into a `Quoted` works with hardwired op and type factories. But maybe this has been already discussed -- in which case it's fine.

>> `addVarsWhenNecessary` is used to add necessary VarOp in the code model before transformation to AST. For example if an op result is used more than once, we introduce a VarOp to hold the value, because that's what the equivalent Java code will have. This makes the transformation from code model to AST a bit easier.
>> We also use it to in case we want an Op (e.g. InvokeOp) to be appended right away to the method we are building. As you now the block of a method is a list of statements, some operations maps to an expression, so they won't be appended until needed. So by putting the result of an op in a VarOp, that VarOp will be mapped to a statement which causes the tree of the op to be added immediately.
>> For example an `InvokeOp` to `Block.Builder::op` is something we want to be transformed to a `JCTree` and added immediately to the method's block, so that we preserve the order of the operations as in the original code model.
>
> Normally, the OpBuilder should produces a model that contains the VarOp when they should be. But I decided to have a seperate transformation as a quick fix. Later I will change the OpBuilder.

Apologies -- I meant whether the `writeTo` should be removed :-)

-------------

PR Review Comment: https://git.openjdk.org/babylon/pull/305#discussion_r2002857554
PR Review Comment: https://git.openjdk.org/babylon/pull/305#discussion_r2002850721


More information about the babylon-dev mailing list