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

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

Issue 1061803002: Detect and recover from infinite task loops (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 8 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
« no previous file with comments | « no previous file | pkg/analyzer/test/src/task/driver_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 88df107a3bc479c8aa6046653c6d118e0eff9f6a..f077b3a3f8d07a1279745d4712fb7b1e402938fa 100644
--- a/pkg/analyzer/lib/src/task/driver.dart
+++ b/pkg/analyzer/lib/src/task/driver.dart
@@ -413,8 +413,46 @@ class WorkOrder implements Iterator<WorkItem> {
while (childItem != null) {
pendingItems.add(currentItem);
currentItem = childItem;
+ if (_hasInfiniteTaskLoop()) {
+ currentItem = pendingItems.removeLast();
+ try {
+ throw new InfiniteTaskLoopException(childItem);
+ } on InfiniteTaskLoopException catch (exception, stackTrace) {
+ currentItem.exception = new CaughtException(exception, stackTrace);
+ }
+ return true;
+ }
childItem = currentItem.gatherInputs(taskManager);
}
return true;
}
+
+ /**
+ * Check to see whether the current work item is attempting to perform the
+ * same task on the same target as any of the pending work items. If it is,
+ * then throw an [InfiniteTaskLoopException].
+ */
+ bool _hasInfiniteTaskLoop() {
+ TaskDescriptor descriptor = currentItem.descriptor;
+ AnalysisTarget target = currentItem.target;
+ for (WorkItem item in pendingItems) {
+ if (item.descriptor == descriptor && item.target == target) {
+ return true;
+ }
+ }
+ return false;
+ }
+}
+
+/**
+ * An exception indicating that an attempt was made to perform a task on a
+ * target while gathering the inputs to perform the same task for the same
+ * target.
+ */
+class InfiniteTaskLoopException extends AnalysisException {
+ /**
+ * Initialize a newly created exception to represent an attempt to perform
+ * the task for the target represented by the given [item].
+ */
+ InfiniteTaskLoopException(WorkItem item) : super('Infinite loop while performing task ${item.descriptor.name} for ${item.target}');
}
« no previous file with comments | « no previous file | pkg/analyzer/test/src/task/driver_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698