this repo has no description
0
fork

Configure Feed

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

tools/flow: support tasks inside slices

Fixes #2365.

Signed-off-by: Roger Peppe <rogpeppe@gmail.com>
Change-Id: I7db79b19357949906761198a26da8299e53e7750
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/553113
Reviewed-by: Marcel van Lohuizen <mpvl@gmail.com>
Unity-Result: CUEcueckoo <cueckoo@cuelang.org>
TryBot-Result: CUEcueckoo <cueckoo@cuelang.org>

+150 -8
+2 -2
tools/flow/flow_test.go
··· 44 44 test.Run(t, func(t *cuetxtar.Test) { 45 45 v := cuecontext.New().BuildInstance(t.Instance()) 46 46 if err := v.Err(); err != nil { 47 - t.Fatal(err) 47 + t.Fatal(errors.Details(err, nil)) 48 48 } 49 49 50 50 seqNum = 0 ··· 166 166 return nil 167 167 }), nil 168 168 } 169 - if err != nil && v.Lookup("$id").Exists() { 169 + if err != nil && v.LookupPath(cue.MakePath(cue.Str("$id"))).Exists() { 170 170 return nil, err 171 171 } 172 172
+22 -6
tools/flow/run.go
··· 206 206 207 207 expr := t.update 208 208 for i := len(t.labels) - 1; i >= 0; i-- { 209 - expr = &adt.StructLit{ 210 - Decls: []adt.Decl{ 211 - &adt.Field{ 212 - Label: t.labels[i], 213 - Value: expr, 209 + label := t.labels[i] 210 + switch label.Typ() { 211 + case adt.StringLabel, adt.HiddenLabel: 212 + expr = &adt.StructLit{ 213 + Decls: []adt.Decl{ 214 + &adt.Field{ 215 + Label: t.labels[i], 216 + Value: expr, 217 + }, 214 218 }, 215 - }, 219 + } 220 + case adt.IntLabel: 221 + i := label.Index() 222 + list := &adt.ListLit{} 223 + any := &adt.Top{} 224 + // TODO(perf): make this a constant thing. This will be possible with the query extension. 225 + for k := 0; k < i; k++ { 226 + list.Elems = append(list.Elems, any) 227 + } 228 + list.Elems = append(list.Elems, expr, &adt.Ellipsis{}) 229 + expr = list 230 + default: 231 + panic(fmt.Errorf("unexpected label type %v", label.Typ())) 216 232 } 217 233 } 218 234
+4
tools/flow/tasks.go
··· 77 77 for iter, _ := v.Fields(opts...); iter.Next(); { 78 78 c.findRootTasks(iter.Value()) 79 79 } 80 + for iter, _ := v.List(); iter.Next(); { 81 + c.findRootTasks(iter.Value()) 82 + } 83 + 80 84 } 81 85 82 86 // This file contains the functionality to locate and record the tasks of
+122
tools/flow/testdata/slice.txtar
··· 1 + #FindHiddenTasks: true 2 + -- in.cue -- 3 + 4 + // TODO test when root has the list embedded and 5 + // some hidden task fields too. See https://github.com/cue-lang/cue/issues/2366. 6 + root: [ 7 + { 8 + $id: "valToOut" 9 + val: "foo" 10 + out: string 11 + }, 12 + { 13 + $id: "valToOut" 14 + $after: root[0] 15 + val: "bar" 16 + out: string 17 + }, 18 + { 19 + $id: "valToOut" 20 + out: root[0].out + root[1].out 21 + }, 22 + ] 23 + 24 + -- out/run/errors -- 25 + -- out/run/t0 -- 26 + graph TD 27 + t0("root[0] [Ready]") 28 + t1("root[1] [Waiting]") 29 + t1-->t0 30 + t2("root[2] [Waiting]") 31 + t2-->t0 32 + t2-->t1 33 + 34 + -- out/run/t1 -- 35 + graph TD 36 + t0("root[0] [Terminated]") 37 + t1("root[1] [Ready]") 38 + t1-->t0 39 + t2("root[2] [Waiting]") 40 + t2-->t0 41 + t2-->t1 42 + 43 + -- out/run/t1/value -- 44 + { 45 + $id: "valToOut" 46 + val: "foo" 47 + out: "foo" 48 + } 49 + -- out/run/t1/stats -- 50 + Leaks: 0 51 + Freed: 17 52 + Reused: 12 53 + Allocs: 5 54 + Retain: 0 55 + 56 + Unifications: 17 57 + Conjuncts: 30 58 + Disjuncts: 17 59 + -- out/run/t2 -- 60 + graph TD 61 + t0("root[0] [Terminated]") 62 + t1("root[1] [Terminated]") 63 + t1-->t0 64 + t2("root[2] [Ready]") 65 + t2-->t0 66 + t2-->t1 67 + 68 + -- out/run/t2/value -- 69 + { 70 + $id: "valToOut" 71 + $after: { 72 + $id: "valToOut" 73 + val: "foo" 74 + out: "foo" 75 + } 76 + val: "bar" 77 + out: "bar" 78 + } 79 + -- out/run/t2/stats -- 80 + Leaks: 0 81 + Freed: 17 82 + Reused: 17 83 + Allocs: 0 84 + Retain: 0 85 + 86 + Unifications: 17 87 + Conjuncts: 33 88 + Disjuncts: 17 89 + -- out/run/t3 -- 90 + graph TD 91 + t0("root[0] [Terminated]") 92 + t1("root[1] [Terminated]") 93 + t1-->t0 94 + t2("root[2] [Terminated]") 95 + t2-->t0 96 + t2-->t1 97 + 98 + -- out/run/t3/value -- 99 + { 100 + $id: "valToOut" 101 + out: "foobar" 102 + } 103 + -- out/run/t3/stats -- 104 + Leaks: 0 105 + Freed: 0 106 + Reused: 0 107 + Allocs: 0 108 + Retain: 0 109 + 110 + Unifications: 0 111 + Conjuncts: 0 112 + Disjuncts: 0 113 + -- out/run/stats/totals -- 114 + Leaks: 0 115 + Freed: 34 116 + Reused: 29 117 + Allocs: 5 118 + Retain: 0 119 + 120 + Unifications: 34 121 + Conjuncts: 63 122 + Disjuncts: 34