Mercurial > hg > openjdk > lambda > langtools
changeset 1589:39145a667f8a
Misc cleanups:
*) Remove fixup of speculative cache
*) Remove 'hack' to make recovery attribution of speculative types work
*) Fixed use of static field Warner.noWarnings causing spurious unchecked warnings during test runs
*) Refactored code for Attr.checkId
line wrap: on
line diff
--- a/src/share/classes/com/sun/tools/javac/code/Symbol.java Fri Nov 02 11:45:58 2012 +0000 +++ b/src/share/classes/com/sun/tools/javac/code/Symbol.java Sat Nov 03 15:00:22 2012 +0000 @@ -1201,7 +1201,7 @@ Type ot = types.memberType(origin.type, other); return types.isSubSignature(mt, ot) && - (!checkResult || types.resultSubtype(mt, ot, Warner.noWarnings)); + (!checkResult || types.resultSubtype(mt, ot, types.noWarnings)); } private boolean isOverridableIn(TypeSymbol origin) {
--- a/src/share/classes/com/sun/tools/javac/code/Types.java Fri Nov 02 11:45:58 2012 +0000 +++ b/src/share/classes/com/sun/tools/javac/code/Types.java Sat Nov 03 15:00:22 2012 +0000 @@ -84,6 +84,8 @@ List<Warner> warnStack = List.nil(); final Name capturedName; private final FunctionDescriptorLookupError functionDescriptorLookupError; + + public final Warner noWarnings; // <editor-fold defaultstate="collapsed" desc="Instantiating"> public static Types instance(Context context) { @@ -108,6 +110,7 @@ messages = JavacMessages.instance(context); diags = JCDiagnostic.Factory.instance(context); functionDescriptorLookupError = new FunctionDescriptorLookupError(); + noWarnings = new Warner(null); } // </editor-fold> @@ -298,7 +301,7 @@ * convertions to s? */ public boolean isConvertible(Type t, Type s) { - return isConvertible(t, s, Warner.noWarnings); + return isConvertible(t, s, noWarnings); } // </editor-fold> @@ -600,7 +603,7 @@ * Is t an unchecked subtype of s? */ public boolean isSubtypeUnchecked(Type t, Type s) { - return isSubtypeUnchecked(t, s, Warner.noWarnings); + return isSubtypeUnchecked(t, s, noWarnings); } /** * Is t an unchecked subtype of s? @@ -1201,7 +1204,7 @@ // <editor-fold defaultstate="collapsed" desc="isCastable"> public boolean isCastable(Type t, Type s) { - return isCastable(t, s, Warner.noWarnings); + return isCastable(t, s, noWarnings); } /** @@ -1264,7 +1267,7 @@ return true; if (s.tag == TYPEVAR) { - if (isCastable(t, s.getUpperBound(), Warner.noWarnings)) { + if (isCastable(t, s.getUpperBound(), noWarnings)) { warnStack.head.warn(LintCategory.UNCHECKED); return true; } else { @@ -1274,7 +1277,7 @@ if (t.isCompound()) { Warner oldWarner = warnStack.head; - warnStack.head = Warner.noWarnings; + warnStack.head = noWarnings; if (!visit(supertype(t), s)) return false; for (Type intf : interfaces(t)) { @@ -1373,7 +1376,7 @@ case BOT: return true; case TYPEVAR: - if (isCastable(s, t, Warner.noWarnings)) { + if (isCastable(s, t, noWarnings)) { warnStack.head.warn(LintCategory.UNCHECKED); return true; } else { @@ -1402,7 +1405,7 @@ case TYPEVAR: if (isSubtype(t, s)) { return true; - } else if (isCastable(t.bound, s, Warner.noWarnings)) { + } else if (isCastable(t.bound, s, noWarnings)) { warnStack.head.warn(LintCategory.UNCHECKED); return true; } else { @@ -1541,7 +1544,7 @@ TypeVar tv = (TypeVar) t; return !isCastable(tv.bound, relaxBound(s), - Warner.noWarnings); + noWarnings); } if (s.tag != WILDCARD) s = upperBound(s); @@ -1844,7 +1847,7 @@ // <editor-fold defaultstate="collapsed" desc="isAssignable"> public boolean isAssignable(Type t, Type s) { - return isAssignable(t, s, Warner.noWarnings); + return isAssignable(t, s, noWarnings); } /** @@ -3435,11 +3438,11 @@ */ public boolean returnTypeSubstitutable(Type r1, Type r2) { if (hasSameArgs(r1, r2)) - return resultSubtype(r1, r2, Warner.noWarnings); + return resultSubtype(r1, r2, noWarnings); else return covariantReturnType(r1.getReturnType(), erasure(r2.getReturnType()), - Warner.noWarnings); + noWarnings); } public boolean returnTypeSubstitutable(Type r1,
--- a/src/share/classes/com/sun/tools/javac/comp/Attr.java Fri Nov 02 11:45:58 2012 +0000 +++ b/src/share/classes/com/sun/tools/javac/comp/Attr.java Sat Nov 03 15:00:22 2012 +0000 @@ -608,8 +608,10 @@ this.env = env; this.resultInfo = resultInfo; tree.accept(this); - if (tree == breakTree) + if (tree == breakTree && + resultInfo.checkContext.deferredAttrContext().mode == AttrMode.CHECK) { throw new BreakAttr(env); + } return result; } catch (CompletionFailure ex) { tree.type = syms.errType; @@ -2073,7 +2075,7 @@ resultInfo.checkContext.inferenceContext().free(resultInfo.pt) ? Type.noType : pt()); Type inferred = deferredAttr.attribSpeculative(tree, env, findDiamondResult).type; if (!inferred.isErroneous() && - types.isAssignable(inferred, pt().tag == NONE ? syms.objectType : pt(), Warner.noWarnings)) { + types.isAssignable(inferred, pt().tag == NONE ? syms.objectType : pt(), types.noWarnings)) { String key = types.isSameType(clazztype, inferred) ? "diamond.redundant.args" : "diamond.redundant.args.1"; @@ -2177,7 +2179,7 @@ } //create an environment for attribution of the lambda expression final Env<AttrContext> localEnv = lambdaEnv(that, env); - boolean needsRecovery = resultInfo.checkContext.deferredAttrContext() == deferredAttr.emptyDeferredAttrContext || + boolean needsRecovery = resultInfo.checkContext.deferredAttrContext().mode == DeferredAttr.AttrMode.CHECK; try { List<Type> explicitParamTypes = null; @@ -2444,7 +2446,6 @@ List<Type> argtypes = desc.getParameterTypes(); boolean allowBoxing = - resultInfo.checkContext.deferredAttrContext() == deferredAttr.emptyDeferredAttrContext || resultInfo.checkContext.deferredAttrContext().phase.isBoxingRequired(); Pair<Symbol, Resolve.ReferenceLookupHelper> refResult = rs.resolveMemberReference(that.pos(), localEnv, that, that.expr.type, that.name, argtypes, typeargtypes, allowBoxing); @@ -2479,14 +2480,21 @@ JCDiagnostic diag = diags.create(diagKind, log.currentSource(), that, "invalid.mref", Kinds.kindName(that.getMode()), detailsDiag); - - if (targetError && target != Type.recoveryType) { - resultInfo.checkContext.report(that, diag); - } else if (!targetError) { - log.report(diag); + + if (targetError && target == Type.recoveryType) { + //a target error doesn't make sense during recovery stage + //as we don't know what actual parameter types are + result = that.type = target; + return; + } else { + if (targetError) { + resultInfo.checkContext.report(that, diag); + } else { + log.report(diag); + } + result = that.type = types.createErrorType(target); + return; } - result = that.type = types.createErrorType(target); - return; } if (desc.getReturnType() == Type.recoveryType) { @@ -2551,7 +2559,7 @@ if (returnType.tag != VOID && resType.tag != VOID) { if (resType.isErroneous() || - new LambdaReturnContext(checkContext).compatible(resType, returnType, Warner.noWarnings)) { + new LambdaReturnContext(checkContext).compatible(resType, returnType, types.noWarnings)) { incompatibleReturnType = null; } } @@ -3064,19 +3072,29 @@ Symbol sym, Env<AttrContext> env, ResultInfo resultInfo) { - boolean isPMeth = - resultInfo.pt.tag == FORALL || resultInfo.pt.tag == METHOD; - Type pt = isPMeth && - !site.isErroneous() ? - resultInfo.pt.map(deferredAttr.new DeferredTypeMap(AttrMode.SPECULATIVE, sym, env.info.pendingResolutionPhase)) : - resultInfo.pt; - - DeferredAttr.DeferredTypeMap recoveryMap = - deferredAttr.new RecoveryDeferredTypeMap(AttrMode.CHECK, sym, env.info.pendingResolutionPhase); - + return (resultInfo.pt.tag == FORALL || resultInfo.pt.tag == METHOD) ? + checkMethodId(tree, site, sym, env, resultInfo) : + checkIdInternal(tree, site, sym, resultInfo.pt, env, resultInfo); + } + + Type checkMethodId(JCTree tree, + Type site, + Symbol sym, + Env<AttrContext> env, + ResultInfo resultInfo) { + Type pt = resultInfo.pt.map(deferredAttr.new RecoveryDeferredTypeMap(AttrMode.SPECULATIVE, sym, env.info.pendingResolutionPhase)); + Type owntype = checkIdInternal(tree, site, sym, pt, env, resultInfo); + resultInfo.pt.map(deferredAttr.new RecoveryDeferredTypeMap(AttrMode.CHECK, sym, env.info.pendingResolutionPhase)); + return owntype; + } + + Type checkIdInternal(JCTree tree, + Type site, + Symbol sym, + Type pt, + Env<AttrContext> env, + ResultInfo resultInfo) { if (pt.isErroneous()) { - if (!site.isErroneous() && isPMeth) - Type.map(resultInfo.pt.getParameterTypes(), recoveryMap); return types.createErrorType(site); } Type owntype; // The computed type of this identifier occurrence. @@ -3159,9 +3177,7 @@ resultInfo.pt.getTypeArguments()); break; } - case PCK: case ERR: - if (!site.isErroneous() && isPMeth) - Type.map(resultInfo.pt.getParameterTypes(), recoveryMap); + case PCK: case ERR: owntype = sym.type; break; default:
--- a/src/share/classes/com/sun/tools/javac/comp/Check.java Fri Nov 02 11:45:58 2012 +0000 +++ b/src/share/classes/com/sun/tools/javac/comp/Check.java Sat Nov 03 15:00:22 2012 +0000 @@ -467,8 +467,6 @@ public Infer.InferenceContext inferenceContext(); public DeferredAttr.DeferredAttrContext deferredAttrContext(); - - public boolean allowBoxing(); } /** @@ -503,10 +501,6 @@ public DeferredAttrContext deferredAttrContext() { return enclosingContext.deferredAttrContext(); } - - public boolean allowBoxing() { - return enclosingContext.allowBoxing(); - } } /** @@ -531,10 +525,6 @@ public DeferredAttrContext deferredAttrContext() { return deferredAttr.emptyDeferredAttrContext; } - - public boolean allowBoxing() { - return true; - } }; /** Check that a given type is assignable to a given proto-type. @@ -642,7 +632,7 @@ a = types.upperBound(a); return types.isSubtype(a, bound); } else if (a.isExtendsBound()) { - return types.isCastable(bound, types.upperBound(a), Warner.noWarnings); + return types.isCastable(bound, types.upperBound(a), types.noWarnings); } else if (a.isSuperBound()) { return !types.notSoftSubtype(types.lowerBound(a), bound); } @@ -1887,8 +1877,8 @@ boolean compat = types.isSameType(rt1, rt2) || rt1.tag >= CLASS && rt2.tag >= CLASS && - (types.covariantReturnType(rt1, rt2, Warner.noWarnings) || - types.covariantReturnType(rt2, rt1, Warner.noWarnings)) || + (types.covariantReturnType(rt1, rt2, types.noWarnings) || + types.covariantReturnType(rt2, rt1, types.noWarnings)) || checkCommonOverriderIn(s1,s2,site); if (!compat) { log.error(pos, "types.incompatible.diff.ret", @@ -1932,8 +1922,8 @@ Type rt23 = types.subst(st3.getReturnType(), tvars3, tvars2); boolean compat = rt13.tag >= CLASS && rt23.tag >= CLASS && - (types.covariantReturnType(rt13, rt1, Warner.noWarnings) && - types.covariantReturnType(rt23, rt2, Warner.noWarnings)); + (types.covariantReturnType(rt13, rt1, types.noWarnings) && + types.covariantReturnType(rt23, rt2, types.noWarnings)); if (compat) return true; }
--- a/src/share/classes/com/sun/tools/javac/comp/DeferredAttr.java Fri Nov 02 11:45:58 2012 +0000 +++ b/src/share/classes/com/sun/tools/javac/comp/DeferredAttr.java Sat Nov 03 15:00:22 2012 +0000 @@ -137,19 +137,6 @@ } /** - * Clone a speculative cache entry as a fresh entry associated - * with a new method (this maybe required to fixup speculative cache - * misses after Resolve.access()) - */ - void dupAllTo(Symbol from, Symbol to) { - Assert.check(cache.get(to) == null); - List<Entry> entries = cache.get(from); - if (entries != null) { - cache.put(to, entries); - } - } - - /** * Retrieve a speculative cache entry corresponding to given symbol * and resolution phase */ @@ -417,7 +404,7 @@ /** an empty deferred attribution context - all methods throw exceptions */ final DeferredAttrContext emptyDeferredAttrContext = - new DeferredAttrContext(null, null, null, null) { + new DeferredAttrContext(AttrMode.CHECK, null, MethodResolutionPhase.BOX, null) { @Override void addDeferredAttrNode(DeferredType dt, ResultInfo ri, List<Type> stuckVars) { Assert.error("Empty deferred context!"); @@ -487,7 +474,7 @@ @Override protected Type typeOf(DeferredType dt) { Type owntype = super.typeOf(dt); - return owntype.tag == NONE ? + return owntype == Type.noType ? recover(dt) : owntype; } @@ -505,27 +492,8 @@ */ private Type recover(DeferredType dt) { dt.check(attr.new RecoveryInfo(deferredAttrContext)); - switch (TreeInfo.skipParens(dt.tree).getTag()) { - case LAMBDA: - case REFERENCE: - case CONDEXPR: - fixup(dt, dt); - } return super.apply(dt); } - - void fixup(DeferredType dt, Type type) { - switch (deferredAttrContext.mode) { - case SPECULATIVE: - //fixup speculative cache - dt.speculativeCache.get(deferredAttrContext.msym, - deferredAttrContext.phase).speculativeTree.type = type; - break; - case CHECK: - //fixup tree type - dt.tree.type = type; - } - } } /**
--- a/src/share/classes/com/sun/tools/javac/comp/GraphInfer.java Fri Nov 02 11:45:58 2012 +0000 +++ b/src/share/classes/com/sun/tools/javac/comp/GraphInfer.java Sat Nov 03 15:00:22 2012 +0000 @@ -687,7 +687,7 @@ * depends on the selected solver strategy. */ void solve(SolverStrategy sstrategy) { - checkWithinBounds(inferenceContext, Warner.noWarnings); //initial propagation of bounds + checkWithinBounds(inferenceContext, types.noWarnings); //initial propagation of bounds while (!sstrategy.done()) { List<Type> varsToSolve = sstrategy.pickNode(new AcyclicInferenceGraph()).node_vars; inferenceContext.save(); @@ -713,14 +713,14 @@ } if (!stuck) { try { - checkWithinBounds(inferenceContext, Warner.noWarnings); + checkWithinBounds(inferenceContext, types.noWarnings); } catch (InferenceException ex) { if (exact) { throw ex; } else { inferenceContext.rollback(); instantiateAsUninferredVars(varsToSolve, inferenceContext); - checkWithinBounds(inferenceContext, Warner.noWarnings); + checkWithinBounds(inferenceContext, types.noWarnings); } } break; @@ -729,7 +729,7 @@ if (stuck) { inferenceContext.rollback(); instantiateAsUninferredVars(varsToSolve, inferenceContext); - checkWithinBounds(inferenceContext, Warner.noWarnings); + checkWithinBounds(inferenceContext, types.noWarnings); } } }
--- a/src/share/classes/com/sun/tools/javac/comp/Resolve.java Fri Nov 02 11:45:58 2012 +0000 +++ b/src/share/classes/com/sun/tools/javac/comp/Resolve.java Sat Nov 03 15:00:22 2012 +0000 @@ -814,10 +814,6 @@ public boolean compatible(Type found, Type req, Warner warn) { return types.isSubtypeUnchecked(found, inferenceContext.asFree(req, types), warn); } - - public boolean allowBoxing() { - return false; - } } /** @@ -834,10 +830,6 @@ public boolean compatible(Type found, Type req, Warner warn) { return types.isConvertible(found, inferenceContext.asFree(req, types), warn); } - - public boolean allowBoxing() { - return true; - } } /** @@ -1085,7 +1077,7 @@ Assert.check(sym.kind < AMBIGUOUS); try { Type mt = rawInstantiate(env, site, sym, null, argtypes, typeargtypes, - allowBoxing, useVarargs, Warner.noWarnings); + allowBoxing, useVarargs, types.noWarnings); if (!operator) currentResolutionContext.addApplicableCandidate(sym, mt); } catch (InapplicableMethodException ex) { @@ -1981,28 +1973,31 @@ (typeargtypes == null || !Type.isErroneous(typeargtypes)); } public List<Type> getArgumentTypes(ResolveError errSym, Symbol accessedSym, Name name, List<Type> argtypes) { - if (syms.operatorNames.contains(name)) { - return argtypes; - } else { - Symbol msym = errSym.kind == WRONG_MTH ? - ((InapplicableSymbolError)errSym).errCandidate().sym : accessedSym; - - List<Type> argtypes2 = Type.map(argtypes, - deferredAttr.new RecoveryDeferredTypeMap(AttrMode.SPECULATIVE, msym, currentResolutionContext.firstErroneousResolutionPhase())); - - if (msym != accessedSym) { - //fixup deferred type caches - this 'hack' is required because the symbol - //returned by InapplicableSymbolError.access() will hide the candidate - //method symbol that can be used for lookups in the speculative cache, - //causing problems in Attr.checkId() - for (Type t : argtypes) { - if (t.tag == DEFERRED) { - DeferredType dt = (DeferredType)t; - dt.speculativeCache.dupAllTo(msym, accessedSym); - } + return (syms.operatorNames.contains(name)) ? + argtypes : + Type.map(argtypes, new ResolveDeferredRecoveryMap(accessedSym)); + } + + class ResolveDeferredRecoveryMap extends DeferredAttr.RecoveryDeferredTypeMap { + + public ResolveDeferredRecoveryMap(Symbol msym) { + deferredAttr.super(AttrMode.SPECULATIVE, msym, currentResolutionContext.firstErroneousResolutionPhase()); + } + + @Override + protected Type typeOf(DeferredType dt) { + Type res = super.typeOf(dt); + if (!res.isErroneous()) { + switch (TreeInfo.skipParens(dt.tree).getTag()) { + case LAMBDA: + case REFERENCE: + return dt; + case CONDEXPR: + return res == Type.recoveryType ? + dt : res; } } - return argtypes2; + return res; } } };
--- a/src/share/classes/com/sun/tools/javac/comp/TransTypes.java Fri Nov 02 11:45:58 2012 +0000 +++ b/src/share/classes/com/sun/tools/javac/comp/TransTypes.java Sat Nov 03 15:00:22 2012 +0000 @@ -133,7 +133,7 @@ JCExpression coerce(JCExpression tree, Type target) { Type btarget = target.baseType(); if (tree.type.isPrimitive() == target.isPrimitive()) { - return types.isAssignable(tree.type, btarget, Warner.noWarnings) + return types.isAssignable(tree.type, btarget, types.noWarnings) ? tree : cast(tree, btarget); }
--- a/src/share/classes/com/sun/tools/javac/model/JavacTypes.java Fri Nov 02 11:45:58 2012 +0000 +++ b/src/share/classes/com/sun/tools/javac/model/JavacTypes.java Sat Nov 03 15:00:22 2012 +0000 @@ -97,7 +97,7 @@ public boolean isAssignable(TypeMirror t1, TypeMirror t2) { validateTypeNotIn(t1, EXEC_OR_PKG); validateTypeNotIn(t2, EXEC_OR_PKG); - return types.isAssignable((Type) t1, (Type) t2, Warner.noWarnings); + return types.isAssignable((Type) t1, (Type) t2, types.noWarnings); } public boolean contains(TypeMirror t1, TypeMirror t2) {
--- a/src/share/classes/com/sun/tools/javac/util/Warner.java Fri Nov 02 11:45:58 2012 +0000 +++ b/src/share/classes/com/sun/tools/javac/util/Warner.java Sat Nov 03 15:00:22 2012 +0000 @@ -39,7 +39,6 @@ * deletion without notice.</b> */ public class Warner { - public static final Warner noWarnings = new Warner(); private DiagnosticPosition pos = null; protected boolean warned = false;
--- a/test/tools/javac/lambda/BadRecovery.out Fri Nov 02 11:45:58 2012 +0000 +++ b/test/tools/javac/lambda/BadRecovery.out Sat Nov 03 15:00:22 2012 +0000 @@ -1,2 +1,3 @@ BadRecovery.java:38:9: compiler.err.cant.apply.symbol: kindname.method, m, BadRecovery.SAM1, @1363, kindname.class, BadRecovery, (compiler.misc.no.conforming.assignment.exists: (compiler.misc.incompatible.arg.types.in.lambda)) -1 error +BadRecovery.java:38:77: compiler.err.cant.resolve.location: kindname.variable, f, , , (compiler.misc.location: kindname.class, BadRecovery, null) +2 errors
--- a/test/tools/javac/lambda/Intersection01.java Fri Nov 02 11:45:58 2012 +0000 +++ b/test/tools/javac/lambda/Intersection01.java Sat Nov 03 15:00:22 2012 +0000 @@ -23,7 +23,7 @@ /* * @test - * @summary check that additional interface bounds are thrown away during Attr (temporrary workaround!) + * @summary check that additional interface bounds are thrown away during Attr (temporary workaround!) * @compile/fail/ref=Intersection01.out -XDrawDiagnostics Intersection01.java */ class Intersection01 {