Skip to content
Permalink
Browse files
8267317: Remove DeferredTypeCompleter
Reviewed-by: vromero
  • Loading branch information
mcimadamore committed May 25, 2021
1 parent b403d39 commit 86a8f4427139f983faa57b9174c90949628236ca
@@ -36,7 +36,6 @@
import com.sun.tools.javac.comp.DeferredAttr.AttrMode;
import com.sun.tools.javac.comp.DeferredAttr.DeferredAttrContext;
import com.sun.tools.javac.comp.DeferredAttr.DeferredType;
import com.sun.tools.javac.comp.DeferredAttr.DeferredTypeCompleter;
import com.sun.tools.javac.comp.DeferredAttr.LambdaReturnScanner;
import com.sun.tools.javac.comp.DeferredAttr.SwitchExpressionScanner;
import com.sun.tools.javac.comp.Infer.PartiallyInferredMethodType;
@@ -55,7 +54,6 @@
import com.sun.tools.javac.tree.JCTree.JCSwitchExpression;
import com.sun.tools.javac.tree.TreeCopier;
import com.sun.tools.javac.tree.TreeInfo;
import com.sun.tools.javac.util.Assert;
import com.sun.tools.javac.util.Context;
import com.sun.tools.javac.util.DiagnosticSource;
import com.sun.tools.javac.util.JCDiagnostic;
@@ -336,7 +334,7 @@ public void visitNewClass(JCNewClass that) {
* perform an overload check without the need of calling back to Attr. This extra information
* is typically stored in the form of a speculative tree.
*/
abstract class ArgumentType<T extends JCExpression> extends DeferredType implements DeferredTypeCompleter {
abstract class ArgumentType<T extends JCExpression> extends DeferredType {

/** The speculative tree carrying type information. */
T speculativeTree;
@@ -351,24 +349,18 @@ public ArgumentType(JCExpression tree, Env<AttrContext> env, T speculativeTree,
}

@Override
final DeferredTypeCompleter completer() {
return this;
}

@Override
public final Type complete(DeferredType dt, ResultInfo resultInfo, DeferredAttrContext deferredAttrContext) {
Assert.check(dt == this);
public final Type complete(ResultInfo resultInfo, DeferredAttrContext deferredAttrContext) {
if (deferredAttrContext.mode == AttrMode.SPECULATIVE) {
Type t = (resultInfo.pt == Type.recoveryType) ?
deferredAttr.basicCompleter.complete(dt, resultInfo, deferredAttrContext) :
super.complete(resultInfo, deferredAttrContext) :
overloadCheck(resultInfo, deferredAttrContext);
speculativeTypes.put(resultInfo, t);
return t;
} else {
if (!env.info.attributionMode.isSpeculative) {
argumentTypeCache.remove(new UniquePos(dt.tree));
argumentTypeCache.remove(new UniquePos(tree));
}
return deferredAttr.basicCompleter.complete(dt, resultInfo, deferredAttrContext);
return super.complete(resultInfo, deferredAttrContext);
}
}

@@ -306,8 +306,21 @@ JCTree speculativeTree(DeferredAttrContext deferredAttrContext) {
return e != null ? e.speculativeTree : stuckTree;
}

DeferredTypeCompleter completer() {
return basicCompleter;
public Type complete(ResultInfo resultInfo, DeferredAttrContext deferredAttrContext) {
switch (deferredAttrContext.mode) {
case SPECULATIVE:
//Note: if a symbol is imported twice we might do two identical
//speculative rounds...
Assert.check(mode == null || mode == AttrMode.SPECULATIVE);
JCTree speculativeTree = attribSpeculative(tree, env, resultInfo);
speculativeCache.put(speculativeTree, resultInfo);
return speculativeTree.type;
case CHECK:
Assert.check(mode != null);
return attr.attribTree(tree, env, resultInfo);
}
Assert.error();
return null;
}

/**
@@ -327,66 +340,30 @@ Type check(ResultInfo resultInfo) {
} else {
deferredStuckPolicy = new CheckStuckPolicy(resultInfo, this);
}
return check(resultInfo, deferredStuckPolicy, completer());
return check(resultInfo, deferredStuckPolicy);
}

private Type check(ResultInfo resultInfo, DeferredStuckPolicy deferredStuckPolicy,
DeferredTypeCompleter deferredTypeCompleter) {
private Type check(ResultInfo resultInfo, DeferredStuckPolicy deferredStuckPolicy) {
DeferredAttrContext deferredAttrContext =
resultInfo.checkContext.deferredAttrContext();
Assert.check(deferredAttrContext != emptyDeferredAttrContext);
if (deferredStuckPolicy.isStuck()) {
notPertinentToApplicability.add(deferredAttrContext.msym);
deferredAttrContext.addDeferredAttrNode(this, resultInfo, deferredStuckPolicy);
if (deferredAttrContext.mode == AttrMode.SPECULATIVE) {
notPertinentToApplicability.add(deferredAttrContext.msym);
mode = AttrMode.SPECULATIVE;
}
return Type.noType;
} else {
try {
return deferredTypeCompleter.complete(this, resultInfo, deferredAttrContext);
return complete(resultInfo, deferredAttrContext);
} finally {
mode = deferredAttrContext.mode;
}
}
}
}

/**
* A completer for deferred types. Defines an entry point for type-checking
* a deferred type.
*/
interface DeferredTypeCompleter {
/**
* Entry point for type-checking a deferred type. Depending on the
* circumstances, type-checking could amount to full attribution
* or partial structural check (aka potential applicability).
*/
Type complete(DeferredType dt, ResultInfo resultInfo, DeferredAttrContext deferredAttrContext);
}


/**
* A basic completer for deferred types. This completer type-checks a deferred type
* using attribution; depending on the attribution mode, this could be either standard
* or speculative attribution.
*/
DeferredTypeCompleter basicCompleter = new DeferredTypeCompleter() {
public Type complete(DeferredType dt, ResultInfo resultInfo, DeferredAttrContext deferredAttrContext) {
switch (deferredAttrContext.mode) {
case SPECULATIVE:
//Note: if a symbol is imported twice we might do two identical
//speculative rounds...
Assert.check(dt.mode == null || dt.mode == AttrMode.SPECULATIVE);
JCTree speculativeTree = attribSpeculative(dt.tree, dt.env, resultInfo);
dt.speculativeCache.put(speculativeTree, resultInfo);
return speculativeTree.type;
case CHECK:
Assert.check(dt.mode != null);
return attr.attribTree(dt.tree, dt.env, resultInfo);
}
Assert.error();
return null;
}
};

/**
* Policy for detecting stuck expressions. Different criteria might cause
* an expression to be judged as stuck, depending on whether the check
@@ -781,7 +758,7 @@ boolean process(final DeferredAttrContext deferredAttrContext) {
switch (deferredAttrContext.mode) {
case SPECULATIVE:
if (deferredStuckPolicy.isStuck()) {
dt.check(resultInfo, dummyStuckPolicy, new StructuralStuckChecker());
new StructuralStuckChecker().check(dt, resultInfo, deferredAttrContext);
return true;
} else {
Assert.error("Cannot get here");
@@ -813,7 +790,7 @@ public DeferredAttrContext deferredAttrContext() {
"attribution shouldn't be happening here");
ResultInfo instResultInfo =
resultInfo.dup(deferredAttrContext.inferenceContext.asInstType(resultInfo.pt));
dt.check(instResultInfo, dummyStuckPolicy, basicCompleter);
dt.check(instResultInfo, dummyStuckPolicy);
return true;
}
default:
@@ -824,19 +801,18 @@ public DeferredAttrContext deferredAttrContext() {
/**
* Structural checker for stuck expressions
*/
class StructuralStuckChecker extends TreeScanner implements DeferredTypeCompleter {
class StructuralStuckChecker extends TreeScanner {

ResultInfo resultInfo;
InferenceContext inferenceContext;
Env<AttrContext> env;

public Type complete(DeferredType dt, ResultInfo resultInfo, DeferredAttrContext deferredAttrContext) {
public void check(DeferredType dt, ResultInfo resultInfo, DeferredAttrContext deferredAttrContext) {
this.resultInfo = resultInfo;
this.inferenceContext = deferredAttrContext.inferenceContext;
this.env = dt.env;
dt.tree.accept(this);
dt.speculativeCache.put(stuckTree, resultInfo);
return Type.noType;
}

@Override

1 comment on commit 86a8f44

@openjdk-notifier

This comment has been minimized.

Copy link

@openjdk-notifier openjdk-notifier bot commented on 86a8f44 May 25, 2021

Please sign in to comment.