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

Unified Diff: pkg/analyzer/lib/src/summary/link.dart

Issue 1839863005: Clean up trivial cycle detection logic. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 9 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/summary/summary_common.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/analyzer/lib/src/summary/link.dart
diff --git a/pkg/analyzer/lib/src/summary/link.dart b/pkg/analyzer/lib/src/summary/link.dart
index 602b357d0959a8cc2913aaf201c012c5f7cedf81..54171dc52bc22804324abf2ca06e29a1a58dddce 100644
--- a/pkg/analyzer/lib/src/summary/link.dart
+++ b/pkg/analyzer/lib/src/summary/link.dart
@@ -957,6 +957,8 @@ abstract class DependencyWalker<NodeType extends Node<NodeType>> {
List<NodeType> stack = <NodeType>[];
void strongConnect(NodeType node) {
+ bool hasTrivialCycle = false;
+
// Assign the current node an index and add it to the stack. We
// haven't seen any of its dependencies yet, so set its lowLink
// to its index, indicating that so far it is the only node in
@@ -972,7 +974,11 @@ abstract class DependencyWalker<NodeType extends Node<NodeType>> {
if (dependency.isEvaluated) {
continue;
}
- if (dependency.index == 0) {
+ if (identical(node, dependency)) {
+ // If a node includes itself as a dependency, there is no need to
+ // explore the dependency further.
+ hasTrivialCycle = true;
+ } else if (dependency.index == 0) {
// The dependency hasn't been seen yet, so recurse on it.
strongConnect(dependency);
// If the dependency's lowLink refers to a node that was
@@ -1001,15 +1007,11 @@ abstract class DependencyWalker<NodeType extends Node<NodeType>> {
// we have finished visiting a strongly connected component, so
// pop the stack and evaluate it before moving on.
if (node.lowLink == node.index) {
- // In the case where the strongly connected component has only
- // one node, determine whether there is a trivial cycle or
- // not.
- //
- // TODO(paulberry): could we figure this out in the for-loop
- // above and save some effort?
+ // The strongly connected component has only one node. If there is a
+ // cycle, it's a trivial one.
if (identical(stack.last, node)) {
stack.removeLast();
- if (_hasTrivialScc(node)) {
+ if (hasTrivialCycle) {
evaluateScc(<NodeType>[node]);
} else {
evaluate(node);
@@ -1033,20 +1035,6 @@ abstract class DependencyWalker<NodeType extends Node<NodeType>> {
// Kick off the algorithm starting with the starting point.
strongConnect(startingPoint);
}
-
- /**
- * The given [node] is in a strongly connected component of size 1.
- * Determine if it contains a trivial cycle (i.e. depends on
- * itself).
- */
- bool _hasTrivialScc(NodeType node) {
- for (NodeType dependency in node.dependencies) {
- if (identical(dependency, node)) {
- return true;
- }
- }
- return false;
- }
}
/**
« no previous file with comments | « no previous file | pkg/analyzer/test/src/summary/summary_common.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698