From f2775f863f4cdeea888aa9cca4ee7273a6f2d2f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Mart=C3=AD?= Date: Wed, 18 Dec 2024 15:39:21 +0000 Subject: [PATCH] cmd/cue: remove support for CUE_DEBUG_SORT_ARCS MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This fairly old debugging flag worked on the old evaluator but never worked on the new evaluator; we instead focused on a new field ordering available for both versions via CUE_EXPERIMENT=toposort, which should be enabled by default very soon, as well as a lexicographical ordering available for now under CUE_DEBUG=sortfields. Given that CUE_DEBUG_SORT_ARCS was never meant for end users nor properly documented, that it never worked for evalv3, and that we now have the two new field ordering mechanisms which work on both evaluator versions, it's time to delete this code for v0.12.0-alpha.1. Signed-off-by: Daniel Martí Change-Id: Ic02403693c871608929b65d4b019432e8a81c849 Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1205985 Unity-Result: CUE porcuepine TryBot-Result: CUEcueckoo Reviewed-by: Matthew Sackman --- cmd/cue/cmd/common.go | 4 --- internal/core/adt/context.go | 42 -------------------------------- internal/core/adt/eval.go | 4 --- internal/core/adt/unify.go | 4 --- internal/core/export/expr.go | 22 +++++++---------- internal/core/export/toposort.go | 10 +++----- tools/flow/flow.go | 1 + 7 files changed, 13 insertions(+), 74 deletions(-) diff --git a/cmd/cue/cmd/common.go b/cmd/cue/cmd/common.go index 841c5a28c91..3e51f633443 100644 --- a/cmd/cue/cmd/common.go +++ b/cmd/cue/cmd/common.go @@ -19,7 +19,6 @@ import ( "os" "path/filepath" "regexp" - "strconv" "strings" "github.com/spf13/pflag" @@ -33,7 +32,6 @@ import ( "cuelang.org/go/cue/parser" "cuelang.org/go/cue/token" "cuelang.org/go/internal" - "cuelang.org/go/internal/core/adt" "cuelang.org/go/internal/encoding" "cuelang.org/go/internal/filetypes" ) @@ -504,8 +502,6 @@ func parseArgs(cmd *Command, args []string, cfg *config) (p *buildPlan, err erro return nil, err } - adt.DebugSort, _ = strconv.Atoi(os.Getenv("CUE_DEBUG_SORT_ARCS")) - builds := loadFromArgs(args, cfg.loadCfg) if builds == nil { return nil, errors.Newf(token.NoPos, "invalid args") diff --git a/internal/core/adt/context.go b/internal/core/adt/context.go index a0b3343e057..8311fb0d391 100644 --- a/internal/core/adt/context.go +++ b/internal/core/adt/context.go @@ -19,7 +19,6 @@ import ( "log" "reflect" "regexp" - "sort" "strings" "github.com/cockroachdb/apd/v3" @@ -33,47 +32,6 @@ import ( "cuelang.org/go/internal/cuedebug" ) -// DebugSort specifies that arcs be sorted consistently between implementations. -// -// 0: default -// 1: sort by Feature: this should be consistent between implementations where -// there is no change in the compiler and indexing code. -// 2: alphabetical -// -// TODO: move to DebugFlags -var DebugSort int - -func DebugSortArcs(c *OpContext, n *Vertex) { - if n.IsList() { - return - } - switch a := n.Arcs; DebugSort { - case 1: - sort.SliceStable(a, func(i, j int) bool { - return a[i].Label < a[j].Label - }) - case 2: - sort.SliceStable(a, func(i, j int) bool { - return a[i].Label.SelectorString(c.Runtime) < - a[j].Label.SelectorString(c.Runtime) - }) - } -} - -func DebugSortFields(c *OpContext, a []Feature) { - switch DebugSort { - case 1: - sort.SliceStable(a, func(i, j int) bool { - return a[i] < a[j] - }) - case 2: - sort.SliceStable(a, func(i, j int) bool { - return a[i].SelectorString(c.Runtime) < - a[j].SelectorString(c.Runtime) - }) - } -} - // Assert panics if the condition is false. Assert can be used to check for // conditions that are considers to break an internal variant or unexpected // condition, but that nonetheless probably will be handled correctly down the diff --git a/internal/core/adt/eval.go b/internal/core/adt/eval.go index 55180400aed..a179c58c821 100644 --- a/internal/core/adt/eval.go +++ b/internal/core/adt/eval.go @@ -809,10 +809,6 @@ func (n *nodeContext) checkClosed(state vertexStatus) bool { func (n *nodeContext) completeArcs(state vertexStatus) { unreachableForDev(n.ctx) - if DebugSort > 0 { - DebugSortArcs(n.ctx, n.node) - } - if n.node.hasAllConjuncts || n.node.Parent == nil { n.node.setParentDone() } diff --git a/internal/core/adt/unify.go b/internal/core/adt/unify.go index e263a7cf315..2745bd204a5 100644 --- a/internal/core/adt/unify.go +++ b/internal/core/adt/unify.go @@ -250,10 +250,6 @@ func (v *Vertex) unify(c *OpContext, needs condition, mode runMode) bool { // done case needs&subFieldsProcessed != 0: - if DebugSort > 0 { - DebugSortArcs(n.ctx, n.node) - } - switch { case assertStructuralCycleV3(n): // TODO: consider bailing on error if n.errs != nil. diff --git a/internal/core/export/expr.go b/internal/core/export/expr.go index 14c00c31768..cf456f8753d 100644 --- a/internal/core/export/expr.go +++ b/internal/core/export/expr.go @@ -189,20 +189,16 @@ func (x *exporter) mergeValues(label adt.Feature, src *adt.Vertex, a []conjunct, return -cmp.Compare(f1, f2) }) - if adt.DebugSort == 0 { - m := sortArcs(extractFeatures(e.structs)) - slices.SortStableFunc(fields, func(f1, f2 adt.Feature) int { - if m[f2] == 0 { - if m[f1] == 0 { - return +1 - } - return -1 + m := sortArcs(extractFeatures(e.structs)) + slices.SortStableFunc(fields, func(f1, f2 adt.Feature) int { + if m[f2] == 0 { + if m[f1] == 0 { + return +1 } - return -cmp.Compare(m[f1], m[f2]) - }) - } else { - adt.DebugSortFields(e.ctx, fields) - } + return -1 + } + return -cmp.Compare(m[f1], m[f2]) + }) if len(e.fields) == 0 && !e.hasEllipsis { switch len(e.embed) + len(e.conjuncts) { diff --git a/internal/core/export/toposort.go b/internal/core/export/toposort.go index b93716f380a..29c548f647a 100644 --- a/internal/core/export/toposort.go +++ b/internal/core/export/toposort.go @@ -32,11 +32,11 @@ func VertexFeatures(c *adt.OpContext, v *adt.Vertex) []adt.Feature { if c.TopoSort { return toposort.VertexFeatures(c, v) } else { - return vertexFeatures(c, v) + return vertexFeatures(v) } } -func vertexFeatures(c *adt.OpContext, v *adt.Vertex) []adt.Feature { +func vertexFeatures(v *adt.Vertex) []adt.Feature { sets := extractFeatures(v.Structs) m := sortArcs(sets) // TODO: use for convenience. @@ -54,11 +54,7 @@ func vertexFeatures(c *adt.OpContext, v *adt.Vertex) []adt.Feature { sets = append(sets, a) } - a = sortedArcs(sets) - if adt.DebugSort > 0 { - adt.DebugSortFields(c, a) - } - return a + return sortedArcs(sets) } func extractFeatures(in []*adt.StructInfo) (a [][]adt.Feature) { diff --git a/tools/flow/flow.go b/tools/flow/flow.go index b417426a06f..71d8b6ab3c4 100644 --- a/tools/flow/flow.go +++ b/tools/flow/flow.go @@ -90,6 +90,7 @@ var ( // TODO: ErrUpdate: update and run a dependency, but don't complete a // dependency as more results may come. This is useful in server mode. + // TODO: move CUE_DEBUG_TOOLS_FLOW=1 to e.g. CUE_DEBUG=toolsflow debug = os.Getenv("CUE_DEBUG_TOOLS_FLOW") != "" )