Index: pkg/compiler/lib/src/ssa/builder.dart |
diff --git a/pkg/compiler/lib/src/ssa/builder.dart b/pkg/compiler/lib/src/ssa/builder.dart |
index 042ac75d1b569b5cdba7d3af37d1698eca6ad3dd..4f1af1efdf943c47e3bb9197ba47a007b4341c40 100644 |
--- a/pkg/compiler/lib/src/ssa/builder.dart |
+++ b/pkg/compiler/lib/src/ssa/builder.dart |
@@ -377,6 +377,7 @@ class SsaBuilder extends ast.Visitor |
// code-analysis too. |
final CodegenRegistry registry; |
final Compiler compiler; |
+ final GlobalTypeInferenceResults inferenceResults; |
final JavaScriptBackend backend; |
final ConstantSystem constantSystem; |
final RuntimeTypes rti; |
@@ -431,7 +432,8 @@ class SsaBuilder extends ast.Visitor |
this.infoReporter = backend.compiler.dumpInfoTask, |
this.backend = backend, |
this.constantSystem = backend.constantSystem, |
- this.rti = backend.rti { |
+ this.rti = backend.rti, |
+ this.inferenceResults = backend.compiler.globalInference.results { |
assert(target.isImplementation); |
graph.element = target; |
sourceElementStack.add(target); |
@@ -674,7 +676,7 @@ class SsaBuilder extends ast.Visitor |
// A generative constructor body is not seen by global analysis, |
// so we should not query for its type. |
if (!element.isGenerativeConstructorBody) { |
- if (compiler.globalInference.throwsAlways(element)) { |
+ if (inferenceResults.throwsAlways(element)) { |
isReachable = false; |
return false; |
} |
@@ -811,7 +813,7 @@ class SsaBuilder extends ast.Visitor |
// ConstructorBodyElements are not in the type inference graph. |
return false; |
} |
- return compiler.globalInference.isCalledOnce(element); |
+ return inferenceResults.isCalledOnce(element); |
} |
bool isCalledOnce(Element element) { |
@@ -2560,8 +2562,8 @@ class SsaBuilder extends ast.Visitor |
} |
} |
- pushInvokeDynamic( |
- node, elements.getSelector(node), elements.getTypeMask(node), [operand], |
+ pushInvokeDynamic(node, elements.getSelector(node), |
+ inferenceResults.typeOfSend(node, elements), [operand], |
sourceInformation: sourceInformationBuilder.buildGeneric(node)); |
} |
@@ -2588,8 +2590,12 @@ class SsaBuilder extends ast.Visitor |
} |
void handleBinary(ast.Send node, ast.Node left, ast.Node right) { |
- visitBinarySend(visitAndPop(left), visitAndPop(right), |
- elements.getSelector(node), elements.getTypeMask(node), node, |
+ visitBinarySend( |
+ visitAndPop(left), |
+ visitAndPop(right), |
+ elements.getSelector(node), |
+ inferenceResults.typeOfSend(node, elements), |
+ node, |
sourceInformation: |
sourceInformationBuilder.buildGeneric(node.selector)); |
} |
@@ -2749,8 +2755,8 @@ class SsaBuilder extends ast.Visitor |
/// Generate a dynamic getter invocation. |
void generateDynamicGet(ast.Send node) { |
HInstruction receiver = generateInstanceSendReceiver(node); |
- generateInstanceGetterWithCompiledReceiver( |
- node, elements.getSelector(node), elements.getTypeMask(node), receiver); |
+ generateInstanceGetterWithCompiledReceiver(node, elements.getSelector(node), |
+ inferenceResults.typeOfSend(node, elements), receiver); |
} |
/// Generate a closurization of the static or top level [function]. |
@@ -2799,7 +2805,7 @@ class SsaBuilder extends ast.Visitor |
generateInstanceGetterWithCompiledReceiver( |
node, |
elements.getSelector(node), |
- elements.getTypeMask(node), |
+ inferenceResults.typeOfSend(node, elements), |
expression); |
}); |
} |
@@ -2870,9 +2876,7 @@ class SsaBuilder extends ast.Visitor |
if (selector == null) { |
assert(send != null); |
selector = elements.getSelector(send); |
- if (mask == null) { |
- mask = elements.getTypeMask(send); |
- } |
+ mask ??= inferenceResults.typeOfSend(send, elements); |
} |
if (location == null) { |
assert(send != null); |
@@ -3144,7 +3148,7 @@ class SsaBuilder extends ast.Visitor |
void _generateDynamicSend(ast.Send node, HInstruction receiver) { |
Selector selector = elements.getSelector(node); |
- TypeMask mask = elements.getTypeMask(node); |
+ TypeMask mask = inferenceResults.typeOfSend(node, elements); |
SourceInformation sourceInformation = |
sourceInformationBuilder.buildCall(node, node.selector); |
@@ -4031,22 +4035,19 @@ class SsaBuilder extends ast.Visitor |
Elements.isFilledListConstructorCall( |
originalElement, send, compiler)) { |
isFixedList = true; |
- TypeMask inferred = |
- TypeMaskFactory.inferredForNode(sourceElement, send, compiler); |
+ TypeMask inferred = _inferredTypeOfNewList(send); |
return inferred.containsAll(compiler.world) |
? backend.fixedArrayType |
: inferred; |
} else if (isGrowableListConstructorCall) { |
- TypeMask inferred = |
- TypeMaskFactory.inferredForNode(sourceElement, send, compiler); |
+ TypeMask inferred = _inferredTypeOfNewList(send); |
return inferred.containsAll(compiler.world) |
? backend.extendableArrayType |
: inferred; |
} else if (Elements.isConstructorOfTypedArraySubclass( |
originalElement, compiler)) { |
isFixedList = true; |
- TypeMask inferred = |
- TypeMaskFactory.inferredForNode(sourceElement, send, compiler); |
+ TypeMask inferred = _inferredTypeOfNewList(send); |
ClassElement cls = element.enclosingClass; |
assert(backend.isNative(cls.thisType.element)); |
return inferred.containsAll(compiler.world) |
@@ -4178,7 +4179,7 @@ class SsaBuilder extends ast.Visitor |
? native.NativeThrowBehavior.MAY |
: native.NativeThrowBehavior.NEVER); |
push(foreign); |
- if (compiler.globalInference.isFixedArrayCheckedForGrowable(send)) { |
+ if (inferenceResults.isFixedArrayCheckedForGrowable(send)) { |
js.Template code = js.js.parseForeignJS(r'#.fixed$length = Array'); |
// We set the instruction as [canThrow] to avoid it being dead code. |
// We need a finer grained side effect. |
@@ -4923,7 +4924,7 @@ class SsaBuilder extends ast.Visitor |
receiver, |
rhs, |
elements.getOperatorSelectorInComplexSendSet(node), |
- elements.getOperatorTypeMaskInComplexSendSet(node), |
+ inferenceResults.typeOfOperator(node, elements), |
node, |
sourceInformation: |
sourceInformationBuilder.buildGeneric(node.assignmentOperator)); |
@@ -5287,7 +5288,7 @@ class SsaBuilder extends ast.Visitor |
} |
pushInvokeDynamic(node, elements.getGetterSelectorInComplexSendSet(node), |
- elements.getGetterTypeMaskInComplexSendSet(node), [receiver, index]); |
+ inferenceResults.typeOfGetter(node, elements), [receiver, index]); |
HInstruction getterInstruction = pop(); |
if (node.isIfNullAssignment) { |
// Compile x[i] ??= e as: |
@@ -5299,16 +5300,22 @@ class SsaBuilder extends ast.Visitor |
brancher.handleIfNull(() => stack.add(getterInstruction), () { |
visit(arguments.head); |
HInstruction value = pop(); |
- pushInvokeDynamic(node, elements.getSelector(node), |
- elements.getTypeMask(node), [receiver, index, value]); |
+ pushInvokeDynamic( |
+ node, |
+ elements.getSelector(node), |
+ inferenceResults.typeOfSend(node, elements), |
+ [receiver, index, value]); |
pop(); |
stack.add(value); |
}); |
} else { |
handleComplexOperatorSend(node, getterInstruction, arguments); |
HInstruction value = pop(); |
- pushInvokeDynamic(node, elements.getSelector(node), |
- elements.getTypeMask(node), [receiver, index, value]); |
+ pushInvokeDynamic( |
+ node, |
+ elements.getSelector(node), |
+ inferenceResults.typeOfSend(node, elements), |
+ [receiver, index, value]); |
pop(); |
if (node.isPostfix) { |
stack.add(getterInstruction); |
@@ -5512,7 +5519,7 @@ class SsaBuilder extends ast.Visitor |
generateInstanceGetterWithCompiledReceiver( |
node, |
elements.getGetterSelectorInComplexSendSet(node), |
- elements.getGetterTypeMaskInComplexSendSet(node), |
+ inferenceResults.typeOfGetter(node, elements), |
receiver); |
HInstruction getterInstruction = pop(); |
if (node.isIfNullAssignment) { |
@@ -5967,12 +5974,15 @@ class SsaBuilder extends ast.Visitor |
instruction = setRtiIfNeeded(instruction, node); |
} |
- TypeMask type = |
- TypeMaskFactory.inferredForNode(sourceElement, node, compiler); |
+ TypeMask type = _inferredTypeOfNewList(node); |
if (!type.containsAll(compiler.world)) instruction.instructionType = type; |
stack.add(instruction); |
} |
+ _inferredTypeOfNewList(ast.Node node) => |
+ inferenceResults.typeOfNewList(sourceElement, node) ?? |
+ compiler.commonMasks.dynamicType; |
+ |
visitConditional(ast.Conditional node) { |
SsaBranchBuilder brancher = new SsaBranchBuilder(this, compiler, node); |
brancher.handleConditional(() => visit(node.condition), |
@@ -6066,7 +6076,7 @@ class SsaBuilder extends ast.Visitor |
HInstruction buildCondition() { |
Selector selector = Selectors.moveNext; |
- TypeMask mask = elements.getMoveNextTypeMask(node); |
+ TypeMask mask = inferenceResults.typeOfIteratorMoveNext(node, elements); |
pushInvokeDynamic(node, selector, mask, [streamIterator]); |
HInstruction future = pop(); |
push(new HAwait(future, |
@@ -6076,17 +6086,17 @@ class SsaBuilder extends ast.Visitor |
void buildBody() { |
Selector call = Selectors.current; |
- TypeMask callMask = elements.getCurrentTypeMask(node); |
+ TypeMask callMask = |
+ inferenceResults.typeOfIteratorCurrent(node, elements); |
pushInvokeDynamic(node, call, callMask, [streamIterator]); |
ast.Node identifier = node.declaredIdentifier; |
Element variable = elements.getForInVariable(node); |
Selector selector = elements.getSelector(identifier); |
- TypeMask mask = elements.getTypeMask(identifier); |
- |
HInstruction value = pop(); |
if (identifier.asSend() != null && |
Elements.isInstanceSend(identifier, elements)) { |
+ TypeMask mask = inferenceResults.typeOfSend(identifier, elements); |
HInstruction receiver = generateInstanceSendReceiver(identifier); |
assert(receiver != null); |
generateInstanceSetterWithCompiledReceiver(null, receiver, value, |
@@ -6100,7 +6110,6 @@ class SsaBuilder extends ast.Visitor |
} |
void buildUpdate() {} |
- ; |
buildProtectedByFinally(() { |
handleLoop( |
@@ -6124,7 +6133,7 @@ class SsaBuilder extends ast.Visitor |
// method is inlined. We would require full scalar replacement in that |
// case. |
- TypeMask mask = elements.getIteratorTypeMask(node); |
+ TypeMask mask = inferenceResults.typeOfIterator(node, elements); |
ClassWorld classWorld = compiler.world; |
if (mask != null && |
@@ -6149,7 +6158,7 @@ class SsaBuilder extends ast.Visitor |
void buildInitializer() { |
Selector selector = Selectors.iterator; |
- TypeMask mask = elements.getIteratorTypeMask(node); |
+ TypeMask mask = inferenceResults.typeOfIterator(node, elements); |
visit(node.expression); |
HInstruction receiver = pop(); |
pushInvokeDynamic(node, selector, mask, [receiver]); |
@@ -6158,14 +6167,14 @@ class SsaBuilder extends ast.Visitor |
HInstruction buildCondition() { |
Selector selector = Selectors.moveNext; |
- TypeMask mask = elements.getMoveNextTypeMask(node); |
+ TypeMask mask = inferenceResults.typeOfIteratorMoveNext(node, elements); |
pushInvokeDynamic(node, selector, mask, [iterator]); |
return popBoolified(); |
} |
void buildBody() { |
Selector call = Selectors.current; |
- TypeMask mask = elements.getCurrentTypeMask(node); |
+ TypeMask mask = inferenceResults.typeOfIteratorCurrent(node, elements); |
pushInvokeDynamic(node, call, mask, [iterator]); |
buildAssignLoopVariable(node, pop()); |
visit(node.body); |
@@ -6178,10 +6187,10 @@ class SsaBuilder extends ast.Visitor |
ast.Node identifier = node.declaredIdentifier; |
Element variable = elements.getForInVariable(node); |
Selector selector = elements.getSelector(identifier); |
- TypeMask mask = elements.getTypeMask(identifier); |
if (identifier.asSend() != null && |
Elements.isInstanceSend(identifier, elements)) { |
+ TypeMask mask = inferenceResults.typeOfSend(identifier, elements); |
HInstruction receiver = generateInstanceSendReceiver(identifier); |
assert(receiver != null); |
generateInstanceSetterWithCompiledReceiver(null, receiver, value, |