On Fri, 5 Aug 2022 20:20:56 GMT, Remi Forax <fo...@univ-mlv.fr> wrote:

> You only need restart index at the beginning and after a when, so in your 
> example, only 0 and 1 are required, you can skip the generation of 2 because 
> you will never restart at 2.
> 

The bootstrap protocol does not specify which cases have guards, so I don't 
think the bootstrap cannot do such a decision.

> If you start to see the typeswitch as a bunch of method handles, i wonder if 
> it's not better to lift any when expressions as a static methods (exactly 
> like a lambda body) and then send them as constant method handles to the type 
> switch so you do not need a restart index.
> 

The issue with guards is that they can not only capture, but also produce new 
bindings. Like:

case Box b when b.o() instanceof String component -> 
System.err.println(component);

This really makes modeling this at runtime notably more difficult than lambdas. 
There were multiple experiments with this, and the runtime API and the handles 
are not really easy to understand.

Jan


> Anyway, i agree that it's a better translation than the existing one.
> 
> I think that in the end game, we will go to the same route as with the lambda 
> proxy, the whole pattern matching with the when expressions as constant 
> method handles will be send to one bootstrap method that will create an 
> intermediary decision tree, generate the corresponding bytecode (using the 
> classfile API) and load it as a hidden class. This provides a clean API 
> separation between the compiler and the runtime that knows how to optimize 
> pattern matching query.
> 
> R?mi

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

PR: https://git.openjdk.org/jdk/pull/9779

Reply via email to