Skip to content

Commit 4a8a873

Browse files
committed
cue: fix default handling for new evaluator
The new evaluator did not erase the Conjuncts field for disjunctions. We plan to record the actual conjuncts that went in to a disjunct for the new evaluator, but this has not been implemented yet. The API depended on the Conjuncts to be nil for disjuncts. We mimic this old behavior, for now, until we have the above implemented. Also, the old evaluator would filter default values from the original expression. This did not handle the ConjunctGroup case yet. This CL implements that. Issue #3060 Signed-off-by: Marcel van Lohuizen <[email protected]> Change-Id: I1e8e653ede94f54df6f9e99f50b2931ef3e3674f Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1194048 Unity-Result: CUE porcuepine <[email protected]> Reviewed-by: Daniel Martí <[email protected]> TryBot-Result: CUEcueckoo <[email protected]>
1 parent b3f170a commit 4a8a873

File tree

3 files changed

+24
-2
lines changed

3 files changed

+24
-2
lines changed

cue/types_test.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1784,8 +1784,6 @@ func TestDefaults(t *testing.T) {
17841784
}}
17851785
for _, tc := range testCases {
17861786
runMatrix(t, tc.value, func(t *testing.T, cfg *evalConfig) {
1787-
TODO_V3(t, cfg)
1788-
17891787
v := cfg.getValue(t, "a: "+tc.value).Lookup("a")
17901788

17911789
v = v.Eval()

internal/core/adt/default.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,22 @@ func stripNonDefaults(elem Elem) (r Elem, stripped bool) {
127127
}
128128
return x, false
129129

130+
case *ConjunctGroup:
131+
// NOTE: this code requires allocations unconditional. This should be
132+
// mitigated once we optimize conjunct groupings.
133+
isNew := false
134+
var a ConjunctGroup = make([]Conjunct, len(*x))
135+
for i, c := range *x {
136+
a[i].x, ok = stripNonDefaults(c.Expr())
137+
if ok {
138+
isNew = true
139+
}
140+
}
141+
if isNew {
142+
return &a, true
143+
}
144+
return x, false
145+
130146
default:
131147
return x, false
132148
}

internal/core/adt/disjunct2.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,14 @@ func (n *nodeContext) finalizeDisjunctions() {
453453
return
454454
}
455455

456+
// TODO: we clear the Conjuncts to be compatible with the old evaluator.
457+
// This is especially relevant for the API. Ideally, though, we should
458+
// update Conjuncts to reflect the actual conjunct that went into the
459+
// disjuncts.
460+
for _, x := range n.disjuncts {
461+
x.node.Conjuncts = nil
462+
}
463+
456464
a := make([]Value, len(n.disjuncts))
457465
p := 0
458466
hasDefaults := false

0 commit comments

Comments
 (0)