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

Side by Side Diff: pkg/compiler/lib/src/ssa/builder.dart

Issue 1051223003: dartj2s: add constructor helpers for map literals with no type parameters. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Added comment. Created 5 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 part of ssa; 5 part of ssa;
6 6
7 class SsaFunctionCompiler implements FunctionCompiler { 7 class SsaFunctionCompiler implements FunctionCompiler {
8 SsaCodeGeneratorTask generator; 8 SsaCodeGeneratorTask generator;
9 SsaBuilderTask builder; 9 SsaBuilderTask builder;
10 SsaOptimizerTask optimizer; 10 SsaOptimizerTask optimizer;
(...skipping 5613 matching lines...) Expand 10 before | Expand all | Expand 10 after
5624 } 5624 }
5625 List<HInstruction> listInputs = <HInstruction>[]; 5625 List<HInstruction> listInputs = <HInstruction>[];
5626 for (Link<ast.Node> link = node.entries.nodes; 5626 for (Link<ast.Node> link = node.entries.nodes;
5627 !link.isEmpty; 5627 !link.isEmpty;
5628 link = link.tail) { 5628 link = link.tail) {
5629 visit(link.head); 5629 visit(link.head);
5630 listInputs.add(pop()); 5630 listInputs.add(pop());
5631 listInputs.add(pop()); 5631 listInputs.add(pop());
5632 } 5632 }
5633 5633
5634 ConstructorElement constructor; 5634 Element constructor;
5635 List<HInstruction> inputs = <HInstruction>[]; 5635 List<HInstruction> inputs = <HInstruction>[];
5636 5636
5637 if (listInputs.isEmpty) { 5637 if (listInputs.isEmpty) {
5638 constructor = backend.mapLiteralConstructorEmpty; 5638 constructor = backend.mapLiteralConstructorEmpty;
5639 } else { 5639 } else {
5640 constructor = backend.mapLiteralConstructor; 5640 constructor = backend.mapLiteralConstructor;
5641 HLiteralList keyValuePairs = buildLiteralList(listInputs); 5641 HLiteralList keyValuePairs = buildLiteralList(listInputs);
5642 add(keyValuePairs); 5642 add(keyValuePairs);
5643 inputs.add(keyValuePairs); 5643 inputs.add(keyValuePairs);
5644 } 5644 }
5645 5645
5646 assert(constructor.isFactoryConstructor); 5646 assert(constructor.isFactoryConstructor);
5647 5647
5648 ConstructorElement functionElement = constructor; 5648 ConstructorElement functionElement = constructor;
5649 constructor = functionElement.effectiveTarget; 5649 constructor = functionElement.effectiveTarget;
5650 5650
5651 InterfaceType type = elements.getType(node); 5651 InterfaceType type = elements.getType(node);
5652 InterfaceType expectedType = 5652 InterfaceType expectedType =
5653 functionElement.computeEffectiveTargetType(type); 5653 functionElement.computeEffectiveTargetType(type);
5654 expectedType = localsHandler.substInContext(expectedType); 5654 expectedType = localsHandler.substInContext(expectedType);
5655 5655
5656 ClassElement cls = constructor.enclosingClass; 5656 ClassElement cls = constructor.enclosingClass;
5657 5657
5658 if (backend.classNeedsRti(cls)) { 5658 if (backend.classNeedsRti(cls)) {
5659 List<HInstruction> typeInputs = <HInstruction>[];
5659 List<DartType> typeVariable = cls.typeVariables; 5660 List<DartType> typeVariable = cls.typeVariables;
5660 expectedType.typeArguments.forEach((DartType argument) { 5661 expectedType.typeArguments.forEach((DartType argument) {
5661 inputs.add(analyzeTypeArgument(argument)); 5662 typeInputs.add(analyzeTypeArgument(argument));
5662 }); 5663 });
5664
5665 // We lift this common call pattern into a helper function to save space
5666 // in the output.
5667 if (typeInputs.every((HInstruction input) => input.isNull())) {
5668 if (listInputs.isEmpty) {
5669 constructor = backend.mapLiteralUntypedEmptyMaker;
5670 } else {
5671 constructor = backend.mapLiteralUntypedMaker;
5672 }
5673 } else {
5674 inputs.addAll(typeInputs);
5675 }
5663 } 5676 }
5664 5677
5678 // If rti is needed and the map literal has no type parameters,
5679 // 'constructor' is a static function that forwards the call to the factory
5680 // constructor without type parameters.
5681 assert(constructor is ConstructorElement || constructor is FunctionElement);
5682
5665 // The instruction type will always be a subtype of the mapLiteralClass, but 5683 // The instruction type will always be a subtype of the mapLiteralClass, but
5666 // type inference might discover a more specific type, or find nothing (in 5684 // type inference might discover a more specific type, or find nothing (in
5667 // dart2js unit tests). 5685 // dart2js unit tests).
5668 TypeMask mapType = 5686 TypeMask mapType =
5669 new TypeMask.nonNullSubtype(backend.mapLiteralClass, compiler.world); 5687 new TypeMask.nonNullSubtype(backend.mapLiteralClass, compiler.world);
5670 TypeMask returnTypeMask = TypeMaskFactory.inferredReturnTypeForElement( 5688 TypeMask returnTypeMask = TypeMaskFactory.inferredReturnTypeForElement(
5671 constructor, compiler); 5689 constructor, compiler);
5672 TypeMask instructionType = 5690 TypeMask instructionType =
5673 mapType.intersection(returnTypeMask, compiler.world); 5691 mapType.intersection(returnTypeMask, compiler.world);
5674 5692
(...skipping 1306 matching lines...) Expand 10 before | Expand all | Expand 10 after
6981 if (unaliased is TypedefType) throw 'unable to unalias $type'; 6999 if (unaliased is TypedefType) throw 'unable to unalias $type';
6982 unaliased.accept(this, builder); 7000 unaliased.accept(this, builder);
6983 } 7001 }
6984 7002
6985 void visitDynamicType(DynamicType type, SsaBuilder builder) { 7003 void visitDynamicType(DynamicType type, SsaBuilder builder) {
6986 JavaScriptBackend backend = builder.compiler.backend; 7004 JavaScriptBackend backend = builder.compiler.backend;
6987 ClassElement cls = backend.findHelper('DynamicRuntimeType'); 7005 ClassElement cls = backend.findHelper('DynamicRuntimeType');
6988 builder.push(new HDynamicType(type, new TypeMask.exact(cls, classWorld))); 7006 builder.push(new HDynamicType(type, new TypeMask.exact(cls, classWorld)));
6989 } 7007 }
6990 } 7008 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/js_backend/backend.dart ('k') | sdk/lib/_internal/compiler/js_lib/collection_patch.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698