RFR: 8314226: Series of colon-style fallthrough switch cases with guards compiled incorrectly
Maurizio Cimadamore
mcimadamore at openjdk.org
Fri Sep 1 10:58:39 UTC 2023
On Fri, 1 Sep 2023 10:51:15 GMT, Maurizio Cimadamore <mcimadamore at openjdk.org> wrote:
> So, as we discussed offline, type tests are normally enforced in the switch bootstrap. The first time we hit the test, we know we have some object and that the first label expects an Integer, so we test for that. But if the `when` clause fails, javac tells us to try again from the second label. Now, while the proposed code to the generated code looks ok - I wonder if this condition shouldn't instead be detected by the switch bootstrap: e.g. we're asking it to start again from a `case` which expects a `String`, but we really have some other Object on our hands, so that label index should never be returned by the switch bootstrap, which should either pick another applicable label index (if it exists) or just pick the default.
>
> This would allow us to keep the generated code as is, and avoid introducing coupling between cases in the generated code.
Btw, looking at the comment in SwitchBootstraps::createRepeatIndexSwitch, it seems that's already the case:
/*
* Construct test chains for labels inside switch, to handle switch repeats:
* switch (idx) {
* case 0 -> if (selector matches label[0]) return 0; else if (selector matches label[1]) return 1; else ...
* case 1 -> if (selector matches label[1]) return 1; else ...
* ...
* }
*/
-------------
PR Comment: https://git.openjdk.org/jdk/pull/15532#issuecomment-1702563195
More information about the compiler-dev
mailing list