RFR: universal type variables: initial prototype

Maurizio Cimadamore mcimadamore at openjdk.java.net
Fri Aug 6 10:42:49 UTC 2021


On Fri, 6 Aug 2021 02:02:47 GMT, Vicente Romero <vromero at openjdk.org> wrote:

>> But you have only one predicate? Anyway - see the other related comment - you really need this predicate when you call this later on:
>> 
>> 
>> attribTypes(tree.arguments, env, arg -> valueOKSet.contains(arg));
>> 
>> 
>> But it feels like the code in there can be simplified so that you use a single `attribType` inside a loop, by passing the right boolean flag for that parameter.
>
> it wont be that simple, see that the method invoked, `Attr.attribTypes`, is doing:
> 
>     List<Type> types = attribAnyTypes(trees, env);
>     return chk.checkRefTypes(trees, types, valueOK);
> 
> 
> and Check.checkRefTypes is doing:
> 
>         List<JCExpression> tl = trees;
>         for (List<Type> l = types; l.nonEmpty(); l = l.tail) {
>             l.head = checkRefType(tl.head.pos(), l.head, valueOK.test(tl.head));
>             tl = tl.tail;
>         }
>         return types;
> 
> and `Check.checkRefType` is the one using the flag, so in order to do all this at the level of `Attr.visitTypeApply` I will have to gather all the code, popping up code that belongs in `Check`, and then the code in `Attr.visitTypeApply` will lose readability. This is why I opted for the current solution.

I see what you mean - it seems like the current code is working against us here. In fact, attribAnyTypes specifically says that clients are expected to check for reference types after the fact...

Here's an idea... you could maybe call attribAnyTypes yourself, to attribute all the types, and then, in the loop you already have, only call checkRefTypes on the types you really need? (e.g. avoid attribTypes)

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

PR: https://git.openjdk.java.net/valhalla/pull/521


More information about the valhalla-dev mailing list