| OLD | NEW |
| 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 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 268 abstract class OpenWorld implements ClassWorld { | 268 abstract class OpenWorld implements ClassWorld { |
| 269 /// Called to add [cls] to the set of known classes. | 269 /// Called to add [cls] to the set of known classes. |
| 270 /// | 270 /// |
| 271 /// This ensures that class hierarchy queries can be performed on [cls] and | 271 /// This ensures that class hierarchy queries can be performed on [cls] and |
| 272 /// classes that extend or implement it. | 272 /// classes that extend or implement it. |
| 273 void registerClass(ClassElement cls); | 273 void registerClass(ClassElement cls); |
| 274 | 274 |
| 275 void registerUsedElement(Element element); | 275 void registerUsedElement(Element element); |
| 276 void registerTypedef(TypedefElement typedef); | 276 void registerTypedef(TypedefElement typedef); |
| 277 | 277 |
| 278 ClosedWorld populate(); | 278 ClosedWorld closeWorld(); |
| 279 | 279 |
| 280 /// Returns an iterable over all mixin applications that mixin [cls]. | 280 /// Returns an iterable over all mixin applications that mixin [cls]. |
| 281 Iterable<MixinApplicationElement> allMixinUsesOf(ClassElement cls); | 281 Iterable<MixinApplicationElement> allMixinUsesOf(ClassElement cls); |
| 282 } | 282 } |
| 283 | 283 |
| 284 class WorldImpl implements ClosedWorld, ClosedWorldRefiner, OpenWorld { | 284 class WorldImpl implements ClosedWorld, ClosedWorldRefiner, OpenWorld { |
| 285 bool _closed = false; |
| 286 |
| 285 /// Cache of [FlatTypeMask]s grouped by the 8 possible values of the | 287 /// Cache of [FlatTypeMask]s grouped by the 8 possible values of the |
| 286 /// `FlatTypeMask.flags` property. | 288 /// `FlatTypeMask.flags` property. |
| 287 List<Map<ClassElement, TypeMask>> canonicalizedTypeMasks = | 289 List<Map<ClassElement, TypeMask>> canonicalizedTypeMasks = |
| 288 new List<Map<ClassElement, TypeMask>>.filled(8, null); | 290 new List<Map<ClassElement, TypeMask>>.filled(8, null); |
| 289 | 291 |
| 290 bool checkInvariants(ClassElement cls, {bool mustBeInstantiated: true}) { | 292 bool checkInvariants(ClassElement cls, {bool mustBeInstantiated: true}) { |
| 291 return invariant(cls, cls.isDeclaration, | 293 return invariant(cls, cls.isDeclaration, |
| 292 message: '$cls must be the declaration.') && | 294 message: '$cls must be the declaration.') && |
| 293 invariant(cls, cls.isResolved, | 295 invariant(cls, cls.isResolved, |
| 294 message: | 296 message: |
| (...skipping 370 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 665 | 667 |
| 666 final Set<Element> sideEffectsFreeElements = new Set<Element>(); | 668 final Set<Element> sideEffectsFreeElements = new Set<Element>(); |
| 667 | 669 |
| 668 final Set<Element> elementsThatCannotThrow = new Set<Element>(); | 670 final Set<Element> elementsThatCannotThrow = new Set<Element>(); |
| 669 | 671 |
| 670 final Set<Element> functionsThatMightBePassedToApply = | 672 final Set<Element> functionsThatMightBePassedToApply = |
| 671 new Set<FunctionElement>(); | 673 new Set<FunctionElement>(); |
| 672 | 674 |
| 673 final Set<Element> alreadyPopulated; | 675 final Set<Element> alreadyPopulated; |
| 674 | 676 |
| 675 bool get isClosed => _compiler.phase > Compiler.PHASE_RESOLVING; | 677 bool get isClosed => _closed; |
| 676 | 678 |
| 677 // Used by selectors. | 679 // Used by selectors. |
| 678 bool isForeign(Element element) { | 680 bool isForeign(Element element) { |
| 679 return backend.isForeign(element); | 681 return backend.isForeign(element); |
| 680 } | 682 } |
| 681 | 683 |
| 682 Set<ClassElement> typesImplementedBySubclassesOf(ClassElement cls) { | 684 Set<ClassElement> typesImplementedBySubclassesOf(ClassElement cls) { |
| 683 return _typesImplementedBySubclasses[cls.declaration]; | 685 return _typesImplementedBySubclasses[cls.declaration]; |
| 684 } | 686 } |
| 685 | 687 |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 785 | 787 |
| 786 void _updateClassHierarchyNodeForClass(ClassElement cls, | 788 void _updateClassHierarchyNodeForClass(ClassElement cls, |
| 787 {bool directlyInstantiated: false}) { | 789 {bool directlyInstantiated: false}) { |
| 788 ClassHierarchyNode node = getClassHierarchyNode(cls); | 790 ClassHierarchyNode node = getClassHierarchyNode(cls); |
| 789 _updateSuperClassHierarchyNodeForClass(node); | 791 _updateSuperClassHierarchyNodeForClass(node); |
| 790 if (directlyInstantiated) { | 792 if (directlyInstantiated) { |
| 791 node.isDirectlyInstantiated = true; | 793 node.isDirectlyInstantiated = true; |
| 792 } | 794 } |
| 793 } | 795 } |
| 794 | 796 |
| 795 ClosedWorld populate() { | 797 ClosedWorld closeWorld() { |
| 796 /// Updates the `isDirectlyInstantiated` and `isIndirectlyInstantiated` | 798 /// Updates the `isDirectlyInstantiated` and `isIndirectlyInstantiated` |
| 797 /// properties of the [ClassHierarchyNode] for [cls]. | 799 /// properties of the [ClassHierarchyNode] for [cls]. |
| 798 | 800 |
| 799 void addSubtypes(ClassElement cls) { | 801 void addSubtypes(ClassElement cls) { |
| 800 if (_compiler.options.hasIncrementalSupport && | 802 if (_compiler.options.hasIncrementalSupport && |
| 801 !alreadyPopulated.add(cls)) { | 803 !alreadyPopulated.add(cls)) { |
| 802 return; | 804 return; |
| 803 } | 805 } |
| 804 assert(cls.isDeclaration); | 806 assert(cls.isDeclaration); |
| 805 if (!cls.isResolved) { | 807 if (!cls.isResolved) { |
| (...skipping 15 matching lines...) Expand all Loading... |
| 821 superclass = superclass.superclass; | 823 superclass = superclass.superclass; |
| 822 } | 824 } |
| 823 } | 825 } |
| 824 | 826 |
| 825 // Use the [:seenClasses:] set to include non-instantiated | 827 // Use the [:seenClasses:] set to include non-instantiated |
| 826 // classes: if the superclass of these classes require RTI, then | 828 // classes: if the superclass of these classes require RTI, then |
| 827 // they also need RTI, so that a constructor passes the type | 829 // they also need RTI, so that a constructor passes the type |
| 828 // variables to the super constructor. | 830 // variables to the super constructor. |
| 829 _compiler.resolverWorld.directlyInstantiatedClasses.forEach(addSubtypes); | 831 _compiler.resolverWorld.directlyInstantiatedClasses.forEach(addSubtypes); |
| 830 | 832 |
| 833 _closed = true; |
| 831 return this; | 834 return this; |
| 832 } | 835 } |
| 833 | 836 |
| 834 @override | 837 @override |
| 835 String dump([ClassElement cls]) { | 838 String dump([ClassElement cls]) { |
| 836 StringBuffer sb = new StringBuffer(); | 839 StringBuffer sb = new StringBuffer(); |
| 837 if (cls != null) { | 840 if (cls != null) { |
| 838 sb.write("Classes in the closed world related to $cls:\n"); | 841 sb.write("Classes in the closed world related to $cls:\n"); |
| 839 } else { | 842 } else { |
| 840 sb.write("Instantiated classes in the closed world:\n"); | 843 sb.write("Instantiated classes in the closed world:\n"); |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 989 return functionsThatMightBePassedToApply.contains(element); | 992 return functionsThatMightBePassedToApply.contains(element); |
| 990 } | 993 } |
| 991 | 994 |
| 992 @override | 995 @override |
| 993 bool getCurrentlyKnownMightBePassedToApply(Element element) { | 996 bool getCurrentlyKnownMightBePassedToApply(Element element) { |
| 994 return getMightBePassedToApply(element); | 997 return getMightBePassedToApply(element); |
| 995 } | 998 } |
| 996 | 999 |
| 997 bool get hasClosedWorldAssumption => !_compiler.options.hasIncrementalSupport; | 1000 bool get hasClosedWorldAssumption => !_compiler.options.hasIncrementalSupport; |
| 998 } | 1001 } |
| OLD | NEW |