Skip to content

Commit 960f0f4

Browse files
committed
x/tools: remove dead code
These unused functions and methods were discovered by a (work in progress) dead function analyzer. Change-Id: Iaa9c5fd4f06bdcd5d7c6e194bcc24d6b37df8f4c Reviewed-on: https://go-review.googlesource.com/c/tools/+/639675 Auto-Submit: Alan Donovan <[email protected]> Reviewed-by: Robert Findley <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]>
1 parent b0dc9b1 commit 960f0f4

File tree

17 files changed

+8
-122
lines changed

17 files changed

+8
-122
lines changed

cmd/splitdwarf/splitdwarf.go

+1
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,7 @@ func CreateMmapFile(outDwarf string, size int64) (*os.File, []byte) {
358358
return dwarfFile, buffer
359359
}
360360

361+
// (dead code; retained for debugging)
361362
func describe(exem *macho.FileTOC) {
362363
note("Type = %s, Flags=0x%x", exem.Type, uint32(exem.Flags))
363364
for i, l := range exem.Loads {

cmd/ssadump/main.go

-5
Original file line numberDiff line numberDiff line change
@@ -188,11 +188,6 @@ func doMain() error {
188188
// e.g. --flag=one --flag=two would produce []string{"one", "two"}.
189189
type stringListValue []string
190190

191-
func newStringListValue(val []string, p *[]string) *stringListValue {
192-
*p = val
193-
return (*stringListValue)(p)
194-
}
195-
196191
func (ss *stringListValue) Get() interface{} { return []string(*ss) }
197192

198193
func (ss *stringListValue) String() string { return fmt.Sprintf("%q", *ss) }

cmd/stringer/endtoend_test.go

-14
Original file line numberDiff line numberDiff line change
@@ -93,20 +93,6 @@ func typeName(fname string) string {
9393
return fmt.Sprintf("%c%s", base[0]+'A'-'a', base[1:len(base)-len(".go")])
9494
}
9595

96-
func moreTests(t *testing.T, dirname, prefix string) []string {
97-
x, err := os.ReadDir(dirname)
98-
if err != nil {
99-
// error, but try the rest of the tests
100-
t.Errorf("can't read type param tess from %s: %v", dirname, err)
101-
return nil
102-
}
103-
names := make([]string, len(x))
104-
for i, f := range x {
105-
names[i] = prefix + "/" + f.Name()
106-
}
107-
return names
108-
}
109-
11096
// TestTags verifies that the -tags flag works as advertised.
11197
func TestTags(t *testing.T) {
11298
stringer := stringerPath(t)

container/intsets/sparse.go

+1-8
Original file line numberDiff line numberDiff line change
@@ -287,14 +287,6 @@ func (s *Sparse) next(b *block) *block {
287287
return b.next
288288
}
289289

290-
// prev returns the previous block in the list, or end if b is the first block.
291-
func (s *Sparse) prev(b *block) *block {
292-
if b.prev == &s.root {
293-
return &none
294-
}
295-
return b.prev
296-
}
297-
298290
// IsEmpty reports whether the set s is empty.
299291
func (s *Sparse) IsEmpty() bool {
300292
return s.root.next == nil || s.root.offset == MaxInt
@@ -1077,6 +1069,7 @@ func (s *Sparse) AppendTo(slice []int) []int {
10771069
// -- Testing/debugging ------------------------------------------------
10781070

10791071
// check returns an error if the representation invariants of s are violated.
1072+
// (unused; retained for debugging)
10801073
func (s *Sparse) check() error {
10811074
s.init()
10821075
if s.root.empty() {

copyright/copyright.go

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import (
1616
"strings"
1717
)
1818

19+
// (used only by tests)
1920
func checkCopyright(dir string) ([]string, error) {
2021
var files []string
2122
err := filepath.WalkDir(dir, func(path string, d fs.DirEntry, err error) error {

go/analysis/internal/analysisflags/flags.go

-9
Original file line numberDiff line numberDiff line change
@@ -250,21 +250,12 @@ const (
250250
setFalse
251251
)
252252

253-
func triStateFlag(name string, value triState, usage string) *triState {
254-
flag.Var(&value, name, usage)
255-
return &value
256-
}
257-
258253
// triState implements flag.Value, flag.Getter, and flag.boolFlag.
259254
// They work like boolean flags: we can say vet -printf as well as vet -printf=true
260255
func (ts *triState) Get() interface{} {
261256
return *ts == setTrue
262257
}
263258

264-
func (ts triState) isTrue() bool {
265-
return ts == setTrue
266-
}
267-
268259
func (ts *triState) Set(value string) error {
269260
b, err := strconv.ParseBool(value)
270261
if err != nil {

go/expect/expect.go

-7
Original file line numberDiff line numberDiff line change
@@ -120,10 +120,3 @@ func MatchBefore(fset *token.FileSet, readFile ReadFile, end token.Pos, pattern
120120
}
121121
return f.Pos(startOffset + matchStart), f.Pos(startOffset + matchEnd), nil
122122
}
123-
124-
func lineEnd(f *token.File, line int) token.Pos {
125-
if line >= f.LineCount() {
126-
return token.Pos(f.Base() + f.Size())
127-
}
128-
return f.LineStart(line + 1)
129-
}

go/packages/gopackages/main.go

-5
Original file line numberDiff line numberDiff line change
@@ -248,11 +248,6 @@ func (app *application) print(lpkg *packages.Package) {
248248
// e.g. --flag=one --flag=two would produce []string{"one", "two"}.
249249
type stringListValue []string
250250

251-
func newStringListValue(val []string, p *[]string) *stringListValue {
252-
*p = val
253-
return (*stringListValue)(p)
254-
}
255-
256251
func (ss *stringListValue) Get() interface{} { return []string(*ss) }
257252

258253
func (ss *stringListValue) String() string { return fmt.Sprintf("%q", *ss) }

go/packages/packages_test.go

-24
Original file line numberDiff line numberDiff line change
@@ -2999,30 +2999,6 @@ func constant(p *packages.Package, name string) *types.Const {
29992999
return c.(*types.Const)
30003000
}
30013001

3002-
func copyAll(srcPath, dstPath string) error {
3003-
return filepath.Walk(srcPath, func(path string, info os.FileInfo, _ error) error {
3004-
if info.IsDir() {
3005-
return nil
3006-
}
3007-
contents, err := os.ReadFile(path)
3008-
if err != nil {
3009-
return err
3010-
}
3011-
rel, err := filepath.Rel(srcPath, path)
3012-
if err != nil {
3013-
return err
3014-
}
3015-
dstFilePath := strings.Replace(filepath.Join(dstPath, rel), "definitelynot_go.mod", "go.mod", -1)
3016-
if err := os.MkdirAll(filepath.Dir(dstFilePath), 0755); err != nil {
3017-
return err
3018-
}
3019-
if err := os.WriteFile(dstFilePath, contents, 0644); err != nil {
3020-
return err
3021-
}
3022-
return nil
3023-
})
3024-
}
3025-
30263002
func TestExportFile(t *testing.T) {
30273003
// This used to trigger the log.Fatal in loadFromExportData.
30283004
// See go.dev/issue/45584.

go/ssa/dom.go

+1
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,7 @@ func printDomTreeText(buf *bytes.Buffer, v *BasicBlock, indent int) {
318318

319319
// printDomTreeDot prints the dominator tree of f in AT&T GraphViz
320320
// (.dot) format.
321+
// (unused; retained for debugging)
321322
func printDomTreeDot(buf *bytes.Buffer, f *Function) {
322323
fmt.Fprintln(buf, "//", f)
323324
fmt.Fprintln(buf, "digraph domtree {")

go/ssa/interp/external.go

-9
Original file line numberDiff line numberDiff line change
@@ -303,15 +303,6 @@ func ext۰time۰Sleep(fr *frame, args []value) value {
303303
return nil
304304
}
305305

306-
func valueToBytes(v value) []byte {
307-
in := v.([]value)
308-
b := make([]byte, len(in))
309-
for i := range in {
310-
b[i] = in[i].(byte)
311-
}
312-
return b
313-
}
314-
315306
func ext۰os۰Getenv(fr *frame, args []value) value {
316307
name := args[0].(string)
317308
switch name {

go/ssa/util.go

+3-10
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
"io"
1515
"os"
1616
"sync"
17+
_ "unsafe" // for go:linkname hack
1718

1819
"golang.org/x/tools/go/types/typeutil"
1920
"golang.org/x/tools/internal/typeparams"
@@ -408,14 +409,6 @@ func (canon *canonizer) instantiateMethod(m *types.Func, targs []types.Type, ctx
408409
}
409410

410411
// Exposed to ssautil using the linkname hack.
412+
//
413+
//go:linkname isSyntactic golang.org/x/tools/go/ssa.isSyntactic
411414
func isSyntactic(pkg *Package) bool { return pkg.syntax }
412-
413-
// mapValues returns a new unordered array of map values.
414-
func mapValues[K comparable, V any](m map[K]V) []V {
415-
vals := make([]V, 0, len(m))
416-
for _, fn := range m {
417-
vals = append(vals, fn)
418-
}
419-
return vals
420-
421-
}

internal/diff/lcs/old.go

+1
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,7 @@ func (e *editGraph) bdone(D, k int) (bool, lcs) {
199199
}
200200

201201
// run the backward algorithm, until success or up to the limit on D.
202+
// (used only by tests)
202203
func backward(e *editGraph) lcs {
203204
e.setBackward(0, 0, e.ux)
204205
if ok, ans := e.bdone(0, 0); ok {

internal/jsonrpc2_v2/jsonrpc2.go

-9
Original file line numberDiff line numberDiff line change
@@ -112,15 +112,6 @@ func (a *async) done() {
112112
close(a.ready)
113113
}
114114

115-
func (a *async) isDone() bool {
116-
select {
117-
case <-a.ready:
118-
return true
119-
default:
120-
return false
121-
}
122-
}
123-
124115
func (a *async) wait() error {
125116
<-a.ready
126117
err := <-a.firstErr

internal/jsonrpc2_v2/serve_go116.go

-5
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,7 @@
88
package jsonrpc2
99

1010
import (
11-
"errors"
1211
"net"
1312
)
1413

1514
var errClosed = net.ErrClosed
16-
17-
func isErrClosed(err error) bool {
18-
return errors.Is(err, errClosed)
19-
}

internal/jsonrpc2_v2/serve_pre116.go

-14
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,8 @@ package jsonrpc2
99

1010
import (
1111
"errors"
12-
"strings"
1312
)
1413

1514
// errClosed is an error with the same string as net.ErrClosed,
1615
// which was added in Go 1.16.
1716
var errClosed = errors.New("use of closed network connection")
18-
19-
// isErrClosed reports whether err ends in the same string as errClosed.
20-
func isErrClosed(err error) bool {
21-
// As of Go 1.16, this could be 'errors.Is(err, net.ErrClosing)', but
22-
// unfortunately gopls still requires compatibility with
23-
// (otherwise-unsupported) older Go versions.
24-
//
25-
// In the meantime, this error string has not changed on any supported Go
26-
// version, and is not expected to change in the future.
27-
// This is not ideal, but since the worst that could happen here is some
28-
// superfluous logging, it is acceptable.
29-
return strings.HasSuffix(err.Error(), "use of closed network connection")
30-
}

internal/refactor/inline/util.go

-3
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,6 @@ func is[T any](x any) bool {
2222
return ok
2323
}
2424

25-
// TODO(adonovan): use go1.21's slices.Clone.
26-
func clone[T any](slice []T) []T { return append([]T{}, slice...) }
27-
2825
// TODO(adonovan): use go1.21's slices.Index.
2926
func index[T comparable](slice []T, x T) int {
3027
for i, elem := range slice {

0 commit comments

Comments
 (0)