Skip to content

Commit

Permalink
Generalize Zinc Worker (#514)
Browse files Browse the repository at this point in the history
* Generalize Zinc worker

- Compiler bridges can now be either pre-compiled or on-demand-compiled
- Scala library/compiler jar discovery is now configurable
- Zinc compiler cache is now configurable, rather than being hardcoded at n=1

* .

* update constructor args

* remove duplicate util/AggWrapper.scala file

* fix

* fix

* fix

* cleanup
  • Loading branch information
lihaoyi authored Dec 19, 2018
1 parent ea36ea3 commit de175e6
Show file tree
Hide file tree
Showing 33 changed files with 248 additions and 291 deletions.
2 changes: 1 addition & 1 deletion ci/shared.sc
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def generateEval(dir: Path) = {
s"""package mill.main
|import mill.eval.Evaluator
|import mill.define.Task
|import mill.util.Strict.Agg
|import mill.api.Strict.Agg
|class EvalGenerated(evaluator: Evaluator) {
| type TT[+X] = Task[X]
| ${(1 to 22).map(generate).mkString("\n")}
Expand Down
2 changes: 1 addition & 1 deletion contrib/scalapblib/src/ScalaPBModule.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import mill.define.Sources
import mill.api.PathRef
import mill.scalalib.Lib.resolveDependencies
import mill.scalalib._
import mill.util.Loose
import mill.api.Loose

trait ScalaPBModule extends ScalaModule {

Expand Down
2 changes: 1 addition & 1 deletion contrib/twirllib/src/TwirlModule.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import mill.define.Sources
import mill.api.PathRef
import mill.scalalib.Lib.resolveDependencies
import mill.scalalib._
import mill.util.Loose
import mill.api.Loose

import scala.io.Codec
import scala.util.Properties
Expand Down
44 changes: 44 additions & 0 deletions main/api/src/mill/api/KeyedLockedCache.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package mill.api

/**
* A combination lock & cache; users provide a key, value-factory, and a
* body function to be called with the value. [[KeyedLockedCache]] ensures that
* the body function is called with the computed/cached value sequentially.
*/
trait KeyedLockedCache[T]{
def withCachedValue[V](key: Long)(f: => T)(f2: T => V): V
}

object KeyedLockedCache{
class RandomBoundedCache[T](hotParallelism: Int, coldCacheSize: Int) extends KeyedLockedCache[T]{
private[this] val random = new scala.util.Random(313373)
val available = new java.util.concurrent.Semaphore(hotParallelism)

// Awful asymptotic complexity, but our caches are tiny n < 10 so it doesn't matter
var cache = Array.fill[Option[(Long, T)]](coldCacheSize)(None)

def withCachedValue[V](key: Long)(f: => T)(f2: T => V): V = {
available.acquire()
val pickedValue = synchronized{
cache.indexWhere(_.exists(_._1 == key)) match {
case -1 => f
case i =>
val (k, v) = cache(i).get
cache(i) = None
v
}
}
val result = f2(pickedValue)
synchronized{
cache.indexWhere(_.isEmpty) match{
// Random eviction #YOLO
case -1 => cache(random.nextInt(cache.length)) = Some((key, pickedValue))
case i => cache(i) = Some((key, pickedValue))
}
}

available.release()
result
}
}
}
2 changes: 1 addition & 1 deletion main/core/src/define/Graph.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package mill.define

import mill.eval.Tarjans
import mill.util.MultiBiMap
import mill.util.Strict.Agg
import mill.api.Strict.Agg

object Graph {

Expand Down
2 changes: 1 addition & 1 deletion main/core/src/eval/Evaluator.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import mill.define.{Ctx => _, _}
import mill.api.Result.OuterStack
import mill.util
import mill.util._
import mill.util.Strict.Agg
import mill.api.Strict.Agg

import scala.collection.mutable
import scala.util.control.NonFatal
Expand Down
119 changes: 0 additions & 119 deletions main/core/src/util/AggWrapper.scala

This file was deleted.

2 changes: 1 addition & 1 deletion main/core/src/util/MultiBiMap.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package mill.util

import scala.collection.mutable
import Strict.Agg
import mill.api.Strict.Agg

/**
* A map from keys to collections of values: you can assign multiple values
Expand Down
2 changes: 1 addition & 1 deletion main/src/main/ReplApplyHandler.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import mill.define.Segment.Label
import mill.define._
import mill.eval.{Evaluator, Result}

import mill.util.Strict.Agg
import mill.api.Strict.Agg

import scala.collection.mutable
object ReplApplyHandler{
Expand Down
2 changes: 1 addition & 1 deletion main/src/main/RunScript.scala
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import mill.define._
import mill.eval.{Evaluator, PathRef, Result}
import mill.util.{EitherOps, ParseArgs, Watched}
import mill.api.Logger
import mill.util.Strict.Agg
import mill.api.Strict.Agg

import scala.collection.mutable
import scala.reflect.ClassTag
Expand Down
2 changes: 1 addition & 1 deletion main/src/modules/Jvm.scala
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import mill.main.client.InputPumper
import mill.eval.{PathRef, Result}
import mill.util.Ctx
import mill.api.IO
import mill.util.Loose.Agg
import mill.api.Loose.Agg

import scala.collection.mutable
import scala.collection.JavaConverters._
Expand Down
5 changes: 3 additions & 2 deletions main/src/modules/Util.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ package mill.modules

import coursier.Repository
import mill.api.{PathRef, IO}
import mill.util.{Ctx, Loose}
import mill.util.Ctx
import mill.api.Loose


object Util {
Expand Down Expand Up @@ -55,7 +56,7 @@ object Util {
val localPath = sys.props(key)
if (localPath != null) {
mill.api.Result.Success(
Loose.Agg.from(localPath.split(',').map(p => PathRef(os.Path(p), quick = true)))
mill.api.Loose.Agg.from(localPath.split(',').map(p => PathRef(os.Path(p), quick = true)))
)
} else {
mill.modules.Jvm.resolveDependencies(
Expand Down
4 changes: 2 additions & 2 deletions main/src/package.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ package object mill extends JsonFormatters{
type PathRef = mill.api.PathRef
type Module = define.Module
type Cross[T] = define.Cross[T]
type Agg[T] = util.Loose.Agg[T]
val Agg = util.Loose.Agg
type Agg[T] = mill.api.Loose.Agg[T]
val Agg = mill.api.Loose.Agg
}
2 changes: 1 addition & 1 deletion main/test/resources/examples/javac/build.sc
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import mill.T
import mill.eval.JavaCompileJarTests.compileAll
import mill.api.PathRef
import mill.modules.Jvm
import mill.util.Loose
import mill.api.Loose

def sourceRootPath = millSourcePath / 'src
def resourceRootPath = millSourcePath / 'resources
Expand Down
2 changes: 1 addition & 1 deletion main/test/src/define/CacherTests.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package mill.define

import mill.util.{DummyLogger, TestEvaluator, TestUtil}
import mill.util.Strict.Agg
import mill.api.Strict.Agg
import mill.T
import mill.api.Result.Success
import utest._
Expand Down
2 changes: 1 addition & 1 deletion main/test/src/define/GraphTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ package mill.define
import mill.eval.Evaluator
import mill.util.{TestGraphs, TestUtil}
import utest._
import mill.util.Strict.Agg
import mill.api.Strict.Agg
object GraphTests extends TestSuite{

val tests = Tests{
Expand Down
2 changes: 1 addition & 1 deletion main/test/src/eval/EvaluationTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import mill.util.TestUtil.{Test, test}
import mill.define.{Discover, Graph, Target, Task}
import mill.{Module, T}
import mill.util.{DummyLogger, TestEvaluator, TestGraphs, TestUtil}
import mill.util.Strict.Agg
import mill.api.Strict.Agg
import utest._
import utest.framework.TestPath

Expand Down
7 changes: 4 additions & 3 deletions main/test/src/eval/JavaCompileJarTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ import mill.define.{Discover, Input, Target, Task}
import mill.modules.Jvm
import mill.api.Ctx.Dest
import mill.{Module, T}
import mill.util.{DummyLogger, Loose, TestEvaluator, TestUtil}
import mill.util.Strict.Agg
import mill.util.{DummyLogger, TestEvaluator, TestUtil}
import mill.api.Strict.Agg
import mill.api.Loose
import utest._
import mill._
object JavaCompileJarTests extends TestSuite{
def compileAll(sources: mill.util.Loose.Agg[PathRef])(implicit ctx: Dest) = {
def compileAll(sources: mill.api.Loose.Agg[PathRef])(implicit ctx: Dest) = {
os.makeDir.all(ctx.dest)

os.proc("javac", sources.map(_.path.toString()).toSeq, "-d", ctx.dest).call(ctx.dest)
Expand Down
2 changes: 1 addition & 1 deletion main/test/src/util/TestEvaluator.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package mill.util
import mill.define.{Input, Target, Task}
import mill.api.Result.OuterStack
import mill.eval.{Evaluator, Result}
import mill.util.Strict.Agg
import mill.api.Strict.Agg
import utest.assert
import utest.framework.TestPath

Expand Down
2 changes: 1 addition & 1 deletion main/test/src/util/TestUtil.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import mill.define._
import mill.api.Result
import mill.api.Result.OuterStack
import utest.assert
import mill.util.Strict.Agg
import mill.api.Strict.Agg
import utest.framework.TestPath

import scala.collection.mutable
Expand Down
3 changes: 2 additions & 1 deletion scalajslib/src/ScalaJSModule.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import mill.eval.{PathRef, Result}
import mill.api.Result.Success
import mill.scalalib.Lib.resolveDependencies
import mill.scalalib.{DepSyntax, Lib, TestModule, TestRunner}
import mill.util.{Ctx, Loose}
import mill.util.Ctx
import mill.api.Loose
import mill.scalajslib.api._
trait ScalaJSModule extends scalalib.ScalaModule { outer =>

Expand Down
Loading

0 comments on commit de175e6

Please sign in to comment.