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

Unified Diff: pkg/compiler/lib/src/ssa/builder_kernel.dart

Issue 2535323002: Recognise x.==(null) and generate HIdentical (Closed)
Patch Set: format Created 4 years, 1 month 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/ssa/builder_kernel.dart
diff --git a/pkg/compiler/lib/src/ssa/builder_kernel.dart b/pkg/compiler/lib/src/ssa/builder_kernel.dart
index ee9f93058ce963398a0e61edf11342f536ec1127..c05772eb6a5ec7278f612276169e05f60af7e3b5 100644
--- a/pkg/compiler/lib/src/ssa/builder_kernel.dart
+++ b/pkg/compiler/lib/src/ssa/builder_kernel.dart
@@ -1533,6 +1533,9 @@ class KernelSsaBuilder extends ir.Visitor with GraphBuilder {
// TODO(het): Decide when to inline
@override
void visitMethodInvocation(ir.MethodInvocation invocation) {
+ // Handle `x == null` specially. When these come from null-aware operators,
+ // there is no mapping in the astAdapter.
+ if (_handleEqualsNull(invocation)) return;
invocation.receiver.accept(this);
HInstruction receiver = pop();
@@ -1543,6 +1546,27 @@ class KernelSsaBuilder extends ir.Visitor with GraphBuilder {
..addAll(_visitArguments(invocation.arguments)));
}
+ bool _handleEqualsNull(ir.MethodInvocation invocation) {
+ if (invocation.name.name == '==') {
+ ir.Arguments arguments = invocation.arguments;
+ if (arguments.types.isEmpty &&
+ arguments.positional.length == 1 &&
+ arguments.named.isEmpty) {
+ bool finish(ir.Expression comparand) {
+ comparand.accept(this);
+ pushCheckNull(pop());
+ return true;
+ }
+
+ ir.Expression receiver = invocation.receiver;
+ ir.Expression argument = arguments.positional.first;
+ if (argument is ir.NullLiteral) return finish(receiver);
+ if (receiver is ir.NullLiteral) return finish(argument);
+ }
+ }
+ return false;
+ }
+
HInterceptor _interceptorFor(HInstruction intercepted) {
HInterceptor interceptor =
new HInterceptor(intercepted, backend.nonNullType);
« 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