Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1262)

Unified Diff: pkg/compiler/lib/src/ssa/builder_kernel.dart

Issue 2905623002: Extract type inference queries from KernelAstAdapter to KernelToTypeInferenceMap (Closed)
Patch Set: Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: pkg/compiler/lib/src/ssa/builder_kernel.dart
diff --git a/pkg/compiler/lib/src/ssa/builder_kernel.dart b/pkg/compiler/lib/src/ssa/builder_kernel.dart
index cd8bbc4b89bccc1578d716ac976325a137827f04..2065bd64fc186afc3953643c15c560a1c54773bc 100644
--- a/pkg/compiler/lib/src/ssa/builder_kernel.dart
+++ b/pkg/compiler/lib/src/ssa/builder_kernel.dart
@@ -83,7 +83,8 @@ class KernelSsaBuilder extends ir.Visitor with GraphBuilder {
TreeElements get elements => astAdapter.elements;
SourceInformationBuilder sourceInformationBuilder;
- KernelToElementMap _elementMap;
+ final KernelToElementMap _elementMap;
+ final KernelToTypeInferenceMap _typeInferenceMap;
LoopHandler<ir.Node> loopHandler;
TypeBuilder typeBuilder;
@@ -98,6 +99,7 @@ class KernelSsaBuilder extends ir.Visitor with GraphBuilder {
this.targetElement,
this.compiler,
this._elementMap,
+ this._typeInferenceMap,
this.closedWorld,
this.registry,
// TODO(het): Should sourceInformationBuilder be in GraphBuilder?
@@ -742,7 +744,8 @@ class KernelSsaBuilder extends ir.Visitor with GraphBuilder {
_pushStaticInvocation(
_commonElements.checkDeferredIsLoaded,
[prefixConstant, uriConstant],
- astAdapter.getReturnTypeOf(_commonElements.checkDeferredIsLoaded));
+ _typeInferenceMap
+ .getReturnTypeOf(_commonElements.checkDeferredIsLoaded));
}
@override
@@ -890,7 +893,7 @@ class KernelSsaBuilder extends ir.Visitor with GraphBuilder {
}
// If the expression being iterated over is a JS indexable type, we can
// generate an optimized version of for-in that uses indexing.
- if (astAdapter.isJsIndexableIterator(forInStatement, closedWorld)) {
+ if (_typeInferenceMap.isJsIndexableIterator(forInStatement, closedWorld)) {
_buildForInIndexable(forInStatement);
} else {
_buildForInIterator(forInStatement);
@@ -935,7 +938,7 @@ class KernelSsaBuilder extends ir.Visitor with GraphBuilder {
_pushStaticInvocation(
_commonElements.checkConcurrentModificationError,
[pop(), array],
- astAdapter.getReturnTypeOf(
+ _typeInferenceMap.getReturnTypeOf(
_commonElements.checkConcurrentModificationError));
pop();
}
@@ -969,7 +972,7 @@ class KernelSsaBuilder extends ir.Visitor with GraphBuilder {
// array, as this is stronger than the iterator's `get current` type, for
// example, `get current` includes null.
// TODO(sra): The element type of a container type mask might be better.
- TypeMask type = astAdapter.inferredIndexType(forInStatement);
+ TypeMask type = _typeInferenceMap.inferredIndexType(forInStatement);
HInstruction index = localsHandler.readLocal(indexVariable);
HInstruction value = new HIndex(array, index, null, type);
@@ -1017,7 +1020,7 @@ class KernelSsaBuilder extends ir.Visitor with GraphBuilder {
HInstruction iterator;
void buildInitializer() {
- TypeMask mask = astAdapter.typeOfIterator(forInStatement);
+ TypeMask mask = _typeInferenceMap.typeOfIterator(forInStatement);
forInStatement.iterable.accept(this);
HInstruction receiver = pop();
_pushDynamicInvocation(forInStatement, mask, <HInstruction>[receiver],
@@ -1026,14 +1029,14 @@ class KernelSsaBuilder extends ir.Visitor with GraphBuilder {
}
HInstruction buildCondition() {
- TypeMask mask = astAdapter.typeOfIteratorMoveNext(forInStatement);
+ TypeMask mask = _typeInferenceMap.typeOfIteratorMoveNext(forInStatement);
_pushDynamicInvocation(forInStatement, mask, <HInstruction>[iterator],
selector: Selectors.moveNext);
return popBoolified();
}
void buildBody() {
- TypeMask mask = astAdapter.typeOfIteratorCurrent(forInStatement);
+ TypeMask mask = _typeInferenceMap.typeOfIteratorCurrent(forInStatement);
_pushDynamicInvocation(forInStatement, mask, [iterator],
selector: Selectors.current);
Local loopVariableLocal = astAdapter.getLocal(forInStatement.variable);
@@ -1058,13 +1061,14 @@ class KernelSsaBuilder extends ir.Visitor with GraphBuilder {
_pushStaticInvocation(
_commonElements.streamIteratorConstructor,
[pop(), graph.addConstantNull(closedWorld)],
- astAdapter.getReturnTypeOf(_commonElements.streamIteratorConstructor));
+ _typeInferenceMap
+ .getReturnTypeOf(_commonElements.streamIteratorConstructor));
streamIterator = pop();
void buildInitializer() {}
HInstruction buildCondition() {
- TypeMask mask = astAdapter.typeOfIteratorMoveNext(forInStatement);
+ TypeMask mask = _typeInferenceMap.typeOfIteratorMoveNext(forInStatement);
_pushDynamicInvocation(forInStatement, mask, [streamIterator],
selector: Selectors.moveNext);
HInstruction future = pop();
@@ -1073,7 +1077,7 @@ class KernelSsaBuilder extends ir.Visitor with GraphBuilder {
}
void buildBody() {
- TypeMask mask = astAdapter.typeOfIteratorCurrent(forInStatement);
+ TypeMask mask = _typeInferenceMap.typeOfIteratorCurrent(forInStatement);
_pushDynamicInvocation(forInStatement, mask, [streamIterator],
selector: Selectors.current);
localsHandler.updateLocal(
@@ -1333,7 +1337,7 @@ class KernelSsaBuilder extends ir.Visitor with GraphBuilder {
void generateTypeError(ir.Node node, String message) {
generateError(node, _commonElements.throwTypeError, message,
- astAdapter.getReturnTypeOf(_commonElements.throwTypeError));
+ _typeInferenceMap.getReturnTypeOf(_commonElements.throwTypeError));
}
@override
@@ -1342,7 +1346,7 @@ class KernelSsaBuilder extends ir.Visitor with GraphBuilder {
if (assertStatement.message == null) {
assertStatement.condition.accept(this);
_pushStaticInvocation(_commonElements.assertHelper, <HInstruction>[pop()],
- astAdapter.getReturnTypeOf(_commonElements.assertHelper));
+ _typeInferenceMap.getReturnTypeOf(_commonElements.assertHelper));
pop();
return;
}
@@ -1351,13 +1355,13 @@ class KernelSsaBuilder extends ir.Visitor with GraphBuilder {
void buildCondition() {
assertStatement.condition.accept(this);
_pushStaticInvocation(_commonElements.assertTest, <HInstruction>[pop()],
- astAdapter.getReturnTypeOf(_commonElements.assertTest));
+ _typeInferenceMap.getReturnTypeOf(_commonElements.assertTest));
}
void fail() {
assertStatement.message.accept(this);
_pushStaticInvocation(_commonElements.assertThrow, <HInstruction>[pop()],
- astAdapter.getReturnTypeOf(_commonElements.assertThrow));
+ _typeInferenceMap.getReturnTypeOf(_commonElements.assertThrow));
pop();
}
@@ -1866,8 +1870,8 @@ class KernelSsaBuilder extends ir.Visitor with GraphBuilder {
setListRuntimeTypeInfoIfNeeded(listInstruction, listLiteral);
}
- TypeMask type =
- astAdapter.typeOfListLiteral(targetElement, listLiteral, closedWorld);
+ TypeMask type = _typeInferenceMap.typeOfListLiteral(
+ targetElement, listLiteral, closedWorld);
if (!type.containsAll(closedWorld)) {
listInstruction.instructionType = type;
}
@@ -1982,7 +1986,7 @@ class KernelSsaBuilder extends ir.Visitor with GraphBuilder {
_pushStaticInvocation(
_commonElements.createRuntimeType,
<HInstruction>[pop()],
- astAdapter.getReturnTypeOf(_commonElements.createRuntimeType));
+ _typeInferenceMap.getReturnTypeOf(_commonElements.createRuntimeType));
}
@override
@@ -1992,8 +1996,8 @@ class KernelSsaBuilder extends ir.Visitor with GraphBuilder {
staticTarget.kind == ir.ProcedureKind.Getter) {
FunctionEntity getter = _elementMap.getMember(staticTarget);
// Invoke the getter
- _pushStaticInvocation(
- getter, const <HInstruction>[], astAdapter.getReturnTypeOf(getter));
+ _pushStaticInvocation(getter, const <HInstruction>[],
+ _typeInferenceMap.getReturnTypeOf(getter));
} else if (staticTarget is ir.Field &&
(staticTarget.isConst ||
staticTarget.isFinal && !_isLazyStatic(staticTarget))) {
@@ -2002,10 +2006,11 @@ class KernelSsaBuilder extends ir.Visitor with GraphBuilder {
} else {
if (_isLazyStatic(staticTarget)) {
FieldEntity field = _elementMap.getField(staticTarget);
- push(new HLazyStatic(field, astAdapter.getInferredTypeOf(field)));
+ push(
+ new HLazyStatic(field, _typeInferenceMap.getInferredTypeOf(field)));
} else {
MemberEntity member = _elementMap.getMember(staticTarget);
- push(new HStatic(member, astAdapter.getInferredTypeOf(member)));
+ push(new HStatic(member, _typeInferenceMap.getInferredTypeOf(member)));
}
}
}
@@ -2023,8 +2028,8 @@ class KernelSsaBuilder extends ir.Visitor with GraphBuilder {
if (staticTarget is ir.Procedure) {
FunctionEntity setter = _elementMap.getMember(staticTarget);
// Invoke the setter
- _pushStaticInvocation(
- setter, <HInstruction>[value], astAdapter.getReturnTypeOf(setter));
+ _pushStaticInvocation(setter, <HInstruction>[value],
+ _typeInferenceMap.getReturnTypeOf(setter));
pop();
} else {
add(new HStaticStore(
@@ -2040,8 +2045,8 @@ class KernelSsaBuilder extends ir.Visitor with GraphBuilder {
propertyGet.receiver.accept(this);
HInstruction receiver = pop();
- _pushDynamicInvocation(propertyGet, astAdapter.typeOfGet(propertyGet),
- <HInstruction>[receiver]);
+ _pushDynamicInvocation(propertyGet,
+ _typeInferenceMap.typeOfGet(propertyGet), <HInstruction>[receiver]);
}
@override
@@ -2066,7 +2071,7 @@ class KernelSsaBuilder extends ir.Visitor with GraphBuilder {
_pushDynamicInvocation(
propertySet,
- astAdapter.typeOfSet(propertySet, closedWorld),
+ _typeInferenceMap.typeOfSet(propertySet, closedWorld),
<HInstruction>[receiver, value]);
pop();
@@ -2242,7 +2247,7 @@ class KernelSsaBuilder extends ir.Visitor with GraphBuilder {
return;
}
FunctionEntity function = _elementMap.getMember(target);
- TypeMask typeMask = astAdapter.getReturnTypeOf(function);
+ TypeMask typeMask = _typeInferenceMap.getReturnTypeOf(function);
// TODO(sra): For JS interop external functions, use a different function to
// build arguments.
@@ -2541,7 +2546,7 @@ class KernelSsaBuilder extends ir.Visitor with GraphBuilder {
message: "No NativeBehavior for $invocation"));
TypeMask ssaType =
- astAdapter.typeFromNativeBehavior(nativeBehavior, closedWorld);
+ _typeInferenceMap.typeFromNativeBehavior(nativeBehavior, closedWorld);
push(new HForeignCode(expr, ssaType, const <HInstruction>[],
nativeBehavior: nativeBehavior));
}
@@ -2585,7 +2590,7 @@ class KernelSsaBuilder extends ir.Visitor with GraphBuilder {
message: "No NativeBehavior for $invocation"));
TypeMask ssaType =
- astAdapter.typeFromNativeBehavior(nativeBehavior, closedWorld);
+ _typeInferenceMap.typeFromNativeBehavior(nativeBehavior, closedWorld);
push(new HForeignCode(template, ssaType, inputs,
nativeBehavior: nativeBehavior));
}
@@ -2673,7 +2678,7 @@ class KernelSsaBuilder extends ir.Visitor with GraphBuilder {
}
TypeMask ssaType =
- astAdapter.typeFromNativeBehavior(nativeBehavior, closedWorld);
+ _typeInferenceMap.typeFromNativeBehavior(nativeBehavior, closedWorld);
SourceInformation sourceInformation = null;
push(new HForeignCode(nativeBehavior.codeTemplate, ssaType, inputs,
@@ -2723,7 +2728,7 @@ class KernelSsaBuilder extends ir.Visitor with GraphBuilder {
}
inputs.addAll(arguments);
- TypeMask type = astAdapter.selectorTypeOf(selector, mask);
+ TypeMask type = _typeInferenceMap.selectorTypeOf(selector, mask);
if (selector.isGetter) {
push(new HInvokeDynamicGetter(selector, mask, null, inputs, type));
} else if (selector.isSetter) {
@@ -2784,7 +2789,7 @@ class KernelSsaBuilder extends ir.Visitor with GraphBuilder {
Selector selector = _elementMap.getSelector(invocation);
_pushDynamicInvocation(
invocation,
- astAdapter.typeOfInvocation(invocation, closedWorld),
+ _typeInferenceMap.typeOfInvocation(invocation, closedWorld),
<HInstruction>[receiver]..addAll(
_visitArgumentsForDynamicTarget(selector, invocation.arguments)));
}
@@ -2893,7 +2898,7 @@ class KernelSsaBuilder extends ir.Visitor with GraphBuilder {
TypeMask typeMask;
if (target is FunctionEntity) {
- typeMask = astAdapter.getReturnTypeOf(target);
+ typeMask = _typeInferenceMap.getReturnTypeOf(target);
} else {
typeMask = closedWorld.commonMasks.dynamicType;
}
@@ -3298,7 +3303,7 @@ class TryCatchFinallyBuilder {
kernelBuilder._pushStaticInvocation(
kernelBuilder._commonElements.exceptionUnwrapper,
[exception],
- kernelBuilder.astAdapter
+ kernelBuilder._typeInferenceMap
.getReturnTypeOf(kernelBuilder._commonElements.exceptionUnwrapper));
HInvokeStatic unwrappedException = kernelBuilder.pop();
tryInstruction.exception = exception;
@@ -3323,7 +3328,7 @@ class TryCatchFinallyBuilder {
kernelBuilder._pushStaticInvocation(
kernelBuilder._commonElements.traceFromException,
[exception],
- kernelBuilder.astAdapter.getReturnTypeOf(
+ kernelBuilder._typeInferenceMap.getReturnTypeOf(
kernelBuilder._commonElements.traceFromException));
HInstruction traceInstruction = kernelBuilder.pop();
LocalVariableElement traceVariable =

Powered by Google App Engine
This is Rietveld 408576698