OLD | NEW |
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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 analyzer.src.task.driver; | 5 library analyzer.src.task.driver; |
6 | 6 |
7 import 'dart:async'; | 7 import 'dart:async'; |
8 import 'dart:collection'; | 8 import 'dart:collection'; |
9 | 9 |
10 import 'package:analyzer/src/context/cache.dart'; | 10 import 'package:analyzer/src/context/cache.dart'; |
11 import 'package:analyzer/src/generated/engine.dart' | 11 import 'package:analyzer/src/generated/engine.dart' |
12 hide AnalysisTask, AnalysisContextImpl, WorkManager; | 12 hide AnalysisTask, AnalysisContextImpl, WorkManager; |
13 import 'package:analyzer/src/generated/java_engine.dart'; | 13 import 'package:analyzer/src/generated/java_engine.dart'; |
14 import 'package:analyzer/src/generated/resolver.dart'; | 14 import 'package:analyzer/src/generated/resolver.dart'; |
15 import 'package:analyzer/src/generated/utilities_general.dart'; | 15 import 'package:analyzer/src/generated/utilities_general.dart'; |
16 import 'package:analyzer/src/task/inputs.dart'; | 16 import 'package:analyzer/src/task/inputs.dart'; |
17 import 'package:analyzer/src/task/manager.dart'; | 17 import 'package:analyzer/src/task/manager.dart'; |
18 import 'package:analyzer/task/model.dart'; | 18 import 'package:analyzer/task/model.dart'; |
19 | 19 |
| 20 final PerformanceTag analysisDriverProcessOutputs = |
| 21 new PerformanceTag('AnalysisDriver.processOutputs'); |
| 22 |
20 final PerformanceTag workOrderMoveNextPerformanceTag = | 23 final PerformanceTag workOrderMoveNextPerformanceTag = |
21 new PerformanceTag('WorkOrder.moveNext'); | 24 new PerformanceTag('WorkOrder.moveNext'); |
22 | 25 |
23 /** | 26 /** |
24 * An object that is used to cause analysis to be performed until all of the | 27 * An object that is used to cause analysis to be performed until all of the |
25 * required analysis information has been computed. | 28 * required analysis information has been computed. |
26 */ | 29 */ |
27 class AnalysisDriver { | 30 class AnalysisDriver { |
28 /** | 31 /** |
29 * The task manager used to figure out how to compute analysis results. | 32 * The task manager used to figure out how to compute analysis results. |
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
259 // Mark all of the results that the task would have computed as being in | 262 // Mark all of the results that the task would have computed as being in |
260 // ERROR with the exception recorded on the work item. | 263 // ERROR with the exception recorded on the work item. |
261 CacheEntry targetEntry = context.getCacheEntry(item.target); | 264 CacheEntry targetEntry = context.getCacheEntry(item.target); |
262 targetEntry.setErrorState(item.exception, item.descriptor.results); | 265 targetEntry.setErrorState(item.exception, item.descriptor.results); |
263 return null; | 266 return null; |
264 } | 267 } |
265 // Otherwise, perform the task. | 268 // Otherwise, perform the task. |
266 AnalysisTask task = item.buildTask(); | 269 AnalysisTask task = item.buildTask(); |
267 _onTaskStartedController.add(task); | 270 _onTaskStartedController.add(task); |
268 task.perform(); | 271 task.perform(); |
269 AnalysisTarget target = task.target; | 272 analysisDriverProcessOutputs.makeCurrentWhile(() { |
270 CacheEntry entry = context.getCacheEntry(target); | 273 AnalysisTarget target = task.target; |
271 if (task.caughtException == null) { | 274 CacheEntry entry = context.getCacheEntry(target); |
272 List<TargetedResult> dependedOn = item.inputTargetedResults.toList(); | 275 if (task.caughtException == null) { |
273 Map<ResultDescriptor, dynamic> outputs = task.outputs; | 276 List<TargetedResult> dependedOn = item.inputTargetedResults.toList(); |
274 for (ResultDescriptor result in task.descriptor.results) { | 277 Map<ResultDescriptor, dynamic> outputs = task.outputs; |
275 // TODO(brianwilkerson) We could check here that a value was produced | 278 for (ResultDescriptor result in task.descriptor.results) { |
276 // and throw an exception if not (unless we want to allow null values). | 279 // TODO(brianwilkerson) We could check here that a value was produced |
277 entry.setValue(result, outputs[result], dependedOn); | 280 // and throw an exception if not (unless we want to allow null values)
. |
| 281 entry.setValue(result, outputs[result], dependedOn); |
278 // if (dependedOn.length > 250) { | 282 // if (dependedOn.length > 250) { |
279 // print('[${dependedOn.length}] $result or $target dependsOn: $depende
dOn'); | 283 // print('[${dependedOn.length}] $result or $target dependsOn: $depende
dOn'); |
280 // } | 284 // } |
| 285 } |
| 286 outputs.forEach((ResultDescriptor descriptor, value) { |
| 287 StreamController<ComputedResult> controller = |
| 288 resultComputedControllers[descriptor]; |
| 289 if (controller != null) { |
| 290 ComputedResult event = |
| 291 new ComputedResult(context, descriptor, target, value); |
| 292 controller.add(event); |
| 293 } |
| 294 }); |
| 295 for (WorkManager manager in workManagers) { |
| 296 manager.resultsComputed(target, outputs); |
| 297 } |
| 298 } else { |
| 299 entry.setErrorState(task.caughtException, item.descriptor.results); |
281 } | 300 } |
282 outputs.forEach((ResultDescriptor descriptor, value) { | 301 }); |
283 StreamController<ComputedResult> controller = | |
284 resultComputedControllers[descriptor]; | |
285 if (controller != null) { | |
286 ComputedResult event = | |
287 new ComputedResult(context, descriptor, target, value); | |
288 controller.add(event); | |
289 } | |
290 }); | |
291 for (WorkManager manager in workManagers) { | |
292 manager.resultsComputed(target, outputs); | |
293 } | |
294 } else { | |
295 entry.setErrorState(task.caughtException, item.descriptor.results); | |
296 } | |
297 _onTaskCompletedController.add(task); | 302 _onTaskCompletedController.add(task); |
298 return task; | 303 return task; |
299 } | 304 } |
300 | 305 |
301 /** | 306 /** |
302 * Reset the state of the driver in response to a change in the state of one | 307 * Reset the state of the driver in response to a change in the state of one |
303 * or more analysis targets. This will cause any analysis that was currently | 308 * or more analysis targets. This will cause any analysis that was currently |
304 * in process to be stopped and for analysis to resume based on the new state. | 309 * in process to be stopped and for analysis to resume based on the new state. |
305 */ | 310 */ |
306 void reset() { | 311 void reset() { |
(...skipping 426 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
733 * A description of the work to be done to compute a desired analysis result. | 738 * A description of the work to be done to compute a desired analysis result. |
734 * The class implements a lazy depth-first traversal of the work item's input. | 739 * The class implements a lazy depth-first traversal of the work item's input. |
735 */ | 740 */ |
736 class WorkOrder implements Iterator<WorkItem> { | 741 class WorkOrder implements Iterator<WorkItem> { |
737 /** | 742 /** |
738 * The dependency walker which is being used to determine what work to do | 743 * The dependency walker which is being used to determine what work to do |
739 * next. | 744 * next. |
740 */ | 745 */ |
741 final _WorkOrderDependencyWalker _dependencyWalker; | 746 final _WorkOrderDependencyWalker _dependencyWalker; |
742 | 747 |
743 List<WorkItem> get workItems => _dependencyWalker._path; | |
744 | |
745 /** | 748 /** |
746 * The strongly connected component most recently returned by | 749 * The strongly connected component most recently returned by |
747 * [_dependencyWalker], minus any [WorkItem]s that the iterator has already | 750 * [_dependencyWalker], minus any [WorkItem]s that the iterator has already |
748 * moved past. | 751 * moved past. |
749 * | 752 * |
750 * Null if the [_dependencyWalker] hasn't been used yet. | 753 * Null if the [_dependencyWalker] hasn't been used yet. |
751 */ | 754 */ |
752 List<WorkItem> currentItems; | 755 List<WorkItem> currentItems; |
753 | 756 |
754 /** | 757 /** |
755 * Initialize a newly created work order to compute the result described by | 758 * Initialize a newly created work order to compute the result described by |
756 * the given work item. | 759 * the given work item. |
757 */ | 760 */ |
758 WorkOrder(TaskManager taskManager, WorkItem item) | 761 WorkOrder(TaskManager taskManager, WorkItem item) |
759 : _dependencyWalker = new _WorkOrderDependencyWalker(taskManager, item); | 762 : _dependencyWalker = new _WorkOrderDependencyWalker(taskManager, item); |
760 | 763 |
761 @override | 764 @override |
762 WorkItem get current { | 765 WorkItem get current { |
763 if (currentItems == null) { | 766 if (currentItems == null) { |
764 return null; | 767 return null; |
765 } else { | 768 } else { |
766 return currentItems.last; | 769 return currentItems.last; |
767 } | 770 } |
768 } | 771 } |
769 | 772 |
| 773 List<WorkItem> get workItems => _dependencyWalker._path; |
| 774 |
770 @override | 775 @override |
771 bool moveNext() { | 776 bool moveNext() { |
772 return workOrderMoveNextPerformanceTag.makeCurrentWhile(() { | 777 return workOrderMoveNextPerformanceTag.makeCurrentWhile(() { |
773 if (currentItems != null && currentItems.length > 1) { | 778 if (currentItems != null && currentItems.length > 1) { |
774 // Yield more items. | 779 // Yield more items. |
775 currentItems.removeLast(); | 780 currentItems.removeLast(); |
776 return true; | 781 return true; |
777 } else { | 782 } else { |
778 // Get a new strongly connected component. | 783 // Get a new strongly connected component. |
779 StronglyConnectedComponent<WorkItem> nextStronglyConnectedComponent = | 784 StronglyConnectedComponent<WorkItem> nextStronglyConnectedComponent = |
(...skipping 27 matching lines...) Expand all Loading... |
807 final TaskManager taskManager; | 812 final TaskManager taskManager; |
808 | 813 |
809 _WorkOrderDependencyWalker(this.taskManager, WorkItem startingNode) | 814 _WorkOrderDependencyWalker(this.taskManager, WorkItem startingNode) |
810 : super(startingNode); | 815 : super(startingNode); |
811 | 816 |
812 @override | 817 @override |
813 WorkItem getNextInput(WorkItem node, List<WorkItem> skipInputs) { | 818 WorkItem getNextInput(WorkItem node, List<WorkItem> skipInputs) { |
814 return node.gatherInputs(taskManager, skipInputs); | 819 return node.gatherInputs(taskManager, skipInputs); |
815 } | 820 } |
816 } | 821 } |
OLD | NEW |