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

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

Issue 2815513006: Compute isSubtype and isSubclass using ClassSet/ClassHierarchyNode (Closed)
Patch Set: 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
« no previous file with comments | « pkg/compiler/lib/src/universe/class_set.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/compiler/lib/src/world.dart
diff --git a/pkg/compiler/lib/src/world.dart b/pkg/compiler/lib/src/world.dart
index 25d9e8199cf586ffec1fe3c0b75bc3231dd65cb1..907ef5743dda447a5bff1dde3db694729b0e1454 100644
--- a/pkg/compiler/lib/src/world.dart
+++ b/pkg/compiler/lib/src/world.dart
@@ -472,6 +472,8 @@ abstract class ClosedWorldBase implements ClosedWorld, ClosedWorldRefiner {
bool _checkClass(ClassEntity cls);
+ bool _checkInvariants(ClassEntity cls, {bool mustBeInstantiated: true});
+
@override
bool isInstantiated(ClassEntity cls) {
assert(_checkClass(cls));
@@ -515,6 +517,21 @@ abstract class ClosedWorldBase implements ClosedWorld, ClosedWorldRefiner {
return _resolverWorld.isImplemented(cls);
}
+ /// Returns `true` if [x] is a subtype of [y], that is, if [x] implements an
+ /// instance of [y].
+ bool isSubtypeOf(ClassEntity x, ClassEntity y) {
+ assert(_checkInvariants(x));
+ assert(_checkInvariants(y, mustBeInstantiated: false));
+ return _classSets[y].hasSubtype(_classHierarchyNodes[x]);
+ }
+
+ /// Return `true` if [x] is a (non-strict) subclass of [y].
+ bool isSubclassOf(ClassEntity x, ClassEntity y) {
+ assert(_checkInvariants(x));
+ assert(_checkInvariants(y));
+ return _classHierarchyNodes[y].hasSubclass(_classHierarchyNodes[x]);
+ }
+
/// Returns an iterable over the directly instantiated classes that extend
/// [cls] possibly including [cls] itself, if it is live.
Iterable<ClassEntity> subclassesOf(ClassEntity cls) {
@@ -927,33 +944,6 @@ class ClosedWorldImpl extends ClosedWorldBase {
;
}
- /// Returns `true` if [x] is a subtype of [y], that is, if [x] implements an
- /// instance of [y].
- bool isSubtypeOf(ClassElement x, ClassElement y) {
- assert(_checkInvariants(x));
- assert(_checkInvariants(y, mustBeInstantiated: false));
-
- if (y == commonElements.objectClass) return true;
- if (x == commonElements.objectClass) return false;
- if (x.asInstanceOf(y) != null) return true;
- if (y != commonElements.functionClass) return false;
- return x.callType != null;
- }
-
- /// Return `true` if [x] is a (non-strict) subclass of [y].
- bool isSubclassOf(ClassElement x, ClassElement y) {
- assert(_checkInvariants(x));
- assert(_checkInvariants(y));
-
- if (y == commonElements.objectClass) return true;
- if (x == commonElements.objectClass) return false;
- while (x != null && x.hierarchyDepth >= y.hierarchyDepth) {
- if (x == y) return true;
- x = x.superclass;
- }
- return false;
- }
-
/// Returns an iterable over the common supertypes of the [classes].
Iterable<ClassElement> commonSupertypesOf(Iterable<ClassElement> classes) {
Iterator<ClassElement> iterator = classes.iterator;
« no previous file with comments | « pkg/compiler/lib/src/universe/class_set.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698