Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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 Loading... | |
| 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. | |
| 479 DartType objectType = compiler.coreTypes.objectType; | |
|
Siggi Cherem (dart-lang)
2015/11/26 02:21:48
delete? (seems unused)
sra1
2015/12/01 02:14:10
Done.
| |
| 473 type = types.addPhiInput( | 480 type = types.addPhiInput( |
| 474 local, types.allocatePhi(locals.block, local, currentType), type); | 481 local, |
| 482 types.allocatePhi(locals.block, local, | |
| 483 types.narrowNotNull(currentType)), | |
| 484 type); | |
| 475 } | 485 } |
| 476 locals[local] = type; | 486 locals[local] = type; |
| 477 if (currentType != type) { | 487 if (currentType != type) { |
| 478 inferrer.recordLocalUpdate(local, type); | 488 inferrer.recordLocalUpdate(local, type); |
| 479 } | 489 } |
| 480 } | 490 } |
| 481 if (capturedAndBoxed.containsKey(local)) { | 491 if (capturedAndBoxed.containsKey(local)) { |
| 482 inferrer.recordTypeOfNonFinalField( | 492 inferrer.recordTypeOfNonFinalField( |
| 483 node, capturedAndBoxed[local], type); | 493 node, capturedAndBoxed[local], type); |
| 484 } else if (inTryBlock) { | 494 } else if (inTryBlock) { |
| (...skipping 632 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1117 NodeList arguments, | 1127 NodeList arguments, |
| 1118 Selector selector, | 1128 Selector selector, |
| 1119 _) { | 1129 _) { |
| 1120 return handleDynamicInvoke(node); | 1130 return handleDynamicInvoke(node); |
| 1121 } | 1131 } |
| 1122 | 1132 |
| 1123 @override | 1133 @override |
| 1124 T visitIfNull(Send node, Node left, Node right, _) { | 1134 T visitIfNull(Send node, Node left, Node right, _) { |
| 1125 T firstType = visit(left); | 1135 T firstType = visit(left); |
| 1126 T secondType = visit(right); | 1136 T secondType = visit(right); |
| 1127 return types.allocateDiamondPhi(firstType, secondType); | 1137 return types.allocateDiamondPhi(types.narrowNotNull(firstType), secondType); |
| 1128 } | 1138 } |
| 1129 | 1139 |
| 1130 @override | 1140 @override |
| 1131 T visitLogicalAnd(Send node, Node left, Node right, _) { | 1141 T visitLogicalAnd(Send node, Node left, Node right, _) { |
| 1132 conditionIsSimple = false; | 1142 conditionIsSimple = false; |
| 1133 bool oldAccumulateIsChecks = accumulateIsChecks; | 1143 bool oldAccumulateIsChecks = accumulateIsChecks; |
| 1134 List<Send> oldIsChecks = isChecks; | 1144 List<Send> oldIsChecks = isChecks; |
| 1135 if (!accumulateIsChecks) { | 1145 if (!accumulateIsChecks) { |
| 1136 accumulateIsChecks = true; | 1146 accumulateIsChecks = true; |
| 1137 isChecks = <Send>[]; | 1147 isChecks = <Send>[]; |
| (...skipping 405 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1543 return type; | 1553 return type; |
| 1544 } | 1554 } |
| 1545 | 1555 |
| 1546 T visitCascade(Cascade node) { | 1556 T visitCascade(Cascade node) { |
| 1547 // Ignore the result of the cascade send and return the type of the cascade | 1557 // Ignore the result of the cascade send and return the type of the cascade |
| 1548 // receiver. | 1558 // receiver. |
| 1549 visit(node.expression); | 1559 visit(node.expression); |
| 1550 return cascadeReceiverStack.removeLast(); | 1560 return cascadeReceiverStack.removeLast(); |
| 1551 } | 1561 } |
| 1552 } | 1562 } |
| OLD | NEW |