-
-
Notifications
You must be signed in to change notification settings - Fork 361
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Minor cleanups for Evaluator logic (#4144)
- Loading branch information
Showing
9 changed files
with
183 additions
and
172 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package mill.eval | ||
|
||
import mill.define.InputImpl | ||
import mill.main.client.OutFiles | ||
import mill.util.SpanningForest | ||
import java.util.concurrent.ConcurrentHashMap | ||
import scala.jdk.CollectionConverters.EnumerationHasAsScala | ||
|
||
private[mill] object EvaluatorLogs { | ||
def logDependencyTree( | ||
interGroupDeps: Map[Terminal, Seq[Terminal]], | ||
indexToTerminal: Array[Terminal], | ||
terminalToIndex: Map[Terminal, Int], | ||
outPath: os.Path | ||
): Unit = { | ||
SpanningForest.writeJsonFile( | ||
outPath / OutFiles.millDependencyTree, | ||
indexToTerminal.map(t => interGroupDeps.getOrElse(t, Nil).map(terminalToIndex).toArray), | ||
indexToTerminal.indices.toSet, | ||
indexToTerminal(_).render | ||
) | ||
} | ||
def logInvalidationTree( | ||
interGroupDeps: Map[Terminal, Seq[Terminal]], | ||
indexToTerminal: Array[Terminal], | ||
terminalToIndex: Map[Terminal, Int], | ||
outPath: os.Path, | ||
uncached: ConcurrentHashMap[Terminal, Unit], | ||
changedValueHash: ConcurrentHashMap[Terminal, Unit] | ||
): Unit = { | ||
|
||
val reverseInterGroupDeps = interGroupDeps | ||
.iterator | ||
.flatMap { case (k, vs) => vs.map(_ -> k) } | ||
.toSeq | ||
.groupMap(_._1)(_._2) | ||
|
||
val changedTerminalIndices = changedValueHash.keys().asScala.toSet | ||
val downstreamIndexEdges = indexToTerminal | ||
.map(t => | ||
if (changedTerminalIndices(t)) | ||
reverseInterGroupDeps.getOrElse(t, Nil).map(terminalToIndex).toArray | ||
else Array.empty[Int] | ||
) | ||
|
||
val edgeSourceIndices = downstreamIndexEdges | ||
.zipWithIndex | ||
.collect { case (es, i) if es.nonEmpty => i } | ||
.toSet | ||
|
||
SpanningForest.writeJsonFile( | ||
outPath / OutFiles.millInvalidationTree, | ||
downstreamIndexEdges, | ||
uncached.keys().asScala | ||
.flatMap { uncachedTask => | ||
val uncachedIndex = terminalToIndex(uncachedTask) | ||
Option.when( | ||
// Filter out input and source tasks which do not cause downstream invalidations | ||
// from the invalidation tree, because most of them are un-interesting and the | ||
// user really only cares about (a) inputs that cause downstream tasks to invalidate | ||
// or (b) non-input tasks that were invalidated alone (e.g. due to a codesig change) | ||
!uncachedTask.task.isInstanceOf[InputImpl[_]] || edgeSourceIndices(uncachedIndex) | ||
) { | ||
uncachedIndex | ||
} | ||
} | ||
.toSet, | ||
indexToTerminal(_).render | ||
) | ||
} | ||
} |
Oops, something went wrong.