Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix handling of cycles in AST traversal in Dependency Analyzer #1519

Merged
merged 1 commit into from
Oct 17, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.bazel.rulesscala.dependencyanalyzer

import scala.collection.mutable
import scala.reflect.io.AbstractFile
import scala.tools.nsc.Global

Expand All @@ -10,6 +11,7 @@ class AstUsedJarFinder(

def findUsedJars: Map[AbstractFile, Global#Position] = {
val jars = collection.mutable.Map[AbstractFile, global.Position]()
val visitedTrees = mutable.Set.empty[Tree]

def recordUse(source: AbstractFile, pos: Position): Unit = {
// We prefer to report locations which have information (e.g.
Expand Down Expand Up @@ -94,12 +96,7 @@ class AstUsedJarFinder(
tree.attachments
.get[global.treeChecker.MacroExpansionAttachment]
.foreach { attach =>
// When we explore the original, the original also has
// this attachment. So we should not examine the original
// again if so.
if (attach.expandee != tree) {
fullyExploreTree(attach.expandee)
}
fullyExploreTree(attach.expandee)
}

val shouldExamine =
Expand Down Expand Up @@ -133,7 +130,11 @@ class AstUsedJarFinder(
}
}

tree.foreach(visitNode)
// handle possible cycles in macro expandees
if (!visitedTrees.contains(tree)) {
visitedTrees += tree
tree.foreach(visitNode)
}
}

currentRun.units.foreach { unit =>
Expand Down