Skip to content

Commit

Permalink
internal/core/adt: rename Closed to RecursivelyClosed
Browse files Browse the repository at this point in the history
This to clearify the meaning, specfically with the
intend to introduce a sibling field to indicate
non-recursive closedness.

Signed-off-by: Marcel van Lohuizen <[email protected]>
Change-Id: I3e767917368f8f7261c2c573be28ccf5d0cd9661
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1202904
TryBot-Result: CUEcueckoo <[email protected]>
Unity-Result: CUE porcuepine <[email protected]>
Reviewed-by: Daniel Martí <[email protected]>
  • Loading branch information
mpvl committed Oct 23, 2024
1 parent ea70704 commit a6d8d34
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 24 deletions.
6 changes: 3 additions & 3 deletions cue/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -1710,9 +1710,9 @@ func allowed(ctx *adt.OpContext, parent, n *adt.Vertex) *adt.Bottom {

func addConjuncts(dst, src *adt.Vertex) {
c := adt.MakeRootConjunct(nil, src)
if src.Closed {
if src.ClosedRecursive {
var root adt.CloseInfo
c.CloseInfo = root.SpawnRef(src, src.Closed, nil)
c.CloseInfo = root.SpawnRef(src, src.ClosedRecursive, nil)
}
dst.AddConjunct(c)
}
Expand All @@ -1738,7 +1738,7 @@ func (v Value) Unify(w Value) Value {

n.Parent = v.v.Parent
n.Label = v.v.Label
n.Closed = v.v.Closed || w.v.Closed
n.ClosedRecursive = v.v.ClosedRecursive || w.v.ClosedRecursive

if err := n.Err(ctx); err != nil {
return makeValue(v.idx, n, v.parent_)
Expand Down
4 changes: 2 additions & 2 deletions internal/core/adt/closed.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func (v *Vertex) IsInOneOf(mask SpanType) bool {
// IsRecursivelyClosed returns true if this value is either a definition or unified
// with a definition.
func (v *Vertex) IsRecursivelyClosed() bool {
return v.Closed || v.IsInOneOf(DefinitionSpan)
return v.ClosedRecursive || v.IsInOneOf(DefinitionSpan)
}

type closeNodeType uint8
Expand Down Expand Up @@ -330,7 +330,7 @@ func isClosed(v *Vertex) bool {
// We could have used IsRecursivelyClosed here, but (effectively)
// implementing it again here allows us to only have to iterate over
// Structs once.
if v.Closed {
if v.ClosedRecursive {
return true
}
for _, s := range v.Structs {
Expand Down
12 changes: 6 additions & 6 deletions internal/core/adt/composite.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,10 +182,10 @@ type Vertex struct {
// ignored.
isData bool

// Closed indicates whether this Vertex is recursively closed. This is the
// case, for instance, if it is a node in a definition or if one of the
// conjuncts, or ancestor conjuncts, is a definition.
Closed bool
// ClosedRecursive indicates whether this Vertex is recursively closed.
// This is the case, for instance, if it is a node in a definition or if one
// of the conjuncts, or ancestor conjuncts, is a definition.
ClosedRecursive bool

// HasEllipsis indicates that this Vertex is open by means of an ellipsis.
// TODO: combine this field with Closed once we removed the old evaluator.
Expand Down Expand Up @@ -1008,7 +1008,7 @@ func (v *Vertex) IsOptional(label Feature) bool {
}

func (v *Vertex) accepts(ok, required bool) bool {
return ok || (!required && !v.Closed)
return ok || (!required && !v.ClosedRecursive)
}

func (v *Vertex) IsClosedStruct() bool {
Expand All @@ -1026,7 +1026,7 @@ func (v *Vertex) IsClosedStruct() bool {
return false

case *Vertex:
return v.Closed && !v.HasEllipsis
return v.ClosedRecursive && !v.HasEllipsis

case *StructMarker:
if x.NeedClose {
Expand Down
2 changes: 1 addition & 1 deletion internal/core/adt/conjunct.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ func (n *nodeContext) scheduleConjunct(c Conjunct, id CloseInfo) {
env := c.Env

if id.cc.isDef {
n.node.Closed = true
n.node.ClosedRecursive = true
}

switch x := c.Elem().(type) {
Expand Down
8 changes: 4 additions & 4 deletions internal/core/adt/eval.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,12 +201,12 @@ func (c *OpContext) unify(v *Vertex, flags combinedFlags) {

case 0:
if v.Label.IsDef() {
v.Closed = true
v.ClosedRecursive = true
}

if v.Parent != nil {
if v.Parent.Closed {
v.Closed = true
if v.Parent.ClosedRecursive {
v.ClosedRecursive = true
}
}

Expand Down Expand Up @@ -794,7 +794,7 @@ func (n *nodeContext) checkClosed(state vertexStatus) bool {
if !v.Label.IsInt() && v.Parent != nil && !ignore && v.ArcType <= ArcRequired {
ctx := n.ctx
// Visit arcs recursively to validate and compute error.
if _, err := verifyArc2(ctx, v.Label, v, v.Closed); err != nil {
if _, err := verifyArc2(ctx, v.Label, v, v.ClosedRecursive); err != nil {
// Record error in child node to allow recording multiple
// conflicts at the appropriate place, to allow valid fields to
// be represented normally and, most importantly, to avoid
Expand Down
4 changes: 2 additions & 2 deletions internal/core/adt/share.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func (n *nodeContext) finalizeSharing() {
n.node.Arcs = v.Arcs
n.node.BaseValue = v.BaseValue
n.node.status = v.status
n.node.Closed = v.Closed
n.node.ClosedRecursive = v.ClosedRecursive
n.node.HasEllipsis = v.HasEllipsis
}
}
Expand Down Expand Up @@ -146,7 +146,7 @@ func (n *nodeContext) shareIfPossible(c Conjunct, arc *Vertex, id CloseInfo) boo
// probably a good idea anyway.
//
// TODO: come up with a mechanism to allow this case.
if n.node.Closed && !arc.Closed {
if n.node.ClosedRecursive && !arc.ClosedRecursive {
return false
}

Expand Down
12 changes: 6 additions & 6 deletions internal/core/adt/unify.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,12 @@ func (n *nodeContext) initBare() {
n.blockOn(scalarKnown | listTypeKnown | arcTypeKnown)

if v.Label.IsDef() {
v.Closed = true
v.ClosedRecursive = true
}

if v.Parent != nil {
if v.Parent.Closed {
v.Closed = true
if v.Parent.ClosedRecursive {
v.ClosedRecursive = true
}
}
}
Expand Down Expand Up @@ -187,7 +187,7 @@ func (v *Vertex) unify(c *OpContext, needs condition, mode runMode) bool {
w := v.DerefDisjunct()
if w != v {
// Should resolve with dereference.
v.Closed = w.Closed
v.ClosedRecursive = w.ClosedRecursive
v.status = w.status
v.ChildErrors = CombineErrors(nil, v.ChildErrors, w.ChildErrors)
v.Arcs = nil
Expand Down Expand Up @@ -315,8 +315,8 @@ func (v *Vertex) unify(c *OpContext, needs condition, mode runMode) bool {
v.Arcs = nil

// Set control fields that are referenced without dereferencing.
if w.Closed {
v.Closed = true
if w.ClosedRecursive {
v.ClosedRecursive = true
}
if w.HasEllipsis {
v.HasEllipsis = true
Expand Down

0 comments on commit a6d8d34

Please sign in to comment.