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

Unified Diff: sdk/lib/_internal/compiler/implementation/types/forwarding_type_mask.dart

Issue 17017003: Introduce an ElementTypeMask to recognize simple constraints like "the type of parameter foo is the… (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 6 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: sdk/lib/_internal/compiler/implementation/types/forwarding_type_mask.dart
===================================================================
--- sdk/lib/_internal/compiler/implementation/types/forwarding_type_mask.dart (revision 24092)
+++ sdk/lib/_internal/compiler/implementation/types/forwarding_type_mask.dart (working copy)
@@ -4,135 +4,101 @@
part of types;
-/// A holder for an element type. We define a special class for it so
-/// that nullable ContainerTypeMask and non-nullable ContainerTypeMask
-/// share the same [ElementTypeHolder].
-class ElementTypeHolder {
- // This field will be set after global analysis.
- TypeMask elementType;
-}
+/**
+ * A type mask that wraps an other one, and delecate all its
+ * implementation methods to it.
+ */
+abstract class ForwardingTypeMask implements TypeMask {
-/// A [ContainerTypeMask] is a [TypeMask] for a specific allocation
-/// site of a container (currently only List) that will get specialized
-/// once the [ListTracer] phase finds an element type for it.
-class ContainerTypeMask implements TypeMask {
+ TypeMask get forwardTo;
- // The flat version of a [ContainerTypeMask] is the container type
- // (for example List).
- final FlatTypeMask asFlat;
+ ForwardingTypeMask();
- // The [Node] where this type mask was created.
- final Node allocationNode;
+ bool get isEmpty => forwardTo.isEmpty;
+ bool get isNullable => forwardTo.isNullable;
+ bool get isExact => forwardTo.isExact;
- // The [Element] where this type mask was created.
- final Element allocationElement;
+ bool get isUnion => false;
+ bool get isContainer => false;
+ bool get isForwarding => true;
+ bool get isElement => false;
- // A holder for the element type. Shared between all
- // [ContainerTypeMask] for the same node.
- final ElementTypeHolder holder;
+ bool containsOnlyInt(Compiler compiler) {
+ return forwardTo.containsOnlyInt(compiler);
+ }
- TypeMask get elementType => holder.elementType;
- void set elementType(TypeMask mask) {
- holder.elementType = mask;
+ bool containsOnlyDouble(Compiler compiler) {
+ return forwardTo.containsOnlyDouble(compiler);
}
- ContainerTypeMask(this.asFlat,
- this.allocationNode,
- this.allocationElement,
- [holder])
- : this.holder = (holder == null) ? new ElementTypeHolder() : holder;
+ bool containsOnlyNum(Compiler compiler) {
+ return forwardTo.containsOnlyNum(compiler);
+ }
- TypeMask nullable() {
- return isNullable
- ? this
- : new ContainerTypeMask(asFlat.nullable(),
- allocationNode,
- allocationElement,
- holder);
+ bool containsOnlyNull(Compiler compiler) {
+ return forwardTo.containsOnlyNull(compiler);
}
- TypeMask nonNullable() {
- return isNullable
- ? new ContainerTypeMask(asFlat.nonNullable(),
- allocationNode,
- allocationElement,
- holder)
- : this;
+ bool containsOnlyBool(Compiler compiler) {
+ return forwardTo.containsOnlyBool(compiler);
}
- TypeMask simplify(Compiler compiler) => this;
+ bool containsOnlyString(Compiler compiler) {
+ return forwardTo.containsOnlyString(compiler);
+ }
- bool get isEmpty => false;
- bool get isNullable => asFlat.isNullable;
- bool get isExact => true;
- bool get isUnion => false;
- bool get isContainer => true;
-
- bool containsOnlyInt(Compiler compiler) => false;
- bool containsOnlyDouble(Compiler compiler) => false;
- bool containsOnlyNum(Compiler compiler) => false;
- bool containsOnlyNull(Compiler compiler) => false;
- bool containsOnlyBool(Compiler compiler) => false;
- bool containsOnlyString(Compiler compiler) => false;
bool containsOnly(ClassElement element) {
- return asFlat.containsOnly(element);
+ return forwardTo.containsOnly(element);
}
bool satisfies(ClassElement cls, Compiler compiler) {
- return asFlat.satisfies(cls, compiler);
+ return forwardTo.satisfies(cls, compiler);
}
bool contains(DartType type, Compiler compiler) {
- return asFlat.contains(type, compiler);
+ return forwardTo.contains(type, compiler);
}
- bool containsAll(Compiler compiler) => false;
+ bool containsAll(Compiler compiler) {
+ return forwardTo.containsAll(compiler);
+ }
ClassElement singleClass(Compiler compiler) {
- return asFlat.singleClass(compiler);
+ return forwardTo.singleClass(compiler);
}
Iterable<ClassElement> containedClasses(Compiler compiler) {
- return asFlat.containedClasses(compiler);
+ return forwardTo.containedClasses(compiler);
}
TypeMask union(other, Compiler compiler) {
- if (other.isContainer
- && other.allocationNode == this.allocationNode) {
+ if (this == other) {
+ return this;
+ } else if (equalsDisregardNull(other)) {
return other.isNullable ? other : this;
} else if (other.isEmpty) {
return other.isNullable ? this.nullable() : this;
}
- return asFlat.union(other, compiler);
+ return forwardTo.union(other, compiler);
}
TypeMask intersection(TypeMask other, Compiler compiler) {
- TypeMask flatIntersection = asFlat.intersection(other, compiler);
- if (flatIntersection.isEmpty) return flatIntersection;
- return flatIntersection.isNullable
- ? nullable()
- : nonNullable();
+ return forwardTo.intersection(other, compiler);
}
bool willHit(Selector selector, Compiler compiler) {
- return asFlat.willHit(selector, compiler);
+ return forwardTo.willHit(selector, compiler);
}
bool canHit(Element element, Selector selector, Compiler compiler) {
- return asFlat.canHit(element, selector, compiler);
+ return forwardTo.canHit(element, selector, compiler);
}
Element locateSingleElement(Selector selector, Compiler compiler) {
- return asFlat.locateSingleElement(selector, compiler);
+ return forwardTo.locateSingleElement(selector, compiler);
}
- bool operator==(other) {
- if (other is! ContainerTypeMask) return false;
- return allocationNode == other.allocationNode
- && isNullable == other.isNullable;
- }
+ TypeMask simplify(Compiler compiler) => forwardTo.simplify(compiler);
- String toString() {
- return 'Container mask: $elementType';
- }
+ bool equalsDisregardNull(other);
}

Powered by Google App Engine
This is Rietveld 408576698