Skip to content

Commit

Permalink
internal/core/adt: pass state to addList
Browse files Browse the repository at this point in the history
Before it was assumed that addList would always be
called in a final stage. However, this is not true if
it is called as a composite literal in an expression,
for intsance `[ expr ][0]`.

Passing this will allow the computation of embeddings
to be defered in a future CL.

Issue #2244
Issue #2351
Issue #2355

Signed-off-by: Marcel van Lohuizen <[email protected]>
Change-Id: I6d27495d8a9413033ad202fc995e297da66e9309
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/556544
Reviewed-by: Daniel Martí <[email protected]>
TryBot-Result: CUEcueckoo <[email protected]>
  • Loading branch information
mpvl committed Jul 24, 2023
1 parent ab15bb8 commit b38aece
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
12 changes: 6 additions & 6 deletions cue/testdata/export/issue2244.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@ m: #step & {
if: _#isReleaseTag
}
-- out/eval/stats --
Leaks: 11
Freed: 18
Reused: 14
Allocs: 15
Retain: 15
Leaks: 17
Freed: 17
Reused: 13
Allocs: 21
Retain: 29

Unifications: 25
Conjuncts: 64
Disjuncts: 33
Disjuncts: 40
-- out/eval --
(struct){
_#matchPattern(:x): (_|_){
Expand Down
6 changes: 3 additions & 3 deletions internal/core/adt/eval.go
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@ func (n *nodeContext) postDisjunct(state vertexStatus) {
for n.maybeSetCache(); n.expandOne(state); n.maybeSetCache() {
}

if !n.addLists() {
if !n.addLists(state) {
break
}
}
Expand Down Expand Up @@ -2146,7 +2146,7 @@ func (n *nodeContext) injectDynamic() (progress bool) {
//
// TODO(embeddedScalars): for embedded scalars, there should be another pass
// of evaluation expressions after expanding lists.
func (n *nodeContext) addLists() (progress bool) {
func (n *nodeContext) addLists(state vertexStatus) (progress bool) {
if len(n.lists) == 0 && len(n.vLists) == 0 {
return false
}
Expand Down Expand Up @@ -2221,7 +2221,7 @@ outer:
for j, elem := range l.list.Elems {
switch x := elem.(type) {
case *Comprehension:
err := c.yield(nil, l.env, x, finalized, func(e *Environment) {
err := c.yield(nil, l.env, x, state, func(e *Environment) {
label, err := MakeLabel(x.Source(), index, IntLabel)
n.addErr(err)
index++
Expand Down

0 comments on commit b38aece

Please sign in to comment.