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

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

Issue 1490923003: dart2js: Guard against imprecise inferred types (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Created 5 years 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 | no next file » | 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 1ce00affd97945832f5043139d2df28a86236513..232914493d66747a2b22da72def3c5b8dd6a168a 100644
--- a/pkg/compiler/lib/src/cps_ir/type_mask_system.dart
+++ b/pkg/compiler/lib/src/cps_ir/type_mask_system.dart
@@ -257,16 +257,23 @@ class TypeMaskSystem implements AbstractValueDomain {
void associateConstantValueWithElement(ConstantValue constant,
Element element) {
- if (constant is ListConstantValue) {
- _constantMasks[constant] = inferrer.getGuaranteedTypeOfElement(element);
+ // TODO(25093): Replace this code with an approach that works for anonymous
+ // constants and non-constant literals.
+ if (constant is ListConstantValue || constant is MapConstantValue) {
+ // Inferred type is usually better (e.g. a ContainerTypeMask) but is
+ // occasionally less general.
+ TypeMask computed = computeTypeMask(inferrer.compiler, constant);
+ TypeMask inferred = inferrer.getGuaranteedTypeOfElement(element);
+ TypeMask best = intersection(inferred, computed);
+ assert(!best.isEmpty);
+ _constantMasks[constant] = best;
}
}
@override
TypeMask getTypeOf(ConstantValue constant) {
- TypeMask mask = _constantMasks[constant];
- if (mask != null) return mask;
- return computeTypeMask(inferrer.compiler, constant);
+ return _constantMasks[constant] ??
+ computeTypeMask(inferrer.compiler, constant);
}
@override
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698