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

Unified Diff: pkg/compiler/lib/src/cps_ir/type_mask_system.dart

Issue 1367353003: dart2js cps_ir: Seed type_propagation with constant bools from inference. (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: value mask can be nullable Created 5 years, 3 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 | pkg/compiler/lib/src/cps_ir/type_propagation.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/compiler/lib/src/cps_ir/type_mask_system.dart
diff --git a/pkg/compiler/lib/src/cps_ir/type_mask_system.dart b/pkg/compiler/lib/src/cps_ir/type_mask_system.dart
index c911b5f6279930e47aa841f36c6fb7180ba4c889..893113f3f7730377908fdefa759a5f3e2c9b1c7e 100644
--- a/pkg/compiler/lib/src/cps_ir/type_mask_system.dart
+++ b/pkg/compiler/lib/src/cps_ir/type_mask_system.dart
@@ -127,6 +127,20 @@ class TypeMaskSystem {
return computeTypeMask(inferrer.compiler, constant);
}
+ // Returns the constant value if a TypeMask represents a single value.
+ // Returns `null` if [mask] is not a constant.
+ ConstantValue getConstantOf(TypeMask mask) {
+ if (!mask.isValue) return null;
+ if (mask.isNullable) return null; // e.g. 'true or null'.
+ ValueTypeMask valueMask = mask;
+ var value = valueMask.value;
+ // TODO(sra): Why is ValueTypeMask.value not a ConstantValue?
+ if (value == false) return new FalseConstantValue();
+ if (value == true) return new TrueConstantValue();
+ // TODO(sra): Consider other values. Be careful with large strings.
+ return null;
+ }
+
TypeMask nonNullExact(ClassElement element) {
// The class world does not know about classes created by
// closure conversion, so just treat those as a subtypes of Function.
« no previous file with comments | « no previous file | pkg/compiler/lib/src/cps_ir/type_propagation.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698