Skip to content

Commit

Permalink
Introduced new failFast parameter to Evaluator with default true
Browse files Browse the repository at this point in the history
Added Aborted result type.
  • Loading branch information
lefou committed Dec 21, 2018
1 parent 868ac2f commit 54bb990
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 10 deletions.
7 changes: 7 additions & 0 deletions main/api/src/mill/api/Result.scala
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@ object Result {
def map[V](f: Nothing => V) = this
}

/**
* A task execution was skipped/aborted because of earlier (maybe unrelated) tasks failed and the evaluation was in fail-fast mode.
*/
case object Aborted extends Result[Nothing] {
def map[V](f: Nothing => V) = this
}

/**
* A failed task execution.
* @tparam T The result type of the computed task.
Expand Down
36 changes: 26 additions & 10 deletions main/core/src/eval/Evaluator.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@ package mill.eval
import java.net.URLClassLoader

import scala.collection.JavaConverters._
import scala.collection.mutable
import scala.util.control.NonFatal

import mill.util.Router.EntryPoint
import ammonite.runtime.SpecialClassLoader
import mill.util.Router.EntryPoint
import mill.define.{Ctx => _, _}
import mill.api.Result.OuterStack
import mill.api.Result.{Aborted, OuterStack, Success}
import mill.util
import mill.util._
import mill.api.Strict.Agg

import scala.collection.mutable
import scala.util.control.NonFatal
case class Labelled[T](task: NamedTask[T],
segments: Segments){
def format = task match{
Expand All @@ -34,18 +34,31 @@ case class Evaluator(home: os.Path,
log: Logger,
classLoaderSig: Seq[(Either[String, os.Path], Long)] = Evaluator.classLoaderSig,
workerCache: mutable.Map[Segments, (Int, Any)] = mutable.Map.empty,
env : Map[String, String] = Evaluator.defaultEnv){
env : Map[String, String] = Evaluator.defaultEnv,
failFast: Boolean = true
){

val classLoaderSignHash = classLoaderSig.hashCode()

def evaluate(goals: Agg[Task[_]]): Evaluator.Results = {
os.makeDir.all(outPath)

val (sortedGroups, transitive) = Evaluator.plan(rootModule, goals)
val (sortedGroups, transitive) = Evaluator.plan(rootModule, goals)

val evaluated = new Agg.Mutable[Task[_]]
val results = mutable.LinkedHashMap.empty[Task[_], Result[(Any, Int)]]
var someTaskFailed: Boolean = false

val timings = mutable.ArrayBuffer.empty[(Either[Task[_], Labelled[_]], Int, Boolean)]
for (((terminal, group), i) <- sortedGroups.items().zipWithIndex){
for (((terminal, group), i) <- sortedGroups.items().zipWithIndex)
if(failFast && someTaskFailed) {
// we exit early and set aborted state for all left tasks
group.foreach { task =>
results.put(task, Aborted)
}

} else {

val startTime = System.currentTimeMillis()
// Increment the counter message by 1 to go from 1/10 to 10/10 instead of 0/10 to 9/10
val counterMsg = (i+1) + "/" + sortedGroups.keyCount
Expand All @@ -55,6 +68,7 @@ case class Evaluator(home: os.Path,
results,
counterMsg
)
someTaskFailed = someTaskFailed || newResults.exists(task => !task._2.isInstanceOf[Success[_]])

for(ev <- newEvaluated){
evaluated.append(ev)
Expand Down Expand Up @@ -97,7 +111,8 @@ case class Evaluator(home: os.Path,
def evaluateGroupCached(terminal: Either[Task[_], Labelled[_]],
group: Agg[Task[_]],
results: collection.Map[Task[_], Result[(Any, Int)]],
counterMsg: String): (collection.Map[Task[_], Result[(Any, Int)]], Seq[Task[_]], Boolean) = {
counterMsg: String
): (collection.Map[Task[_], Result[(Any, Int)]], Seq[Task[_]], Boolean) = {

val externalInputsHash = scala.util.hashing.MurmurHash3.orderedHash(
group.items.flatMap(_.inputs).filter(!group.contains(_))
Expand Down Expand Up @@ -232,7 +247,8 @@ case class Evaluator(home: os.Path,
upickle.default.write(
Evaluator.Cached(json, hashCode, inputsHash),
indent = 4
)
),
createFolders = true
)
}
}
Expand All @@ -243,7 +259,7 @@ case class Evaluator(home: os.Path,
inputsHash: Int,
paths: Option[Evaluator.Paths],
maybeTargetLabel: Option[String],
counterMsg: String) = {
counterMsg: String): (mutable.LinkedHashMap[Task[_], Result[(Any, Int)]], mutable.Buffer[Task[_]]) = {


val newEvaluated = mutable.Buffer.empty[Task[_]]
Expand Down

0 comments on commit 54bb990

Please # to comment.