Index: pkg/compiler/lib/src/world.dart |
diff --git a/pkg/compiler/lib/src/world.dart b/pkg/compiler/lib/src/world.dart |
index 1d684ee2f1b434cb0b36e37b46060b756ee610eb..35676fd32efd9ec167996638a8538267ec20c706 100644 |
--- a/pkg/compiler/lib/src/world.dart |
+++ b/pkg/compiler/lib/src/world.dart |
@@ -171,6 +171,17 @@ abstract class ClassWorld { |
/// This method is only provided for testing. For queries on classes, use the |
/// methods defined in [ClassWorld]. |
ClassHierarchyNode getClassHierarchyNode(ClassElement cls); |
+ |
+ /// Returns [ClassSet] for [cls] used to model the extends and implements |
+ /// relations of known classes. |
+ /// |
+ /// This method is only provided for testing. For queries on classes, use the |
+ /// methods defined in [ClassWorld]. |
+ ClassSet getClassSet(ClassElement cls); |
+ |
+ // TODO(johnniwinther): Find a better strategy for caching these. |
+ @deprecated |
+ List<Map<ClassElement, TypeMask>> get canonicalizedTypeMasks; |
} |
abstract class ClosedWorld extends ClassWorld { |
@@ -248,7 +259,23 @@ abstract class InferenceWorld { |
void registerClosureClass(ClassElement cls); |
} |
-class World implements ClosedWorld, InferenceWorld { |
+abstract class OpenWorld implements ClassWorld { |
+ /// Called to add [cls] to the set of known classes. |
+ /// |
+ /// This ensures that class hierarchy queries can be performed on [cls] and |
+ /// classes that extend or implement it. |
+ void registerClass(ClassElement cls); |
+ |
+ void registerUsedElement(Element element); |
+ void registerTypedef(TypedefElement typedef); |
+ |
+ ClosedWorld populate(); |
+ |
+ /// Returns an iterable over all mixin applications that mixin [cls]. |
+ Iterable<MixinApplicationElement> allMixinUsesOf(ClassElement cls); |
+} |
+ |
+class WorldImpl implements ClosedWorld, InferenceWorld, OpenWorld { |
/// Cache of [FlatTypeMask]s grouped by the 8 possible values of the |
/// `FlatTypeMask.flags` property. |
List<Map<ClassElement, TypeMask>> canonicalizedTypeMasks = |
@@ -606,7 +633,7 @@ class World implements ClosedWorld, InferenceWorld { |
final Set<Element> functionsCalledInLoop = new Set<Element>(); |
final Map<Element, SideEffects> sideEffects = new Map<Element, SideEffects>(); |
- final Set<TypedefElement> allTypedefs = new Set<TypedefElement>(); |
+ final Set<TypedefElement> _allTypedefs = new Set<TypedefElement>(); |
final Map<ClassElement, Set<MixinApplicationElement>> _mixinUses = |
new Map<ClassElement, Set<MixinApplicationElement>>(); |
@@ -644,7 +671,7 @@ class World implements ClosedWorld, InferenceWorld { |
return _typesImplementedBySubclasses[cls.declaration]; |
} |
- World(Compiler compiler) |
+ WorldImpl(Compiler compiler) |
: allFunctions = new FunctionSet(compiler), |
this._compiler = compiler, |
alreadyPopulated = compiler.cacheStrategy.newSet(); |
@@ -670,6 +697,12 @@ class World implements ClosedWorld, InferenceWorld { |
} |
} |
+ void registerTypedef(TypedefElement typdef) { |
+ _allTypedefs.add(typdef); |
+ } |
+ |
+ Iterable<TypedefElement> get allTypedefs => _allTypedefs; |
+ |
/// Returns [ClassHierarchyNode] for [cls] used to model the class hierarchies |
/// of known classes. |
/// |
@@ -747,7 +780,7 @@ class World implements ClosedWorld, InferenceWorld { |
} |
} |
- void populate() { |
+ ClosedWorld populate() { |
/// Updates the `isDirectlyInstantiated` and `isIndirectlyInstantiated` |
/// properties of the [ClassHierarchyNode] for [cls]. |
@@ -782,6 +815,8 @@ class World implements ClosedWorld, InferenceWorld { |
// they also need RTI, so that a constructor passes the type |
// variables to the super constructor. |
_compiler.resolverWorld.directlyInstantiatedClasses.forEach(addSubtypes); |
+ |
+ return this; |
} |
@override |