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

Unified Diff: pkg/compiler/lib/src/universe/element_world_builder.dart

Issue 2829223003: Check equivalence of closed world based on kernel elements. (Closed)
Patch Set: Updated cf. comments. Created 3 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 side-by-side diff with in-line comments
Download patch
Index: pkg/compiler/lib/src/universe/element_world_builder.dart
diff --git a/pkg/compiler/lib/src/universe/element_world_builder.dart b/pkg/compiler/lib/src/universe/element_world_builder.dart
index 1880a3d3faa90b640d80bcba90c3051f67e0dac6..75ae5c96c8a84775e41d52d73701c546f334ea22 100644
--- a/pkg/compiler/lib/src/universe/element_world_builder.dart
+++ b/pkg/compiler/lib/src/universe/element_world_builder.dart
@@ -106,7 +106,7 @@ class ElementResolutionWorldBuilder extends ResolutionWorldBuilderBase {
///
/// This ensures that class hierarchy queries can be performed on [cls] and
/// classes that extend or implement it.
- void registerClass(ClassEntity cls) => _registerClass(cls);
+ void registerClass(ClassElement cls) => _registerClass(cls.declaration);
void _registerClass(ClassEntity cls, {bool isDirectlyInstantiated: false}) {
_ensureClassSet(cls);
@@ -122,109 +122,38 @@ class ElementResolutionWorldBuilder extends ResolutionWorldBuilderBase {
super._processInstantiatedClassMember(cls, member, memberUsed);
}
- 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, cls.hierarchyDepth);
- });
- }
-
- ClassSet _ensureClassSet(ClassElement cls) {
- cls = cls.declaration;
- return _classSets.putIfAbsent(cls, () {
- ClassHierarchyNode node = _ensureClassHierarchyNode(cls);
- ClassSet classSet = new ClassSet(node);
-
- for (ResolutionInterfaceType 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);
+ @override
+ ClassEntity getAppliedMixin(ClassElement cls) {
+ if (cls.isMixinApplication) {
+ MixinApplicationElement mixinApplication = cls;
+ // Note: If [mixinApplication] is malformed [mixin] is `null`.
+ return mixinApplication.mixin;
}
+ return null;
}
- 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;
- }
- }
+ @override
+ int getHierarchyDepth(ClassElement cls) => cls.hierarchyDepth;
- ClosedWorld closeWorld() {
- Map<ClassEntity, Set<ClassEntity>> typesImplementedBySubclasses =
- new Map<ClassEntity, Set<ClassEntity>>();
+ @override
+ bool checkClass(ClassElement cls) => cls.isDeclaration;
- /// Updates the `isDirectlyInstantiated` and `isIndirectlyInstantiated`
- /// properties of the [ClassHierarchyNode] for [cls].
+ @override
+ bool validateClass(ClassElement cls) => cls.isResolved;
- void addSubtypes(ClassElement cls, InstantiationInfo info) {
- if (!info.hasInstantiation) {
- return;
- }
- assert(cls.isDeclaration);
- if (!cls.isResolved) {
- throw new SpannableAssertionFailure(
- cls, 'Class "${cls.name}" is not resolved.');
- }
+ @override
+ bool implementsFunction(ClassElement cls) =>
+ cls.implementsFunction(_commonElements);
- _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<ClassEntity> typesImplementedBySubclassesOfCls =
- typesImplementedBySubclasses.putIfAbsent(
- superclass, () => new Set<ClassEntity>());
- for (ResolutionInterfaceType current in cls.allSupertypes) {
- typesImplementedBySubclassesOfCls.add(current.element);
- }
- superclass = superclass.superclass;
- }
- }
+ @override
+ ClassEntity getSuperClass(ClassElement cls) => cls.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.
- forEachInstantiatedClass(addSubtypes);
+ @override
+ Iterable<InterfaceType> getSupertypes(ClassElement cls) => cls.allSupertypes;
+ ClosedWorld closeWorld() {
+ Map<ClassEntity, Set<ClassEntity>> typesImplementedBySubclasses =
+ populateHierarchyNodes();
_closed = true;
return _closedWorldCache = new ClosedWorldImpl(
commonElements: _commonElements,
« no previous file with comments | « pkg/compiler/lib/src/kernel/world_builder.dart ('k') | pkg/compiler/lib/src/universe/resolution_world_builder.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698