[prev in list] [next in list] [prev in thread] [next in thread] 

List:       openjdk-compiler-dev
Subject:    Re: RFR: 8314226: Series of colon-style fallthrough switch cases with guards compiled incorrectly [v
From:       Vicente Romero <vromero () openjdk ! org>
Date:       2023-09-13 14:57:43
Message-ID: FwZSvZ2z6w1p9DsqD2SmZe0Io3nRZCbI-2wa6qMH4hY=.1cd46942-0a50-4552-9735-dc4da751ad2c () github ! com
[Download RAW message or body]

On Fri, 8 Sep 2023 20:25:42 GMT, Aggelos Biboudis <abimpoudis@openjdk.org> wrote:

> > The `switch` structure is translated in `handleSwitch` where we rewrite pattern \
> > matching switches. In some occasions a switch has multiple cases with multiple \
> > patterns where the n-th case does not complete normally and falls through to the \
> > n+1-st case: 
> > 
> > switch (obj) {
> > case Integer _ when ((Integer) obj) > 0:
> > case String _ when !((String) obj).isEmpty():
> > return 1;
> > default:
> > return -1;
> > }
> > 
> > 
> > This PR addresses that by translating the second case correctly and also \
> > replicates the body of the latter to the former (which we can do because no \
> > bindings are introduced in either statement blocks by the definition of unnamed \
> > variables.). 
> > Previously the code was translated into:
> > 
> > 
> > switch (java.lang.runtime.SwitchBootstraps.typeSwitch(selector0$temp, index$1)) {
> > case 0:
> > Integer _;
> > if (!(true && ((Integer)obj) > 0)) {
> > index$1 = 1;
> > continue;
> > }
> > 
> > case 1 when !((String)obj).isEmpty():
> > return 1;
> > 
> > default:
> > return -1;
> > }
> > 
> > 
> > This PR adjusts the translation into:
> > 
> > 
> > switch (java.lang.runtime.SwitchBootstraps.typeSwitch(selector0$temp, index$1)) {
> > case 0:
> > Integer _;
> > if (!(true && ((Integer)obj) > 0)) {
> > index$1 = 1;
> > continue;
> > }
> > return 1;
> > 
> > case 1:
> > String _;
> > if (!((selector0$temp instanceof String || false) && (true && \
> > !((String)obj).isEmpty()))) { index$1 = 2;
> > continue;
> > }
> > return 1;
> > }
> 
> Aggelos Biboudis has updated the pull request incrementally with one additional \
> commit since the last revision: 
> Improving the desugared code. (#4)

looks sensible

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

Marked as reviewed by vromero (Reviewer).

PR Review: https://git.openjdk.org/jdk/pull/15532#pullrequestreview-1624772234


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic