diff options
author | Li Haoyi <haoyi.sg@gmail.com> | 2017-10-27 09:07:58 -0700 |
---|---|---|
committer | Li Haoyi <haoyi.sg@gmail.com> | 2017-10-27 09:07:58 -0700 |
commit | b1a682a400922506a2bb7e42e0597625a8cbca16 (patch) | |
tree | f03a0bd85747848689f056a0897492c2d2d75239 /src | |
parent | f53db8482c86f30c917d16b6312ad4804b37f2df (diff) | |
download | mill-b1a682a400922506a2bb7e42e0597625a8cbca16.tar.gz mill-b1a682a400922506a2bb7e42e0597625a8cbca16.tar.bz2 mill-b1a682a400922506a2bb7e42e0597625a8cbca16.zip |
Got grouped evaluation working
Diffstat (limited to 'src')
-rw-r--r-- | src/main/scala/forge/Evaluator.scala | 19 | ||||
-rw-r--r-- | src/main/scala/forge/Target.scala | 10 | ||||
-rw-r--r-- | src/test/scala/forge/EvaluationTests.scala | 8 | ||||
-rw-r--r-- | src/test/scala/forge/GraphTests.scala | 20 | ||||
-rw-r--r-- | src/test/scala/forge/TestUtil.scala | 8 |
5 files changed, 29 insertions, 36 deletions
diff --git a/src/main/scala/forge/Evaluator.scala b/src/main/scala/forge/Evaluator.scala index ecbf4260..32a3c9d0 100644 --- a/src/main/scala/forge/Evaluator.scala +++ b/src/main/scala/forge/Evaluator.scala @@ -50,12 +50,13 @@ class Evaluator(workspacePath: jnio.Path, val targetDestPath = workspacePath.resolve( jnio.Paths.get(enclosingStr.stripSuffix(enclosingBase.label)) ) + val anyDirty = group.exists(_.dirty) deleteRec(targetDestPath) val inputsHash = inputResults.hashCode - (primeTerminal.dirty, resultCache.get(primeTerminal.defCtx.label)) match{ - case (Some(dirtyCheck), Some((hash, terminalResults))) - if hash == inputsHash && !dirtyCheck() => + resultCache.get(primeTerminal.defCtx.label) match{ + case Some((hash, terminalResults)) + if hash == inputsHash && !anyDirty => for((terminal, res) <- terminals.items.zip(terminalResults)){ newResults(terminal) = primeTerminal.formatter.reads(Json.parse(res)).get @@ -64,14 +65,16 @@ class Evaluator(workspacePath: jnio.Path, case _ => val terminalResults = mutable.Buffer.empty[String] for(target <- group.items){ - newEvaluated.append(target) - if (target.defCtx.anonId.isDefined && target.dirty.isEmpty) { - val res = target.evaluate(new Args(inputResults, targetDestPath)) + val targetInputValues = target.inputs.toVector.map(x => + newResults.getOrElse(x, results(x)) + ) + if (target.defCtx.anonId.isDefined) { + val res = target.evaluate(new Args(targetInputValues, targetDestPath)) newResults(target) = res }else{ val (res, serialized) = target.evaluateAndWrite( - new Args(inputResults, targetDestPath) + new Args(targetInputValues, targetDestPath) ) if (!internalInputSet(target)){ terminalResults.append(serialized) @@ -117,7 +120,7 @@ object Evaluator{ val targetGroup = grouping.lookupValue(target) for(upstream <- target.inputs){ grouping.lookupValueOpt(upstream) match{ - case None if upstream.dirty.isEmpty && upstream.defCtx.anonId.nonEmpty => + case None if upstream.defCtx.anonId.nonEmpty => grouping.add(targetGroup, upstream) case Some(upstreamGroup) if upstreamGroup == targetGroup => val upstreamTargets = grouping.removeAll(upstreamGroup) diff --git a/src/main/scala/forge/Target.scala b/src/main/scala/forge/Target.scala index adf2cb99..6f434030 100644 --- a/src/main/scala/forge/Target.scala +++ b/src/main/scala/forge/Target.scala @@ -21,12 +21,8 @@ abstract class Target[T](implicit formatter: Format[T]) extends Target.Ops[T]{ /** * Even if this target's inputs did not change, does it need to re-evaluate * anyway? - * - * - None means it never needs to re-evaluate unless its inputs do - * - Some(f) contains a function that returns whether or not it should re-evaluate, - * e.g. if the files this target represents on disk changed */ - val dirty: Option[() => Boolean] = Some(() => false) + def dirty: Boolean = false } @@ -67,9 +63,9 @@ object Target{ var lastCounter = counter def evaluate(args: Args) = { lastCounter = counter - counter + args.args.map(_.asInstanceOf[Int]).sum + counter + args.args.map(_.asInstanceOf[Int]).sum } - override val dirty = if (pure) None else Some(() => lastCounter != counter) + override def dirty = lastCounter != counter } def traverse[T: Format](source: Seq[Target[T]])(implicit defCtx: DefCtx) = { new Traverse[T](source, defCtx) diff --git a/src/test/scala/forge/EvaluationTests.scala b/src/test/scala/forge/EvaluationTests.scala index 2ab6d31e..0ae5f62a 100644 --- a/src/test/scala/forge/EvaluationTests.scala +++ b/src/test/scala/forge/EvaluationTests.scala @@ -53,7 +53,7 @@ object EvaluationTests extends TestSuite{ check(down, expValue = 0, expEvaled = OSet(up, middle, down)) down.counter += 1 - check(down, expValue = 1, expEvaled = OSet(down)) + check(down, expValue = 1, expEvaled = OSet(middle, down)) up.counter += 1 check(down, expValue = 2, expEvaled = OSet(up, middle, down)) @@ -86,17 +86,17 @@ object EvaluationTests extends TestSuite{ check(down, expValue = 0, expEvaled = OSet(up, left, right, down)) down.counter += 1 - check(down, expValue = 1, expEvaled = OSet(down)) + check(down, expValue = 1, expEvaled = OSet(left, right, down)) up.counter += 1 // Increment by 2 because up is referenced twice: once by left once by right check(down, expValue = 3, expEvaled = OSet(up, left, right, down)) left.counter += 1 - check(down, expValue = 4, expEvaled = OSet(left, down)) + check(down, expValue = 4, expEvaled = OSet(left, right, down)) right.counter += 1 - check(down, expValue = 5, expEvaled = OSet(right, down)) + check(down, expValue = 5, expEvaled = OSet(left, right, down)) } // 'anonImpureDiamond - { // import AnonImpureDiamond._ diff --git a/src/test/scala/forge/GraphTests.scala b/src/test/scala/forge/GraphTests.scala index 648ad873..35430795 100644 --- a/src/test/scala/forge/GraphTests.scala +++ b/src/test/scala/forge/GraphTests.scala @@ -142,24 +142,18 @@ object GraphTests extends TestSuite{ anonDiamond.down, OSet( OSet("up"), - OSet("down2", "down1", "down") + OSet("down1", "down2", "down") ) ) 'bigSingleTerminal - check( bigSingleTerminal.j, OSet( - OSet("i1"), - OSet("e4"), - OSet("a1"), - OSet("a2"), - OSet("a"), - OSet("b1"), - OSet("b"), - OSet("e5", "e2", "e8", "e1", "e7", "e6", "e3", "e"), - OSet("i2", "i5", "i4", "i3", "i"), - OSet("f2"), - OSet("f3", "f1", "f"), - OSet("j3", "j2", "j1", "j") + OSet("a1", "a2", "a"), + OSet("b1", "b"), + OSet("e4", "e1", "e5", "e3", "e2", "e8", "e7", "e6", "e"), + OSet("i1", "i3", "i2", "i5", "i4", "i"), + OSet("f2", "f3", "f1", "f"), + OSet("j1", "j2", "j3", "j") ) ) } diff --git a/src/test/scala/forge/TestUtil.scala b/src/test/scala/forge/TestUtil.scala index d0dcd755..580f814a 100644 --- a/src/test/scala/forge/TestUtil.scala +++ b/src/test/scala/forge/TestUtil.scala @@ -41,17 +41,17 @@ object TestUtil { val down = T{ test(test(up), test(up)) } } - // x g-----o + // o g-----o // \ \ \ - // x o h-----I---o + // o o h-----I---o // \ / \ / \ / \ \ // A---c--o E o-o \ \ // / \ / \ / \ o---J - // x d o--o o / / + // o d o--o o / / // \ / \ / / // o o---F---o // / / - // x--B x + // o--B o object bigSingleTerminal{ val a = T{ test(test(), test()) } val b = T{ test(test()) } |