On Tue, 22 Jun 2021 19:41:55 GMT, Jan Lahoda <jlah...@openjdk.org> 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: > > Updating javadoc, as suggested. src/java.base/share/classes/java/lang/runtime/SwitchBootstraps.java line 175: > 173: * Bootstrap method for linking an {@code invokedynamic} call site > that > 174: * implements a {@code switch} on a target of an enum type. The > static > 175: * arguments are used to encode the case labels associated to the > switch `String` and `Class` should appear in code blocks perhaps, or link tags? Also, I think this text could be improved by splitting the sentence by using a bullet list: The static arguments are used to encode the case labels associated to the switch construct, where each label can be encoded in two ways: * as a String value, which represents the name of the enum constant associated with the label * as a Class value, which represents the enum type associated with a type test pattern src/java.base/share/classes/java/lang/runtime/SwitchBootstraps.java line 218: > 216: * {@code Class} of the target enum type. > 217: * @throws Throwable if there is any error linking the call site > 218: * @jvms 4.4.6 The CONSTANT_NameAndType_info Structure Not sure what we do for other bootstraps, but I wonder if the throws clause here should be more specific - for instance the LambdaMetafactory tells when an exception is gonna be triggered. Here it seems like there are a couple of cases which can be called out, where we know that linkage is going to fail. ------------- PR: https://git.openjdk.java.net/jdk17/pull/81