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

Unified Diff: pkg/compiler/lib/src/kernel/element_map.dart

Issue 2872833003: Rewrite Constantifier.visitLet (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 | « 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/kernel/element_map.dart
diff --git a/pkg/compiler/lib/src/kernel/element_map.dart b/pkg/compiler/lib/src/kernel/element_map.dart
index da2fb5f80f9f9511f6868783290a3dfc97f1877a..321d88f2147e52bcfde427e4d5d531d83d216e22 100644
--- a/pkg/compiler/lib/src/kernel/element_map.dart
+++ b/pkg/compiler/lib/src/kernel/element_map.dart
@@ -721,22 +721,26 @@ class Constantifier extends ir.ExpressionVisitor<ConstantExpression> {
@override
ConstantExpression visitLet(ir.Let node) {
- if (node.body is ir.ConditionalExpression) {
- ir.ConditionalExpression conditional = node.body;
- if (conditional.condition is ir.MethodInvocation) {
- ir.MethodInvocation methodInvocation = conditional.condition;
- if (methodInvocation.name.name == BinaryOperator.EQ.name &&
- methodInvocation.receiver is ir.VariableGet &&
- methodInvocation.arguments.positional.single is ir.NullLiteral &&
- conditional.otherwise is ir.VariableGet) {
- ir.VariableGet variableGet1 = methodInvocation.receiver;
- ir.VariableGet variableGet2 = conditional.otherwise;
- if (variableGet1.variable == node.variable &&
- variableGet2.variable == node.variable) {
+ ir.Expression body = node.body;
+ if (body is ir.ConditionalExpression) {
+ ir.Expression condition = body.condition;
+ if (condition is ir.MethodInvocation) {
+ ir.Expression receiver = condition.receiver;
+ ir.Expression otherwise = body.otherwise;
+ if (condition.name.name == BinaryOperator.EQ.name &&
+ receiver is ir.VariableGet &&
+ condition.arguments.positional.single is ir.NullLiteral &&
+ otherwise is ir.VariableGet) {
+ if (receiver.variable == node.variable &&
+ otherwise.variable == node.variable) {
// We have <left> ?? <right> encoded as:
// let #1 = <left> in #1 == null ? <right> : #1
ConstantExpression left = visit(node.variable.initializer);
- ConstantExpression right = visit(conditional.then);
+ ConstantExpression right = visit(body.then);
+ // TODO(johnniwinther): Remove [IF_NULL] binary constant expression
+ // when the resolver is removed; then we no longer need the
+ // expressions to be structurally equivalence for equivalence
+ // testing.
return new BinaryConstantExpression(
left, BinaryOperator.IF_NULL, right);
}
« 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