Skip to content

Commit

Permalink
tools/flow: add IgnoreConcrete option
Browse files Browse the repository at this point in the history
Ignore dependencies which point to immutable values.

This is the behavior of `cue cmd`. It is not sure whether
this is necessarily desirable, so this has been added as an option.

It would be possible to always have this behavior, though.

Change-Id: I3feacf5600a7ea1b69986e12fb5c7a285c9f413a
Reviewed-on: https://cue-review.googlesource.com/c/cue/+/7642
Reviewed-by: Marcel van Lohuizen <mpvl@golang.org>
Reviewed-by: CUE cueckoo <cueckoo@gmail.com>
  • Loading branch information
mpvl committed Nov 17, 2020
1 parent 00f345b commit d3ff4a1
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 3 deletions.
4 changes: 4 additions & 0 deletions tools/flow/flow.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,10 @@ type Config struct {
// by any of the tasks defined within Root.
InferTasks bool

// IgnoreConcrete ignores references for which the values are already
// concrete and cannot change.
IgnoreConcrete bool

// UpdateFunc is called whenever the information in the controller is
// updated. This includes directly after initialization. The task may be
// nil if this call is not the result of a task completing.
Expand Down
7 changes: 4 additions & 3 deletions tools/flow/flow_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,10 @@ func TestFlow(t *testing.T) {
}

cfg := &flow.Config{
Root: cue.ParsePath("root"),
InferTasks: t.Bool("InferTasks"),
UpdateFunc: updateFunc,
Root: cue.ParsePath("root"),
InferTasks: t.Bool("InferTasks"),
IgnoreConcrete: t.Bool("IgnoreConcrete"),
UpdateFunc: updateFunc,
}

c := flow.New(cfg, inst, taskFunc)
Expand Down
6 changes: 6 additions & 0 deletions tools/flow/tasks.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,12 @@ func (c *Controller) findImpliedTask(d dep.Dependency) *Task {

n := d.Node
for ; n != nil; n = n.Parent {
if c.cfg.IgnoreConcrete && n.Value.Concreteness() <= adt.Concrete {
if k := n.Value.Kind(); k != adt.StructKind && k != adt.ListKind {
return nil
}
}

t, ok := c.nodes[n]
if ok || !c.cfg.InferTasks {
return t
Expand Down
46 changes: 46 additions & 0 deletions tools/flow/testdata/concrete.txtar
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#IgnoreConcrete: true
-- in.cue --
root: {
t1: {
$id: "sequenced"
seq: 1
text: t2.value
value: "v"
}
t2: {
$id: "sequenced"
seq: 2
text: t1.value
value: "v"
}
}
-- out/run/errors --
-- out/run/t0 --
graph TD
t0("root.t1 [Ready]")
t1("root.t2 [Ready]")

-- out/run/t1 --
graph TD
t0("root.t1 [Terminated]")
t1("root.t2 [Running]")

-- out/run/t1/value --
{
$id: "sequenced"
seq: 1
text: "v"
value: "v"
}
-- out/run/t2 --
graph TD
t0("root.t1 [Terminated]")
t1("root.t2 [Terminated]")

-- out/run/t2/value --
{
$id: "sequenced"
seq: 2
text: "v"
value: "v"
}

0 comments on commit d3ff4a1

Please sign in to comment.