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

Unified Diff: sdk/lib/_internal/compiler/implementation/ssa/builder.dart

Issue 228293008: Redo "Construct literal maps using factory constructor." (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: add constructors to mock libraries for dart2js tests Created 6 years, 8 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: sdk/lib/_internal/compiler/implementation/ssa/builder.dart
diff --git a/sdk/lib/_internal/compiler/implementation/ssa/builder.dart b/sdk/lib/_internal/compiler/implementation/ssa/builder.dart
index 7ee27ee56b56183a0e46fb890bbb59897ebe116f..07f25bc8f9795c5730821acb64583872f861c3f9 100644
--- a/sdk/lib/_internal/compiler/implementation/ssa/builder.dart
+++ b/sdk/lib/_internal/compiler/implementation/ssa/builder.dart
@@ -5039,19 +5039,61 @@ class SsaBuilder extends ResolvedVisitor {
stack.add(addConstant(node));
return;
}
- List<HInstruction> inputs = <HInstruction>[];
+ List<HInstruction> listInputs = <HInstruction>[];
for (Link<ast.Node> link = node.entries.nodes;
!link.isEmpty;
link = link.tail) {
visit(link.head);
- inputs.add(pop());
- inputs.add(pop());
+ listInputs.add(pop());
+ listInputs.add(pop());
+ }
+
+ Element constructor;
+ List<HInstruction> inputs = <HInstruction>[];
+
+ if (listInputs.isEmpty) {
+ constructor = backend.mapLiteralConstructorEmpty;
+ } else {
+ constructor = backend.mapLiteralConstructor;
+ HLiteralList keyValuePairs = buildLiteralList(listInputs);
+ add(keyValuePairs);
+ inputs.add(keyValuePairs);
+ }
+
+ assert(constructor.isFactoryConstructor());
+
+ FunctionElement functionElement = constructor;
+ constructor = functionElement.redirectionTarget;
+
+ InterfaceType type = elements.getType(node);
+ InterfaceType expectedType = functionElement.computeTargetType(type);
+
+ if (constructor.isFactoryConstructor()) {
+ compiler.enqueuer.codegen.registerFactoryWithTypeArguments(elements);
}
- HLiteralList keyValuePairs = buildLiteralList(inputs);
- add(keyValuePairs);
+
+ ClassElement cls = constructor.getEnclosingClass();
+
+ if (backend.classNeedsRti(cls)) {
+ Link<DartType> typeVariable = cls.typeVariables;
+ expectedType.typeArguments.forEach((DartType argument) {
+ inputs.add(analyzeTypeArgument(argument));
+ typeVariable = typeVariable.tail;
+ });
+ assert(typeVariable.isEmpty);
+ }
+
+ // The instruction type will always be a subtype of the mapLiteralClass, but
+ // type inference might discover a more specific type, or find nothing (in
+ // dart2js unit tests).
TypeMask mapType = new TypeMask.nonNullSubtype(backend.mapLiteralClass);
- pushInvokeStatic(node, backend.getMapMaker(), [keyValuePairs], mapType);
- stack.add(setRtiIfNeeded(pop(), node));
+ TypeMask returnTypeMask = TypeMaskFactory.inferredReturnTypeForElement(
+ constructor, compiler);
+ TypeMask instructionType = mapType.intersection(returnTypeMask, compiler);
+
+ addInlinedInstantiation(expectedType);
+ pushInvokeStatic(node, constructor, inputs, instructionType);
+ removeInlinedInstantiation(expectedType);
}
visitLiteralMapEntry(ast.LiteralMapEntry node) {
« no previous file with comments | « sdk/lib/_internal/compiler/implementation/js_backend/backend.dart ('k') | sdk/lib/_internal/lib/collection_patch.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698