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

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

Issue 1550463002: Better NullCheck for null-or-number (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/inline.dart
diff --git a/pkg/compiler/lib/src/cps_ir/inline.dart b/pkg/compiler/lib/src/cps_ir/inline.dart
index 0e37570cdabce4bf1c96e795819c17ea695ceb4a..c50b56108f04e1c62df49c82fbb30eb64cedb1e1 100644
--- a/pkg/compiler/lib/src/cps_ir/inline.dart
+++ b/pkg/compiler/lib/src/cps_ir/inline.dart
@@ -379,10 +379,8 @@ class InliningVisitor extends TrampolineRecursiveVisitor {
// Add a null check to the inlined function body if necessary. The
// cached function body does not contain the null check.
if (dartReceiver != null && abstractReceiver.isNullable) {
- Primitive check =
- _fragment.letPrim(new NullCheck(dartReceiver.definition,
- invoke.sourceInformation));
- check.type = abstractReceiver.nonNullable();
+ Primitive check = nullReceiverGuard(
+ invoke, _fragment, dartReceiver.definition, abstractReceiver);
if (invoke.callingConvention == CallingConvention.Intercepted) {
arguments[0] = check;
} else {
@@ -455,6 +453,31 @@ class InliningVisitor extends TrampolineRecursiveVisitor {
hint: invoke.hint);
}
+ Primitive nullReceiverGuard(InvocationPrimitive invoke,
+ CpsFragment fragment,
+ Primitive dartReceiver,
+ TypeMask abstractReceiver) {
+ Selector selector = invoke is InvokeMethod ? invoke.selector : null;
Harry Terkelsen 2015/12/28 19:30:41 maybe move inside the "if" since that is the only
+ if (typeSystem.isDefinitelyNum(abstractReceiver, allowNull: true)) {
+ Primitive condition = _fragment.letPrim(
+ new ApplyBuiltinOperator(BuiltinOperator.IsNotNumber,
+ <Primitive>[dartReceiver],
+ invoke.sourceInformation));
+ condition.type = typeSystem.boolType;
+ Primitive check = _fragment.letPrim(
+ new NullCheck.guarded(
+ condition, dartReceiver, selector, invoke.sourceInformation));
+ check.type = abstractReceiver.nonNullable();
+ return check;
+ }
+
+ Primitive check = _fragment.letPrim(
+ new NullCheck(dartReceiver, invoke.sourceInformation));
+ check.type = abstractReceiver.nonNullable();
+ return check;
+ }
+
+
@override
Primitive visitInvokeStatic(InvokeStatic node) {
return tryInlining(node, node.target, null);
« 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