summaryrefslogtreecommitdiff
path: root/core/src/main
diff options
context:
space:
mode:
authorLi Haoyi <haoyi.sg@gmail.com>2017-11-04 13:21:08 -0700
committerLi Haoyi <haoyi.sg@gmail.com>2017-11-04 13:21:08 -0700
commit8a9e1ade269f644664fd4499f65dfa445ab2ac55 (patch)
tree9a61f58c8b22722bbe61bc3d189ef97697a3c6ad /core/src/main
parent546261a0c801daa4ab7be2464ed275e88a6c0787 (diff)
downloadmill-8a9e1ade269f644664fd4499f65dfa445ab2ac55.tar.gz
mill-8a9e1ade269f644664fd4499f65dfa445ab2ac55.tar.bz2
mill-8a9e1ade269f644664fd4499f65dfa445ab2ac55.zip
- Get rid of lazy `Target` wrapper since we're using lazy `def`s everywhere
- Switch to using just `sourcecode.Enclosing` to key the `cacherLazyMap`, since the caller is already present as the `this` owning the `cacherLazyMap` and does not need to be stored
Diffstat (limited to 'core/src/main')
-rw-r--r--core/src/main/scala/forge/Target.scala16
-rw-r--r--core/src/main/scala/forge/util/Caller.scala12
2 files changed, 5 insertions, 23 deletions
diff --git a/core/src/main/scala/forge/Target.scala b/core/src/main/scala/forge/Target.scala
index df9d9cc3..ba18184c 100644
--- a/core/src/main/scala/forge/Target.scala
+++ b/core/src/main/scala/forge/Target.scala
@@ -33,11 +33,10 @@ abstract class Target[T] extends Target.Ops[T]{
object Target{
trait Cacher{
- val cacherLazyMap = mutable.Map.empty[(Any, sourcecode.Line, sourcecode.Enclosing), Target[_]]
+ val cacherLazyMap = mutable.Map.empty[sourcecode.Enclosing, Target[_]]
def T[T](t: T): Target[T] = macro impl[T]
- def T[T](t: => Target[T])
- (implicit c: forge.util.Caller, l: sourcecode.Line, e: sourcecode.Enclosing): Target[T] = {
- cacherLazyMap.getOrElseUpdate((c, l, e), t).asInstanceOf[Target[T]]
+ def T[T](t: => Target[T])(implicit c: sourcecode.Enclosing): Target[T] = {
+ cacherLazyMap.getOrElseUpdate(c, t).asInstanceOf[Target[T]]
}
}
class Target0[T](t: T) extends Target[T]{
@@ -45,12 +44,7 @@ object Target{
val inputs = Nil
def evaluate(args: Args) = t0
}
- class Target1[T](t: => Target[T]) extends Target[T]{
- lazy val t0 = t
- lazy val inputs = t0.inputs
- def evaluate(args: Args) = t0.evaluate(args)
- }
- def apply[T](t: => Target[T]): Target[T] = new Target1(t)
+ def apply[T](t: Target[T]): Target[T] = t
def apply[T](t: T): Target[T] = macro impl[T]
def impl[T: c.WeakTypeTag](c: Context)(t: c.Expr[T]): c.Expr[Target[T]] = {
import c.universe._
@@ -76,7 +70,7 @@ object Target{
val bindings = symbols.map(c.internal.valDef(_))
- val newTargetTree = q"new forge.Target.Target1(forge.zipMap(..$exprs){ (..$bindings) => $transformed })"
+ val newTargetTree = q"forge.zipMap(..$exprs){ (..$bindings) => $transformed }"
val embedded =
if (!(c.prefix.tree.tpe <:< typeOf[Cacher])) newTargetTree
diff --git a/core/src/main/scala/forge/util/Caller.scala b/core/src/main/scala/forge/util/Caller.scala
deleted file mode 100644
index 30dcb22a..00000000
--- a/core/src/main/scala/forge/util/Caller.scala
+++ /dev/null
@@ -1,12 +0,0 @@
-package forge.util
-
-import scala.reflect.macros.blackbox
-import language.experimental.macros
-case class Caller(value: Any)
-object Caller {
- implicit def generate: Caller = macro impl
- def impl(c: blackbox.Context): c.Tree = {
- import c.universe._
- q"new _root_.forge.util.Caller(this)"
- }
-}