[code-reflection] RFR: Update the model of pattern matching when pattern variable identifier is underscore [v2]
Mourad Abbay
mabbay at openjdk.org
Wed Sep 11 03:22:41 UTC 2024
On Wed, 11 Sep 2024 00:59:30 GMT, Paul Sandoz <psandoz at openjdk.org> wrote:
>> Yep - this PR is about a type test pattern whose binding name is left unspecified (`_`). I was observing that unspecified names can occur in many places (method parameters, local var decls, etc.) so we probably need some uniform way to handle with "missing names" ? What I'm objecting to, in this PR, is that we're creating a binding, where the binding name is `_` - which strikes me as incorrect. The name is missing/absent, `_` is just the Java way of denoting missing names.
>
> Right, they are interconnected. I proposed to Mourad we should use `null` to signal no binding/name. The corresponding Var modeling the pattern variable can have `null` for its name, which we can do generally for variables with no name.
>
> For example for:
>
> `boolean x = o instanceof String s`
>
> the model is:
>
>
> %4 : java.lang.String = constant @null;
> %5 : Var<java.lang.String> = var %4 @"s";
> %6 : boolean = pattern.match %3
> ()java.lang.reflect.code.ExtendedOp$Pattern$Binding<java.lang.String> -> {
> %7 : java.lang.reflect.code.ExtendedOp$Pattern$Binding<java.lang.String> = pattern.binding @"s";
> yield %7;
> }
> (%8 : java.lang.String)void -> {
> var.store %5 %8;
> yield;
> };
> %9 : Var<boolean> = var %6 @"x";
>
>
> For:
>
> `boolean _ = o instanceof String _`
>
> we could generate:
>
>
> %4 : java.lang.String = constant @null;
> %5 : Var<java.lang.String> = var %4;
> %6 : boolean = pattern.match %3
> ()java.lang.reflect.code.ExtendedOp$Pattern$Binding<java.lang.String> -> {
> %7 : java.lang.reflect.code.ExtendedOp$Pattern$Binding<java.lang.String> = pattern.binding;
> yield %7;
> }
> (%8 : java.lang.String)void -> {
> var.store %5 %8;
> yield;
> };
> %9 : Var<boolean> = var %6;
>
>
> When lowering it might be possible to remove unnamed variables, they are never loaded.
I suggest to not have Var that correspond to unnamed pattern variable
-------------
PR Review Comment: https://git.openjdk.org/babylon/pull/227#discussion_r1753065370
More information about the babylon-dev
mailing list