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

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

Issue 2278143003: locateSingleElement improvement for mixins. (Closed)
Patch Set: dartfmt Created 4 years, 4 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/types/flat_type_mask.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 88cd29496623428cd6936bbc33b6a8c04ee625c0..87090deb797ef77020dc2caf090676d0e593a610 100644
--- a/pkg/compiler/lib/src/world.dart
+++ b/pkg/compiler/lib/src/world.dart
@@ -167,6 +167,13 @@ abstract class ClassWorld {
/// of [superclass].
bool hasAnySubclassThatMixes(ClassElement superclass, ClassElement mixin);
+ /// Returns `true` if [cls] or any superclass mixes in [mixin].
+ bool isSubclassOfMixinUseOf(ClassElement cls, ClassElement mixin);
+
+ /// Returns `true` if every subtype of [x] is a subclass of [y] or a subclass
+ /// of a mixin application of [y].
+ bool everySubtypeIsSubclassOfOrMixinUseOf(ClassElement x, ClassElement y);
+
/// Returns `true` if any subclass of [superclass] implements [type].
bool hasAnySubclassThatImplements(ClassElement superclass, ClassElement type);
@@ -504,6 +511,34 @@ class World implements ClassWorld {
return mixinUsesOf(mixin).any((each) => each.isSubclassOf(superclass));
}
+ /// Returns `true` if [cls] or any superclass mixes in [mixin].
+ bool isSubclassOfMixinUseOf(ClassElement cls, ClassElement mixin) {
+ if (isUsedAsMixin(mixin)) {
+ ClassElement current = cls.declaration;
+ mixin = mixin.declaration;
+ while (current != null) {
+ current = current.declaration;
+ if (current.isMixinApplication) {
+ MixinApplicationElement application = current;
+ if (application.mixin.declaration == mixin) return true;
+ }
+ current = current.superclass;
+ }
+ }
+ return false;
+ }
+
+ /// Returns `true` if every subtype of [x] is a subclass of [y] or a subclass
+ /// of a mixin application of [y].
+ bool everySubtypeIsSubclassOfOrMixinUseOf(ClassElement x, ClassElement y) {
+ x = x.declaration;
+ y = y.declaration;
+ Map<ClassElement, bool> secondMap =
+ _subtypeCoveredByCache[x] ??= <ClassElement, bool>{};
+ return secondMap[y] ??= subtypesOf(x).every((ClassElement cls) =>
+ isSubclassOf(cls, y) || isSubclassOfMixinUseOf(cls, y));
+ }
+
/// Returns `true` if any subclass of [superclass] implements [type].
bool hasAnySubclassThatImplements(
ClassElement superclass, ClassElement type) {
@@ -533,6 +568,9 @@ class World implements ClassWorld {
<ClassElement, ClassHierarchyNode>{};
final Map<ClassElement, ClassSet> _classSets = <ClassElement, ClassSet>{};
+ final Map<ClassElement, Map<ClassElement, bool>> _subtypeCoveredByCache =
+ <ClassElement, Map<ClassElement, bool>>{};
+
final Set<Element> sideEffectsFreeElements = new Set<Element>();
final Set<Element> elementsThatCannotThrow = new Set<Element>();
« no previous file with comments | « pkg/compiler/lib/src/types/flat_type_mask.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698