Skip to content

Commit

Permalink
internal/core/adt: add lifetime check for closedness
Browse files Browse the repository at this point in the history
Once a counter was decremented to zero, it is no longer
allowed to be incremented.

Issue #2884

Signed-off-by: Marcel van Lohuizen <mpvl@gmail.com>
Change-Id: I82e0883467babd474ae8aaecb729418365181929
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1174013
Reviewed-by: Daniel Martí <mvdan@mvdan.cc>
Unity-Result: CUE porcuepine <cue.porcuepine@gmail.com>
TryBot-Result: CUEcueckoo <cueckoo@gmail.com>
  • Loading branch information
mpvl committed Mar 7, 2024
1 parent f55405b commit cdcb6fa
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions internal/core/adt/fields.go
Expand Up @@ -195,6 +195,9 @@ type closeContext struct {
// values.
isTotal bool

// done is true if all dependencies have been decremented.
done bool

// needsCloseInSchedule is non-nil if a closeContext that was created
// as an arc still needs to be decremented. It points to the creating arc
// for reporting purposes.
Expand Down Expand Up @@ -425,6 +428,13 @@ func (c *closeContext) incDependent(kind depKind, dependant *closeContext) (debu

debug = c.addDependent(kind, dependant)

if c.done {
ctx := c.src.state.ctx
openDebugGraph(ctx, c.src, "incDependent: already checked")

panic(fmt.Sprintf("incDependent: already closed: %p", c))
}

c.conjunctCount++
return debug
}
Expand All @@ -446,6 +456,8 @@ func (c *closeContext) decDependent(ctx *OpContext, kind depKind, dependant *clo
return
}

c.done = true

p := c.parent

if c.isDef {
Expand Down

0 comments on commit cdcb6fa

Please sign in to comment.