8035891: javac, rename method asFree() in InferenceContext to asUndetVar() which reflects better it's purpose
Reviewed-by: jjg
--- a/langtools/src/share/classes/com/sun/tools/javac/comp/Attr.java Thu Feb 27 13:57:57 2014 -0800
+++ b/langtools/src/share/classes/com/sun/tools/javac/comp/Attr.java Fri Feb 28 18:27:14 2014 +0000
@@ -248,7 +248,7 @@
if (!owntype.hasTag(ERROR) && !resultInfo.pt.hasTag(METHOD) && !resultInfo.pt.hasTag(FORALL)) {
if (allowPoly && inferenceContext.free(found)) {
if ((ownkind & ~resultInfo.pkind) == 0) {
- owntype = resultInfo.check(tree, inferenceContext.asFree(owntype));
+ owntype = resultInfo.check(tree, inferenceContext.asUndetVar(owntype));
} else {
log.error(tree.pos(), "unexpected.type",
kindNames(resultInfo.pkind),
@@ -2406,7 +2406,7 @@
//add thrown types as bounds to the thrown types free variables if needed:
if (resultInfo.checkContext.inferenceContext().free(lambdaType.getThrownTypes())) {
List<Type> inferredThrownTypes = flow.analyzeLambdaThrownTypes(env, that, make);
- List<Type> thrownTypes = resultInfo.checkContext.inferenceContext().asFree(lambdaType.getThrownTypes());
+ List<Type> thrownTypes = resultInfo.checkContext.inferenceContext().asUndetVars(lambdaType.getThrownTypes());
chk.unhandled(inferredThrownTypes, thrownTypes);
}
@@ -2547,7 +2547,7 @@
@Override
public boolean compatible(Type found, Type req, Warner warn) {
//return type must be compatible in both current context and assignment context
- return chk.basicHandler.compatible(found, inferenceContext().asFree(req), warn);
+ return chk.basicHandler.compatible(found, inferenceContext().asUndetVar(req), warn);
}
@Override
@@ -2580,7 +2580,7 @@
* types must be compatible with the return type of the expected descriptor.
*/
private void checkLambdaCompatible(JCLambda tree, Type descriptor, CheckContext checkContext) {
- Type returnType = checkContext.inferenceContext().asFree(descriptor.getReturnType());
+ Type returnType = checkContext.inferenceContext().asUndetVar(descriptor.getReturnType());
//return values have already been checked - but if lambda has no return
//values, we must ensure that void/value compatibility is correct;
@@ -2592,7 +2592,7 @@
diags.fragment("missing.ret.val", returnType)));
}
- List<Type> argTypes = checkContext.inferenceContext().asFree(descriptor.getParameterTypes());
+ List<Type> argTypes = checkContext.inferenceContext().asUndetVars(descriptor.getParameterTypes());
if (!types.isSameTypes(argTypes, TreeInfo.types(tree.params))) {
checkContext.report(tree, diags.fragment("incompatible.arg.types.in.lambda"));
}
@@ -2836,7 +2836,7 @@
if (that.kind.isUnbound() &&
resultInfo.checkContext.inferenceContext().free(argtypes.head)) {
//re-generate inference constraints for unbound receiver
- if (!types.isSubtype(resultInfo.checkContext.inferenceContext().asFree(argtypes.head), exprType)) {
+ if (!types.isSubtype(resultInfo.checkContext.inferenceContext().asUndetVar(argtypes.head), exprType)) {
//cannot happen as this has already been checked - we just need
//to regenerate the inference constraints, as that has been lost
//as a result of the call to inferenceContext.save()
@@ -2874,7 +2874,7 @@
@SuppressWarnings("fallthrough")
void checkReferenceCompatible(JCMemberReference tree, Type descriptor, Type refType, CheckContext checkContext, boolean speculativeAttr) {
- Type returnType = checkContext.inferenceContext().asFree(descriptor.getReturnType());
+ Type returnType = checkContext.inferenceContext().asUndetVar(descriptor.getReturnType());
Type resType;
switch (tree.getMode()) {
@@ -2906,7 +2906,7 @@
}
if (!speculativeAttr) {
- List<Type> thrownTypes = checkContext.inferenceContext().asFree(descriptor.getThrownTypes());
+ List<Type> thrownTypes = checkContext.inferenceContext().asUndetVars(descriptor.getThrownTypes());
if (chk.unhandled(refType.getThrownTypes(), thrownTypes).nonEmpty()) {
log.error(tree, "incompatible.thrown.types.in.mref", refType.getThrownTypes());
}
--- a/langtools/src/share/classes/com/sun/tools/javac/comp/Infer.java Thu Feb 27 13:57:57 2014 -0800
+++ b/langtools/src/share/classes/com/sun/tools/javac/comp/Infer.java Fri Feb 28 18:27:14 2014 +0000
@@ -219,9 +219,10 @@
*/
Type generateReturnConstraints(Attr.ResultInfo resultInfo,
MethodType mt, InferenceContext inferenceContext) {
+ InferenceContext rsInfoInfContext = resultInfo.checkContext.inferenceContext();
Type from = mt.getReturnType();
if (mt.getReturnType().containsAny(inferenceContext.inferencevars) &&
- resultInfo.checkContext.inferenceContext() != emptyContext) {
+ rsInfoInfContext != emptyContext) {
from = types.capture(from);
//add synthetic captured ivars
for (Type t : from.getTypeArguments()) {
@@ -230,13 +231,13 @@
}
}
}
- Type qtype1 = inferenceContext.asFree(from);
+ Type qtype1 = inferenceContext.asUndetVar(from);
Type to = returnConstraintTarget(qtype1, resultInfo.pt);
- Assert.check(allowGraphInference || !resultInfo.checkContext.inferenceContext().free(to),
+ Assert.check(allowGraphInference || !rsInfoInfContext.free(to),
"legacy inference engine cannot handle constraints on both sides of a subtyping assertion");
//we need to skip capture?
Warner retWarn = new Warner();
- if (!resultInfo.checkContext.compatible(qtype1, resultInfo.checkContext.inferenceContext().asFree(to), retWarn) ||
+ if (!resultInfo.checkContext.compatible(qtype1, rsInfoInfContext.asUndetVar(to), retWarn) ||
//unchecked conversion is not allowed in source 7 mode
(!allowGraphInference && retWarn.hasLint(Lint.LintCategory.UNCHECKED))) {
throw inferenceException
@@ -279,7 +280,7 @@
ListBuffer<Type> todo = new ListBuffer<>();
//step 1 - create fresh tvars
for (Type t : vars) {
- UndetVar uv = (UndetVar)inferenceContext.asFree(t);
+ UndetVar uv = (UndetVar)inferenceContext.asUndetVar(t);
List<Type> upperBounds = uv.getBounds(InferenceBound.UPPER);
if (Type.containsAny(upperBounds, vars)) {
TypeSymbol fresh_tvar = new TypeVariableSymbol(Flags.SYNTHETIC, uv.qtype.tsym.name, null, uv.qtype.tsym.owner);
@@ -398,7 +399,7 @@
return types.createErrorType(funcInterface);
}
for (Type p : descParameterTypes) {
- if (!types.isSameType(funcInterfaceContext.asFree(p), paramTypes.head)) {
+ if (!types.isSameType(funcInterfaceContext.asUndetVar(p), paramTypes.head)) {
checkContext.report(pos, diags.fragment("no.suitable.functional.intf.inst", funcInterface));
return types.createErrorType(funcInterface);
}
@@ -532,22 +533,23 @@
if (uv.inst != null) {
Type inst = uv.inst;
for (Type u : uv.getBounds(InferenceBound.UPPER)) {
- if (!isSubtype(inst, inferenceContext.asFree(u), warn, infer)) {
+ if (!isSubtype(inst, inferenceContext.asUndetVar(u), warn, infer)) {
infer.reportBoundError(uv, BoundErrorKind.UPPER);
}
}
for (Type l : uv.getBounds(InferenceBound.LOWER)) {
- if (!isSubtype(inferenceContext.asFree(l), inst, warn, infer)) {
+ if (!isSubtype(inferenceContext.asUndetVar(l), inst, warn, infer)) {
infer.reportBoundError(uv, BoundErrorKind.LOWER);
}
}
for (Type e : uv.getBounds(InferenceBound.EQ)) {
- if (!isSameType(inst, inferenceContext.asFree(e), infer)) {
+ if (!isSameType(inst, inferenceContext.asUndetVar(e), infer)) {
infer.reportBoundError(uv, BoundErrorKind.EQ);
}
}
}
}
+
@Override
boolean accepts(UndetVar uv, InferenceContext inferenceContext) {
//applies to all undetvars
@@ -599,12 +601,12 @@
for (Type e : uv.getBounds(InferenceBound.EQ)) {
if (e.containsAny(inferenceContext.inferenceVars())) continue;
for (Type u : uv.getBounds(InferenceBound.UPPER)) {
- if (!isSubtype(e, inferenceContext.asFree(u), warn, infer)) {
+ if (!isSubtype(e, inferenceContext.asUndetVar(u), warn, infer)) {
infer.reportBoundError(uv, BoundErrorKind.BAD_EQ_UPPER);
}
}
for (Type l : uv.getBounds(InferenceBound.LOWER)) {
- if (!isSubtype(inferenceContext.asFree(l), e, warn, infer)) {
+ if (!isSubtype(inferenceContext.asUndetVar(l), e, warn, infer)) {
infer.reportBoundError(uv, BoundErrorKind.BAD_EQ_LOWER);
}
}
@@ -625,7 +627,7 @@
Infer infer = inferenceContext.infer();
for (Type b1 : uv.getBounds(InferenceBound.UPPER)) {
for (Type b2 : uv.getBounds(InferenceBound.LOWER)) {
- isSubtype(inferenceContext.asFree(b2), inferenceContext.asFree(b1), warn , infer);
+ isSubtype(inferenceContext.asUndetVar(b2), inferenceContext.asUndetVar(b1), warn , infer);
}
}
}
@@ -646,7 +648,7 @@
Infer infer = inferenceContext.infer();
for (Type b1 : uv.getBounds(InferenceBound.UPPER)) {
for (Type b2 : uv.getBounds(InferenceBound.EQ)) {
- isSubtype(inferenceContext.asFree(b2), inferenceContext.asFree(b1), warn, infer);
+ isSubtype(inferenceContext.asUndetVar(b2), inferenceContext.asUndetVar(b1), warn, infer);
}
}
}
@@ -667,7 +669,7 @@
Infer infer = inferenceContext.infer();
for (Type b1 : uv.getBounds(InferenceBound.EQ)) {
for (Type b2 : uv.getBounds(InferenceBound.LOWER)) {
- isSubtype(inferenceContext.asFree(b2), inferenceContext.asFree(b1), warn, infer);
+ isSubtype(inferenceContext.asUndetVar(b2), inferenceContext.asUndetVar(b1), warn, infer);
}
}
}
@@ -689,7 +691,7 @@
for (Type b1 : uv.getBounds(InferenceBound.EQ)) {
for (Type b2 : uv.getBounds(InferenceBound.EQ)) {
if (b1 != b2) {
- isSameType(inferenceContext.asFree(b2), inferenceContext.asFree(b1), infer);
+ isSameType(inferenceContext.asUndetVar(b2), inferenceContext.asUndetVar(b1), infer);
}
}
}
@@ -710,7 +712,7 @@
Infer infer = inferenceContext.infer();
for (Type b : uv.getBounds(InferenceBound.UPPER)) {
if (inferenceContext.inferenceVars().contains(b)) {
- UndetVar uv2 = (UndetVar)inferenceContext.asFree(b);
+ UndetVar uv2 = (UndetVar)inferenceContext.asUndetVar(b);
if (uv2.isCaptured()) continue;
//alpha <: beta
//0. set beta :> alpha
@@ -742,7 +744,7 @@
Infer infer = inferenceContext.infer();
for (Type b : uv.getBounds(InferenceBound.LOWER)) {
if (inferenceContext.inferenceVars().contains(b)) {
- UndetVar uv2 = (UndetVar)inferenceContext.asFree(b);
+ UndetVar uv2 = (UndetVar)inferenceContext.asUndetVar(b);
if (uv2.isCaptured()) continue;
//alpha :> beta
//0. set beta <: alpha
@@ -774,7 +776,7 @@
Infer infer = inferenceContext.infer();
for (Type b : uv.getBounds(InferenceBound.EQ)) {
if (inferenceContext.inferenceVars().contains(b)) {
- UndetVar uv2 = (UndetVar)inferenceContext.asFree(b);
+ UndetVar uv2 = (UndetVar)inferenceContext.asUndetVar(b);
if (uv2.isCaptured()) continue;
//alpha == beta
//0. set beta == alpha
@@ -1526,7 +1528,7 @@
StringBuilder buf = new StringBuilder();
String sep = "";
for (Type from : data) {
- UndetVar uv = (UndetVar)inferenceContext.asFree(from);
+ UndetVar uv = (UndetVar)inferenceContext.asUndetVar(from);
for (Type bound : uv.getBounds(InferenceBound.values())) {
if (bound.containsAny(List.from(to.data))) {
buf.append(sep);
@@ -1735,7 +1737,7 @@
Set<Type> optDepsByNode = stuckDeps.get(i);
for (Node n_j : nodes) {
Type j = n_j.data.first();
- UndetVar uv_i = (UndetVar)inferenceContext.asFree(i);
+ UndetVar uv_i = (UndetVar)inferenceContext.asUndetVar(i);
if (Type.containsAny(uv_i.getBounds(InferenceBound.values()), List.of(j))) {
//update i's bound dependencies
n_i.addDependency(DependencyKind.BOUND, n_j);
@@ -1883,6 +1885,8 @@
});
}
+ /* Returns the corresponding inference variables.
+ */
private List<Type> filterVars(Filter<UndetVar> fu) {
ListBuffer<Type> res = new ListBuffer<>();
for (Type t : undetvars) {
@@ -1940,14 +1944,14 @@
* undet vars (used ahead of subtyping/compatibility checks to allow propagation
* of inference constraints).
*/
- final Type asFree(Type t) {
+ final Type asUndetVar(Type t) {
return types.subst(t, inferencevars, undetvars);
}
- final List<Type> asFree(List<Type> ts) {
+ final List<Type> asUndetVars(List<Type> ts) {
ListBuffer<Type> buf = new ListBuffer<>();
for (Type t : ts) {
- buf.append(asFree(t));
+ buf.append(asUndetVar(t));
}
return buf.toList();
}
@@ -2123,7 +2127,7 @@
private boolean solveBasic(List<Type> varsToSolve, EnumSet<InferenceStep> steps) {
boolean changed = false;
for (Type t : varsToSolve.intersect(restvars())) {
- UndetVar uv = (UndetVar)asFree(t);
+ UndetVar uv = (UndetVar)asUndetVar(t);
for (InferenceStep step : steps) {
if (step.accepts(uv, this)) {
uv.inst = step.solve(uv, this);
--- a/langtools/src/share/classes/com/sun/tools/javac/comp/Resolve.java Thu Feb 27 13:57:57 2014 -0800
+++ b/langtools/src/share/classes/com/sun/tools/javac/comp/Resolve.java Fri Feb 28 18:27:14 2014 +0000
@@ -898,7 +898,7 @@
@Override
public boolean compatible(Type found, Type req, Warner warn) {
- found = pendingInferenceContext.asFree(found);
+ found = pendingInferenceContext.asUndetVar(found);
req = infer.returnConstraintTarget(found, req);
return super.compatible(found, req, warn);
}
@@ -935,8 +935,8 @@
public boolean compatible(Type found, Type req, Warner warn) {
return strict ?
- types.isSubtypeUnchecked(found, deferredAttrContext.inferenceContext.asFree(req), warn) :
- types.isConvertible(found, deferredAttrContext.inferenceContext.asFree(req), warn);
+ types.isSubtypeUnchecked(found, deferredAttrContext.inferenceContext.asUndetVar(req), warn) :
+ types.isConvertible(found, deferredAttrContext.inferenceContext.asUndetVar(req), warn);
}
public void report(DiagnosticPosition pos, JCDiagnostic details) {
@@ -1141,7 +1141,7 @@
Type desc_t = types.findDescriptorType(t);
Type desc_s = types.findDescriptorType(s);
if (types.isSameTypes(desc_t.getParameterTypes(),
- inferenceContext().asFree(desc_s.getParameterTypes()))) {
+ inferenceContext().asUndetVars(desc_s.getParameterTypes()))) {
if (types.asSuper(t, s.tsym) != null ||
types.asSuper(s, t.tsym) != null) {
result &= MostSpecificCheckContext.super.compatible(t, s, warn);
@@ -1168,7 +1168,7 @@
Type desc_t = types.findDescriptorType(t);
Type desc_s = types.findDescriptorType(s);
if (types.isSameTypes(desc_t.getParameterTypes(),
- inferenceContext().asFree(desc_s.getParameterTypes()))) {
+ inferenceContext().asUndetVars(desc_s.getParameterTypes()))) {
if (types.asSuper(t, s.tsym) != null ||
types.asSuper(s, t.tsym) != null) {
result &= MostSpecificCheckContext.super.compatible(t, s, warn);
@@ -3151,7 +3151,7 @@
if (TreeInfo.isStaticSelector(referenceTree.expr, names) &&
argtypes.nonEmpty() &&
(argtypes.head.hasTag(NONE) ||
- types.isSubtypeUnchecked(inferenceContext.asFree(argtypes.head), site))) {
+ types.isSubtypeUnchecked(inferenceContext.asUndetVar(argtypes.head), site))) {
return new UnboundMethodReferenceLookupHelper(referenceTree, name,
site, argtypes, typeargtypes, maxPhase);
} else {
@@ -4263,7 +4263,11 @@
}
DeferredAttrContext deferredAttrContext(Symbol sym, InferenceContext inferenceContext, ResultInfo pendingResult, Warner warn) {
- return deferredAttr.new DeferredAttrContext(attrMode, sym, step, inferenceContext, pendingResult != null ? pendingResult.checkContext.deferredAttrContext() : deferredAttr.emptyDeferredAttrContext, warn);
+ DeferredAttrContext parent = (pendingResult == null)
+ ? deferredAttr.emptyDeferredAttrContext
+ : pendingResult.checkContext.deferredAttrContext();
+ return deferredAttr.new DeferredAttrContext(attrMode, sym, step,
+ inferenceContext, parent, warn);
}
/**