this repo has no description
0
fork

Configure Feed

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

internal/core/adt: remove StructInfo for unused structs

Since the introduction of the new comprehension implementation,
it is possible to have uninitialized StructInfos in the list. We should
skip these for the purpose of feature set analysis.

We picked the solution to remove these after completing the arcs,
rather than filtering out ununitialized structs when needed. This
throws away some information, but it seems more robust overall.

It may reorder some fields, because the features in dropped
StructLits, which are now no longer there, can no longer
influence the topological ordering computed in feature
extraction. This should improve the ordering as the user
probably does not expect to have fields in dropped
comprehensions influenece order.

Fixes #1879

Change-Id: I86a08cb87c26a3a1463fc1e4e8ff6fb383283530
Signed-off-by: Marcel van Lohuizen <mpvl@gmail.com>
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/543404
Reviewed-by: Daniel Martí <mvdan@mvdan.cc>
TryBot-Result: CUEcueckoo <cueckoo@cuelang.org>
Reviewed-by: Roger Peppe <rogpeppe@gmail.com>
Reviewed-by: Paul Jolly <paul@myitcv.io>

+54 -2
+2 -1
cue/types.go
··· 1431 1431 1432 1432 // Struct returns the underlying struct of a value or an error if the value 1433 1433 // is not a struct. 1434 + // 1435 + // Deprecated: use Fields. 1434 1436 func (v hiddenValue) Struct() (*Struct, error) { 1435 - // TODO: deprecate 1436 1437 ctx := v.ctx() 1437 1438 obj, err := v.structValOpts(ctx, options{}) 1438 1439 if err != nil {
+37
cue/types_test.go
··· 93 93 return res 94 94 }, 95 95 want: "_|_ // w.ction: field not allowed", 96 + }, { 97 + // Issue #1879 98 + input: ` 99 + #Steps: { 100 + ... 101 + } 102 + 103 + test: #Steps & { 104 + if true { 105 + test1: "test1" 106 + } 107 + if false { 108 + test2: "test2" 109 + } 110 + } 111 + `, 112 + 113 + fun: func(i *Instance) (val Value) { 114 + v := i.Value() 115 + 116 + sub := v.LookupPath(ParsePath("test")) 117 + st, err := sub.Struct() 118 + if err != nil { 119 + panic(err) 120 + } 121 + 122 + for i := 0; i < st.Len(); i++ { 123 + val = st.Field(i).Value 124 + } 125 + 126 + return val 127 + }, 128 + want: `"test1"`, 96 129 }} 97 130 for _, tc := range testCases { 98 131 if tc.skip { ··· 811 844 }, { 812 845 value: `{_a:"a", b?: "b", #c: 3}`, 813 846 res: `{_a:"a",b?:"b",#c:3,}`, 847 + }, { 848 + // Issue #1879 849 + value: `{a: 1, if false { b: 2 }}`, 850 + res: `{a:1,}`, 814 851 }} 815 852 for _, tc := range testCases { 816 853 t.Run(tc.value, func(t *testing.T) {
+1 -1
doc/tutorial/kubernetes/testdata/manual.out
··· 1267 1267 name: "ETCD_AUTO_COMPACTION_RETENTION" 1268 1268 value: "4" 1269 1269 }] 1270 + command: ["/usr/local/bin/etcd"] 1270 1271 volumeMounts: [{ 1271 1272 name: "etcd3" 1272 1273 mountPath: "/data" 1273 1274 }] 1274 - command: ["/usr/local/bin/etcd"] 1275 1275 ports: [{ 1276 1276 name: "client" 1277 1277 containerPort: 2379
+14
internal/core/adt/eval.go
··· 778 778 n.checkClosed(state) 779 779 } 780 780 781 + // Strip struct literals that were not initialized and are not part 782 + // of the output. 783 + // 784 + // TODO(perf): we could keep track if any such structs exist and only 785 + // do this removal if there is a change of shrinking the list. 786 + k := 0 787 + for _, s := range n.node.Structs { 788 + if s.initialized { 789 + n.node.Structs[k] = s 790 + k++ 791 + } 792 + } 793 + n.node.Structs = n.node.Structs[:k] 794 + 781 795 n.node.UpdateStatus(Finalized) 782 796 } 783 797