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

Unified Diff: pkg/compiler/lib/src/types/type_mask.dart

Issue 1413613010: Normalize type masks to use the least upper instantiated subclass/type. (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Fix try/poi Created 5 years, 1 month 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/types/flat_type_mask.dart ('k') | pkg/compiler/lib/src/universe/class_set.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/compiler/lib/src/types/type_mask.dart
diff --git a/pkg/compiler/lib/src/types/type_mask.dart b/pkg/compiler/lib/src/types/type_mask.dart
index 2f5754fd880ea1d11a3078ad17afdc385ac7a772..e5c1dc7d41d667c44176b564b3ebb2fd42439549 100644
--- a/pkg/compiler/lib/src/types/type_mask.dart
+++ b/pkg/compiler/lib/src/types/type_mask.dart
@@ -89,7 +89,7 @@ abstract class TypeMask implements ReceiverConstraint {
factory TypeMask.exact(ClassElement base, ClassWorld classWorld) {
assert(invariant(base, classWorld.isInstantiated(base),
message: () => "Cannot create exact type mask for uninstantiated "
- "class $base.\n${classWorld.dump()}"));
+ "class $base.\n${classWorld.dump(base)}"));
return new FlatTypeMask.exact(base);
}
@@ -99,21 +99,31 @@ abstract class TypeMask implements ReceiverConstraint {
}
factory TypeMask.subclass(ClassElement base, ClassWorld classWorld) {
- if (classWorld.hasAnyStrictSubclass(base)) {
- return new FlatTypeMask.subclass(base);
+ assert(invariant(base, classWorld.isInstantiated(base),
+ message: () => "Cannot create subclass type mask for uninstantiated "
+ "class $base.\n${classWorld.dump(base)}"));
+ ClassElement topmost = classWorld.getLubOfInstantiatedSubclasses(base);
+ if (topmost == null) {
+ return new TypeMask.empty();
+ } else if (classWorld.hasAnyStrictSubclass(topmost)) {
+ return new FlatTypeMask.subclass(topmost);
} else {
- return new TypeMask.exactOrEmpty(base, classWorld);
+ return new TypeMask.exact(topmost, classWorld);
}
}
factory TypeMask.subtype(ClassElement base, ClassWorld classWorld) {
- if (classWorld.hasOnlySubclasses(base)) {
- return new TypeMask.subclass(base, classWorld);
+ ClassElement topmost = classWorld.getLubOfInstantiatedSubtypes(base);
+ if (topmost == null) {
+ return new TypeMask.empty();
+ }
+ if (classWorld.hasOnlySubclasses(topmost)) {
+ return new TypeMask.subclass(topmost, classWorld);
}
- if (classWorld.hasAnyStrictSubtype(base)) {
- return new FlatTypeMask.subtype(base);
+ if (classWorld.hasAnyStrictSubtype(topmost)) {
+ return new FlatTypeMask.subtype(topmost);
} else {
- return new TypeMask.exactOrEmpty(base, classWorld);
+ return new TypeMask.exact(topmost, classWorld);
}
}
@@ -121,8 +131,8 @@ abstract class TypeMask implements ReceiverConstraint {
factory TypeMask.nonNullExact(ClassElement base, ClassWorld classWorld) {
assert(invariant(base, classWorld.isInstantiated(base),
- message: () => "Cannot create exact type mask for "
- "uninstantiated class $base.\n${classWorld.dump(base)}"));
+ message: () => "Cannot create exact type mask for uninstantiated "
+ "class $base.\n${classWorld.dump(base)}"));
return new FlatTypeMask.nonNullExact(base);
}
@@ -135,21 +145,31 @@ abstract class TypeMask implements ReceiverConstraint {
}
factory TypeMask.nonNullSubclass(ClassElement base, ClassWorld classWorld) {
- if (classWorld.hasAnyStrictSubclass(base)) {
- return new FlatTypeMask.nonNullSubclass(base);
+ assert(invariant(base, classWorld.isInstantiated(base),
+ message: () => "Cannot create subclass type mask for uninstantiated "
+ "class $base.\n${classWorld.dump(base)}"));
+ ClassElement topmost = classWorld.getLubOfInstantiatedSubclasses(base);
+ if (topmost == null) {
+ return new TypeMask.nonNullEmpty();
+ } else if (classWorld.hasAnyStrictSubclass(topmost)) {
+ return new FlatTypeMask.nonNullSubclass(topmost);
} else {
- return new TypeMask.nonNullExactOrEmpty(base, classWorld);
+ return new TypeMask.nonNullExact(topmost, classWorld);
}
}
factory TypeMask.nonNullSubtype(ClassElement base, ClassWorld classWorld) {
- if (classWorld.hasOnlySubclasses(base)) {
- return new TypeMask.nonNullSubclass(base, classWorld);
+ ClassElement topmost = classWorld.getLubOfInstantiatedSubtypes(base);
+ if (topmost == null) {
+ return new TypeMask.nonNullEmpty();
+ }
+ if (classWorld.hasOnlySubclasses(topmost)) {
+ return new TypeMask.nonNullSubclass(topmost, classWorld);
}
- if (classWorld.hasAnyStrictSubtype(base)) {
- return new FlatTypeMask.nonNullSubtype(base);
+ if (classWorld.hasAnyStrictSubtype(topmost)) {
+ return new FlatTypeMask.nonNullSubtype(topmost);
} else {
- return new TypeMask.nonNullExactOrEmpty(base, classWorld);
+ return new TypeMask.nonNullExact(topmost, classWorld);
}
}
« no previous file with comments | « pkg/compiler/lib/src/types/flat_type_mask.dart ('k') | pkg/compiler/lib/src/universe/class_set.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698