this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

internal/core/dep: adapt Recurse to mimic dep.Visit

https://cuelang.org/cl/556460 swapped two indirect calls to func Visit
with calls to the method visitor.visit, allowing better memory reuse.

However, it missed that the two call sites weren't equal semantically:

* The call site in internal/core/export/self.go called markDeps,
which then called dep.Visit with the Config.Descend option set.

* The call site in tools/flow/tasks called markTaskDependencies,
which then called dep.Visit with the Config.Dynamic option set.

The former caused Visit to call visitor.visit, like our new code,
but the latter caused Visit to call visitor.dynamic,
which our new code certainly does not do.

To fix this unintentional change in behavior in the refactor above,
factor out the logic based on Dynamic so that Recurse can reuse it,
and remember the value of Dynamic in visitor so Recurse can apply it.

In the added test output, we can now see that root.run depends on
root.prepare again, like v0.5.0 did, and unlike the previous commit.

Fixes #2517.

Signed-off-by: Daniel Martí <mvdan@mvdan.cc>
Change-Id: I299000385ffdfa79218ddbe8b8faa901b5006a9d
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/557477
Reviewed-by: Marcel van Lohuizen <mpvl@gmail.com>
Unity-Result: CUE porcuepine <cue.porcuepine@gmail.com>
TryBot-Result: CUEcueckoo <cueckoo@cuelang.org>

+100 -13
+21 -13
internal/core/dep/dep.go
··· 132 132 d.visitor.all = d.visitor.recurse 133 133 d.visitor.top = true 134 134 135 - d.visitor.visit(d.Node, false) 135 + d.visitor.visitReusingVisitor(d.Node, false) 136 136 137 137 d.visitor.all = savedAll 138 138 d.visitor.top = savedTop ··· 186 186 panic("nil context") 187 187 } 188 188 v := visitor{ 189 - ctxt: c, 190 - fn: f, 191 - pkg: cfg.Pkg, 192 - recurse: cfg.Descend, 193 - all: cfg.Descend, 194 - top: true, 189 + ctxt: c, 190 + fn: f, 191 + pkg: cfg.Pkg, 192 + recurse: cfg.Descend, 193 + all: cfg.Descend, 194 + top: true, 195 + cfgDynamic: cfg.Dynamic, 195 196 } 196 - 197 - if cfg.Dynamic { 198 - v.marked = marked{} 197 + return v.visitReusingVisitor(n, true) 198 + } 199 199 200 + // visitReusingVisitor is factored out of Visit so that we may reuse visitor. 201 + func (v *visitor) visitReusingVisitor(n *adt.Vertex, top bool) error { 202 + if v.cfgDynamic { 203 + if v.marked == nil { 204 + v.marked = marked{} 205 + } 200 206 v.marked.markExpr(n) 201 207 202 - v.dynamic(n, true) 208 + v.dynamic(n, top) 203 209 } else { 204 - v.visit(n, true) 210 + v.visit(n, top) 205 211 } 206 - 207 212 return v.err 208 213 } 209 214 ··· 254 259 topRef adt.Resolver 255 260 pathStack []refEntry 256 261 numRefs int // count of reported dependencies 262 + 263 + // cfgDynamic is kept from the original config. 264 + cfgDynamic bool 257 265 258 266 marked marked 259 267 }
+79
tools/flow/testdata/issue2517.txtar
··· 1 + #IgnoreConcrete: true 2 + #InferTasks: true 3 + -- in.cue -- 4 + package x 5 + 6 + root: { 7 + prepare: { 8 + $id: "prepare" 9 + } 10 + env2: { 11 + input: prepare.stdout 12 + } 13 + run: { 14 + $id: "run" 15 + env: env2 16 + } 17 + } 18 + -- out/run/errors -- 19 + -- out/run/t0 -- 20 + graph TD 21 + t0("root.prepare [Ready]") 22 + t1("root.run [Waiting]") 23 + t1-->t0 24 + 25 + -- out/run/t1 -- 26 + graph TD 27 + t0("root.prepare [Terminated]") 28 + t1("root.run [Ready]") 29 + t1-->t0 30 + 31 + -- out/run/t1/value -- 32 + { 33 + $id: "prepare" 34 + stdout: "foo" 35 + } 36 + -- out/run/t1/stats -- 37 + Leaks: 0 38 + Freed: 11 39 + Reused: 6 40 + Allocs: 5 41 + Retain: 0 42 + 43 + Unifications: 11 44 + Conjuncts: 17 45 + Disjuncts: 11 46 + -- out/run/t2 -- 47 + graph TD 48 + t0("root.prepare [Terminated]") 49 + t1("root.run [Terminated]") 50 + t1-->t0 51 + 52 + -- out/run/t2/value -- 53 + { 54 + $id: "run" 55 + stdout: "foo" 56 + env: { 57 + input: "foo" 58 + } 59 + } 60 + -- out/run/t2/stats -- 61 + Leaks: 0 62 + Freed: 12 63 + Reused: 12 64 + Allocs: 0 65 + Retain: 0 66 + 67 + Unifications: 12 68 + Conjuncts: 21 69 + Disjuncts: 12 70 + -- out/run/stats/totals -- 71 + Leaks: 0 72 + Freed: 23 73 + Reused: 18 74 + Allocs: 5 75 + Retain: 0 76 + 77 + Unifications: 23 78 + Conjuncts: 38 79 + Disjuncts: 23