diff options
author | Li Haoyi <haoyi.sg@gmail.com> | 2017-10-17 06:39:56 -0700 |
---|---|---|
committer | Li Haoyi <haoyi.sg@gmail.com> | 2017-10-17 06:39:56 -0700 |
commit | 51d8c6b9be66d3a8205bfa95d6986197b715877f (patch) | |
tree | 86ac79b0484f8885b6688fe0ffa62a18631ff013 | |
parent | aa5eb186c044e0c00d512e0c009e9d519a753e0c (diff) | |
download | mill-51d8c6b9be66d3a8205bfa95d6986197b715877f.tar.gz mill-51d8c6b9be66d3a8205bfa95d6986197b715877f.tar.bz2 mill-51d8c6b9be66d3a8205bfa95d6986197b715877f.zip |
fleshed out `evaluateTargetGraph` a little
-rw-r--r-- | src/main/scala/hbt/Main.scala | 35 |
1 files changed, 31 insertions, 4 deletions
diff --git a/src/main/scala/hbt/Main.scala b/src/main/scala/hbt/Main.scala index b4b5757c..c6323e8f 100644 --- a/src/main/scala/hbt/Main.scala +++ b/src/main/scala/hbt/Main.scala @@ -3,9 +3,11 @@ import java.io.FileOutputStream import collection.JavaConverters._ import java.nio.{file => jnio} - import java.util.jar.JarEntry + import sourcecode.Enclosing + +import scala.collection.mutable class Args(val args: IndexedSeq[_]){ def length = args.length def apply[T](index: Int): T = { @@ -114,8 +116,33 @@ object Main{ } def evaluateTargetGraph[T](t: Target[T]): T = { - ??? -// val evaluated = collection.mutable.Map.empty[Target[_], Any] -// val forwardEdges + val targetSet = mutable.Set.empty[Target[_]] + def rec(t: Target[_]): Unit = { + if (targetSet.contains(t)) () // do nothing + else { + targetSet.add(t) + t.inputs.foreach(rec) + } + } + rec(t) + val targets = targetSet.toIndexedSeq + val targetIndices = targets.zipWithIndex.toMap + + val numberedEdges = + for(i <- targets.indices) + yield targets(i).inputs.map(targetIndices) + + val sortedClusters = Tarjans(numberedEdges) + val nonTrivialClusters = sortedClusters.filter(_.length > 1) + assert(nonTrivialClusters.isEmpty, nonTrivialClusters) + + val results = mutable.Map.empty[Target[_], Any] + for (cluster <- sortedClusters){ + val Seq(singletonIndex) = cluster + val singleton = targets(singletonIndex) + val inputResults = singleton.inputs.map(results) + results(singleton) = singleton.evaluate(new Args(inputResults.toIndexedSeq)) + } + results(t).asInstanceOf[T] } }
\ No newline at end of file |