From d581f90b35836c292140fdbfaebc4d2b34fd0d02 Mon Sep 17 00:00:00 2001 From: Marcel van Lohuizen Date: Sat, 5 Oct 2024 09:57:05 +0200 Subject: [PATCH] internal/core/adt: more usage of Status 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 Change-Id: I2abe6e30cfebfdb00d791baec09c43d791754814 Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1202262 TryBot-Result: CUEcueckoo Reviewed-by: Matthew Sackman Unity-Result: CUE porcuepine --- internal/core/adt/composite.go | 12 ++++++++---- internal/core/adt/context.go | 3 ++- internal/core/adt/debug.go | 2 +- internal/core/adt/eval.go | 4 +++- internal/core/adt/states.go | 2 +- 5 files changed, 15 insertions(+), 8 deletions(-) diff --git a/internal/core/adt/composite.go b/internal/core/adt/composite.go index 039a2c48dad..bff45f37d98 100644 --- a/internal/core/adt/composite.go +++ b/internal/core/adt/composite.go @@ -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 @@ -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) } } @@ -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 { diff --git a/internal/core/adt/context.go b/internal/core/adt/context.go index 84ade01191b..a3b9ce8e580 100644 --- a/internal/core/adt/context.go +++ b/internal/core/adt/context.go @@ -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 } @@ -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) } } diff --git a/internal/core/adt/debug.go b/internal/core/adt/debug.go index 1fc4b051252..fecdbd98d9e 100644 --- a/internal/core/adt/debug.go +++ b/internal/core/adt/debug.go @@ -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" diff --git a/internal/core/adt/eval.go b/internal/core/adt/eval.go index ad26a7a393a..64935b2215f 100644 --- a/internal/core/adt/eval.go +++ b/internal/core/adt/eval.go @@ -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 { @@ -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 diff --git a/internal/core/adt/states.go b/internal/core/adt/states.go index f229bfe61ff..4d819a7d38a 100644 --- a/internal/core/adt/states.go +++ b/internal/core/adt/states.go @@ -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