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

Unified Diff: pkg/analyzer/lib/src/task/driver.dart

Issue 1124003007: In the new task model, use explicit dependencies on the type provider. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Reformat Created 5 years, 7 months 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 side-by-side diff with in-line comments
Download patch
Index: pkg/analyzer/lib/src/task/driver.dart
diff --git a/pkg/analyzer/lib/src/task/driver.dart b/pkg/analyzer/lib/src/task/driver.dart
index ab8ab9dc706e98f47490ba4994842eee9b4446d8..64dc30c3931c3ea38c6fe9d1e4668c27d6640a92 100644
--- a/pkg/analyzer/lib/src/task/driver.dart
+++ b/pkg/analyzer/lib/src/task/driver.dart
@@ -207,34 +207,40 @@ class AnalysisDriver {
* Return the performed [AnalysisTask].
*/
AnalysisTask performWorkItem(WorkItem item) {
- if (item.exception != null) {
- // Mark all of the results that the task would have computed as being in
- // ERROR with the exception recorded on the work item.
- CacheEntry targetEntry = context.getCacheEntry(item.target);
- targetEntry.setErrorState(item.exception, item.descriptor.results);
- return null;
- }
- // Otherwise, perform the task.
- AnalysisTask task = item.buildTask();
- _onTaskStartedController.add(task);
- task.perform();
- CacheEntry entry = context.getCacheEntry(task.target);
- if (task.caughtException == null) {
- List<TargetedResult> dependedOn = item.inputTargetedResults.toList();
- Map<ResultDescriptor, dynamic> outputs = task.outputs;
- for (ResultDescriptor result in task.descriptor.results) {
- // TODO(brianwilkerson) We could check here that a value was produced
- // and throw an exception if not (unless we want to allow null values).
- entry.setValue(result, outputs[result], dependedOn);
+ try {
Paul Berry 2015/05/13 21:32:00 Note: it's not obvious from the diff, but the only
+ assert(!taskManager.isTaskRunning);
+ taskManager.isTaskRunning = true;
+ if (item.exception != null) {
+ // Mark all of the results that the task would have computed as being in
+ // ERROR with the exception recorded on the work item.
+ CacheEntry targetEntry = context.getCacheEntry(item.target);
+ targetEntry.setErrorState(item.exception, item.descriptor.results);
+ return null;
}
- for (WorkManager manager in workManagers) {
- manager.resultsComputed(task.target, outputs);
+ // Otherwise, perform the task.
+ AnalysisTask task = item.buildTask();
+ _onTaskStartedController.add(task);
+ task.perform();
+ CacheEntry entry = context.getCacheEntry(task.target);
+ if (task.caughtException == null) {
+ List<TargetedResult> dependedOn = item.inputTargetedResults.toList();
+ Map<ResultDescriptor, dynamic> outputs = task.outputs;
+ for (ResultDescriptor result in task.descriptor.results) {
+ // TODO(brianwilkerson) We could check here that a value was produced
+ // and throw an exception if not (unless we want to allow null values).
+ entry.setValue(result, outputs[result], dependedOn);
+ }
+ for (WorkManager manager in workManagers) {
+ manager.resultsComputed(task.target, outputs);
+ }
+ } else {
+ entry.setErrorState(task.caughtException, item.descriptor.results);
}
- } else {
- entry.setErrorState(task.caughtException, item.descriptor.results);
+ _onTaskCompletedController.add(task);
+ return task;
+ } finally {
+ taskManager.isTaskRunning = false;
}
- _onTaskCompletedController.add(task);
- return task;
}
/**
@@ -363,44 +369,50 @@ class WorkItem {
* tasks' results should be marked as being in ERROR.
*/
WorkItem gatherInputs(TaskManager taskManager) {
- while (builder != null) {
- AnalysisTarget inputTarget = builder.currentTarget;
- ResultDescriptor inputResult = builder.currentResult;
- inputTargetedResults.add(new TargetedResult(inputTarget, inputResult));
- CacheEntry inputEntry = context.getCacheEntry(inputTarget);
- CacheState inputState = inputEntry.getState(inputResult);
- if (inputState == CacheState.ERROR) {
- exception = inputEntry.exception;
- return null;
- } else if (inputState == CacheState.IN_PROCESS) {
- //
- // TODO(brianwilkerson) Implement this case.
- //
- // One possibility would be to return a WorkItem that would perform a
- // no-op task in order to cause us to come back to this work item on the
- // next iteration. It would be more efficient, in general, to push this
- // input onto a waiting list and proceed to the next input so that work
- // could proceed, but given that the only result that can currently be
- // IN_PROCESS is CONTENT, I don't know that it's worth the extra effort
- // to implement the general solution at this point.
- //
- } else if (inputState != CacheState.VALID) {
- try {
- TaskDescriptor descriptor =
- taskManager.findTask(inputTarget, inputResult);
- return new WorkItem(context, inputTarget, descriptor);
- } on AnalysisException catch (exception, stackTrace) {
- this.exception = new CaughtException(exception, stackTrace);
+ try {
+ assert(!taskManager.isTaskRunning);
+ taskManager.isTaskRunning = true;
+ while (builder != null) {
+ AnalysisTarget inputTarget = builder.currentTarget;
+ ResultDescriptor inputResult = builder.currentResult;
+ inputTargetedResults.add(new TargetedResult(inputTarget, inputResult));
+ CacheEntry inputEntry = context.getCacheEntry(inputTarget);
+ CacheState inputState = inputEntry.getState(inputResult);
+ if (inputState == CacheState.ERROR) {
+ exception = inputEntry.exception;
return null;
+ } else if (inputState == CacheState.IN_PROCESS) {
+ //
+ // TODO(brianwilkerson) Implement this case.
+ //
+ // One possibility would be to return a WorkItem that would perform a
+ // no-op task in order to cause us to come back to this work item on the
+ // next iteration. It would be more efficient, in general, to push this
+ // input onto a waiting list and proceed to the next input so that work
+ // could proceed, but given that the only result that can currently be
+ // IN_PROCESS is CONTENT, I don't know that it's worth the extra effort
+ // to implement the general solution at this point.
+ //
+ } else if (inputState != CacheState.VALID) {
+ try {
+ TaskDescriptor descriptor =
+ taskManager.findTask(inputTarget, inputResult);
+ return new WorkItem(context, inputTarget, descriptor);
+ } on AnalysisException catch (exception, stackTrace) {
+ this.exception = new CaughtException(exception, stackTrace);
+ return null;
+ }
+ }
+ builder.currentValue = inputEntry.getValue(inputResult);
+ if (!builder.moveNext()) {
+ inputs = builder.inputValue;
+ builder = null;
}
}
- builder.currentValue = inputEntry.getValue(inputResult);
- if (!builder.moveNext()) {
- inputs = builder.inputValue;
- builder = null;
- }
+ return null;
+ } finally {
+ taskManager.isTaskRunning = false;
}
- return null;
}
@override

Powered by Google App Engine
This is Rietveld 408576698