Skip to content

Commit

Permalink
internal/core/adt: export arcType and friends
Browse files Browse the repository at this point in the history
Needed for optional field rework.
The ArcType will be used to determine whether
a field is regular, optional, or required.

Signed-off-by: Marcel van Lohuizen <mpvl@gmail.com>
Change-Id: Iae38d61ea2c97726b3dce5570cfd70cfa24da4a4
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/549251
Unity-Result: CUEcueckoo <cueckoo@cuelang.org>
TryBot-Result: CUEcueckoo <cueckoo@cuelang.org>
Reviewed-by: Roger Peppe <rogpeppe@gmail.com>
  • Loading branch information
mpvl committed Mar 16, 2023
1 parent c8e580e commit 4f32fb4
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 20 deletions.
22 changes: 11 additions & 11 deletions internal/core/adt/composite.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,8 @@ type Vertex struct {
// Used for cycle detection.
IsDynamic bool

// arcType indicates the level of optionality of this arc.
arcType arcType
// ArcType indicates the level of optionality of this arc.
ArcType ArcType

// cyclicReferences is a linked list of internal references pointing to this
// Vertex. This is used to shorten the path of some structural cycles.
Expand Down Expand Up @@ -230,7 +230,7 @@ type Vertex struct {
// isDefined indicates whether this arc is a "value" field, and not a constraint
// or void arc.
func (v *Vertex) isDefined() bool {
return v.arcType == arcMember
return v.ArcType == ArcMember
}

// IsDefined indicates whether this arc is defined meaning it is not a
Expand All @@ -245,22 +245,22 @@ func (v *Vertex) IsDefined(c *OpContext) bool {
return v.isDefined()
}

type arcType uint8
type ArcType uint8

const (
// arcMember means that this arc is a normal non-optional field
// ArcMember means that this arc is a normal non-optional field
// (including regular, hidden, and definition fields).
arcMember arcType = iota
ArcMember ArcType = iota

// TODO: define a type for optional arcs. This will be needed for pulling
// in optional fields into the Vertex, which, in turn, is needed for
// structure sharing, among other things.
// We could also define types for required fields and potentially lets.

// arcVoid means that an arc does not exist. This happens when an arc
// ArcVoid means that an arc does not exist. This happens when an arc
// is provisionally added as part of a comprehension, but when this
// comprehension has not yet yielded any results.
arcVoid
ArcVoid
)

func (v *Vertex) Clone() *Vertex {
Expand Down Expand Up @@ -746,7 +746,7 @@ func (v *Vertex) Elems() []*Vertex {

// GetArc returns a Vertex for the outgoing arc with label f. It creates and
// ads one if it doesn't yet exist.
func (v *Vertex) GetArc(c *OpContext, f Feature, t arcType) (arc *Vertex, isNew bool) {
func (v *Vertex) GetArc(c *OpContext, f Feature, t ArcType) (arc *Vertex, isNew bool) {
arc = v.Lookup(f)
if arc != nil {
return arc, false
Expand All @@ -762,7 +762,7 @@ func (v *Vertex) GetArc(c *OpContext, f Feature, t arcType) (arc *Vertex, isNew
"field %s not allowed by earlier comprehension or reference cycle", f)
}
}
arc = &Vertex{Parent: v, Label: f, arcType: t}
arc = &Vertex{Parent: v, Label: f, ArcType: t}
v.Arcs = append(v.Arcs, arc)
return arc, true
}
Expand Down Expand Up @@ -795,7 +795,7 @@ func (v *Vertex) hasConjunct(c Conjunct) (added bool) {
switch c.x.(type) {
case *OptionalField, *BulkOptionalField, *Ellipsis:
default:
v.arcType = arcMember
v.ArcType = ArcMember
}
for _, x := range v.Conjuncts {
// TODO: disregard certain fields from comparison (e.g. Refs)?
Expand Down
6 changes: 3 additions & 3 deletions internal/core/adt/comprehension.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ func (n *nodeContext) insertComprehension(
case *Field:
numFixed++

arc, _ := n.node.GetArc(n.ctx, f.Label, arcVoid)
arc, _ := n.node.GetArc(n.ctx, f.Label, ArcVoid)

// Create partial comprehension
c := &Comprehension{
Expand All @@ -193,7 +193,7 @@ func (n *nodeContext) insertComprehension(

numFixed++

arc, _ := n.node.GetArc(n.ctx, f.Label, arcVoid)
arc, _ := n.node.GetArc(n.ctx, f.Label, ArcVoid)
arc.MultiLet = f.IsMulti

// Create partial comprehension
Expand Down Expand Up @@ -405,7 +405,7 @@ func (n *nodeContext) injectComprehensions(allP *[]envYield, allowCycle bool, st

v := n.node
for c := d.leaf; c.parent != nil; c = c.parent {
v.arcType = arcMember
v.ArcType = ArcMember
v = c.arc
}

Expand Down
10 changes: 5 additions & 5 deletions internal/core/adt/eval.go
Original file line number Diff line number Diff line change
Expand Up @@ -486,8 +486,8 @@ func (n *nodeContext) postDisjunct(state VertexStatus) {

switch err := n.getErr(); {
case err != nil:
if err.Code < IncompleteError && n.node.arcType == arcVoid {
n.node.arcType = arcMember
if err.Code < IncompleteError && n.node.ArcType == ArcVoid {
n.node.ArcType = ArcMember
}
n.node.BaseValue = err
n.errs = nil
Expand Down Expand Up @@ -673,7 +673,7 @@ func (n *nodeContext) incompleteErrors(final bool) *Bottom {
err = incompleteSentinel
}
if err.Code < IncompleteError {
n.node.arcType = arcMember
n.node.ArcType = ArcMember
}
return err
}
Expand Down Expand Up @@ -732,7 +732,7 @@ func (n *nodeContext) completeArcs(state VertexStatus) {
if state <= Conjuncts &&
// Is allowed to go one step back. See Vertex.UpdateStatus.
n.node.status <= state+1 &&
n.node.arcType != arcVoid {
n.node.ArcType != ArcVoid {

n.node.UpdateStatus(Conjuncts)
return
Expand Down Expand Up @@ -1976,7 +1976,7 @@ func (n *nodeContext) addStruct(
// disjunctions.
func (n *nodeContext) insertField(f Feature, x Conjunct) *Vertex {
ctx := n.ctx
arc, isNew := n.node.GetArc(ctx, f, arcMember)
arc, isNew := n.node.GetArc(ctx, f, ArcMember)
if f.IsLet() && !isNew {
arc.MultiLet = true
return arc
Expand Down
2 changes: 1 addition & 1 deletion internal/core/adt/expr.go
Original file line number Diff line number Diff line change
Expand Up @@ -1912,7 +1912,7 @@ func (x *ForClause) yield(s *compState) {
}

c.Unify(a, Partial)
if a.arcType == arcVoid {
if a.ArcType == ArcVoid {
continue
}

Expand Down

0 comments on commit 4f32fb4

Please sign in to comment.