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

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

Issue 1583263007: dart2js cps: Update null checks when updating refinements. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Fix type annotations Created 4 years, 11 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/js_backend/codegen/task.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/update_refinements.dart
diff --git a/pkg/compiler/lib/src/cps_ir/update_refinements.dart b/pkg/compiler/lib/src/cps_ir/update_refinements.dart
index d93e747a9ec589e8774868353bd58b9da72b8b64..48e3242457e27fb3b8c8826e67e1357462ead8ab 100644
--- a/pkg/compiler/lib/src/cps_ir/update_refinements.dart
+++ b/pkg/compiler/lib/src/cps_ir/update_refinements.dart
@@ -20,7 +20,7 @@ class UpdateRefinements extends TrampolineRecursiveVisitor implements Pass {
final TypeMaskSystem typeSystem;
- Map<Primitive, Refinement> refinementFor = <Primitive, Refinement>{};
+ Map<Primitive, Primitive> refinementFor = <Primitive, Primitive>{};
UpdateRefinements(this.typeSystem);
@@ -29,11 +29,33 @@ class UpdateRefinements extends TrampolineRecursiveVisitor implements Pass {
}
Expression traverseLetPrim(LetPrim node) {
+ Expression next = node.body;
visit(node.primitive);
- return node.body;
+ return next;
+ }
+
+ visitNullCheck(NullCheck node) {
+ if (refine(node.value)) {
+ Primitive value = node.value.definition;
+ if (value.type.isNullable) {
+ // Update the type if the input has changed.
+ node.type = value.type.nonNullable();
+ } else {
+ node..replaceUsesWith(value)..destroy();
+ LetPrim letPrim = node.parent;
+ letPrim.remove();
+ return;
+ }
+ }
+ // Use the NullCheck as a refinement.
+ Primitive value = node.effectiveDefinition;
+ Primitive old = refinementFor[value];
+ refinementFor[value] = node;
+ pushAction(() {
+ refinementFor[value] = old;
+ });
}
- @override
visitRefinement(Refinement node) {
if (refine(node.value)) {
// Update the type if the input has changed.
@@ -41,14 +63,13 @@ class UpdateRefinements extends TrampolineRecursiveVisitor implements Pass {
node.refineType);
}
Primitive value = node.effectiveDefinition;
- Refinement old = refinementFor[value];
+ Primitive old = refinementFor[value];
refinementFor[value] = node;
pushAction(() {
refinementFor[value] = old;
});
}
- @override
processReference(Reference ref) {
refine(ref);
}
@@ -56,7 +77,7 @@ class UpdateRefinements extends TrampolineRecursiveVisitor implements Pass {
bool refine(Reference ref) {
Definition def = ref.definition;
if (def is Primitive) {
- Refinement refinement = refinementFor[def.effectiveDefinition];
+ Primitive refinement = refinementFor[def.effectiveDefinition];
if (refinement != null && refinement != ref.definition) {
ref.changeTo(refinement);
return true;
« no previous file with comments | « no previous file | pkg/compiler/lib/src/js_backend/codegen/task.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698