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

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

Issue 1326913003: dart2js cps: Insert refinements for identical(x, null) in condition. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: 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 | 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/insert_refinements.dart
diff --git a/pkg/compiler/lib/src/cps_ir/insert_refinements.dart b/pkg/compiler/lib/src/cps_ir/insert_refinements.dart
index 5b6ce826aba97ffdbdef32d7df9812b43a726e6f..03cafdf3054ef89e8b366d65898f76eeffbcfc10 100644
--- a/pkg/compiler/lib/src/cps_ir/insert_refinements.dart
+++ b/pkg/compiler/lib/src/cps_ir/insert_refinements.dart
@@ -182,25 +182,46 @@ class InsertRefinements extends RecursiveVisitor implements Pass {
}
// If the condition is comparison with a constant, promote the other value.
- if (call is InvokeMethod && call.selector == Selectors.equals) {
- Primitive first = call.arguments[0].definition;
- Primitive second = call.arguments[1].definition;
+ // This can happen either for calls to `==` or `identical` calls, such
+ // as the ones inserted by the unsugaring pass.
+
+ void refineEquality(Primitive first,
+ Primitive second,
+ Continuation trueCont,
+ Continuation falseCont) {
if (second is Constant && second.value.isNull) {
Refinement refinedTrue = new Refinement(first, nullType);
Refinement refinedFalse = new Refinement(first, nonNullType);
pushRefinement(trueCont, refinedTrue);
pushRefinement(falseCont, refinedFalse);
- return;
- }
- if (first is Constant && first.value.isNull) {
+ } else if (first is Constant && first.value.isNull) {
Refinement refinedTrue = new Refinement(second, nullType);
Refinement refinedFalse = new Refinement(second, nonNullType);
pushRefinement(trueCont, refinedTrue);
pushRefinement(falseCont, refinedFalse);
- return;
+ } else {
+ push(trueCont);
+ push(falseCont);
}
}
+ if (call is InvokeMethod && call.selector == Selectors.equals) {
+ refineEquality(call.arguments[0].definition,
+ call.arguments[1].definition,
+ trueCont,
+ falseCont);
+ return;
+ }
+
+ if (condition is ApplyBuiltinOperator &&
+ condition.operator == BuiltinOperator.Identical) {
+ refineEquality(condition.arguments[0].definition,
+ condition.arguments[1].definition,
+ trueCont,
+ falseCont);
+ return;
+ }
+
push(trueCont);
push(falseCont);
}
« 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