[code-reflection] RFR: 8337158: Modeling and lowering of switch statement [v13]
Paul Sandoz
psandoz at openjdk.org
Fri Aug 16 16:13:00 UTC 2024
On Fri, 16 Aug 2024 14:17:07 GMT, Maurizio Cimadamore <mcimadamore at openjdk.org> wrote:
>> src/jdk.compiler/share/classes/com/sun/tools/javac/comp/ReflectMethods.java line 1676:
>>
>>> 1674:
>>> 1675: @Override
>>> 1676: public void visitSwitch(JCTree.JCSwitch tree) {
>>
>> This method seems 90% the same as the one for switch expression, we should try to consolidate. I've left a comment on how to maybe simplify the logic to add a throwing default - let's see where we are after that's addressed.
>
> In particular, this big chunk of code:
>
>
> for (JCTree.JCCase c : tree.cases) {
> ...
> switch (c.caseKind) {
>
>
> Seems to be virtually identical for both switch expression and statement, except for _one_ line:
>
>
> bodies.add(stack.body);
>
>
> Which is added more lazily in the cases of switch expressions. I'm not super sure as to what is the reason for that discrepancy. If we could somehow eliminate that, at least all this big portion of code could be shared. (and, even if the difference cannot be eliminated, perhaps a shared routine which returns the default body would enable clients to use that as they see fit).
Mourad and I chatted off-line about this. My suggestion was to swiftly follow up with another PR that consolidates, since this PR contains a comprehensive set of tests to detect any bugs in such refactoring.
-------------
PR Review Comment: https://git.openjdk.org/babylon/pull/211#discussion_r1720043127
More information about the babylon-dev
mailing list