Skip to content

Commit

Permalink
cmd/cue: remove support for CUE_DEBUG_SORT_ARCS
Browse files Browse the repository at this point in the history
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í <mvdan@mvdan.cc>
Change-Id: Ic02403693c871608929b65d4b019432e8a81c849
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1205985
Unity-Result: CUE porcuepine <cue.porcuepine@gmail.com>
TryBot-Result: CUEcueckoo <cueckoo@cuelang.org>
Reviewed-by: Matthew Sackman <matthew@cue.works>
  • Loading branch information
mvdan committed Dec 18, 2024
1 parent 962fafa commit f2775f8
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 74 deletions.
4 changes: 0 additions & 4 deletions cmd/cue/cmd/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import (
"os"
"path/filepath"
"regexp"
"strconv"
"strings"

"github.com/spf13/pflag"
Expand All @@ -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"
)
Expand Down Expand Up @@ -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")
Expand Down
42 changes: 0 additions & 42 deletions internal/core/adt/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import (
"log"
"reflect"
"regexp"
"sort"
"strings"

"github.com/cockroachdb/apd/v3"
Expand All @@ -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
Expand Down
4 changes: 0 additions & 4 deletions internal/core/adt/eval.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down
4 changes: 0 additions & 4 deletions internal/core/adt/unify.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
22 changes: 9 additions & 13 deletions internal/core/export/expr.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
10 changes: 3 additions & 7 deletions internal/core/export/toposort.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand All @@ -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) {
Expand Down
1 change: 1 addition & 0 deletions tools/flow/flow.go
Original file line number Diff line number Diff line change
Expand Up @@ -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") != ""
)

Expand Down

0 comments on commit f2775f8

Please sign in to comment.