[code-reflection] RFR: Support storing the code that builds the code model [v11]
Maurizio Cimadamore
mcimadamore at openjdk.org
Thu Feb 27 11:42:15 UTC 2025
On Thu, 27 Feb 2025 11:36:16 GMT, Maurizio Cimadamore <mcimadamore at openjdk.org> wrote:
>> Mourad Abbay has updated the pull request incrementally with one additional commit since the last revision:
>>
>> Ensure that block params are inserted in the correct order
>
> src/jdk.incubator.code/share/classes/jdk/incubator/code/internal/CodeModelToAST.java line 128:
>
>> 126: var lastParam = invokeOp.invokeDescriptor().type().parameterTypes().getLast();
>> 127: Assert.check(lastParam instanceof ArrayType);
>> 128: methodInvocation.varargsElement = typeElementToType(((ArrayType) lastParam).componentType());
>
> Same problem as described above -- here we're copying the vararg array at the declaration site into a type at the use-site -- for something like `List::of` this won't give the result you expect.
Now -- while all the points I made above apply (e.g. if you were to try and type-check the generated AST using `Attr` you will get several errors), the saving grace here is that you are sending this tree into javac's backend anyway. And the backend plays a lot looser with types, only inserting casts where absolutely needed. Since you are using the op result type on the `MethodType` instance you are generating, I believe that should be enough for the backend to at least insert 90% of the type conversions that might be required because of erasure. So, in practice, even if incorrect, the code above might work fine.
-------------
PR Review Comment: https://git.openjdk.org/babylon/pull/305#discussion_r1973412610
More information about the babylon-dev
mailing list