package dwarfgen
import (
+ "cmp"
"debug/dwarf"
"fmt"
"internal/platform"
"os"
"path/filepath"
"runtime"
- "sort"
+ "slices"
"strconv"
"strings"
"testing"
}
switch e.Tag {
case 0:
- sort.Slice(scope.vars, func(i, j int) bool {
- return scope.vars[i].expr < scope.vars[j].expr
+ slices.SortFunc(scope.vars, func(a, b variable) int {
+ return cmp.Compare(a.expr, b.expr)
})
return
case dwarf.TagFormalParameter:
package gc
import (
+ "cmp"
"internal/race"
"math/rand"
- "sort"
+ "slices"
"sync"
"cmd/compile/internal/base"
// Compile the longest functions first,
// since they're most likely to be the slowest.
// This helps avoid stragglers.
- sort.Slice(compilequeue, func(i, j int) bool {
- return len(compilequeue[i].Body) > len(compilequeue[j].Body)
+ slices.SortFunc(compilequeue, func(a, b *ir.Func) int {
+ return cmp.Compare(len(b.Body), len(a.Body))
})
}
"cmd/compile/internal/ir"
"cmd/compile/internal/pgoir"
"cmd/compile/internal/types"
+ "cmp"
"fmt"
"os"
- "sort"
+ "slices"
"strconv"
"strings"
)
csl = append(csl, cs)
}
scoreCallsCache.csl = csl[:0]
- sort.Slice(csl, func(i, j int) bool {
- return csl[i].ID < csl[j].ID
+ slices.SortFunc(csl, func(a, b *CallSite) int {
+ return cmp.Compare(a.ID, b.ID)
})
// Score each call site.
for _, cs := range allCallSites {
sl = append(sl, cs)
}
- sort.Slice(sl, func(i, j int) bool {
- if sl[i].Score != sl[j].Score {
- return sl[i].Score < sl[j].Score
+ slices.SortFunc(sl, func(a, b *CallSite) int {
+ if a.Score != b.Score {
+ return cmp.Compare(a.Score, b.Score)
}
- fni := ir.PkgFuncName(sl[i].Callee)
- fnj := ir.PkgFuncName(sl[j].Callee)
+ fni := ir.PkgFuncName(a.Callee)
+ fnj := ir.PkgFuncName(b.Callee)
if fni != fnj {
- return fni < fnj
+ return cmp.Compare(fni, fnj)
}
- ecsi := EncodeCallSiteKey(sl[i])
- ecsj := EncodeCallSiteKey(sl[j])
- return ecsi < ecsj
+ ecsi := EncodeCallSiteKey(a)
+ ecsj := EncodeCallSiteKey(b)
+ return cmp.Compare(ecsi, ecsj)
})
mkname := func(fn *ir.Func) string {
"io/fs"
"log"
"os"
- "sort"
+ "slices"
"strings"
)
}
}
// Sort for deterministic output.
- sort.Slice(concreteNodes, func(i, j int) bool {
- return concreteNodes[i].Name.Name < concreteNodes[j].Name.Name
+ slices.SortFunc(concreteNodes, func(a, b *ast.TypeSpec) int {
+ return strings.Compare(a.Name.Name, b.Name.Name)
})
// Generate code for each concrete type.
for _, t := range concreteNodes {
"fmt"
"os"
"path/filepath"
+ "slices"
"sort"
"strings"
)
leaders = append(leaders, n)
}
}
- sort.Slice(leaders, func(i, j int) bool {
- return leaders[i].Sym().Name < leaders[j].Sym().Name
+ slices.SortFunc(leaders, func(a, b *ir.Name) int {
+ return strings.Compare(a.Sym().Name, b.Sym().Name)
})
var sb strings.Builder
for _, n := range leaders {
for k := range indirectUE {
ids = append(ids, k)
}
- sort.Slice(ids, func(i, j int) bool { return ids[i] < ids[j] })
+ slices.Sort(ids)
for _, id := range ids {
fmt.Fprintf(os.Stderr, " v%d:", id)
for _, n := range indirectUE[id] {
package liveness
import (
+ "cmp"
"fmt"
"os"
+ "slices"
"sort"
"strings"
}
// Sort variables from lowest to highest address.
- sort.Slice(vars, func(i, j int) bool { return vars[i].FrameOffset() < vars[j].FrameOffset() })
+ slices.SortFunc(vars, func(a, b *ir.Name) int { return cmp.Compare(a.FrameOffset(), b.FrameOffset()) })
// Populate the stack object data.
// Format must match runtime/stack.go:stackObjectRecord.
package noder
import (
+ "cmp"
"fmt"
"internal/buildcfg"
"internal/pkgbits"
"internal/types/errors"
"io"
"runtime"
- "sort"
+ "slices"
"strings"
"cmd/compile/internal/base"
for _, idx := range l.decls {
idxs = append(idxs, idx)
}
- sort.Slice(idxs, func(i, j int) bool { return idxs[i] < idxs[j] })
+ slices.Sort(idxs)
w := publicRootWriter
for sym, idx := range l.bodies {
bodies = append(bodies, symIdx{sym, idx})
}
- sort.Slice(bodies, func(i, j int) bool { return bodies[i].idx < bodies[j].idx })
+ slices.SortFunc(bodies, func(a, b symIdx) int { return cmp.Compare(a.idx, b.idx) })
w := privateRootWriter
import (
"bufio"
"bytes"
+ "cmp"
"flag"
"fmt"
"internal/testenv"
"reflect"
"regexp"
"runtime"
- "sort"
+ "slices"
"strconv"
"strings"
"testing"
}
func sortInlineStacks(x [][]int) {
- sort.Slice(x, func(i, j int) bool {
- if len(x[i]) != len(x[j]) {
- return len(x[i]) < len(x[j])
+ slices.SortFunc(x, func(a, b []int) int {
+ if len(a) != len(b) {
+ return cmp.Compare(len(a), len(b))
}
- for k := range x[i] {
- if x[i][k] != x[j][k] {
- return x[i][k] < x[j][k]
+ for k := range a {
+ if a[k] != b[k] {
+ return cmp.Compare(a[k], b[k])
}
}
- return false
+ return 0
})
}
import (
"cmd/compile/internal/types"
- "sort"
+ "cmp"
+ "slices"
)
// decompose converts phi ops on compound builtin types into phi
// removes all values with OpInvalid, and re-sorts the list of Names.
func deleteNamedVals(f *Func, toDelete []namedVal) {
// Arrange to delete from larger indices to smaller, to ensure swap-with-end deletion does not invalidate pending indices.
- sort.Slice(toDelete, func(i, j int) bool {
- if toDelete[i].locIndex != toDelete[j].locIndex {
- return toDelete[i].locIndex > toDelete[j].locIndex
+ slices.SortFunc(toDelete, func(a, b namedVal) int {
+ if a.locIndex != b.locIndex {
+ return cmp.Compare(b.locIndex, a.locIndex)
}
- return toDelete[i].valIndex > toDelete[j].valIndex
-
+ return cmp.Compare(b.valIndex, a.valIndex)
})
// Get rid of obsolete names
"cmd/compile/internal/base"
"cmd/compile/internal/types"
"cmd/internal/src"
- "sort"
+ "cmp"
+ "slices"
)
// memcombine combines smaller loads and stores into larger ones.
}
// Sort in memory address order.
- sort.Slice(r, func(i, j int) bool {
- return r[i].offset < r[j].offset
+ slices.SortFunc(r, func(a, b LoadRecord) int {
+ return cmp.Compare(a.offset, b.offset)
})
// Check that we have contiguous offsets.
pos := a[n-1].store.Pos
// Sort stores in increasing address order.
- sort.Slice(a, func(i, j int) bool {
- return a[i].offset < a[j].offset
+ slices.SortFunc(a, func(sr1, sr2 StoreRecord) int {
+ return cmp.Compare(sr1.offset, sr2.offset)
})
// Check that everything is written to sequential locations.
import (
"cmd/compile/internal/base"
"cmd/compile/internal/types"
+ "cmp"
"container/heap"
"slices"
"sort"
}
// Sort all the edges by source Value ID.
- sort.Slice(edges, func(i, j int) bool {
- return edges[i].x.ID < edges[j].x.ID
+ slices.SortFunc(edges, func(a, b edge) int {
+ return cmp.Compare(a.x.ID, b.x.ID)
})
// Compute inEdges for values in this block.
for _, e := range edges {
import (
cmddwarf "cmd/internal/dwarf"
"cmd/internal/quoted"
+ "cmp"
"debug/dwarf"
"debug/elf"
"debug/macho"
"io"
"os"
"runtime"
- "sort"
+ "slices"
+ "strings"
"testing"
)
}
t.Logf("Saw %d out of %d lines without statement marks", len(nonStmtLines), len(lines))
if testing.Verbose() {
- sort.Slice(nonStmtLines, func(i, j int) bool {
- if nonStmtLines[i].File != nonStmtLines[j].File {
- return nonStmtLines[i].File < nonStmtLines[j].File
+ slices.SortFunc(nonStmtLines, func(a, b Line) int {
+ if a.File != b.File {
+ return strings.Compare(a.File, b.File)
}
- return nonStmtLines[i].Line < nonStmtLines[j].Line
+ return cmp.Compare(a.Line, b.Line)
})
for _, l := range nonStmtLines {
t.Logf("%s:%d has no DWARF is_stmt mark\n", l.File, l.Line)
"fmt"
"internal/buildcfg"
"os"
+ "slices"
"sort"
+ "strings"
"sync"
"cmd/compile/internal/base"
for sym := range tracked {
trackSyms = append(trackSyms, sym)
}
- sort.Slice(trackSyms, func(i, j int) bool { return trackSyms[i].Name < trackSyms[j].Name })
+ slices.SortFunc(trackSyms, func(a, b *obj.LSym) int { return strings.Compare(a.Name, b.Name) })
for _, sym := range trackSyms {
r := obj.Addrel(fnsym)
r.Sym = sym
"go/constant"
"io"
"os"
- "sort"
+ "slices"
"strconv"
+ "strings"
"sync"
"cmd/compile/internal/base"
}
func WriteFuncSyms() {
- sort.Slice(funcsyms, func(i, j int) bool {
- return funcsyms[i].Linksym().Name < funcsyms[j].Linksym().Name
+ slices.SortFunc(funcsyms, func(a, b *ir.Name) int {
+ return strings.Compare(a.Linksym().Name, b.Linksym().Name)
})
for _, nam := range funcsyms {
s := nam.Sym()
package walk
import (
+ "cmp"
"fmt"
"go/constant"
"go/token"
"math/bits"
+ "slices"
"sort"
+ "strings"
"cmd/compile/internal/base"
"cmd/compile/internal/ir"
// much cheaper to compare lengths than values, and
// all we need here is consistency. We respect this
// sorting below.
- sort.Slice(cc, func(i, j int) bool {
- si := ir.StringVal(cc[i].lo)
- sj := ir.StringVal(cc[j].lo)
+ slices.SortFunc(cc, func(a, b exprClause) int {
+ si := ir.StringVal(a.lo)
+ sj := ir.StringVal(b.lo)
if len(si) != len(sj) {
- return len(si) < len(sj)
+ return cmp.Compare(len(si), len(sj))
}
- return si < sj
+ return strings.Compare(si, sj)
})
// runLen returns the string length associated with a
return
}
- sort.Slice(cc, func(i, j int) bool { return cc[i].hash < cc[j].hash })
+ slices.SortFunc(cc, func(a, b typeClause) int { return cmp.Compare(a.hash, b.hash) })
// Combine adjacent cases with the same hash.
merged := cc[:1]
hashes = append(hashes, h)
}
// Order by increasing hash.
- sort.Slice(hashes, func(j, k int) bool {
- return hashes[j] < hashes[k]
- })
+ slices.Sort(hashes)
for j := 1; j < len(hashes); j++ {
if hashes[j] == hashes[j-1] {
// There is a duplicate hash; try a different b/i pair.