On Thu, 17 Jun 2021 18:33:56 GMT, Jan Lahoda <[email protected]> wrote:
>> Currently, an enum switch with patterns is desugared in a very non-standard,
>> and potentially slow, way. It would be better to use the standard
>> `typeSwitch` bootstrap to classify the enum constants. The bootstrap needs
>> to accept enum constants as labels in order to allow this. A complication is
>> that if an enum constant is missing, that is not an incompatible change for
>> the switch, and the switch should simply work as if the case for the missing
>> constant didn't exist. So, the proposed solution is to have a new bootstrap
>> `enumConstant` that converts the enum constant name to the enum constant,
>> returning `null`, if the constant does not exist. It delegates to
>> `ConstantBootstraps.enumConstant` to do the actual conversion. And
>> `typeSwitch` accepts `null`s as padding.
>>
>> How does this look?
>
> Jan Lahoda has updated the pull request incrementally with one additional
> commit since the last revision:
>
> Creating a new bootstrap method for (pattern matching) enum switches, as
> suggested.
src/java.base/share/classes/java/lang/runtime/SwitchBootstraps.java line 222:
> 220: String invocationName,
> 221: MethodType invocationType,
> 222: Object... labels) throws Throwable
> {
Is it not better to take a Class and a String... as separated parameters
instead of taking Object... and doing the conversion to a Class and an array of
String later in Java
src/java.base/share/classes/java/lang/runtime/SwitchBootstraps.java line 238:
> 236: MethodHandle target =
> 237: MethodHandles.insertArguments(DO_ENUM_SWITCH, 2,
> (Object) labels);
> 238: target = MethodHandles.explicitCastArguments(target,
> invocationType);
why explicitCast is used here instead of the classical cast asType() ?
-------------
PR: https://git.openjdk.java.net/jdk17/pull/81