mirror of
https://github.com/sbt/sbt.git
synced 2026-10-06 10:03:56 +02:00
[2.x] Short-circuit x := expr.value (#9831)
**Problem** Identity map of a task (x := expr.value) goes through the task macro machinery requiring JsonFormat etc for cached task. This is not necessary for dynamic task etc. **Solution** This implements a short-circuit for x := expr.value shaped tree.
This commit is contained in:
@@ -128,7 +128,13 @@ object TaskMacro:
|
||||
val cached = ContextUtil.isTaskCacheByDefault && !isUncacheApplied && cl.nonEmpty
|
||||
t match
|
||||
case '{ if $cond then $thenp else $elsep } => taskIfImpl[A1](t, cached)
|
||||
case _ =>
|
||||
case '{ InputWrapper.`wrapInitTask_\u2603\u2603`[A1]($in) }
|
||||
if in.isExprOf[Initialize[Task[A1]]] =>
|
||||
if in.isExprOf[Scoped] then
|
||||
val convert1 = new FullConvert(qctx, 0)
|
||||
convert1.contMapN[A1, F, Id](t, convert1.appExpr, None)
|
||||
else in.asExprOf[Initialize[Task[A1]]]
|
||||
case _ =>
|
||||
val convert1 = new FullConvert(qctx, 0)
|
||||
validateTaskReferences(convert1, t)
|
||||
if cached then
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
val example = taskKey[Uncacheable]("example")
|
||||
val alias = taskKey[Uncacheable]("alias")
|
||||
val both = taskKey[Unit]("both")
|
||||
val check = taskKey[Unit]("check")
|
||||
|
||||
example := Def.taskDyn {
|
||||
Def.task {
|
||||
Uncacheable.counter.incrementAndGet()
|
||||
new Uncacheable()
|
||||
}
|
||||
}.value
|
||||
|
||||
alias := example.value
|
||||
|
||||
both := Def.uncached {
|
||||
val a = example.value
|
||||
val b = alias.value
|
||||
assert(a eq b)
|
||||
}
|
||||
|
||||
check := assert(Uncacheable.counter.get == 1, s"counter = ${Uncacheable.counter.get}")
|
||||
@@ -0,0 +1,7 @@
|
||||
import java.util.concurrent.atomic.AtomicInteger
|
||||
|
||||
class Uncacheable:
|
||||
override def toString: String = "Uncacheable"
|
||||
|
||||
object Uncacheable:
|
||||
val counter = new AtomicInteger(0)
|
||||
@@ -0,0 +1,2 @@
|
||||
> both
|
||||
> check
|
||||
Reference in New Issue
Block a user