[code-reflection] RFR: Super expressions [v2]

Paul Sandoz psandoz at openjdk.org
Fri Sep 6 17:51:27 UTC 2024


On Fri, 6 Sep 2024 08:06:38 GMT, Maurizio Cimadamore <mcimadamore at openjdk.org> wrote:

>> I wonder if a modelling where `super` is its own expression would be beneficial. E.g. like some kind of "virtual field" on `this`. E.g. one would load `this` and then access `super` onto it (and maybe there's a core op for _that_). Then the result is used for either a method receiver, or field access expression.
>
> Although I suppose in my example, we still generate a `getfield` for `super.o`, just with a different symbolic description - so the generated model ends up being fine. I suppose I'm not 100% comfortable with the fact that the model here seems to capture a bytecode distinction (e.g. super calls use a special invocation mode, but super field access do not, so we only model the former), rather than a syntactic difference in the original source (e.g. for both method and field access, the `super` keyword is there).

Right, well spotted. AFAICT the expression `super.o` is the same as `((A) this).o`, there is nothing "special" about it i suppose. The same operations/bytecode are generated for either expression. So it does not seem necessary to make the syntactic distinction as this level of modeling.

If someone wanted to lift back up to syntactically equivalent source it might be tricky bit not impossible, although we loose the distinction between the two expressions. Fernflower lifts the bytecode of both expressions to `super.o` :-)

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

PR Review Comment: https://git.openjdk.org/babylon/pull/221#discussion_r1747505721


More information about the babylon-dev mailing list