Skip to content

Commit f2775f8

Browse files
committed
cmd/cue: remove support for CUE_DEBUG_SORT_ARCS
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í <[email protected]> Change-Id: Ic02403693c871608929b65d4b019432e8a81c849 Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1205985 Unity-Result: CUE porcuepine <[email protected]> TryBot-Result: CUEcueckoo <[email protected]> Reviewed-by: Matthew Sackman <[email protected]>
1 parent 962fafa commit f2775f8

File tree

7 files changed

+13
-74
lines changed

7 files changed

+13
-74
lines changed

cmd/cue/cmd/common.go

-4
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import (
1919
"os"
2020
"path/filepath"
2121
"regexp"
22-
"strconv"
2322
"strings"
2423

2524
"github.com/spf13/pflag"
@@ -33,7 +32,6 @@ import (
3332
"cuelang.org/go/cue/parser"
3433
"cuelang.org/go/cue/token"
3534
"cuelang.org/go/internal"
36-
"cuelang.org/go/internal/core/adt"
3735
"cuelang.org/go/internal/encoding"
3836
"cuelang.org/go/internal/filetypes"
3937
)
@@ -504,8 +502,6 @@ func parseArgs(cmd *Command, args []string, cfg *config) (p *buildPlan, err erro
504502
return nil, err
505503
}
506504

507-
adt.DebugSort, _ = strconv.Atoi(os.Getenv("CUE_DEBUG_SORT_ARCS"))
508-
509505
builds := loadFromArgs(args, cfg.loadCfg)
510506
if builds == nil {
511507
return nil, errors.Newf(token.NoPos, "invalid args")

internal/core/adt/context.go

-42
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import (
1919
"log"
2020
"reflect"
2121
"regexp"
22-
"sort"
2322
"strings"
2423

2524
"github.com/cockroachdb/apd/v3"
@@ -33,47 +32,6 @@ import (
3332
"cuelang.org/go/internal/cuedebug"
3433
)
3534

36-
// DebugSort specifies that arcs be sorted consistently between implementations.
37-
//
38-
// 0: default
39-
// 1: sort by Feature: this should be consistent between implementations where
40-
// there is no change in the compiler and indexing code.
41-
// 2: alphabetical
42-
//
43-
// TODO: move to DebugFlags
44-
var DebugSort int
45-
46-
func DebugSortArcs(c *OpContext, n *Vertex) {
47-
if n.IsList() {
48-
return
49-
}
50-
switch a := n.Arcs; DebugSort {
51-
case 1:
52-
sort.SliceStable(a, func(i, j int) bool {
53-
return a[i].Label < a[j].Label
54-
})
55-
case 2:
56-
sort.SliceStable(a, func(i, j int) bool {
57-
return a[i].Label.SelectorString(c.Runtime) <
58-
a[j].Label.SelectorString(c.Runtime)
59-
})
60-
}
61-
}
62-
63-
func DebugSortFields(c *OpContext, a []Feature) {
64-
switch DebugSort {
65-
case 1:
66-
sort.SliceStable(a, func(i, j int) bool {
67-
return a[i] < a[j]
68-
})
69-
case 2:
70-
sort.SliceStable(a, func(i, j int) bool {
71-
return a[i].SelectorString(c.Runtime) <
72-
a[j].SelectorString(c.Runtime)
73-
})
74-
}
75-
}
76-
7735
// Assert panics if the condition is false. Assert can be used to check for
7836
// conditions that are considers to break an internal variant or unexpected
7937
// condition, but that nonetheless probably will be handled correctly down the

internal/core/adt/eval.go

-4
Original file line numberDiff line numberDiff line change
@@ -809,10 +809,6 @@ func (n *nodeContext) checkClosed(state vertexStatus) bool {
809809
func (n *nodeContext) completeArcs(state vertexStatus) {
810810
unreachableForDev(n.ctx)
811811

812-
if DebugSort > 0 {
813-
DebugSortArcs(n.ctx, n.node)
814-
}
815-
816812
if n.node.hasAllConjuncts || n.node.Parent == nil {
817813
n.node.setParentDone()
818814
}

internal/core/adt/unify.go

-4
Original file line numberDiff line numberDiff line change
@@ -250,10 +250,6 @@ func (v *Vertex) unify(c *OpContext, needs condition, mode runMode) bool {
250250
// done
251251

252252
case needs&subFieldsProcessed != 0:
253-
if DebugSort > 0 {
254-
DebugSortArcs(n.ctx, n.node)
255-
}
256-
257253
switch {
258254
case assertStructuralCycleV3(n):
259255
// TODO: consider bailing on error if n.errs != nil.

internal/core/export/expr.go

+9-13
Original file line numberDiff line numberDiff line change
@@ -189,20 +189,16 @@ func (x *exporter) mergeValues(label adt.Feature, src *adt.Vertex, a []conjunct,
189189
return -cmp.Compare(f1, f2)
190190
})
191191

192-
if adt.DebugSort == 0 {
193-
m := sortArcs(extractFeatures(e.structs))
194-
slices.SortStableFunc(fields, func(f1, f2 adt.Feature) int {
195-
if m[f2] == 0 {
196-
if m[f1] == 0 {
197-
return +1
198-
}
199-
return -1
192+
m := sortArcs(extractFeatures(e.structs))
193+
slices.SortStableFunc(fields, func(f1, f2 adt.Feature) int {
194+
if m[f2] == 0 {
195+
if m[f1] == 0 {
196+
return +1
200197
}
201-
return -cmp.Compare(m[f1], m[f2])
202-
})
203-
} else {
204-
adt.DebugSortFields(e.ctx, fields)
205-
}
198+
return -1
199+
}
200+
return -cmp.Compare(m[f1], m[f2])
201+
})
206202

207203
if len(e.fields) == 0 && !e.hasEllipsis {
208204
switch len(e.embed) + len(e.conjuncts) {

internal/core/export/toposort.go

+3-7
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,11 @@ func VertexFeatures(c *adt.OpContext, v *adt.Vertex) []adt.Feature {
3232
if c.TopoSort {
3333
return toposort.VertexFeatures(c, v)
3434
} else {
35-
return vertexFeatures(c, v)
35+
return vertexFeatures(v)
3636
}
3737
}
3838

39-
func vertexFeatures(c *adt.OpContext, v *adt.Vertex) []adt.Feature {
39+
func vertexFeatures(v *adt.Vertex) []adt.Feature {
4040
sets := extractFeatures(v.Structs)
4141
m := sortArcs(sets) // TODO: use for convenience.
4242

@@ -54,11 +54,7 @@ func vertexFeatures(c *adt.OpContext, v *adt.Vertex) []adt.Feature {
5454
sets = append(sets, a)
5555
}
5656

57-
a = sortedArcs(sets)
58-
if adt.DebugSort > 0 {
59-
adt.DebugSortFields(c, a)
60-
}
61-
return a
57+
return sortedArcs(sets)
6258
}
6359

6460
func extractFeatures(in []*adt.StructInfo) (a [][]adt.Feature) {

tools/flow/flow.go

+1
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ var (
9090
// TODO: ErrUpdate: update and run a dependency, but don't complete a
9191
// dependency as more results may come. This is useful in server mode.
9292

93+
// TODO: move CUE_DEBUG_TOOLS_FLOW=1 to e.g. CUE_DEBUG=toolsflow
9394
debug = os.Getenv("CUE_DEBUG_TOOLS_FLOW") != ""
9495
)
9596

0 commit comments

Comments
 (0)