RFR: 8300543 Compiler Implementation for Pattern Matching for switch [v2]
Jan Lahoda
jlahoda at openjdk.org
Thu Apr 20 13:44:56 UTC 2023
On Wed, 19 Apr 2023 15:36:08 GMT, Vicente Romero <vromero at openjdk.org> wrote:
>> Jan Lahoda has updated the pull request incrementally with six additional commits since the last revision:
>>
>> - Fixing infinite loop where a binding pattern is replaced with a binding pattern for the same type.
>> - Reflecting review comments.
>> - Fixing exhaustiveness for unsealed supertype pattern.
>> - No need to enable features after error reported.
>> - SwitchBootstraps.typeSwitch should not initialize enum classes.
>> - A prototype of avoiding enum initialization.
>
> src/java.base/share/classes/java/lang/runtime/SwitchBootstraps.java line 279:
>
>> 277: }
>> 278:
>> 279: private static int lazyDoEnumSwitch(Enum<?> target, int startIndex, Object[] labels, MethodHandles.Lookup lookup, Class<?> enumClass, MutableCallSite callSite) throws Throwable {
>
> out of curiosity, under what conditions the `startIndex` would be different from `0`? also shouldn't we check that `startIndex` is `>= 0`?
`startIndex` may be non-0 when there are guards in the switch. In the case of the `enumSwitch`, something like:
enum E {A, B;}
E e = E.B;
switch (e) {
case E ee when ee == E.A -> {}
case E ee -> {}
}
the method will be called twice, one with `startIndex == 0` and once with `startIndex == 1`, after the guard fails/returns `false`.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/13074#discussion_r1172609212
More information about the core-libs-dev
mailing list