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

Side by Side Diff: pkg/compiler/lib/src/world.dart

Issue 2349163003: Move towards using WorldImpact for codegen (Closed)
Patch Set: Cleanup. Created 4 years, 3 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
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 library dart2js.world; 5 library dart2js.world;
6 6
7 import 'closure.dart' show SynthesizedCallMethodElementX; 7 import 'closure.dart' show SynthesizedCallMethodElementX;
8 import 'common/backend_api.dart' show Backend; 8 import 'common/backend_api.dart' show Backend;
9 import 'common.dart'; 9 import 'common.dart';
10 import 'compiler.dart' show Compiler; 10 import 'compiler.dart' show Compiler;
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after
262 abstract class OpenWorld implements ClassWorld { 262 abstract class OpenWorld implements ClassWorld {
263 /// Called to add [cls] to the set of known classes. 263 /// Called to add [cls] to the set of known classes.
264 /// 264 ///
265 /// This ensures that class hierarchy queries can be performed on [cls] and 265 /// This ensures that class hierarchy queries can be performed on [cls] and
266 /// classes that extend or implement it. 266 /// classes that extend or implement it.
267 void registerClass(ClassElement cls); 267 void registerClass(ClassElement cls);
268 268
269 void registerUsedElement(Element element); 269 void registerUsedElement(Element element);
270 void registerTypedef(TypedefElement typedef); 270 void registerTypedef(TypedefElement typedef);
271 271
272 ClosedWorld populate(); 272 ClosedWorld closeWorld();
273 273
274 /// Returns an iterable over all mixin applications that mixin [cls]. 274 /// Returns an iterable over all mixin applications that mixin [cls].
275 Iterable<MixinApplicationElement> allMixinUsesOf(ClassElement cls); 275 Iterable<MixinApplicationElement> allMixinUsesOf(ClassElement cls);
276 } 276 }
277 277
278 class WorldImpl implements ClosedWorld, InferenceWorld, OpenWorld { 278 class WorldImpl implements ClosedWorld, InferenceWorld, OpenWorld {
279 bool _closed = false;
280
279 /// Cache of [FlatTypeMask]s grouped by the 8 possible values of the 281 /// Cache of [FlatTypeMask]s grouped by the 8 possible values of the
280 /// `FlatTypeMask.flags` property. 282 /// `FlatTypeMask.flags` property.
281 List<Map<ClassElement, TypeMask>> canonicalizedTypeMasks = 283 List<Map<ClassElement, TypeMask>> canonicalizedTypeMasks =
282 new List<Map<ClassElement, TypeMask>>.filled(8, null); 284 new List<Map<ClassElement, TypeMask>>.filled(8, null);
283 285
284 bool checkInvariants(ClassElement cls, {bool mustBeInstantiated: true}) { 286 bool checkInvariants(ClassElement cls, {bool mustBeInstantiated: true}) {
285 return invariant(cls, cls.isDeclaration, 287 return invariant(cls, cls.isDeclaration,
286 message: '$cls must be the declaration.') && 288 message: '$cls must be the declaration.') &&
287 invariant(cls, cls.isResolved, 289 invariant(cls, cls.isResolved,
288 message: 290 message:
(...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after
653 655
654 final Set<Element> sideEffectsFreeElements = new Set<Element>(); 656 final Set<Element> sideEffectsFreeElements = new Set<Element>();
655 657
656 final Set<Element> elementsThatCannotThrow = new Set<Element>(); 658 final Set<Element> elementsThatCannotThrow = new Set<Element>();
657 659
658 final Set<Element> functionsThatMightBePassedToApply = 660 final Set<Element> functionsThatMightBePassedToApply =
659 new Set<FunctionElement>(); 661 new Set<FunctionElement>();
660 662
661 final Set<Element> alreadyPopulated; 663 final Set<Element> alreadyPopulated;
662 664
663 bool get isClosed => _compiler.phase > Compiler.PHASE_RESOLVING; 665 bool get isClosed => _closed;
664 666
665 // Used by selectors. 667 // Used by selectors.
666 bool isForeign(Element element) { 668 bool isForeign(Element element) {
667 return backend.isForeign(element); 669 return backend.isForeign(element);
668 } 670 }
669 671
670 Set<ClassElement> typesImplementedBySubclassesOf(ClassElement cls) { 672 Set<ClassElement> typesImplementedBySubclassesOf(ClassElement cls) {
671 return _typesImplementedBySubclasses[cls.declaration]; 673 return _typesImplementedBySubclasses[cls.declaration];
672 } 674 }
673 675
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
773 775
774 void _updateClassHierarchyNodeForClass(ClassElement cls, 776 void _updateClassHierarchyNodeForClass(ClassElement cls,
775 {bool directlyInstantiated: false}) { 777 {bool directlyInstantiated: false}) {
776 ClassHierarchyNode node = getClassHierarchyNode(cls); 778 ClassHierarchyNode node = getClassHierarchyNode(cls);
777 _updateSuperClassHierarchyNodeForClass(node); 779 _updateSuperClassHierarchyNodeForClass(node);
778 if (directlyInstantiated) { 780 if (directlyInstantiated) {
779 node.isDirectlyInstantiated = true; 781 node.isDirectlyInstantiated = true;
780 } 782 }
781 } 783 }
782 784
783 ClosedWorld populate() { 785 ClosedWorld closeWorld() {
784 /// Updates the `isDirectlyInstantiated` and `isIndirectlyInstantiated` 786 /// Updates the `isDirectlyInstantiated` and `isIndirectlyInstantiated`
785 /// properties of the [ClassHierarchyNode] for [cls]. 787 /// properties of the [ClassHierarchyNode] for [cls].
786 788
787 void addSubtypes(ClassElement cls) { 789 void addSubtypes(ClassElement cls) {
788 if (_compiler.options.hasIncrementalSupport && 790 if (_compiler.options.hasIncrementalSupport &&
789 !alreadyPopulated.add(cls)) { 791 !alreadyPopulated.add(cls)) {
790 return; 792 return;
791 } 793 }
792 assert(cls.isDeclaration); 794 assert(cls.isDeclaration);
793 if (!cls.isResolved) { 795 if (!cls.isResolved) {
(...skipping 15 matching lines...) Expand all
809 superclass = superclass.superclass; 811 superclass = superclass.superclass;
810 } 812 }
811 } 813 }
812 814
813 // Use the [:seenClasses:] set to include non-instantiated 815 // Use the [:seenClasses:] set to include non-instantiated
814 // classes: if the superclass of these classes require RTI, then 816 // classes: if the superclass of these classes require RTI, then
815 // they also need RTI, so that a constructor passes the type 817 // they also need RTI, so that a constructor passes the type
816 // variables to the super constructor. 818 // variables to the super constructor.
817 _compiler.resolverWorld.directlyInstantiatedClasses.forEach(addSubtypes); 819 _compiler.resolverWorld.directlyInstantiatedClasses.forEach(addSubtypes);
818 820
821 _closed = true;
819 return this; 822 return this;
820 } 823 }
821 824
822 @override 825 @override
823 String dump([ClassElement cls]) { 826 String dump([ClassElement cls]) {
824 StringBuffer sb = new StringBuffer(); 827 StringBuffer sb = new StringBuffer();
825 if (cls != null) { 828 if (cls != null) {
826 sb.write("Classes in the closed world related to $cls:\n"); 829 sb.write("Classes in the closed world related to $cls:\n");
827 } else { 830 } else {
828 sb.write("Instantiated classes in the closed world:\n"); 831 sb.write("Instantiated classes in the closed world:\n");
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
967 // function expressions's element. 970 // function expressions's element.
968 // TODO(herhut): Generate classes for function expressions earlier. 971 // TODO(herhut): Generate classes for function expressions earlier.
969 if (element is SynthesizedCallMethodElementX) { 972 if (element is SynthesizedCallMethodElementX) {
970 return getMightBePassedToApply(element.expression); 973 return getMightBePassedToApply(element.expression);
971 } 974 }
972 return functionsThatMightBePassedToApply.contains(element); 975 return functionsThatMightBePassedToApply.contains(element);
973 } 976 }
974 977
975 bool get hasClosedWorldAssumption => !_compiler.options.hasIncrementalSupport; 978 bool get hasClosedWorldAssumption => !_compiler.options.hasIncrementalSupport;
976 } 979 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698