Skip to content

Commit

Permalink
internal/core/adt: fix counter related to close builtin
Browse files Browse the repository at this point in the history
The spawnCloseContext used to pass isClosedOnce
might never be incremented itself. As a result
decDependent might never be called and the parent
never decremented.

We use the DEFER counter to agitate an increment
and decrement after the conjunct is added.

The case where the counter is removed is in
builtins/default, most notably the line:

    Close: close(*{} | 0)

Note that this also increases a counter, which
is always a possibility. We deal with that later.

Signed-off-by: Marcel van Lohuizen <[email protected]>
Change-Id: I18e9759a7958addb36ad437b6be0f49f43d7ea6a
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1207519
TryBot-Result: CUEcueckoo <[email protected]>
Unity-Result: CUE porcuepine <[email protected]>
Reviewed-by: Daniel Martí <[email protected]>
  • Loading branch information
mpvl committed Jan 21, 2025
1 parent 74c12e0 commit aa6781f
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 1 deletion.
2 changes: 2 additions & 0 deletions internal/core/adt/conjunct.go
Original file line number Diff line number Diff line change
Expand Up @@ -580,6 +580,8 @@ func (n *nodeContext) insertValueConjunct(env *Environment, v Value, id CloseInf
n.node.ClosedNonRecursive = true
var cc *closeContext
id, cc = id.spawnCloseContext(n.ctx, 0)
cc.incDependent(n.ctx, DEFER, nil)
defer cc.decDependent(n.ctx, DEFER, nil)
cc.isClosedOnce = true

if v, ok := x.BaseValue.(*Vertex); ok {
Expand Down
1 change: 0 additions & 1 deletion internal/core/adt/eval_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ var needFix = map[string]string{
// counter errors.
// TODO: These counters should all go to zero.
var skipDebugDepErrors = map[string]int{
"builtins/default": 1,
"compile/scope": 1,
"comprehensions/pushdown": 2,
"cycle/builtins": 2,
Expand Down

0 comments on commit aa6781f

Please sign in to comment.