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

Unified Diff: pkg/compiler/lib/src/world.dart

Issue 2582393002: Merge WorldImpl with ResolutionWorldBuilderImpl (Closed)
Patch Set: Updated cf. comment Created 4 years 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: pkg/compiler/lib/src/world.dart
diff --git a/pkg/compiler/lib/src/world.dart b/pkg/compiler/lib/src/world.dart
index 3fe2657eec9cfa636414cc2450d547ceab92c3c3..c25ef03f17ea6d308c2a3957a5698ce39eda1c1d 100644
--- a/pkg/compiler/lib/src/world.dart
+++ b/pkg/compiler/lib/src/world.dart
@@ -4,7 +4,6 @@
library dart2js.world;
-import 'cache_strategy.dart';
import 'closure.dart' show ClosureClassElement, SynthesizedCallMethodElementX;
import 'common/backend_api.dart' show BackendClasses;
import 'common.dart';
@@ -26,8 +25,7 @@ import 'universe/class_set.dart';
import 'universe/function_set.dart' show FunctionSet, FunctionSetBuilder;
import 'universe/selector.dart' show Selector;
import 'universe/side_effects.dart' show SideEffects;
-import 'universe/world_builder.dart'
- show InstantiationInfo, ResolutionWorldBuilder;
+import 'universe/world_builder.dart' show ResolutionWorldBuilder;
import 'util/util.dart' show Link;
/// Common superinterface for [OpenWorld] and [ClosedWorld].
@@ -350,210 +348,6 @@ abstract class OpenWorld implements World {
Iterable<MixinApplicationElement> allMixinUsesOf(ClassElement cls);
}
-class WorldImpl implements OpenWorld {
- bool _closed = false;
- ClosedWorld _closedWorldCache;
-
- final JavaScriptBackend _backend;
- FunctionSetBuilder _allFunctions;
-
- final Set<TypedefElement> _allTypedefs = new Set<TypedefElement>();
-
- final Map<ClassElement, Set<MixinApplicationElement>> _mixinUses =
- new Map<ClassElement, Set<MixinApplicationElement>>();
-
- // We keep track of subtype and subclass relationships in four
- // distinct sets to make class hierarchy analysis faster.
- final Map<ClassElement, ClassHierarchyNode> _classHierarchyNodes =
- <ClassElement, ClassHierarchyNode>{};
- final Map<ClassElement, ClassSet> _classSets = <ClassElement, ClassSet>{};
-
- final Map<ClassElement, Map<ClassElement, bool>> _subtypeCoveredByCache =
- <ClassElement, Map<ClassElement, bool>>{};
-
- final Set<Element> alreadyPopulated;
-
- final CommonElements commonElements;
-
- final CoreTypes coreTypes;
-
- final CacheStrategy cacheStrategy;
-
- final ResolutionWorldBuilder resolverWorld;
-
- bool get isClosed => _closed;
-
- WorldImpl(this.resolverWorld, this._backend, this.commonElements,
- this.coreTypes, CacheStrategy cacheStrategy)
- : this.cacheStrategy = cacheStrategy,
- alreadyPopulated = cacheStrategy.newSet() {
- _allFunctions = new FunctionSetBuilder();
- }
-
- /// Returns an iterable over all mixin applications that mixin [cls].
- Iterable<MixinApplicationElement> allMixinUsesOf(ClassElement cls) {
- Iterable<MixinApplicationElement> uses = _mixinUses[cls];
- return uses != null ? uses : const <MixinApplicationElement>[];
- }
-
- /// 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) => _registerClass(cls);
-
- void _registerClass(ClassElement cls, {bool isDirectlyInstantiated: false}) {
- _ensureClassSet(cls);
- if (isDirectlyInstantiated) {
- _updateClassHierarchyNodeForClass(cls, directlyInstantiated: true);
- }
- }
-
- void registerTypedef(TypedefElement typdef) {
- _allTypedefs.add(typdef);
- }
-
- ClassHierarchyNode _ensureClassHierarchyNode(ClassElement cls) {
- cls = cls.declaration;
- return _classHierarchyNodes.putIfAbsent(cls, () {
- ClassHierarchyNode parentNode;
- if (cls.superclass != null) {
- parentNode = _ensureClassHierarchyNode(cls.superclass);
- }
- return new ClassHierarchyNode(parentNode, cls);
- });
- }
-
- ClassSet _ensureClassSet(ClassElement cls) {
- cls = cls.declaration;
- return _classSets.putIfAbsent(cls, () {
- ClassHierarchyNode node = _ensureClassHierarchyNode(cls);
- ClassSet classSet = new ClassSet(node);
-
- for (InterfaceType type in cls.allSupertypes) {
- // TODO(johnniwinther): Optimization: Avoid adding [cls] to
- // superclasses.
- ClassSet subtypeSet = _ensureClassSet(type.element);
- subtypeSet.addSubtype(node);
- }
- if (cls.isMixinApplication) {
- // TODO(johnniwinther): Store this in the [ClassSet].
- MixinApplicationElement mixinApplication = cls;
- if (mixinApplication.mixin != null) {
- // If [mixinApplication] is malformed [mixin] is `null`.
- registerMixinUse(mixinApplication, mixinApplication.mixin);
- }
- }
-
- return classSet;
- });
- }
-
- void _updateSuperClassHierarchyNodeForClass(ClassHierarchyNode node) {
- // Ensure that classes implicitly implementing `Function` are in its
- // subtype set.
- ClassElement cls = node.cls;
- if (cls != commonElements.functionClass &&
- cls.implementsFunction(commonElements)) {
- ClassSet subtypeSet = _ensureClassSet(commonElements.functionClass);
- subtypeSet.addSubtype(node);
- }
- if (!node.isInstantiated && node.parentNode != null) {
- _updateSuperClassHierarchyNodeForClass(node.parentNode);
- }
- }
-
- void _updateClassHierarchyNodeForClass(ClassElement cls,
- {bool directlyInstantiated: false, bool abstractlyInstantiated: false}) {
- ClassHierarchyNode node = _ensureClassHierarchyNode(cls);
- _updateSuperClassHierarchyNodeForClass(node);
- if (directlyInstantiated) {
- node.isDirectlyInstantiated = true;
- }
- if (abstractlyInstantiated) {
- node.isAbstractlyInstantiated = true;
- }
- }
-
- ClosedWorld closeWorld(DiagnosticReporter reporter) {
- Map<ClassElement, Set<ClassElement>> typesImplementedBySubclasses =
- new Map<ClassElement, Set<ClassElement>>();
-
- /// Updates the `isDirectlyInstantiated` and `isIndirectlyInstantiated`
- /// properties of the [ClassHierarchyNode] for [cls].
-
- void addSubtypes(ClassElement cls, InstantiationInfo info) {
- if (!info.hasInstantiation) {
- return;
- }
- if (cacheStrategy.hasIncrementalSupport && !alreadyPopulated.add(cls)) {
- return;
- }
- assert(cls.isDeclaration);
- if (!cls.isResolved) {
- reporter.internalError(cls, 'Class "${cls.name}" is not resolved.');
- }
-
- _updateClassHierarchyNodeForClass(cls,
- directlyInstantiated: info.isDirectlyInstantiated,
- abstractlyInstantiated: info.isAbstractlyInstantiated);
-
- // Walk through the superclasses, and record the types
- // implemented by that type on the superclasses.
- ClassElement superclass = cls.superclass;
- while (superclass != null) {
- Set<Element> typesImplementedBySubclassesOfCls =
- typesImplementedBySubclasses.putIfAbsent(
- superclass, () => new Set<ClassElement>());
- for (DartType current in cls.allSupertypes) {
- typesImplementedBySubclassesOfCls.add(current.element);
- }
- superclass = superclass.superclass;
- }
- }
-
- // Use the [:seenClasses:] set to include non-instantiated
- // classes: if the superclass of these classes require RTI, then
- // they also need RTI, so that a constructor passes the type
- // variables to the super constructor.
- resolverWorld.forEachInstantiatedClass(addSubtypes);
-
- _closed = true;
- return _closedWorldCache = new ClosedWorldImpl(
- backend: _backend,
- commonElements: commonElements,
- coreTypes: coreTypes,
- resolverWorld: resolverWorld,
- functionSetBuilder: _allFunctions,
- allTypedefs: _allTypedefs,
- mixinUses: _mixinUses,
- typesImplementedBySubclasses: typesImplementedBySubclasses,
- classHierarchyNodes: _classHierarchyNodes,
- classSets: _classSets);
- }
-
- void registerMixinUse(
- MixinApplicationElement mixinApplication, ClassElement mixin) {
- // TODO(johnniwinther): Add map restricted to live classes.
- // We don't support patch classes as mixin.
- assert(mixin.isDeclaration);
- Set<MixinApplicationElement> users =
- _mixinUses.putIfAbsent(mixin, () => new Set<MixinApplicationElement>());
- users.add(mixinApplication);
- }
-
- void registerUsedElement(Element element) {
- if (element.isInstanceMember && !element.isAbstract) {
- _allFunctions.add(element);
- }
- }
-
- ClosedWorld get closedWorldCache {
- assert(isClosed);
- return _closedWorldCache;
- }
-}
-
/// Enum values defining subset of classes included in queries.
enum ClassQuery {
/// Only the class itself is included.
« no previous file with comments | « pkg/compiler/lib/src/universe/world_builder.dart ('k') | tests/compiler/dart2js/kernel/closed_world_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698