RFR: universal type variables: initial prototype [v3]

Maurizio Cimadamore mcimadamore at openjdk.java.net
Tue Aug 10 21:27:40 UTC 2021


On Tue, 10 Aug 2021 19:10:14 GMT, Vicente Romero <vromero at openjdk.org> wrote:

>> First iteration of the protype for universal type variables
>
> Vicente Romero has updated the pull request incrementally with one additional commit since the last revision:
> 
>   second iteration of review comments

src/jdk.compiler/share/classes/com/sun/tools/javac/code/Types.java line 1186:

> 1184:                      return isSubtypeNoCapture(t.getUpperBound(), s);
> 1185:                  case BOT:
> 1186:                      if (allowUniversalTVars && s.hasTag(TYPEVAR) && ((TypeVar)s).isValueProjection()) {

I agree that here you need `isValueProjection`

src/jdk.compiler/share/classes/com/sun/tools/javac/code/Types.java line 3614:

> 3612:                 }
> 3613:                 if (allowUniversalTVars &&
> 3614:                         !t.isValueProjection() &&

Not sure about this here - "not value projection might also mean it's a regular tvar". Doesn't this test want to check for `T.ref` (in which case you should check for `isReferenceProjection`

src/jdk.compiler/share/classes/com/sun/tools/javac/code/Types.java line 3616:

> 3614:                         !t.isValueProjection() &&
> 3615:                         from.head.hasTag(TYPEVAR) &&
> 3616:                         ((TypeVar)from.head).projection != null &&

Shouldn't this test be `isUniversal()` ?

src/jdk.compiler/share/classes/com/sun/tools/javac/code/Types.java line 3617:

> 3615:                         from.head.hasTag(TYPEVAR) &&
> 3616:                         ((TypeVar)from.head).projection != null &&
> 3617:                         t.equalsIgnoreMetadata(((TypeVar)from.head).projection)) {

and here, we should call `referencceProjection()` ?

src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Attr.java line 2663:

> 2661:                         && ((JCFieldAccess)tree.meth).selected.hasTag(IDENT)
> 2662:                         && TreeInfo.name(((JCFieldAccess)tree.meth).selected) == names._super;
> 2663:                 boolean qualifierIsUniversal = allowUniversalTVars && qualifier.hasTag(TYPEVAR) && ((TypeVar)qualifier).isValueProjection();

This should be `isUniversal()` I think - `wait` and friends should warn, even on `.ref` stuff.

src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Attr.java line 4600:

> 4598:                 throw new AssertionError(tree);
> 4599:             case TYPEVAR:
> 4600:                 if (allowUniversalTVars && name == names.ref && ((TypeVar)site).isValueProjection()) {

This should be `isUniversal()` ?

src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Attr.java line 5149:

> 5147:             argTypes2 = argTypes = attribAnyTypes(args, env);
> 5148:             for (Type t : ((ClassType) clazztype.tsym.type).typarams_field) {
> 5149:                 argTypes.head = chk.checkRefType(args.head.pos(), argTypes.head, ((TypeVar) t).isValueProjection());

this should be `isUniversal()`, no?

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

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



More information about the valhalla-dev mailing list