From 033b247f742fee487996ced80c9daaf8eb10d5f1 Mon Sep 17 00:00:00 2001 From: Li Haoyi Date: Sat, 11 Nov 2017 20:49:39 -0800 Subject: `T{}` blocks can now be implicit --- core/src/main/scala/mill/define/Task.scala | 14 +++++++++++++- core/src/main/scala/mill/eval/PathRef.scala | 1 - core/src/main/scala/mill/modules/Jvm.scala | 2 +- 3 files changed, 14 insertions(+), 3 deletions(-) (limited to 'core/src/main') diff --git a/core/src/main/scala/mill/define/Task.scala b/core/src/main/scala/mill/define/Task.scala index ad6248d9..c1568a8f 100644 --- a/core/src/main/scala/mill/define/Task.scala +++ b/core/src/main/scala/mill/define/Task.scala @@ -47,7 +47,8 @@ object Task extends Applicative.Applyer[Task, Task, Args]{ def evaluate(args: Args) = t0 } - def apply[T](t: T): Target[T] = macro targetCachedImpl[T] + implicit def apply[T](t: T): Target[T] = macro targetCachedImpl[T] + def apply[T](t: Task[T]): Target[T] = macro Cacher.impl0[Task, T] def command[T](t: T): Command[T] = macro targetCommandImpl[T] @@ -71,6 +72,17 @@ object Task extends Applicative.Applyer[Task, Task, Args]{ ) ) } + def targetCachedImpl2[T: c.WeakTypeTag, V: c.WeakTypeTag] + (c: Context) + (t: c.Expr[T]) + (f: c.Expr[T => V]): c.Expr[Target[V]] = { + import c.universe._ + c.Expr[Target[V]]( + mill.define.Cacher.wrapCached(c)( + q"""${Applicative.impl[Task, T, Args](c)(t).tree}.map($f)""" + ) + ) + } abstract class Ops[+T]{ this: Task[T] => def map[V](f: T => V) = new Task.Mapped(this, f) diff --git a/core/src/main/scala/mill/eval/PathRef.scala b/core/src/main/scala/mill/eval/PathRef.scala index 6d99ad91..5f7efe89 100644 --- a/core/src/main/scala/mill/eval/PathRef.scala +++ b/core/src/main/scala/mill/eval/PathRef.scala @@ -55,7 +55,6 @@ case class PathRef(path: ammonite.ops.Path){ } object PathRef{ - implicit def make(p: ammonite.ops.Path): PathRef = PathRef(p) private implicit val pathFormat: Format[Path] = JsonFormatters.pathFormat implicit def jsonFormatter: Format[PathRef] = Json.format } diff --git a/core/src/main/scala/mill/modules/Jvm.scala b/core/src/main/scala/mill/modules/Jvm.scala index bbaf1474..bfb7defe 100644 --- a/core/src/main/scala/mill/modules/Jvm.scala +++ b/core/src/main/scala/mill/modules/Jvm.scala @@ -64,7 +64,7 @@ object Jvm { val inputs = roots def evaluate(args: Args): PathRef = { createJar(args.dest, args.args.map(_.asInstanceOf[PathRef].path)) - args.dest + PathRef(args.dest) } } } -- cgit v1.2.3