1.1 --- a/src/share/classes/com/sun/tools/javac/comp/Infer.java Wed Apr 16 18:15:48 2014 -0700 1.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Infer.java Fri Apr 18 23:50:41 2014 +0100 1.3 @@ -220,9 +220,10 @@ 1.4 */ 1.5 Type generateReturnConstraints(Attr.ResultInfo resultInfo, 1.6 MethodType mt, InferenceContext inferenceContext) { 1.7 + InferenceContext rsInfoInfContext = resultInfo.checkContext.inferenceContext(); 1.8 Type from = mt.getReturnType(); 1.9 if (mt.getReturnType().containsAny(inferenceContext.inferencevars) && 1.10 - resultInfo.checkContext.inferenceContext() != emptyContext) { 1.11 + rsInfoInfContext != emptyContext) { 1.12 from = types.capture(from); 1.13 //add synthetic captured ivars 1.14 for (Type t : from.getTypeArguments()) { 1.15 @@ -231,13 +232,13 @@ 1.16 } 1.17 } 1.18 } 1.19 - Type qtype1 = inferenceContext.asFree(from); 1.20 + Type qtype1 = inferenceContext.asUndetVar(from); 1.21 Type to = returnConstraintTarget(qtype1, resultInfo.pt); 1.22 - Assert.check(allowGraphInference || !resultInfo.checkContext.inferenceContext().free(to), 1.23 + Assert.check(allowGraphInference || !rsInfoInfContext.free(to), 1.24 "legacy inference engine cannot handle constraints on both sides of a subtyping assertion"); 1.25 //we need to skip capture? 1.26 Warner retWarn = new Warner(); 1.27 - if (!resultInfo.checkContext.compatible(qtype1, resultInfo.checkContext.inferenceContext().asFree(to), retWarn) || 1.28 + if (!resultInfo.checkContext.compatible(qtype1, rsInfoInfContext.asUndetVar(to), retWarn) || 1.29 //unchecked conversion is not allowed in source 7 mode 1.30 (!allowGraphInference && retWarn.hasLint(Lint.LintCategory.UNCHECKED))) { 1.31 throw inferenceException 1.32 @@ -280,7 +281,7 @@ 1.33 ListBuffer<Type> todo = new ListBuffer<>(); 1.34 //step 1 - create fresh tvars 1.35 for (Type t : vars) { 1.36 - UndetVar uv = (UndetVar)inferenceContext.asFree(t); 1.37 + UndetVar uv = (UndetVar)inferenceContext.asUndetVar(t); 1.38 List<Type> upperBounds = uv.getBounds(InferenceBound.UPPER); 1.39 if (Type.containsAny(upperBounds, vars)) { 1.40 TypeSymbol fresh_tvar = new TypeVariableSymbol(Flags.SYNTHETIC, uv.qtype.tsym.name, null, uv.qtype.tsym.owner); 1.41 @@ -399,7 +400,7 @@ 1.42 return types.createErrorType(funcInterface); 1.43 } 1.44 for (Type p : descParameterTypes) { 1.45 - if (!types.isSameType(funcInterfaceContext.asFree(p), paramTypes.head)) { 1.46 + if (!types.isSameType(funcInterfaceContext.asUndetVar(p), paramTypes.head)) { 1.47 checkContext.report(pos, diags.fragment("no.suitable.functional.intf.inst", funcInterface)); 1.48 return types.createErrorType(funcInterface); 1.49 } 1.50 @@ -533,22 +534,23 @@ 1.51 if (uv.inst != null) { 1.52 Type inst = uv.inst; 1.53 for (Type u : uv.getBounds(InferenceBound.UPPER)) { 1.54 - if (!isSubtype(inst, inferenceContext.asFree(u), warn, infer)) { 1.55 + if (!isSubtype(inst, inferenceContext.asUndetVar(u), warn, infer)) { 1.56 infer.reportBoundError(uv, BoundErrorKind.UPPER); 1.57 } 1.58 } 1.59 for (Type l : uv.getBounds(InferenceBound.LOWER)) { 1.60 - if (!isSubtype(inferenceContext.asFree(l), inst, warn, infer)) { 1.61 + if (!isSubtype(inferenceContext.asUndetVar(l), inst, warn, infer)) { 1.62 infer.reportBoundError(uv, BoundErrorKind.LOWER); 1.63 } 1.64 } 1.65 for (Type e : uv.getBounds(InferenceBound.EQ)) { 1.66 - if (!isSameType(inst, inferenceContext.asFree(e), infer)) { 1.67 + if (!isSameType(inst, inferenceContext.asUndetVar(e), infer)) { 1.68 infer.reportBoundError(uv, BoundErrorKind.EQ); 1.69 } 1.70 } 1.71 } 1.72 } 1.73 + 1.74 @Override 1.75 boolean accepts(UndetVar uv, InferenceContext inferenceContext) { 1.76 //applies to all undetvars 1.77 @@ -594,12 +596,12 @@ 1.78 for (Type e : uv.getBounds(InferenceBound.EQ)) { 1.79 if (e.containsAny(inferenceContext.inferenceVars())) continue; 1.80 for (Type u : uv.getBounds(InferenceBound.UPPER)) { 1.81 - if (!isSubtype(e, inferenceContext.asFree(u), warn, infer)) { 1.82 + if (!isSubtype(e, inferenceContext.asUndetVar(u), warn, infer)) { 1.83 infer.reportBoundError(uv, BoundErrorKind.BAD_EQ_UPPER); 1.84 } 1.85 } 1.86 for (Type l : uv.getBounds(InferenceBound.LOWER)) { 1.87 - if (!isSubtype(inferenceContext.asFree(l), e, warn, infer)) { 1.88 + if (!isSubtype(inferenceContext.asUndetVar(l), e, warn, infer)) { 1.89 infer.reportBoundError(uv, BoundErrorKind.BAD_EQ_LOWER); 1.90 } 1.91 } 1.92 @@ -615,7 +617,7 @@ 1.93 Infer infer = inferenceContext.infer(); 1.94 for (Type b1 : uv.getBounds(InferenceBound.UPPER)) { 1.95 for (Type b2 : uv.getBounds(InferenceBound.LOWER)) { 1.96 - isSubtype(inferenceContext.asFree(b2), inferenceContext.asFree(b1), warn , infer); 1.97 + isSubtype(inferenceContext.asUndetVar(b2), inferenceContext.asUndetVar(b1), warn , infer); 1.98 } 1.99 } 1.100 } 1.101 @@ -629,7 +631,7 @@ 1.102 Infer infer = inferenceContext.infer(); 1.103 for (Type b1 : uv.getBounds(InferenceBound.UPPER)) { 1.104 for (Type b2 : uv.getBounds(InferenceBound.EQ)) { 1.105 - isSubtype(inferenceContext.asFree(b2), inferenceContext.asFree(b1), warn, infer); 1.106 + isSubtype(inferenceContext.asUndetVar(b2), inferenceContext.asUndetVar(b1), warn, infer); 1.107 } 1.108 } 1.109 } 1.110 @@ -643,7 +645,7 @@ 1.111 Infer infer = inferenceContext.infer(); 1.112 for (Type b1 : uv.getBounds(InferenceBound.EQ)) { 1.113 for (Type b2 : uv.getBounds(InferenceBound.LOWER)) { 1.114 - isSubtype(inferenceContext.asFree(b2), inferenceContext.asFree(b1), warn, infer); 1.115 + isSubtype(inferenceContext.asUndetVar(b2), inferenceContext.asUndetVar(b1), warn, infer); 1.116 } 1.117 } 1.118 } 1.119 @@ -658,7 +660,7 @@ 1.120 for (Type b1 : uv.getBounds(InferenceBound.EQ)) { 1.121 for (Type b2 : uv.getBounds(InferenceBound.EQ)) { 1.122 if (b1 != b2) { 1.123 - isSameType(inferenceContext.asFree(b2), inferenceContext.asFree(b1), infer); 1.124 + isSameType(inferenceContext.asUndetVar(b2), inferenceContext.asUndetVar(b1), infer); 1.125 } 1.126 } 1.127 } 1.128 @@ -673,7 +675,7 @@ 1.129 Infer infer = inferenceContext.infer(); 1.130 for (Type b : uv.getBounds(InferenceBound.UPPER)) { 1.131 if (inferenceContext.inferenceVars().contains(b)) { 1.132 - UndetVar uv2 = (UndetVar)inferenceContext.asFree(b); 1.133 + UndetVar uv2 = (UndetVar)inferenceContext.asUndetVar(b); 1.134 if (uv2.isCaptured()) continue; 1.135 //alpha <: beta 1.136 //0. set beta :> alpha 1.137 @@ -699,7 +701,7 @@ 1.138 Infer infer = inferenceContext.infer(); 1.139 for (Type b : uv.getBounds(InferenceBound.LOWER)) { 1.140 if (inferenceContext.inferenceVars().contains(b)) { 1.141 - UndetVar uv2 = (UndetVar)inferenceContext.asFree(b); 1.142 + UndetVar uv2 = (UndetVar)inferenceContext.asUndetVar(b); 1.143 if (uv2.isCaptured()) continue; 1.144 //alpha :> beta 1.145 //0. set beta <: alpha 1.146 @@ -725,7 +727,7 @@ 1.147 Infer infer = inferenceContext.infer(); 1.148 for (Type b : uv.getBounds(InferenceBound.EQ)) { 1.149 if (inferenceContext.inferenceVars().contains(b)) { 1.150 - UndetVar uv2 = (UndetVar)inferenceContext.asFree(b); 1.151 + UndetVar uv2 = (UndetVar)inferenceContext.asUndetVar(b); 1.152 if (uv2.isCaptured()) continue; 1.153 //alpha == beta 1.154 //0. set beta == alpha 1.155 @@ -1475,7 +1477,7 @@ 1.156 StringBuilder buf = new StringBuilder(); 1.157 String sep = ""; 1.158 for (Type from : data) { 1.159 - UndetVar uv = (UndetVar)inferenceContext.asFree(from); 1.160 + UndetVar uv = (UndetVar)inferenceContext.asUndetVar(from); 1.161 for (Type bound : uv.getBounds(InferenceBound.values())) { 1.162 if (bound.containsAny(List.from(to.data))) { 1.163 buf.append(sep); 1.164 @@ -1684,7 +1686,7 @@ 1.165 Set<Type> optDepsByNode = stuckDeps.get(i); 1.166 for (Node n_j : nodes) { 1.167 Type j = n_j.data.first(); 1.168 - UndetVar uv_i = (UndetVar)inferenceContext.asFree(i); 1.169 + UndetVar uv_i = (UndetVar)inferenceContext.asUndetVar(i); 1.170 if (Type.containsAny(uv_i.getBounds(InferenceBound.values()), List.of(j))) { 1.171 //update i's bound dependencies 1.172 n_i.addDependency(DependencyKind.BOUND, n_j); 1.173 @@ -1833,6 +1835,8 @@ 1.174 }); 1.175 } 1.176 1.177 + /* Returns the corresponding inference variables. 1.178 + */ 1.179 private List<Type> filterVars(Filter<UndetVar> fu) { 1.180 ListBuffer<Type> res = new ListBuffer<>(); 1.181 for (Type t : undetvars) { 1.182 @@ -1890,14 +1894,14 @@ 1.183 * undet vars (used ahead of subtyping/compatibility checks to allow propagation 1.184 * of inference constraints). 1.185 */ 1.186 - final Type asFree(Type t) { 1.187 + final Type asUndetVar(Type t) { 1.188 return types.subst(t, inferencevars, undetvars); 1.189 } 1.190 1.191 - final List<Type> asFree(List<Type> ts) { 1.192 + final List<Type> asUndetVars(List<Type> ts) { 1.193 ListBuffer<Type> buf = new ListBuffer<>(); 1.194 for (Type t : ts) { 1.195 - buf.append(asFree(t)); 1.196 + buf.append(asUndetVar(t)); 1.197 } 1.198 return buf.toList(); 1.199 } 1.200 @@ -2073,7 +2077,7 @@ 1.201 private boolean solveBasic(List<Type> varsToSolve, EnumSet<InferenceStep> steps) { 1.202 boolean changed = false; 1.203 for (Type t : varsToSolve.intersect(restvars())) { 1.204 - UndetVar uv = (UndetVar)asFree(t); 1.205 + UndetVar uv = (UndetVar)asUndetVar(t); 1.206 for (InferenceStep step : steps) { 1.207 if (step.accepts(uv, this)) { 1.208 uv.inst = step.solve(uv, this);