diff options
author | Li Haoyi <haoyi.sg@gmail.com> | 2017-11-05 16:19:30 -0800 |
---|---|---|
committer | Li Haoyi <haoyi.sg@gmail.com> | 2017-11-05 16:19:30 -0800 |
commit | 427134c820f4c9a9e281ba3607ab4879c6185613 (patch) | |
tree | f53529f14234e00a2ac41c3275d4898298e74957 /core/src/main/scala/forge/define/Applicative.scala | |
parent | 44bd42587532755439fcdc175eb95604966bbea8 (diff) | |
download | mill-427134c820f4c9a9e281ba3607ab4879c6185613.tar.gz mill-427134c820f4c9a9e281ba3607ab4879c6185613.tar.bz2 mill-427134c820f4c9a9e281ba3607ab4879c6185613.zip |
Break out `Cacher.scala` from `Applicative.scala` to fully separate the gnarly macros
Diffstat (limited to 'core/src/main/scala/forge/define/Applicative.scala')
-rw-r--r-- | core/src/main/scala/forge/define/Applicative.scala | 36 |
1 files changed, 4 insertions, 32 deletions
diff --git a/core/src/main/scala/forge/define/Applicative.scala b/core/src/main/scala/forge/define/Applicative.scala index 2185c3d4..6a4d1d0c 100644 --- a/core/src/main/scala/forge/define/Applicative.scala +++ b/core/src/main/scala/forge/define/Applicative.scala @@ -37,18 +37,9 @@ object Applicative { def zip[A, B, C, D, E, F](a: T[A], b: T[B], c: T[C], d: T[D], e: T[E], f: T[F]): T[(A, B, C, D, E, F)] def zip[A, B, C, D, E, F, G](a: T[A], b: T[B], c: T[C], d: T[D], e: T[E], f: T[F], g: T[G]): T[(A, B, C, D, E, F, G)] } - trait Cacher[C]{ - private[this] val cacherLazyMap = mutable.Map.empty[sourcecode.Enclosing, C] - protected[this] def cachedTarget[T <: C](t: => T) - (implicit c: sourcecode.Enclosing): T = synchronized{ - cacherLazyMap.getOrElseUpdate(c, t).asInstanceOf[T] - } - } - def impl0[M[_], T: c.WeakTypeTag](c: Context)(t: c.Expr[M[T]]): c.Expr[M[T]] = { - wrapCached(c)(t.tree) - } - def impl[M[_], T: c.WeakTypeTag](c: Context)(t: c.Expr[T])(implicit tt: c.WeakTypeTag[M[_]]): c.Expr[M[T]] = { + def impl[M[_], T: c.WeakTypeTag](c: Context) + (t: c.Expr[T]): c.Expr[M[T]] = { import c.universe._ def rec(t: Tree): Iterator[c.Tree] = Iterator(t) ++ t.children.flatMap(rec(_)) @@ -92,26 +83,7 @@ object Applicative { c.internal.changeOwner(transformed, c.internal.enclosingOwner, callback.symbol) - wrapCached(c)(res) - } - def wrapCached[M[_], T](c: Context)(t: c.Tree) = { - import c.universe._ - val owner = c.internal.enclosingOwner - val ownerIsCacherClass = - owner.owner.isClass && - owner.owner.asClass.baseClasses.exists(_.fullName == "forge.define.Applicative.Cacher") - - if (ownerIsCacherClass && !owner.isMethod){ - c.abort( - c.enclosingPosition, - "T{} members defined in a Cacher class/trait/object body must be defs" - ) - }else{ - val embedded = - if (!ownerIsCacherClass) t - else q"this.cachedTarget($t)" - - c.Expr[M[T]](embedded) - } + c.Expr[M[T]](res) } + } |