8035891: javac, rename method asFree() in InferenceContext to asUndetVar() which reflects better it's purpose

Fri, 18 Apr 2014 23:50:41 +0100

author
vromero
date
Fri, 18 Apr 2014 23:50:41 +0100
changeset 2368
0524f786d7e8
parent 2367
1737ad9ac984
child 2369
77352397867a

8035891: javac, rename method asFree() in InferenceContext to asUndetVar() which reflects better it's purpose
Reviewed-by: jjg

src/share/classes/com/sun/tools/javac/comp/Attr.java file | annotate | diff | comparison | revisions
src/share/classes/com/sun/tools/javac/comp/Infer.java file | annotate | diff | comparison | revisions
src/share/classes/com/sun/tools/javac/comp/Resolve.java file | annotate | diff | comparison | revisions
     1.1 --- a/src/share/classes/com/sun/tools/javac/comp/Attr.java	Wed Apr 16 18:15:48 2014 -0700
     1.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Attr.java	Fri Apr 18 23:50:41 2014 +0100
     1.3 @@ -249,7 +249,7 @@
     1.4          if (!owntype.hasTag(ERROR) && !resultInfo.pt.hasTag(METHOD) && !resultInfo.pt.hasTag(FORALL)) {
     1.5              if (allowPoly && inferenceContext.free(found)) {
     1.6                  if ((ownkind & ~resultInfo.pkind) == 0) {
     1.7 -                    owntype = resultInfo.check(tree, inferenceContext.asFree(owntype));
     1.8 +                    owntype = resultInfo.check(tree, inferenceContext.asUndetVar(owntype));
     1.9                  } else {
    1.10                      log.error(tree.pos(), "unexpected.type",
    1.11                              kindNames(resultInfo.pkind),
    1.12 @@ -2402,7 +2402,7 @@
    1.13                  //add thrown types as bounds to the thrown types free variables if needed:
    1.14                  if (resultInfo.checkContext.inferenceContext().free(lambdaType.getThrownTypes())) {
    1.15                      List<Type> inferredThrownTypes = flow.analyzeLambdaThrownTypes(env, that, make);
    1.16 -                    List<Type> thrownTypes = resultInfo.checkContext.inferenceContext().asFree(lambdaType.getThrownTypes());
    1.17 +                    List<Type> thrownTypes = resultInfo.checkContext.inferenceContext().asUndetVars(lambdaType.getThrownTypes());
    1.18  
    1.19                      chk.unhandled(inferredThrownTypes, thrownTypes);
    1.20                  }
    1.21 @@ -2543,7 +2543,7 @@
    1.22              @Override
    1.23              public boolean compatible(Type found, Type req, Warner warn) {
    1.24                  //return type must be compatible in both current context and assignment context
    1.25 -                return chk.basicHandler.compatible(found, inferenceContext().asFree(req), warn);
    1.26 +                return chk.basicHandler.compatible(found, inferenceContext().asUndetVar(req), warn);
    1.27              }
    1.28  
    1.29              @Override
    1.30 @@ -2576,7 +2576,7 @@
    1.31          * types must be compatible with the return type of the expected descriptor.
    1.32          */
    1.33          private void checkLambdaCompatible(JCLambda tree, Type descriptor, CheckContext checkContext) {
    1.34 -            Type returnType = checkContext.inferenceContext().asFree(descriptor.getReturnType());
    1.35 +            Type returnType = checkContext.inferenceContext().asUndetVar(descriptor.getReturnType());
    1.36  
    1.37              //return values have already been checked - but if lambda has no return
    1.38              //values, we must ensure that void/value compatibility is correct;
    1.39 @@ -2588,7 +2588,7 @@
    1.40                          diags.fragment("missing.ret.val", returnType)));
    1.41              }
    1.42  
    1.43 -            List<Type> argTypes = checkContext.inferenceContext().asFree(descriptor.getParameterTypes());
    1.44 +            List<Type> argTypes = checkContext.inferenceContext().asUndetVars(descriptor.getParameterTypes());
    1.45              if (!types.isSameTypes(argTypes, TreeInfo.types(tree.params))) {
    1.46                  checkContext.report(tree, diags.fragment("incompatible.arg.types.in.lambda"));
    1.47              }
    1.48 @@ -2832,7 +2832,7 @@
    1.49              if (that.kind.isUnbound() &&
    1.50                      resultInfo.checkContext.inferenceContext().free(argtypes.head)) {
    1.51                  //re-generate inference constraints for unbound receiver
    1.52 -                if (!types.isSubtype(resultInfo.checkContext.inferenceContext().asFree(argtypes.head), exprType)) {
    1.53 +                if (!types.isSubtype(resultInfo.checkContext.inferenceContext().asUndetVar(argtypes.head), exprType)) {
    1.54                      //cannot happen as this has already been checked - we just need
    1.55                      //to regenerate the inference constraints, as that has been lost
    1.56                      //as a result of the call to inferenceContext.save()
    1.57 @@ -2870,7 +2870,7 @@
    1.58  
    1.59      @SuppressWarnings("fallthrough")
    1.60      void checkReferenceCompatible(JCMemberReference tree, Type descriptor, Type refType, CheckContext checkContext, boolean speculativeAttr) {
    1.61 -        Type returnType = checkContext.inferenceContext().asFree(descriptor.getReturnType());
    1.62 +        Type returnType = checkContext.inferenceContext().asUndetVar(descriptor.getReturnType());
    1.63  
    1.64          Type resType;
    1.65          switch (tree.getMode()) {
    1.66 @@ -2902,7 +2902,7 @@
    1.67          }
    1.68  
    1.69          if (!speculativeAttr) {
    1.70 -            List<Type> thrownTypes = checkContext.inferenceContext().asFree(descriptor.getThrownTypes());
    1.71 +            List<Type> thrownTypes = checkContext.inferenceContext().asUndetVars(descriptor.getThrownTypes());
    1.72              if (chk.unhandled(refType.getThrownTypes(), thrownTypes).nonEmpty()) {
    1.73                  log.error(tree, "incompatible.thrown.types.in.mref", refType.getThrownTypes());
    1.74              }
     2.1 --- a/src/share/classes/com/sun/tools/javac/comp/Infer.java	Wed Apr 16 18:15:48 2014 -0700
     2.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Infer.java	Fri Apr 18 23:50:41 2014 +0100
     2.3 @@ -220,9 +220,10 @@
     2.4       */
     2.5      Type generateReturnConstraints(Attr.ResultInfo resultInfo,
     2.6              MethodType mt, InferenceContext inferenceContext) {
     2.7 +        InferenceContext rsInfoInfContext = resultInfo.checkContext.inferenceContext();
     2.8          Type from = mt.getReturnType();
     2.9          if (mt.getReturnType().containsAny(inferenceContext.inferencevars) &&
    2.10 -                resultInfo.checkContext.inferenceContext() != emptyContext) {
    2.11 +                rsInfoInfContext != emptyContext) {
    2.12              from = types.capture(from);
    2.13              //add synthetic captured ivars
    2.14              for (Type t : from.getTypeArguments()) {
    2.15 @@ -231,13 +232,13 @@
    2.16                  }
    2.17              }
    2.18          }
    2.19 -        Type qtype1 = inferenceContext.asFree(from);
    2.20 +        Type qtype1 = inferenceContext.asUndetVar(from);
    2.21          Type to = returnConstraintTarget(qtype1, resultInfo.pt);
    2.22 -        Assert.check(allowGraphInference || !resultInfo.checkContext.inferenceContext().free(to),
    2.23 +        Assert.check(allowGraphInference || !rsInfoInfContext.free(to),
    2.24                  "legacy inference engine cannot handle constraints on both sides of a subtyping assertion");
    2.25          //we need to skip capture?
    2.26          Warner retWarn = new Warner();
    2.27 -        if (!resultInfo.checkContext.compatible(qtype1, resultInfo.checkContext.inferenceContext().asFree(to), retWarn) ||
    2.28 +        if (!resultInfo.checkContext.compatible(qtype1, rsInfoInfContext.asUndetVar(to), retWarn) ||
    2.29                  //unchecked conversion is not allowed in source 7 mode
    2.30                  (!allowGraphInference && retWarn.hasLint(Lint.LintCategory.UNCHECKED))) {
    2.31              throw inferenceException
    2.32 @@ -280,7 +281,7 @@
    2.33          ListBuffer<Type> todo = new ListBuffer<>();
    2.34          //step 1 - create fresh tvars
    2.35          for (Type t : vars) {
    2.36 -            UndetVar uv = (UndetVar)inferenceContext.asFree(t);
    2.37 +            UndetVar uv = (UndetVar)inferenceContext.asUndetVar(t);
    2.38              List<Type> upperBounds = uv.getBounds(InferenceBound.UPPER);
    2.39              if (Type.containsAny(upperBounds, vars)) {
    2.40                  TypeSymbol fresh_tvar = new TypeVariableSymbol(Flags.SYNTHETIC, uv.qtype.tsym.name, null, uv.qtype.tsym.owner);
    2.41 @@ -399,7 +400,7 @@
    2.42                  return types.createErrorType(funcInterface);
    2.43              }
    2.44              for (Type p : descParameterTypes) {
    2.45 -                if (!types.isSameType(funcInterfaceContext.asFree(p), paramTypes.head)) {
    2.46 +                if (!types.isSameType(funcInterfaceContext.asUndetVar(p), paramTypes.head)) {
    2.47                      checkContext.report(pos, diags.fragment("no.suitable.functional.intf.inst", funcInterface));
    2.48                      return types.createErrorType(funcInterface);
    2.49                  }
    2.50 @@ -533,22 +534,23 @@
    2.51                  if (uv.inst != null) {
    2.52                      Type inst = uv.inst;
    2.53                      for (Type u : uv.getBounds(InferenceBound.UPPER)) {
    2.54 -                        if (!isSubtype(inst, inferenceContext.asFree(u), warn, infer)) {
    2.55 +                        if (!isSubtype(inst, inferenceContext.asUndetVar(u), warn, infer)) {
    2.56                              infer.reportBoundError(uv, BoundErrorKind.UPPER);
    2.57                          }
    2.58                      }
    2.59                      for (Type l : uv.getBounds(InferenceBound.LOWER)) {
    2.60 -                        if (!isSubtype(inferenceContext.asFree(l), inst, warn, infer)) {
    2.61 +                        if (!isSubtype(inferenceContext.asUndetVar(l), inst, warn, infer)) {
    2.62                              infer.reportBoundError(uv, BoundErrorKind.LOWER);
    2.63                          }
    2.64                      }
    2.65                      for (Type e : uv.getBounds(InferenceBound.EQ)) {
    2.66 -                        if (!isSameType(inst, inferenceContext.asFree(e), infer)) {
    2.67 +                        if (!isSameType(inst, inferenceContext.asUndetVar(e), infer)) {
    2.68                              infer.reportBoundError(uv, BoundErrorKind.EQ);
    2.69                          }
    2.70                      }
    2.71                  }
    2.72              }
    2.73 +
    2.74              @Override
    2.75              boolean accepts(UndetVar uv, InferenceContext inferenceContext) {
    2.76                  //applies to all undetvars
    2.77 @@ -594,12 +596,12 @@
    2.78                  for (Type e : uv.getBounds(InferenceBound.EQ)) {
    2.79                      if (e.containsAny(inferenceContext.inferenceVars())) continue;
    2.80                      for (Type u : uv.getBounds(InferenceBound.UPPER)) {
    2.81 -                        if (!isSubtype(e, inferenceContext.asFree(u), warn, infer)) {
    2.82 +                        if (!isSubtype(e, inferenceContext.asUndetVar(u), warn, infer)) {
    2.83                              infer.reportBoundError(uv, BoundErrorKind.BAD_EQ_UPPER);
    2.84                          }
    2.85                      }
    2.86                      for (Type l : uv.getBounds(InferenceBound.LOWER)) {
    2.87 -                        if (!isSubtype(inferenceContext.asFree(l), e, warn, infer)) {
    2.88 +                        if (!isSubtype(inferenceContext.asUndetVar(l), e, warn, infer)) {
    2.89                              infer.reportBoundError(uv, BoundErrorKind.BAD_EQ_LOWER);
    2.90                          }
    2.91                      }
    2.92 @@ -615,7 +617,7 @@
    2.93                  Infer infer = inferenceContext.infer();
    2.94                  for (Type b1 : uv.getBounds(InferenceBound.UPPER)) {
    2.95                      for (Type b2 : uv.getBounds(InferenceBound.LOWER)) {
    2.96 -                        isSubtype(inferenceContext.asFree(b2), inferenceContext.asFree(b1), warn , infer);
    2.97 +                        isSubtype(inferenceContext.asUndetVar(b2), inferenceContext.asUndetVar(b1), warn , infer);
    2.98                      }
    2.99                  }
   2.100              }
   2.101 @@ -629,7 +631,7 @@
   2.102                  Infer infer = inferenceContext.infer();
   2.103                  for (Type b1 : uv.getBounds(InferenceBound.UPPER)) {
   2.104                      for (Type b2 : uv.getBounds(InferenceBound.EQ)) {
   2.105 -                        isSubtype(inferenceContext.asFree(b2), inferenceContext.asFree(b1), warn, infer);
   2.106 +                        isSubtype(inferenceContext.asUndetVar(b2), inferenceContext.asUndetVar(b1), warn, infer);
   2.107                      }
   2.108                  }
   2.109              }
   2.110 @@ -643,7 +645,7 @@
   2.111                  Infer infer = inferenceContext.infer();
   2.112                  for (Type b1 : uv.getBounds(InferenceBound.EQ)) {
   2.113                      for (Type b2 : uv.getBounds(InferenceBound.LOWER)) {
   2.114 -                        isSubtype(inferenceContext.asFree(b2), inferenceContext.asFree(b1), warn, infer);
   2.115 +                        isSubtype(inferenceContext.asUndetVar(b2), inferenceContext.asUndetVar(b1), warn, infer);
   2.116                      }
   2.117                  }
   2.118              }
   2.119 @@ -658,7 +660,7 @@
   2.120                  for (Type b1 : uv.getBounds(InferenceBound.EQ)) {
   2.121                      for (Type b2 : uv.getBounds(InferenceBound.EQ)) {
   2.122                          if (b1 != b2) {
   2.123 -                            isSameType(inferenceContext.asFree(b2), inferenceContext.asFree(b1), infer);
   2.124 +                            isSameType(inferenceContext.asUndetVar(b2), inferenceContext.asUndetVar(b1), infer);
   2.125                          }
   2.126                      }
   2.127                  }
   2.128 @@ -673,7 +675,7 @@
   2.129                  Infer infer = inferenceContext.infer();
   2.130                  for (Type b : uv.getBounds(InferenceBound.UPPER)) {
   2.131                      if (inferenceContext.inferenceVars().contains(b)) {
   2.132 -                        UndetVar uv2 = (UndetVar)inferenceContext.asFree(b);
   2.133 +                        UndetVar uv2 = (UndetVar)inferenceContext.asUndetVar(b);
   2.134                          if (uv2.isCaptured()) continue;
   2.135                          //alpha <: beta
   2.136                          //0. set beta :> alpha
   2.137 @@ -699,7 +701,7 @@
   2.138                  Infer infer = inferenceContext.infer();
   2.139                  for (Type b : uv.getBounds(InferenceBound.LOWER)) {
   2.140                      if (inferenceContext.inferenceVars().contains(b)) {
   2.141 -                        UndetVar uv2 = (UndetVar)inferenceContext.asFree(b);
   2.142 +                        UndetVar uv2 = (UndetVar)inferenceContext.asUndetVar(b);
   2.143                          if (uv2.isCaptured()) continue;
   2.144                          //alpha :> beta
   2.145                          //0. set beta <: alpha
   2.146 @@ -725,7 +727,7 @@
   2.147                  Infer infer = inferenceContext.infer();
   2.148                  for (Type b : uv.getBounds(InferenceBound.EQ)) {
   2.149                      if (inferenceContext.inferenceVars().contains(b)) {
   2.150 -                        UndetVar uv2 = (UndetVar)inferenceContext.asFree(b);
   2.151 +                        UndetVar uv2 = (UndetVar)inferenceContext.asUndetVar(b);
   2.152                          if (uv2.isCaptured()) continue;
   2.153                          //alpha == beta
   2.154                          //0. set beta == alpha
   2.155 @@ -1475,7 +1477,7 @@
   2.156                          StringBuilder buf = new StringBuilder();
   2.157                          String sep = "";
   2.158                          for (Type from : data) {
   2.159 -                            UndetVar uv = (UndetVar)inferenceContext.asFree(from);
   2.160 +                            UndetVar uv = (UndetVar)inferenceContext.asUndetVar(from);
   2.161                              for (Type bound : uv.getBounds(InferenceBound.values())) {
   2.162                                  if (bound.containsAny(List.from(to.data))) {
   2.163                                      buf.append(sep);
   2.164 @@ -1684,7 +1686,7 @@
   2.165                      Set<Type> optDepsByNode = stuckDeps.get(i);
   2.166                      for (Node n_j : nodes) {
   2.167                          Type j = n_j.data.first();
   2.168 -                        UndetVar uv_i = (UndetVar)inferenceContext.asFree(i);
   2.169 +                        UndetVar uv_i = (UndetVar)inferenceContext.asUndetVar(i);
   2.170                          if (Type.containsAny(uv_i.getBounds(InferenceBound.values()), List.of(j))) {
   2.171                              //update i's bound dependencies
   2.172                              n_i.addDependency(DependencyKind.BOUND, n_j);
   2.173 @@ -1833,6 +1835,8 @@
   2.174              });
   2.175          }
   2.176  
   2.177 +        /* Returns the corresponding inference variables.
   2.178 +         */
   2.179          private List<Type> filterVars(Filter<UndetVar> fu) {
   2.180              ListBuffer<Type> res = new ListBuffer<>();
   2.181              for (Type t : undetvars) {
   2.182 @@ -1890,14 +1894,14 @@
   2.183           * undet vars (used ahead of subtyping/compatibility checks to allow propagation
   2.184           * of inference constraints).
   2.185           */
   2.186 -        final Type asFree(Type t) {
   2.187 +        final Type asUndetVar(Type t) {
   2.188              return types.subst(t, inferencevars, undetvars);
   2.189          }
   2.190  
   2.191 -        final List<Type> asFree(List<Type> ts) {
   2.192 +        final List<Type> asUndetVars(List<Type> ts) {
   2.193              ListBuffer<Type> buf = new ListBuffer<>();
   2.194              for (Type t : ts) {
   2.195 -                buf.append(asFree(t));
   2.196 +                buf.append(asUndetVar(t));
   2.197              }
   2.198              return buf.toList();
   2.199          }
   2.200 @@ -2073,7 +2077,7 @@
   2.201          private boolean solveBasic(List<Type> varsToSolve, EnumSet<InferenceStep> steps) {
   2.202              boolean changed = false;
   2.203              for (Type t : varsToSolve.intersect(restvars())) {
   2.204 -                UndetVar uv = (UndetVar)asFree(t);
   2.205 +                UndetVar uv = (UndetVar)asUndetVar(t);
   2.206                  for (InferenceStep step : steps) {
   2.207                      if (step.accepts(uv, this)) {
   2.208                          uv.inst = step.solve(uv, this);
     3.1 --- a/src/share/classes/com/sun/tools/javac/comp/Resolve.java	Wed Apr 16 18:15:48 2014 -0700
     3.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Resolve.java	Fri Apr 18 23:50:41 2014 +0100
     3.3 @@ -899,7 +899,7 @@
     3.4  
     3.5                  @Override
     3.6                  public boolean compatible(Type found, Type req, Warner warn) {
     3.7 -                    found = pendingInferenceContext.asFree(found);
     3.8 +                    found = pendingInferenceContext.asUndetVar(found);
     3.9                      req = infer.returnConstraintTarget(found, req);
    3.10                      return super.compatible(found, req, warn);
    3.11                  }
    3.12 @@ -936,8 +936,8 @@
    3.13  
    3.14          public boolean compatible(Type found, Type req, Warner warn) {
    3.15              return strict ?
    3.16 -                    types.isSubtypeUnchecked(found, deferredAttrContext.inferenceContext.asFree(req), warn) :
    3.17 -                    types.isConvertible(found, deferredAttrContext.inferenceContext.asFree(req), warn);
    3.18 +                    types.isSubtypeUnchecked(found, deferredAttrContext.inferenceContext.asUndetVar(req), warn) :
    3.19 +                    types.isConvertible(found, deferredAttrContext.inferenceContext.asUndetVar(req), warn);
    3.20          }
    3.21  
    3.22          public void report(DiagnosticPosition pos, JCDiagnostic details) {
    3.23 @@ -1142,7 +1142,7 @@
    3.24                          Type desc_t = types.findDescriptorType(t);
    3.25                          Type desc_s = types.findDescriptorType(s);
    3.26                          if (types.isSameTypes(desc_t.getParameterTypes(),
    3.27 -                                inferenceContext().asFree(desc_s.getParameterTypes()))) {
    3.28 +                                inferenceContext().asUndetVars(desc_s.getParameterTypes()))) {
    3.29                              if (types.asSuper(t, s.tsym) != null ||
    3.30                                  types.asSuper(s, t.tsym) != null) {
    3.31                                  result &= MostSpecificCheckContext.super.compatible(t, s, warn);
    3.32 @@ -1169,7 +1169,7 @@
    3.33                          Type desc_t = types.findDescriptorType(t);
    3.34                          Type desc_s = types.findDescriptorType(s);
    3.35                          if (types.isSameTypes(desc_t.getParameterTypes(),
    3.36 -                                inferenceContext().asFree(desc_s.getParameterTypes()))) {
    3.37 +                                inferenceContext().asUndetVars(desc_s.getParameterTypes()))) {
    3.38                              if (types.asSuper(t, s.tsym) != null ||
    3.39                                  types.asSuper(s, t.tsym) != null) {
    3.40                                  result &= MostSpecificCheckContext.super.compatible(t, s, warn);
    3.41 @@ -3152,7 +3152,7 @@
    3.42              if (TreeInfo.isStaticSelector(referenceTree.expr, names) &&
    3.43                      argtypes.nonEmpty() &&
    3.44                      (argtypes.head.hasTag(NONE) ||
    3.45 -                    types.isSubtypeUnchecked(inferenceContext.asFree(argtypes.head), site))) {
    3.46 +                    types.isSubtypeUnchecked(inferenceContext.asUndetVar(argtypes.head), site))) {
    3.47                  return new UnboundMethodReferenceLookupHelper(referenceTree, name,
    3.48                          site, argtypes, typeargtypes, maxPhase);
    3.49              } else {
    3.50 @@ -4265,7 +4265,11 @@
    3.51          }
    3.52  
    3.53          DeferredAttrContext deferredAttrContext(Symbol sym, InferenceContext inferenceContext, ResultInfo pendingResult, Warner warn) {
    3.54 -            return deferredAttr.new DeferredAttrContext(attrMode, sym, step, inferenceContext, pendingResult != null ? pendingResult.checkContext.deferredAttrContext() : deferredAttr.emptyDeferredAttrContext, warn);
    3.55 +            DeferredAttrContext parent = (pendingResult == null)
    3.56 +                ? deferredAttr.emptyDeferredAttrContext
    3.57 +                : pendingResult.checkContext.deferredAttrContext();
    3.58 +            return deferredAttr.new DeferredAttrContext(attrMode, sym, step,
    3.59 +                    inferenceContext, parent, warn);
    3.60          }
    3.61  
    3.62          /**

mercurial