Skip to content

Commit

Permalink
internal/core/adt: more usage of Status
Browse files Browse the repository at this point in the history
Getting the wrong status code can influence
evaluation negatively. This also is a step towards
hoisting the adt into a separate package.

Signed-off-by: Marcel van Lohuizen <[email protected]>
Change-Id: I2abe6e30cfebfdb00d791baec09c43d791754814
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1202262
TryBot-Result: CUEcueckoo <[email protected]>
Reviewed-by: Matthew Sackman <[email protected]>
Unity-Result: CUE porcuepine <[email protected]>
  • Loading branch information
mpvl committed Oct 10, 2024
1 parent 8399737 commit d581f90
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 8 deletions.
12 changes: 8 additions & 4 deletions internal/core/adt/composite.go
Original file line number Diff line number Diff line change
Expand Up @@ -535,6 +535,11 @@ const (
finalized
)

// Status returns the status of the current node. When reading the status, one
// should always use this method over directly reading status field.
//
// NOTE: this only matters for EvalV3 and beyonds, so a lot of the old code
// might still access it directly.
func (v *Vertex) Status() vertexStatus {
v = v.DerefValue()
return v.status
Expand All @@ -547,13 +552,13 @@ func (v *Vertex) ForceDone() {

// IsUnprocessed reports whether v is unprocessed.
func (v *Vertex) IsUnprocessed() bool {
return v.status == unprocessed
return v.Status() == unprocessed
}

func (v *Vertex) updateStatus(s vertexStatus) {
if !isCyclePlaceholder(v.BaseValue) {
if !v.IsErr() && v.state != nil {
Assertf(v.state.ctx, v.status <= s+1, "attempt to regress status from %d to %d", v.Status(), s)
Assertf(v.state.ctx, v.Status() <= s+1, "attempt to regress status from %d to %d", v.Status(), s)
}
}

Expand Down Expand Up @@ -677,8 +682,7 @@ func (v *Vertex) isFinal() bool {
// TODO(deref): the accounting of what is final should be recorded
// in the original node. Remove this dereference once the old
// evaluator has been removed.
v = v.DerefValue()
return v.status == finalized
return v.Status() == finalized
}

func (x *Vertex) IsConcrete() bool {
Expand Down
3 changes: 2 additions & 1 deletion internal/core/adt/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ func New(v *Vertex, cfg *Config) *OpContext {
return ctx
}

// See also: unreachableForDev
func (c *OpContext) isDevVersion() bool {
return c.Version == internal.DevVersion
}
Expand Down Expand Up @@ -873,7 +874,7 @@ func (c *OpContext) unifyNode(v Expr, state combinedFlags) (result Value) {
n.process(arcTypeKnown, yield)
}
} else {
if v.isUndefined() || state.vertexStatus() > v.status {
if v.isUndefined() || state.vertexStatus() > v.Status() {
c.unify(v, state)
}
}
Expand Down
2 changes: 1 addition & 1 deletion internal/core/adt/debug.go
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ func (m *mermaidContext) vertex(v *Vertex) *mermaidVertex {

var status string
switch {
case v.status == finalized:
case v.Status() == finalized:
status = "finalized"
case v.state == nil:
status = "ready"
Expand Down
4 changes: 3 additions & 1 deletion internal/core/adt/eval.go
Original file line number Diff line number Diff line change
Expand Up @@ -689,6 +689,8 @@ func (n *nodeContext) validateValue(state vertexStatus) {
// incompleteErrors reports all errors from uncompleted conjuncts.
// If final is true, errors are permanent and reported to parents.
func (n *nodeContext) incompleteErrors(final bool) *Bottom {
unreachableForDev(n.ctx)

// collect incomplete errors.
var err *Bottom // n.incomplete
for _, d := range n.dynamicFields {
Expand Down Expand Up @@ -1474,7 +1476,7 @@ func (n *nodeContext) hasErr() bool {
if n.node.ChildErrors != nil {
return true
}
if n.node.status > evaluating && n.node.IsErr() {
if n.node.Status() > evaluating && n.node.IsErr() {
return true
}
return n.ctx.HasErr() || n.errs != nil
Expand Down
2 changes: 1 addition & 1 deletion internal/core/adt/states.go
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ func (v *Vertex) allChildConjunctsKnown() bool {
return true
}

if v.status == finalized {
if v.Status() == finalized {
// This can happen, for instance, if this is called on a parent of a
// rooted node that is marked as a parent for a dynamic node.
// In practice this should be handled by the caller, but we add this
Expand Down

0 comments on commit d581f90

Please sign in to comment.