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

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

Issue 12381039: Get rid of HBoundedPotentialPrimitiveString. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 10 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 | « no previous file | tests/compiler/dart2js/type_combination_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sdk/lib/_internal/compiler/implementation/ssa/types.dart
diff --git a/sdk/lib/_internal/compiler/implementation/ssa/types.dart b/sdk/lib/_internal/compiler/implementation/ssa/types.dart
index 46e11eb8e6e3dce0d1252ede78e9b27fe153e12b..974539aff6c28dcfd0fe47fd59a961ae3718aabe 100644
--- a/sdk/lib/_internal/compiler/implementation/ssa/types.dart
+++ b/sdk/lib/_internal/compiler/implementation/ssa/types.dart
@@ -47,8 +47,6 @@ abstract class HType {
} else if (mask.isSubtype) {
if (Elements.isNumberOrStringSupertype(element, compiler)) {
return new HBoundedPotentialPrimitiveNumberOrString(mask);
- } else if (Elements.isStringOnlySupertype(element, compiler)) {
- return new HBoundedPotentialPrimitiveString(mask);
}
}
if (!mask.isExact && (element == compiler.objectClass ||
@@ -722,8 +720,7 @@ class HStringOrNullType extends HPrimitiveOrNullType {
return other;
} else {
HBoundedType boundedType = other;
- return new HBoundedPotentialPrimitiveString(
- boundedType.mask.nullable());
+ return new HBoundedType(boundedType.mask.nullable());
}
}
if (other.isNull()) return HType.STRING_OR_NULL;
@@ -915,8 +912,8 @@ class HBoundedType extends HType {
bool canBeNull() => mask.isNullable;
bool canBePrimitive(Compiler compiler) {
- // TODO(kasperl): Check for string, etc.
- return canBePrimitiveArray(compiler);
+ return canBePrimitiveArray(compiler)
+ || canBePrimitiveString(compiler);
}
bool canBePrimitiveArray(Compiler compiler) {
@@ -925,6 +922,12 @@ class HBoundedType extends HType {
return mask.contains(jsArrayType, compiler);
}
+ bool canBePrimitiveString(Compiler compiler) {
+ JavaScriptBackend backend = compiler.backend;
+ DartType jsStringType = backend.jsStringClass.computeType(compiler);
+ return mask.contains(jsStringType, compiler);
+ }
+
DartType computeType(Compiler compiler) => mask.base;
TypeMask computeMask(Compiler compiler) => mask;
@@ -947,6 +950,15 @@ class HBoundedType extends HType {
if (other.isIndexablePrimitive()) return HType.READABLE_ARRAY;
}
+ if (canBePrimitiveString(compiler)) {
+ if (other.isArray()) return HType.CONFLICTING;
+ if (other.isString()) return HType.STRING;
+ if (other.isStringOrNull()) {
+ return canBeNull() ? HType.STRING_OR_NULL : HType.STRING;
+ }
+ if (other.isIndexablePrimitive()) return HType.STRING;
+ }
+
TypeMask otherMask = other.computeMask(compiler);
if (otherMask != null) {
TypeMask intersection = mask.intersection(otherMask, compiler.types);
@@ -1065,44 +1077,3 @@ class HBoundedPotentialPrimitiveNumberOrString
return super.intersection(other, compiler);
}
}
-
-class HBoundedPotentialPrimitiveString extends HBoundedPotentialPrimitiveType {
- const HBoundedPotentialPrimitiveString(TypeMask mask)
- : super(mask, false);
-
- bool isPrimitiveOrNull() => true;
-
- bool canBePrimitiveString(Compiler compiler) => true;
-
- HType union(HType other, Compiler compiler) {
- if (other.isString()) return this;
- if (other.isStringOrNull()) {
- if (canBeNull()) {
- return this;
- } else {
- return new HBoundedPotentialPrimitiveString(mask.nullable());
- }
- }
- if (other.isNull()) {
- if (canBeNull()) {
- return this;
- } else {
- return new HBoundedPotentialPrimitiveString(mask.nullable());
- }
- }
- // TODO(ngeoffray): implement union types.
- if (other.isIndexablePrimitive()) return HType.UNKNOWN;
- return super.union(other, compiler);
- }
-
- HType intersection(HType other, Compiler compiler) {
- if (other.isConflicting()) return HType.CONFLICTING;
- if (other.isString()) return HType.STRING;
- if (other.isStringOrNull()) {
- return canBeNull() ? HType.STRING_OR_NULL : HType.STRING;
- }
- if (other.isReadableArray()) return HType.CONFLICTING;
- if (other.isIndexablePrimitive()) return HType.STRING;
- return super.intersection(other, compiler);
- }
-}
« no previous file with comments | « no previous file | tests/compiler/dart2js/type_combination_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698