8000 WIP BFS for Tagger by gzm0 · Pull Request #4987 · scala-js/scala-js · GitHub
[go: up one dir, main page]

Skip to content

WIP BFS for Tagger #4987

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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
Expand Up @@ -166,7 +166,14 @@ private class Tagger(infos: ModuleAnalyzer.DependencyInfo,

final def tagAll(modulesToAvoid: Iterable[ModuleID]): scala.collection.Map[ClassName, ModuleID] = {
val internalModIDGenerator = new InternalModuleIDGenerator.ForDigests(modulesToAvoid)
tagEntryPoints()

val edgesToProcess = mutable.Queue.empty[Edge]
edgesToProcess ++= entryPointEdges()

while (edgesToProcess.nonEmpty) {
edgesToProcess ++= processEdge(edgesToProcess.dequeue())
}

for {
(className, paths) <- allPaths
if !excludedClasses.contains(className)
Expand All @@ -175,8 +182,9 @@ private class Tagger(infos: ModuleAnalyzer.DependencyInfo,
}
}

private def tag(className: ClassName, pathRoot: ModuleID, pathSteps: List[ClassName],
excludedHopCount: Int, fromExcluded: Boolean): Unit = {
private def processEdge(edge: Edge): Iterable[Edge] = {
import edge._

val isExcluded = excludedClasses.contains(className)

val newExcludedHopCount =
Expand All @@ -189,31 +197,35 @@ private class Tagger(infos: ModuleAnalyzer.DependencyInfo,

if (updated) {
val classInfo = infos.classDependencies(className)
classInfo
val staticEdges = classInfo
.staticDependencies
.foreach(staticEdge(_, pathRoot, pathSteps, newExcludedHopCount, fromExcluded = isExcluded))
.map(staticEdge(_, pathRoot, pathSteps, newExcludedHopCount, fromExcluded = isExcluded))

classInfo
val dynamicEdges = classInfo
.dynamicDependencies
.foreach(dynamicEdge(_, pathRoot, pathSteps, newExcludedHopCount, fromExcluded = isExcluded))
.map(dynamicEdge(_, pathRoot, pathSteps, newExcludedHopCount, fromExcluded = isExcluded))

staticEdges ++ dynamicEdges
} else {
Iterable.empty
}
}

private def staticEdge(className: ClassName, pathRoot: ModuleID, pathSteps: List[ClassName],
excludedHopCount: Int, fromExcluded: Boolean): Unit = {
tag(className, pathRoot, pathSteps, excludedHopCount, fromExcluded)
excludedHopCount: Int, fromExcluded: Boolean): Edge = {
new Edge(className, pathRoot, pathSteps, excludedHopCount, fromExcluded)
}

private def dynamicEdge(className: ClassName, pathRoot: ModuleID, pathSteps: List[ClassName],
excludedHopCount: Int, fromExcluded: Boolean): Unit = {
tag(className, pathRoot, pathSteps :+ className, excludedHopCount, fromExcluded)
excludedHopCount: Int, fromExcluded: Boolean): Edge = {
new Edge(className, pathRoot, pathSteps :+ className, excludedHopCount, fromExcluded)
}

private def tagEntryPoints(): Unit = {
private def entryPointEdges(): Iterable[Edge] = {
for {
(moduleID, deps) <- infos.publicModuleDependencies
className <- deps
} {
} yield {
staticEdge(className, pathRoot = moduleID, pathSteps = Nil,
excludedHopCount = 0, fromExcluded = false)
}
Expand All @@ -222,6 +234,14 @@ private class Tagger(infos: ModuleAnalyzer.DependencyInfo,

private object Tagger {

private final class Edge(
val className: ClassName,
val pathRoot: ModuleID,
val pathSteps: List[ClassName],
val excludedHopCount: Int,
val fromExcluded: Boolean
)

/** "Interesting" paths that can lead to a given class.
*
* "Interesting" in this context means:
Expand Down
0