Skip to content

Commit

Permalink
[analyzer] Break infinite loops (dotnet/linker#1659)
Browse files Browse the repository at this point in the history
Avoid getting caught in infinite loops. I think these are related to
new DynamicDependency attributes. So stop graph traversal and report
the loop as warning.

Commit migrated from dotnet/linker@4f7f661
  • Loading branch information
radekdoulik authored Nov 30, 2020
1 parent cbde55b commit a3a0020
Showing 1 changed file with 24 additions and 2 deletions.
26 changes: 24 additions & 2 deletions src/tools/illink/src/analyzer/ConsoleDependencyGraph.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,15 +80,37 @@ public void ShowDependencies (VertexData vertex)
Console.WriteLine ("Root dependency");
} else {
int i = 0;
var visited = new HashSet<int> ();

foreach (int index in vertex.parentIndexes) {
Console.WriteLine ("Dependency #{0}", ++i);
Console.WriteLine ($"\t{vertex.value}{SizeString (vertex)}");

var childVertex = Vertex (index);
Console.WriteLine ("\t| {0}{1}", childVertex.value, childVertex.DepsCount);

visited.Clear ();
visited.Add (index);

while (childVertex.parentIndexes != null) {
childVertex = Vertex (childVertex.parentIndexes [0]);
int pi = 0, childIdx;

do {
childIdx = childVertex.parentIndexes [pi];
pi++;
} while (visited.Contains (childIdx) && pi < childVertex.parentIndexes.Count);

childVertex = Vertex (childIdx);

if (visited.Contains (childIdx)) {
Console.WriteLine ($"\twarning: loop to {childVertex.value}");
break;
}

visited.Add (childIdx);
Console.WriteLine ("\t| {0}{1}", childVertex.value, childVertex.DepsCount);
}

if (Tree)
break;
}
Expand Down Expand Up @@ -175,7 +197,7 @@ static void Line ()
Console.WriteLine ();
}

static public void Header (string header, params object[] values)
public static void Header (string header, params object[] values)
{
string formatted = string.Format (header, values);
Console.WriteLine ();
Expand Down

0 comments on commit a3a0020

Please sign in to comment.