RFR: universal type variables: initial prototype

Vicente Romero vromero at openjdk.java.net
Fri Aug 6 02:08:44 UTC 2021

On Thu, 5 Aug 2021 13:15:49 GMT, Maurizio Cimadamore <mcimadamore at openjdk.org> wrote:

>> the thing is that one value only doesn't apply to all cases, what if some type variables are universal but others aren't?
> 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 unfold all this 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.


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

More information about the valhalla-dev mailing list