| 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 compiler.src.inferrer.list_tracer; | 5 library compiler.src.inferrer.list_tracer; |
| 6 | 6 |
| 7 import '../elements/elements.dart'; | 7 import '../elements/elements.dart'; |
| 8 import '../universe/selector.dart' show Selector; | 8 import '../universe/selector.dart' show Selector; |
| 9 import '../util/util.dart' show Setlet; | 9 import '../util/util.dart' show Setlet; |
| 10 | 10 |
| 11 import 'node_tracer.dart'; | 11 import 'node_tracer.dart'; |
| 12 import 'type_graph_nodes.dart'; | 12 import 'type_graph_nodes.dart'; |
| 13 | 13 |
| 14 /** | 14 /** |
| 15 * A set of selector names that [List] implements, that we know do not | 15 * A set of selector names that [List] implements, that we know do not |
| 16 * change the element type of the list, or let the list escape to code | 16 * change the element type of the list, or let the list escape to code |
| 17 * that might change the element type. | 17 * that might change the element type. |
| 18 */ | 18 */ |
| 19 Set<String> okListSelectorsSet = new Set<String>.from( | 19 Set<String> okListSelectorsSet = new Set<String>.from(const <String>[ |
| 20 const <String>[ | 20 // From Object. |
| 21 // From Object. | 21 '==', |
| 22 '==', | 22 'hashCode', |
| 23 'hashCode', | 23 'toString', |
| 24 'toString', | 24 'noSuchMethod', |
| 25 'noSuchMethod', | 25 'runtimeType', |
| 26 'runtimeType', | |
| 27 | 26 |
| 28 // From Iterable. | 27 // From Iterable. |
| 29 'iterator', | 28 'iterator', |
| 30 'map', | 29 'map', |
| 31 'where', | 30 'where', |
| 32 'expand', | 31 'expand', |
| 33 'contains', | 32 'contains', |
| 34 'forEach', | 33 'forEach', |
| 35 'reduce', | 34 'reduce', |
| 36 'fold', | 35 'fold', |
| 37 'every', | 36 'every', |
| 38 'join', | 37 'join', |
| 39 'any', | 38 'any', |
| 40 'toList', | 39 'toList', |
| 41 'toSet', | 40 'toSet', |
| 42 'length', | 41 'length', |
| 43 'isEmpty', | 42 'isEmpty', |
| 44 'isNotEmpty', | 43 'isNotEmpty', |
| 45 'take', | 44 'take', |
| 46 'takeWhile', | 45 'takeWhile', |
| 47 'skip', | 46 'skip', |
| 48 'skipWhile', | 47 'skipWhile', |
| 49 'first', | 48 'first', |
| 50 'last', | 49 'last', |
| 51 'single', | 50 'single', |
| 52 'firstWhere', | 51 'firstWhere', |
| 53 'lastWhere', | 52 'lastWhere', |
| 54 'singleWhere', | 53 'singleWhere', |
| 55 'elementAt', | 54 'elementAt', |
| 56 | 55 |
| 57 // From List. | 56 // From List. |
| 58 '[]', | 57 '[]', |
| 59 'length', | 58 'length', |
| 60 'reversed', | 59 'reversed', |
| 61 'sort', | 60 'sort', |
| 62 'indexOf', | 61 'indexOf', |
| 63 'lastIndexOf', | 62 'lastIndexOf', |
| 64 'clear', | 63 'clear', |
| 65 'remove', | 64 'remove', |
| 66 'removeAt', | 65 'removeAt', |
| 67 'removeLast', | 66 'removeLast', |
| 68 'removeWhere', | 67 'removeWhere', |
| 69 'retainWhere', | 68 'retainWhere', |
| 70 'sublist', | 69 'sublist', |
| 71 'getRange', | 70 'getRange', |
| 72 'removeRange', | 71 'removeRange', |
| 73 'asMap', | 72 'asMap', |
| 74 | 73 |
| 75 // From JSArray. | 74 // From JSArray. |
| 76 'checkMutable', | 75 'checkMutable', |
| 77 'checkGrowable', | 76 'checkGrowable', |
| 78 ]); | 77 ]); |
| 79 | 78 |
| 80 Set<String> doNotChangeLengthSelectorsSet = new Set<String>.from( | 79 Set<String> doNotChangeLengthSelectorsSet = new Set<String>.from(const <String>[ |
| 81 const <String>[ | 80 // From Object. |
| 82 // From Object. | 81 '==', |
| 83 '==', | 82 'hashCode', |
| 84 'hashCode', | 83 'toString', |
| 85 'toString', | 84 'noSuchMethod', |
| 86 'noSuchMethod', | 85 'runtimeType', |
| 87 'runtimeType', | |
| 88 | 86 |
| 89 // From Iterable. | 87 // From Iterable. |
| 90 'iterator', | 88 'iterator', |
| 91 'map', | 89 'map', |
| 92 'where', | 90 'where', |
| 93 'expand', | 91 'expand', |
| 94 'contains', | 92 'contains', |
| 95 'forEach', | 93 'forEach', |
| 96 'reduce', | 94 'reduce', |
| 97 'fold', | 95 'fold', |
| 98 'every', | 96 'every', |
| 99 'join', | 97 'join', |
| 100 'any', | 98 'any', |
| 101 'toList', | 99 'toList', |
| 102 'toSet', | 100 'toSet', |
| 103 'length', | 101 'length', |
| 104 'isEmpty', | 102 'isEmpty', |
| 105 'isNotEmpty', | 103 'isNotEmpty', |
| 106 'take', | 104 'take', |
| 107 'takeWhile', | 105 'takeWhile', |
| 108 'skip', | 106 'skip', |
| 109 'skipWhile', | 107 'skipWhile', |
| 110 'first', | 108 'first', |
| 111 'last', | 109 'last', |
| 112 'single', | 110 'single', |
| 113 'firstWhere', | 111 'firstWhere', |
| 114 'lastWhere', | 112 'lastWhere', |
| 115 'singleWhere', | 113 'singleWhere', |
| 116 'elementAt', | 114 'elementAt', |
| 117 | 115 |
| 118 // From List. | 116 // From List. |
| 119 '[]', | 117 '[]', |
| 120 '[]=', | 118 '[]=', |
| 121 'length', | 119 'length', |
| 122 'reversed', | 120 'reversed', |
| 123 'sort', | 121 'sort', |
| 124 'indexOf', | 122 'indexOf', |
| 125 'lastIndexOf', | 123 'lastIndexOf', |
| 126 'sublist', | 124 'sublist', |
| 127 'getRange', | 125 'getRange', |
| 128 'asMap', | 126 'asMap', |
| 129 | 127 |
| 130 // From JSArray. | 128 // From JSArray. |
| 131 'checkMutable', | 129 'checkMutable', |
| 132 'checkGrowable', | 130 'checkGrowable', |
| 133 ]); | 131 ]); |
| 134 | |
| 135 | 132 |
| 136 class ListTracerVisitor extends TracerVisitor<ListTypeInformation> { | 133 class ListTracerVisitor extends TracerVisitor<ListTypeInformation> { |
| 137 // The [Set] of found assignments to the list. | 134 // The [Set] of found assignments to the list. |
| 138 Set<TypeInformation> assignments = new Setlet<TypeInformation>(); | 135 Set<TypeInformation> assignments = new Setlet<TypeInformation>(); |
| 139 bool callsGrowableMethod = false; | 136 bool callsGrowableMethod = false; |
| 140 | 137 |
| 141 ListTracerVisitor(tracedType, inferrer) : super(tracedType, inferrer); | 138 ListTracerVisitor(tracedType, inferrer) : super(tracedType, inferrer); |
| 142 | 139 |
| 143 /** | 140 /** |
| 144 * Returns [true] if the analysis completed successfully, [false] if it | 141 * Returns [true] if the analysis completed successfully, [false] if it |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 201 } | 198 } |
| 202 } | 199 } |
| 203 if (!doNotChangeLengthSelectorsSet.contains(selectorName)) { | 200 if (!doNotChangeLengthSelectorsSet.contains(selectorName)) { |
| 204 callsGrowableMethod = true; | 201 callsGrowableMethod = true; |
| 205 } | 202 } |
| 206 if (selectorName == 'length' && selector.isSetter) { | 203 if (selectorName == 'length' && selector.isSetter) { |
| 207 callsGrowableMethod = true; | 204 callsGrowableMethod = true; |
| 208 assignments.add(inferrer.types.nullType); | 205 assignments.add(inferrer.types.nullType); |
| 209 } | 206 } |
| 210 } else if (selector.isCall && | 207 } else if (selector.isCall && |
| 211 !info.targets.every((element) => element.isFunction)) { | 208 !info.targets.every((element) => element.isFunction)) { |
| 212 bailout('Passed to a closure'); | 209 bailout('Passed to a closure'); |
| 213 return; | 210 return; |
| 214 } | 211 } |
| 215 } | 212 } |
| 216 } | 213 } |
| OLD | NEW |