Remove special casing of == null

This avoid reversing the operands for `null == x`
- and make Hello World! fully equivalent.

R=sigmund@google.com

Review-Url: https://codereview.chromium.org/2954123002 .
This commit is contained in:
Johnni Winther
2017-06-26 12:47:14 +02:00
parent 52f1f25d34
commit ecb5767bba
3 changed files with 13 additions and 31 deletions
@@ -719,12 +719,6 @@ class KernelSsaGraphBuilder extends ir.Visitor
graph.finalize();
}
/// Pushes a boolean checking [expression] against null.
pushCheckNull(HInstruction expression) {
push(new HIdentity(expression, graph.addConstantNull(closedWorld), null,
commonMasks.boolType));
}
@override
void defaultExpression(ir.Expression expression) {
// TODO(het): This is only to get tests working.
@@ -2888,9 +2882,6 @@ class KernelSsaGraphBuilder extends ir.Visitor
// 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();
Selector selector = _elementMap.getSelector(invocation);
@@ -2901,27 +2892,6 @@ class KernelSsaGraphBuilder extends ir.Visitor
_visitArgumentsForDynamicTarget(selector, 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, commonMasks.nonNullType);
@@ -580,7 +580,12 @@ class KernelAstTypeInferenceMap implements KernelToTypeInferenceMap {
if (send.name.name == '[]=') {
return closedWorld.commonMasks.dynamicType;
}
return _resultOf(_target).typeOfSend(_astAdapter.getNode(send));
ast.Node node = _astAdapter.getNodeOrNull(send);
if (node == null) {
assert(send.name.name == '==');
return closedWorld.commonMasks.dynamicType;
}
return _resultOf(_target).typeOfSend(node);
}
TypeMask typeOfGet(ir.PropertyGet getter) {
@@ -49,10 +49,17 @@ main() {
new Class('');
Class.staticField;
var x = null;
var y1 = x == null;
var y2 = null == x;
var z1 = x?.toString();
var z2 = x ?? y1;
var z3 = x ??= y2;
var w = x == null ? null : x.toString();
for (int i = 0; i < 10; i++) {
x = i;
if (i == 5) break;
}
print(x);
return x;
}
'''