[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:
eugene yokota
2026-09-26 18:30:17 -04:00
committed by GitHub
parent 637c5d2a05
commit 8a2ec14cc8
4 changed files with 37 additions and 1 deletions
@@ -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
+21
View File
@@ -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)
+2
View File
@@ -0,0 +1,2 @@
> both
> check