Skip to content

Commit

Permalink
x/tools: remove dead code
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
adonovan committed Jan 2, 2025
1 parent b0dc9b1 commit 960f0f4
Show file tree
Hide file tree
Showing 17 changed files with 8 additions and 122 deletions.
1 change: 1 addition & 0 deletions cmd/splitdwarf/splitdwarf.go
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,7 @@ func CreateMmapFile(outDwarf string, size int64) (*os.File, []byte) {
return dwarfFile, buffer
}

// (dead code; retained for debugging)
func describe(exem *macho.FileTOC) {
note("Type = %s, Flags=0x%x", exem.Type, uint32(exem.Flags))
for i, l := range exem.Loads {
Expand Down
5 changes: 0 additions & 5 deletions cmd/ssadump/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,11 +188,6 @@ func doMain() error {
// e.g. --flag=one --flag=two would produce []string{"one", "two"}.
type stringListValue []string

func newStringListValue(val []string, p *[]string) *stringListValue {
*p = val
return (*stringListValue)(p)
}

func (ss *stringListValue) Get() interface{} { return []string(*ss) }

func (ss *stringListValue) String() string { return fmt.Sprintf("%q", *ss) }
Expand Down
14 changes: 0 additions & 14 deletions cmd/stringer/endtoend_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,20 +93,6 @@ func typeName(fname string) string {
return fmt.Sprintf("%c%s", base[0]+'A'-'a', base[1:len(base)-len(".go")])
}

func moreTests(t *testing.T, dirname, prefix string) []string {
x, err := os.ReadDir(dirname)
if err != nil {
// error, but try the rest of the tests
t.Errorf("can't read type param tess from %s: %v", dirname, err)
return nil
}
names := make([]string, len(x))
for i, f := range x {
names[i] = prefix + "/" + f.Name()
}
return names
}

// TestTags verifies that the -tags flag works as advertised.
func TestTags(t *testing.T) {
stringer := stringerPath(t)
Expand Down
9 changes: 1 addition & 8 deletions container/intsets/sparse.go
Original file line number Diff line number Diff line change
Expand Up @@ -287,14 +287,6 @@ func (s *Sparse) next(b *block) *block {
return b.next
}

// prev returns the previous block in the list, or end if b is the first block.
func (s *Sparse) prev(b *block) *block {
if b.prev == &s.root {
return &none
}
return b.prev
}

// IsEmpty reports whether the set s is empty.
func (s *Sparse) IsEmpty() bool {
return s.root.next == nil || s.root.offset == MaxInt
Expand Down Expand Up @@ -1077,6 +1069,7 @@ func (s *Sparse) AppendTo(slice []int) []int {
// -- Testing/debugging ------------------------------------------------

// check returns an error if the representation invariants of s are violated.
// (unused; retained for debugging)
func (s *Sparse) check() error {
s.init()
if s.root.empty() {
Expand Down
1 change: 1 addition & 0 deletions copyright/copyright.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"strings"
)

// (used only by tests)
func checkCopyright(dir string) ([]string, error) {
var files []string
err := filepath.WalkDir(dir, func(path string, d fs.DirEntry, err error) error {
Expand Down
9 changes: 0 additions & 9 deletions go/analysis/internal/analysisflags/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,21 +250,12 @@ const (
setFalse
)

func triStateFlag(name string, value triState, usage string) *triState {
flag.Var(&value, name, usage)
return &value
}

// triState implements flag.Value, flag.Getter, and flag.boolFlag.
// They work like boolean flags: we can say vet -printf as well as vet -printf=true
func (ts *triState) Get() interface{} {
return *ts == setTrue
}

func (ts triState) isTrue() bool {
return ts == setTrue
}

func (ts *triState) Set(value string) error {
b, err := strconv.ParseBool(value)
if err != nil {
Expand Down
7 changes: 0 additions & 7 deletions go/expect/expect.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,3 @@ func MatchBefore(fset *token.FileSet, readFile ReadFile, end token.Pos, pattern
}
return f.Pos(startOffset + matchStart), f.Pos(startOffset + matchEnd), nil
}

func lineEnd(f *token.File, line int) token.Pos {
if line >= f.LineCount() {
return token.Pos(f.Base() + f.Size())
}
return f.LineStart(line + 1)
}
5 changes: 0 additions & 5 deletions go/packages/gopackages/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,11 +248,6 @@ func (app *application) print(lpkg *packages.Package) {
// e.g. --flag=one --flag=two would produce []string{"one", "two"}.
type stringListValue []string

func newStringListValue(val []string, p *[]string) *stringListValue {
*p = val
return (*stringListValue)(p)
}

func (ss *stringListValue) Get() interface{} { return []string(*ss) }

func (ss *stringListValue) String() string { return fmt.Sprintf("%q", *ss) }
Expand Down
24 changes: 0 additions & 24 deletions go/packages/packages_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2999,30 +2999,6 @@ func constant(p *packages.Package, name string) *types.Const {
return c.(*types.Const)
}

func copyAll(srcPath, dstPath string) error {
return filepath.Walk(srcPath, func(path string, info os.FileInfo, _ error) error {
if info.IsDir() {
return nil
}
contents, err := os.ReadFile(path)
if err != nil {
return err
}
rel, err := filepath.Rel(srcPath, path)
if err != nil {
return err
}
dstFilePath := strings.Replace(filepath.Join(dstPath, rel), "definitelynot_go.mod", "go.mod", -1)
if err := os.MkdirAll(filepath.Dir(dstFilePath), 0755); err != nil {
return err
}
if err := os.WriteFile(dstFilePath, contents, 0644); err != nil {
return err
}
return nil
})
}

func TestExportFile(t *testing.T) {
// This used to trigger the log.Fatal in loadFromExportData.
// See go.dev/issue/45584.
Expand Down
1 change: 1 addition & 0 deletions go/ssa/dom.go
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,7 @@ func printDomTreeText(buf *bytes.Buffer, v *BasicBlock, indent int) {

// printDomTreeDot prints the dominator tree of f in AT&T GraphViz
// (.dot) format.
// (unused; retained for debugging)
func printDomTreeDot(buf *bytes.Buffer, f *Function) {
fmt.Fprintln(buf, "//", f)
fmt.Fprintln(buf, "digraph domtree {")
Expand Down
9 changes: 0 additions & 9 deletions go/ssa/interp/external.go
Original file line number Diff line number Diff line change
Expand Up @@ -303,15 +303,6 @@ func ext۰time۰Sleep(fr *frame, args []value) value {
return nil
}

func valueToBytes(v value) []byte {
in := v.([]value)
b := make([]byte, len(in))
for i := range in {
b[i] = in[i].(byte)
}
return b
}

func ext۰os۰Getenv(fr *frame, args []value) value {
name := args[0].(string)
switch name {
Expand Down
13 changes: 3 additions & 10 deletions go/ssa/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"io"
"os"
"sync"
_ "unsafe" // for go:linkname hack

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

// Exposed to ssautil using the linkname hack.
//
//go:linkname isSyntactic golang.org/x/tools/go/ssa.isSyntactic
func isSyntactic(pkg *Package) bool { return pkg.syntax }

// mapValues returns a new unordered array of map values.
func mapValues[K comparable, V any](m map[K]V) []V {
vals := make([]V, 0, len(m))
for _, fn := range m {
vals = append(vals, fn)
}
return vals

}
1 change: 1 addition & 0 deletions internal/diff/lcs/old.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ func (e *editGraph) bdone(D, k int) (bool, lcs) {
}

// run the backward algorithm, until success or up to the limit on D.
// (used only by tests)
func backward(e *editGraph) lcs {
e.setBackward(0, 0, e.ux)
if ok, ans := e.bdone(0, 0); ok {
Expand Down
9 changes: 0 additions & 9 deletions internal/jsonrpc2_v2/jsonrpc2.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,15 +112,6 @@ func (a *async) done() {
close(a.ready)
}

func (a *async) isDone() bool {
select {
case <-a.ready:
return true
default:
return false
}
}

func (a *async) wait() error {
<-a.ready
err := <-a.firstErr
Expand Down
5 changes: 0 additions & 5 deletions internal/jsonrpc2_v2/serve_go116.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,7 @@
package jsonrpc2

import (
"errors"
"net"
)

var errClosed = net.ErrClosed

func isErrClosed(err error) bool {
return errors.Is(err, errClosed)
}
14 changes: 0 additions & 14 deletions internal/jsonrpc2_v2/serve_pre116.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,8 @@ package jsonrpc2

import (
"errors"
"strings"
)

// errClosed is an error with the same string as net.ErrClosed,
// which was added in Go 1.16.
var errClosed = errors.New("use of closed network connection")

// isErrClosed reports whether err ends in the same string as errClosed.
func isErrClosed(err error) bool {
// As of Go 1.16, this could be 'errors.Is(err, net.ErrClosing)', but
// unfortunately gopls still requires compatibility with
// (otherwise-unsupported) older Go versions.
//
// In the meantime, this error string has not changed on any supported Go
// version, and is not expected to change in the future.
// This is not ideal, but since the worst that could happen here is some
// superfluous logging, it is acceptable.
return strings.HasSuffix(err.Error(), "use of closed network connection")
}
3 changes: 0 additions & 3 deletions internal/refactor/inline/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@ func is[T any](x any) bool {
return ok
}

// TODO(adonovan): use go1.21's slices.Clone.
func clone[T any](slice []T) []T { return append([]T{}, slice...) }

// TODO(adonovan): use go1.21's slices.Index.
func index[T comparable](slice []T, x T) int {
for i, elem := range slice {
Expand Down

0 comments on commit 960f0f4

Please sign in to comment.