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

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

Issue 2898083002: dart2js kernel: generate `other==null` header for operator== methods (Closed)
Patch Set: Created 3 years, 7 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 | « pkg/compiler/lib/src/js_backend/backend.dart ('k') | 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 0f94d7f155e0a0d0bf1438c275cf01b17abadd71..38902b25916dca1981ad4ca16f8abd3ba0f9c413 100644
--- a/pkg/compiler/lib/src/ssa/builder_kernel.dart
+++ b/pkg/compiler/lib/src/ssa/builder_kernel.dart
@@ -648,11 +648,37 @@ class KernelSsaBuilder extends ir.Visitor with GraphBuilder {
/// Procedures.
void buildFunctionNode(ir.FunctionNode functionNode) {
openFunction();
- if (functionNode.parent is ir.Procedure &&
- (functionNode.parent as ir.Procedure).kind ==
- ir.ProcedureKind.Factory) {
+ ir.TreeNode parent = functionNode.parent;
+ if (parent is ir.Procedure && parent.kind == ir.ProcedureKind.Factory) {
_addClassTypeVariablesIfNeeded(functionNode.parent);
}
+
+ // If [functionNode] is `operator==` we explicitly add a null check at the
+ // beginning of the method. This is to avoid having call sites do the null
+ // check.
+ if (parent is ir.Procedure &&
+ parent.kind == ir.ProcedureKind.Operator &&
+ parent.name.name == '==') {
+ if (!backend
+ .operatorEqHandlesNullArgument(astAdapter.getMethod(parent))) {
+ handleIf(
+ visitCondition: () {
+ HParameterValue parameter = parameters.values.first;
+ push(new HIdentity(parameter, graph.addConstantNull(closedWorld),
+ null, commonMasks.boolType));
+ },
+ visitThen: () {
+ closeAndGotoExit(new HReturn(
+ graph.addConstantBool(false, closedWorld),
+ sourceInformationBuilder
+ .buildImplicitReturn(astAdapter.getElement(parent))));
+ },
+ visitElse: null,
+ // TODO(27394): Add sourceInformation via
+ // `sourceInformationBuilder.buildIf(?)`.
+ );
+ }
+ }
functionNode.body.accept(this);
closeFunction();
}
« no previous file with comments | « pkg/compiler/lib/src/js_backend/backend.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698