| 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 part of type_graph_inferrer; | 5 part of type_graph_inferrer; |
| 6 | 6 |
| 7 // A set of selectors we know do not escape the elements inside the | 7 // A set of selectors we know do not escape the elements inside the |
| 8 // list. | 8 // list. |
| 9 Set<String> doesNotEscapeListSet = new Set<String>.from( | 9 Set<String> doesNotEscapeListSet = new Set<String>.from( |
| 10 const <String>[ | 10 const <String>[ |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 97 // The current [TypeInformation] in the analysis. | 97 // The current [TypeInformation] in the analysis. |
| 98 TypeInformation currentUser; | 98 TypeInformation currentUser; |
| 99 bool continueAnalyzing = true; | 99 bool continueAnalyzing = true; |
| 100 | 100 |
| 101 void addNewEscapeInformation(TypeInformation info) { | 101 void addNewEscapeInformation(TypeInformation info) { |
| 102 if (flowsInto.contains(info)) return; | 102 if (flowsInto.contains(info)) return; |
| 103 flowsInto.add(info); | 103 flowsInto.add(info); |
| 104 workList.add(info); | 104 workList.add(info); |
| 105 } | 105 } |
| 106 | 106 |
| 107 bool _wouldBeTooManyUsers(Set users) { |
| 108 int seenSoFar = analyzedElements.length; |
| 109 if (seenSoFar + users.length <= MAX_ANALYSIS_COUNT) return false; |
| 110 int actualWork = users |
| 111 .where((TypeInformation user) => !analyzedElements.contains(user.owner)) |
| 112 .length; |
| 113 return seenSoFar + actualWork > MAX_ANALYSIS_COUNT; |
| 114 } |
| 115 |
| 107 void analyze() { | 116 void analyze() { |
| 108 // Collect the [TypeInformation] where the list can flow in, | 117 // Collect the [TypeInformation] where the list can flow in, |
| 109 // as well as the operations done on all these [TypeInformation]s. | 118 // as well as the operations done on all these [TypeInformation]s. |
| 110 addNewEscapeInformation(tracedType); | 119 addNewEscapeInformation(tracedType); |
| 111 while (!workList.isEmpty) { | 120 while (!workList.isEmpty) { |
| 112 currentUser = workList.removeLast(); | 121 currentUser = workList.removeLast(); |
| 113 int expectedWork = analyzedElements.length + currentUser.users.length; | 122 if (_wouldBeTooManyUsers(currentUser.users)) { |
| 114 if (expectedWork > MAX_ANALYSIS_COUNT) { | |
| 115 bailout('Too many users'); | 123 bailout('Too many users'); |
| 116 break; | 124 break; |
| 117 } | 125 } |
| 118 for (TypeInformation info in currentUser.users) { | 126 for (TypeInformation info in currentUser.users) { |
| 119 analyzedElements.add(info.owner); | 127 analyzedElements.add(info.owner); |
| 120 info.accept(this); | 128 info.accept(this); |
| 121 } | 129 } |
| 122 while (!listsToAnalyze.isEmpty) { | 130 while (!listsToAnalyze.isEmpty) { |
| 123 analyzeStoredIntoList(listsToAnalyze.removeLast()); | 131 analyzeStoredIntoList(listsToAnalyze.removeLast()); |
| 124 } | 132 } |
| (...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 378 } | 386 } |
| 379 if (isParameterOfListAddingMethod(info.element) || | 387 if (isParameterOfListAddingMethod(info.element) || |
| 380 isParameterOfMapAddingMethod(info.element)) { | 388 isParameterOfMapAddingMethod(info.element)) { |
| 381 // These elements are being handled in | 389 // These elements are being handled in |
| 382 // [visitDynamicCallSiteTypeInformation]. | 390 // [visitDynamicCallSiteTypeInformation]. |
| 383 return; | 391 return; |
| 384 } | 392 } |
| 385 addNewEscapeInformation(info); | 393 addNewEscapeInformation(info); |
| 386 } | 394 } |
| 387 } | 395 } |
| OLD | NEW |