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

Side by Side Diff: pkg/compiler/lib/src/kernel/ir_element_map.dart

Issue 2866463005: Handle ?? in Constantifier (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 unified diff | Download patch
« no previous file with comments | « no previous file | tests/compiler/dart2js/kernel/impact_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 import 'package:kernel/ast.dart' as ir; 5 import 'package:kernel/ast.dart' as ir;
6 6
7 import '../common.dart'; 7 import '../common.dart';
8 import '../common/names.dart'; 8 import '../common/names.dart';
9 import '../constants/constructors.dart'; 9 import '../constants/constructors.dart';
10 import '../constants/expressions.dart'; 10 import '../constants/expressions.dart';
(...skipping 701 matching lines...) Expand 10 before | Expand all | Expand 10 after
712 BinaryOperator operator = BinaryOperator.parse(node.operator); 712 BinaryOperator operator = BinaryOperator.parse(node.operator);
713 if (operator != null) { 713 if (operator != null) {
714 ConstantExpression left = visit(node.left); 714 ConstantExpression left = visit(node.left);
715 ConstantExpression right = visit(node.right); 715 ConstantExpression right = visit(node.right);
716 return new BinaryConstantExpression(left, operator, right); 716 return new BinaryConstantExpression(left, operator, right);
717 } 717 }
718 throw new UnimplementedError( 718 throw new UnimplementedError(
719 'Unexpected constant expression $node (${node.runtimeType})'); 719 'Unexpected constant expression $node (${node.runtimeType})');
720 } 720 }
721 721
722 @override
723 ConstantExpression visitLet(ir.Let node) {
724 if (node.body is ir.ConditionalExpression) {
725 ir.ConditionalExpression conditional = node.body;
sra1 2017/05/08 15:58:52 The conversion here (implicit as-check in strong m
Johnni Winther 2017/05/09 10:20:25 OK, I'll rewrite it.
726 if (conditional.condition is ir.MethodInvocation) {
727 ir.MethodInvocation methodInvocation = conditional.condition;
728 if (methodInvocation.name.name == BinaryOperator.EQ.name &&
729 methodInvocation.receiver is ir.VariableGet &&
730 methodInvocation.arguments.positional.single is ir.NullLiteral &&
731 conditional.otherwise is ir.VariableGet) {
732 ir.VariableGet variableGet1 = methodInvocation.receiver;
733 ir.VariableGet variableGet2 = conditional.otherwise;
734 if (variableGet1.variable == node.variable &&
735 variableGet2.variable == node.variable) {
736 // We have <left> ?? <right> encoded as:
737 // let #1 = <left> in #1 == null ? <right> : #1
738 ConstantExpression left = visit(node.variable.initializer);
739 ConstantExpression right = visit(conditional.then);
740 return new BinaryConstantExpression(
741 left, BinaryOperator.IF_NULL, right);
Siggi Cherem (dart-lang) 2017/05/05 18:13:37 nothing to change here, but I just wonder if it is
Johnni Winther 2017/05/08 09:01:06 I'd like the expressions to be structurally equiva
sra1 2017/05/08 15:58:52 It would be nice to have a TODO that explains this
Johnni Winther 2017/05/09 10:20:25 Will add a TODO
742 }
743 }
744 }
745 }
746 throw new UnimplementedError(
747 'Unexpected constant expression $node (${node.runtimeType})');
748 }
749
722 /// Compute the [ConstantConstructor] corresponding to the const constructor 750 /// Compute the [ConstantConstructor] corresponding to the const constructor
723 /// [node]. 751 /// [node].
724 ConstantConstructor computeConstantConstructor(ir.Constructor node) { 752 ConstantConstructor computeConstantConstructor(ir.Constructor node) {
725 assert(node.isConst); 753 assert(node.isConst);
726 ir.Class cls = node.enclosingClass; 754 ir.Class cls = node.enclosingClass;
727 InterfaceType type = elementAdapter.elementEnvironment 755 InterfaceType type = elementAdapter.elementEnvironment
728 .getThisType(elementAdapter.getClass(cls)); 756 .getThisType(elementAdapter.getClass(cls));
729 757
730 Map<dynamic, ConstantExpression> defaultValues = 758 Map<dynamic, ConstantExpression> defaultValues =
731 <dynamic, ConstantExpression>{}; 759 <dynamic, ConstantExpression>{};
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
780 } 808 }
781 if (isRedirecting) { 809 if (isRedirecting) {
782 return new RedirectingGenerativeConstantConstructor( 810 return new RedirectingGenerativeConstantConstructor(
783 defaultValues, superConstructorInvocation); 811 defaultValues, superConstructorInvocation);
784 } else { 812 } else {
785 return new GenerativeConstantConstructor( 813 return new GenerativeConstantConstructor(
786 type, defaultValues, fieldMap, superConstructorInvocation); 814 type, defaultValues, fieldMap, superConstructorInvocation);
787 } 815 }
788 } 816 }
789 } 817 }
OLDNEW
« no previous file with comments | « no previous file | tests/compiler/dart2js/kernel/impact_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698