mirror of
https://github.com/dart-lang/sdk
synced 2024-09-16 00:39:49 +00:00
Recognise x.==(null) and generate HIdentical
This handles many of the kernel null-aware expansions, which do not map back to Ast nodes. R=efortuna@google.com, sigmund@google.com Review URL: https://codereview.chromium.org/2535323002 .
This commit is contained in:
parent
061cbb170e
commit
9871523b61
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue