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") != "" )