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

Side by Side Diff: pkg/compiler/lib/src/inferrer/inferrer_visitor.dart

Issue 1469353008: dart2js: Type inferrence: Account for implicit null test in '??' and '??='. (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Created 5 years 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 | pkg/compiler/lib/src/inferrer/simple_types_inferrer.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) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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 library inferrer_visitor; 5 library inferrer_visitor;
6 6
7 import 'dart:collection' show 7 import 'dart:collection' show
8 IterableMixin; 8 IterableMixin;
9 9
10 import '../common.dart'; 10 import '../common.dart';
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 T computeLUB(T firstType, T secondType); 84 T computeLUB(T firstType, T secondType);
85 85
86 /** 86 /**
87 * Returns the intersection between [T] and [annotation]. 87 * Returns the intersection between [T] and [annotation].
88 * [isNullable] indicates whether the annotation implies a null 88 * [isNullable] indicates whether the annotation implies a null
89 * type. 89 * type.
90 */ 90 */
91 T narrowType(T type, DartType annotation, {bool isNullable: true}); 91 T narrowType(T type, DartType annotation, {bool isNullable: true});
92 92
93 /** 93 /**
94 * Returns the non-nullable type [T].
95 */
96 T narrowNotNull(T type);
97
98 /**
94 * Returns a new type that unions [firstInput] and [secondInput]. 99 * Returns a new type that unions [firstInput] and [secondInput].
95 */ 100 */
96 T allocateDiamondPhi(T firstInput, T secondInput); 101 T allocateDiamondPhi(T firstInput, T secondInput);
97 102
98 /** 103 /**
99 * Returns a new type for holding the potential types of [element]. 104 * Returns a new type for holding the potential types of [element].
100 * [inputType] is the first incoming type of the phi. 105 * [inputType] is the first incoming type of the phi.
101 */ 106 */
102 T allocatePhi(Node node, Local variable, T inputType); 107 T allocatePhi(Node node, Local variable, T inputType);
103 108
(...skipping 358 matching lines...) Expand 10 before | Expand all | Expand 10 after
462 void update(LocalElement local, T type, Node node) { 467 void update(LocalElement local, T type, Node node) {
463 assert(type != null); 468 assert(type != null);
464 if (compiler.trustTypeAnnotations || compiler.enableTypeAssertions) { 469 if (compiler.trustTypeAnnotations || compiler.enableTypeAssertions) {
465 type = types.narrowType(type, local.type); 470 type = types.narrowType(type, local.type);
466 } 471 }
467 updateLocal() { 472 updateLocal() {
468 T currentType = locals[local]; 473 T currentType = locals[local];
469 474
470 SendSet send = node != null ? node.asSendSet() : null; 475 SendSet send = node != null ? node.asSendSet() : null;
471 if (send != null && send.isIfNullAssignment && currentType != null) { 476 if (send != null && send.isIfNullAssignment && currentType != null) {
472 // If-null assignments may return either the new or the original value. 477 // If-null assignments may return either the new or the original value
478 // narrowed to non-null.
473 type = types.addPhiInput( 479 type = types.addPhiInput(
474 local, types.allocatePhi(locals.block, local, currentType), type); 480 local,
481 types.allocatePhi(locals.block, local,
482 types.narrowNotNull(currentType)),
483 type);
475 } 484 }
476 locals[local] = type; 485 locals[local] = type;
477 if (currentType != type) { 486 if (currentType != type) {
478 inferrer.recordLocalUpdate(local, type); 487 inferrer.recordLocalUpdate(local, type);
479 } 488 }
480 } 489 }
481 if (capturedAndBoxed.containsKey(local)) { 490 if (capturedAndBoxed.containsKey(local)) {
482 inferrer.recordTypeOfNonFinalField( 491 inferrer.recordTypeOfNonFinalField(
483 node, capturedAndBoxed[local], type); 492 node, capturedAndBoxed[local], type);
484 } else if (inTryBlock) { 493 } else if (inTryBlock) {
(...skipping 632 matching lines...) Expand 10 before | Expand all | Expand 10 after
1117 NodeList arguments, 1126 NodeList arguments,
1118 Selector selector, 1127 Selector selector,
1119 _) { 1128 _) {
1120 return handleDynamicInvoke(node); 1129 return handleDynamicInvoke(node);
1121 } 1130 }
1122 1131
1123 @override 1132 @override
1124 T visitIfNull(Send node, Node left, Node right, _) { 1133 T visitIfNull(Send node, Node left, Node right, _) {
1125 T firstType = visit(left); 1134 T firstType = visit(left);
1126 T secondType = visit(right); 1135 T secondType = visit(right);
1127 return types.allocateDiamondPhi(firstType, secondType); 1136 return types.allocateDiamondPhi(types.narrowNotNull(firstType), secondType);
1128 } 1137 }
1129 1138
1130 @override 1139 @override
1131 T visitLogicalAnd(Send node, Node left, Node right, _) { 1140 T visitLogicalAnd(Send node, Node left, Node right, _) {
1132 conditionIsSimple = false; 1141 conditionIsSimple = false;
1133 bool oldAccumulateIsChecks = accumulateIsChecks; 1142 bool oldAccumulateIsChecks = accumulateIsChecks;
1134 List<Send> oldIsChecks = isChecks; 1143 List<Send> oldIsChecks = isChecks;
1135 if (!accumulateIsChecks) { 1144 if (!accumulateIsChecks) {
1136 accumulateIsChecks = true; 1145 accumulateIsChecks = true;
1137 isChecks = <Send>[]; 1146 isChecks = <Send>[];
(...skipping 405 matching lines...) Expand 10 before | Expand all | Expand 10 after
1543 return type; 1552 return type;
1544 } 1553 }
1545 1554
1546 T visitCascade(Cascade node) { 1555 T visitCascade(Cascade node) {
1547 // Ignore the result of the cascade send and return the type of the cascade 1556 // Ignore the result of the cascade send and return the type of the cascade
1548 // receiver. 1557 // receiver.
1549 visit(node.expression); 1558 visit(node.expression);
1550 return cascadeReceiverStack.removeLast(); 1559 return cascadeReceiverStack.removeLast();
1551 } 1560 }
1552 } 1561 }
OLDNEW
« no previous file with comments | « no previous file | pkg/compiler/lib/src/inferrer/simple_types_inferrer.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698