Skip to content

Commit

Permalink
x/tools/gopls: delete code obsoleted by go1.23
Browse files Browse the repository at this point in the history
The util/slices package has been deleted; but util/maps
has been renamed to moremaps since it still has some
useful things.

Note: the standard maps.Clone may return nil.

Updates golang/go#65917

Change-Id: Ide8cbb9aa13d80a35cdab258912a6e18a7db97c6
Reviewed-on: https://go-review.googlesource.com/c/tools/+/611837
Auto-Submit: Alan Donovan <adonovan@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Robert Findley <rfindley@google.com>
  • Loading branch information
adonovan authored and gopherbot committed Sep 9, 2024
1 parent 4bcf6a3 commit 9d7d14e
Show file tree
Hide file tree
Showing 44 changed files with 135 additions and 310 deletions.
15 changes: 3 additions & 12 deletions gopls/doc/generate/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,13 @@ import (
"go/ast"
"go/token"
"go/types"
"maps"
"os"
"os/exec"
"path/filepath"
"reflect"
"regexp"
"slices"
"sort"
"strconv"
"strings"
Expand All @@ -41,7 +43,6 @@ import (
"golang.org/x/tools/gopls/internal/golang"
"golang.org/x/tools/gopls/internal/mod"
"golang.org/x/tools/gopls/internal/settings"
"golang.org/x/tools/gopls/internal/util/maps"
"golang.org/x/tools/gopls/internal/util/safetoken"
)

Expand All @@ -56,14 +57,6 @@ func main() {
// - if write, it updates them;
// - if !write, it reports whether they would change.
func doMain(write bool) (bool, error) {
// TODO(adonovan): when we can rely on go1.23,
// switch to gotypesalias=1 behavior.
//
// (Since this program is run by 'go run',
// the gopls/go.mod file's go 1.19 directive doesn't
// have its usual effect of setting gotypesalias=0.)
os.Setenv("GODEBUG", "gotypesalias=0")

api, err := loadAPI()
if err != nil {
return false, err
Expand Down Expand Up @@ -472,9 +465,7 @@ func loadLenses(settingsPkg *packages.Package, defaults map[settings.CodeLensSou
// Build list of Lens descriptors.
var lenses []*doc.Lens
addAll := func(sources map[settings.CodeLensSource]cache.CodeLensSourceFunc, fileType string) error {
slice := maps.Keys(sources)
sort.Slice(slice, func(i, j int) bool { return slice[i] < slice[j] })
for _, source := range slice {
for _, source := range slices.Sorted(maps.Keys(sources)) {
docText, ok := enumDoc[string(source)]
if !ok {
return fmt.Errorf("missing CodeLensSource declaration for %s", source)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import (
"golang.org/x/tools/go/analysis"
"golang.org/x/tools/go/analysis/passes/inspect"
"golang.org/x/tools/go/ast/inspector"
"golang.org/x/tools/gopls/internal/util/astutil"
"golang.org/x/tools/internal/analysisinternal"
)

Expand All @@ -38,7 +37,7 @@ func run(pass *analysis.Pass) (interface{}, error) {
// Gather information whether file is generated or not
generated := make(map[*token.File]bool)
for _, file := range pass.Files {
if astutil.IsGenerated(file) {
if ast.IsGenerated(file) {
generated[pass.Fset.File(file.Pos())] = true
}
}
Expand Down
3 changes: 1 addition & 2 deletions gopls/internal/analysis/simplifyrange/simplifyrange.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (
"golang.org/x/tools/go/analysis"
"golang.org/x/tools/go/analysis/passes/inspect"
"golang.org/x/tools/go/ast/inspector"
"golang.org/x/tools/gopls/internal/util/astutil"
"golang.org/x/tools/internal/analysisinternal"
)

Expand All @@ -33,7 +32,7 @@ func run(pass *analysis.Pass) (interface{}, error) {
// Gather information whether file is generated or not
generated := make(map[*token.File]bool)
for _, file := range pass.Files {
if astutil.IsGenerated(file) {
if ast.IsGenerated(file) {
generated[pass.Fset.File(file.Pos())] = true
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ package simplifyrange_test

import (
"go/build"
"slices"
"testing"

"golang.org/x/tools/go/analysis/analysistest"
"golang.org/x/tools/gopls/internal/analysis/simplifyrange"
"golang.org/x/tools/gopls/internal/util/slices"
)

func Test(t *testing.T) {
Expand Down
3 changes: 1 addition & 2 deletions gopls/internal/analysis/simplifyslice/simplifyslice.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (
"golang.org/x/tools/go/analysis"
"golang.org/x/tools/go/analysis/passes/inspect"
"golang.org/x/tools/go/ast/inspector"
"golang.org/x/tools/gopls/internal/util/astutil"
"golang.org/x/tools/internal/analysisinternal"
)

Expand All @@ -42,7 +41,7 @@ func run(pass *analysis.Pass) (interface{}, error) {
// Gather information whether file is generated or not
generated := make(map[*token.File]bool)
for _, file := range pass.Files {
if astutil.IsGenerated(file) {
if ast.IsGenerated(file) {
generated[pass.Fset.File(file.Pos())] = true
}
}
Expand Down
4 changes: 2 additions & 2 deletions gopls/internal/analysis/unusedparams/unusedparams.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
"golang.org/x/tools/go/analysis"
"golang.org/x/tools/go/analysis/passes/inspect"
"golang.org/x/tools/go/ast/inspector"
"golang.org/x/tools/gopls/internal/util/slices"
"golang.org/x/tools/gopls/internal/util/moreslices"
"golang.org/x/tools/internal/analysisinternal"
)

Expand Down Expand Up @@ -194,7 +194,7 @@ func run(pass *analysis.Pass) (any, error) {
// Edge case: f = func() {...}
// should not count as a use.
if pass.TypesInfo.Uses[id] != nil {
usesOutsideCall[fn] = slices.Remove(usesOutsideCall[fn], id)
usesOutsideCall[fn] = moreslices.Remove(usesOutsideCall[fn], id)
}

if fn == nil && id.Name == "_" {
Expand Down
10 changes: 3 additions & 7 deletions gopls/internal/cache/analysis.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"reflect"
"runtime"
"runtime/debug"
"slices"
"sort"
"strings"
"sync"
Expand All @@ -43,8 +44,7 @@ import (
"golang.org/x/tools/gopls/internal/util/astutil"
"golang.org/x/tools/gopls/internal/util/bug"
"golang.org/x/tools/gopls/internal/util/frob"
"golang.org/x/tools/gopls/internal/util/maps"
"golang.org/x/tools/gopls/internal/util/slices"
"golang.org/x/tools/gopls/internal/util/moremaps"
"golang.org/x/tools/internal/analysisinternal"
"golang.org/x/tools/internal/event"
"golang.org/x/tools/internal/facts"
Expand Down Expand Up @@ -769,11 +769,7 @@ func (an *analysisNode) cacheKey() [sha256.Size]byte {
}

// vdeps, in PackageID order
depIDs := maps.Keys(an.succs)
// TODO(adonovan): use go1.2x slices.Sort(depIDs).
sort.Slice(depIDs, func(i, j int) bool { return depIDs[i] < depIDs[j] })
for _, depID := range depIDs {
vdep := an.succs[depID]
for _, vdep := range moremaps.Sorted(an.succs) {
fmt.Fprintf(hasher, "dep: %s\n", vdep.mp.PkgPath)
fmt.Fprintf(hasher, "export: %s\n", vdep.summary.DeepExportHash)

Expand Down
2 changes: 1 addition & 1 deletion gopls/internal/cache/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"go/types"
"regexp"
"runtime"
"slices"
"sort"
"strings"
"sync"
Expand All @@ -32,7 +33,6 @@ import (
"golang.org/x/tools/gopls/internal/protocol"
"golang.org/x/tools/gopls/internal/util/bug"
"golang.org/x/tools/gopls/internal/util/safetoken"
"golang.org/x/tools/gopls/internal/util/slices"
"golang.org/x/tools/internal/analysisinternal"
"golang.org/x/tools/internal/event"
"golang.org/x/tools/internal/gcimporter"
Expand Down
2 changes: 1 addition & 1 deletion gopls/internal/cache/load.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"errors"
"fmt"
"path/filepath"
"slices"
"sort"
"strings"
"sync/atomic"
Expand All @@ -23,7 +24,6 @@ import (
"golang.org/x/tools/gopls/internal/util/bug"
"golang.org/x/tools/gopls/internal/util/immutable"
"golang.org/x/tools/gopls/internal/util/pathutil"
"golang.org/x/tools/gopls/internal/util/slices"
"golang.org/x/tools/internal/event"
"golang.org/x/tools/internal/gocommand"
"golang.org/x/tools/internal/packagesinternal"
Expand Down
2 changes: 1 addition & 1 deletion gopls/internal/cache/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"fmt"
"os"
"path/filepath"
"slices"
"sort"
"strconv"
"strings"
Expand All @@ -24,7 +25,6 @@ import (
"golang.org/x/tools/gopls/internal/protocol"
"golang.org/x/tools/gopls/internal/util/bug"
"golang.org/x/tools/gopls/internal/util/persistent"
"golang.org/x/tools/gopls/internal/util/slices"
"golang.org/x/tools/gopls/internal/vulncheck"
"golang.org/x/tools/internal/event"
"golang.org/x/tools/internal/event/keys"
Expand Down
2 changes: 1 addition & 1 deletion gopls/internal/cache/snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"path/filepath"
"regexp"
"runtime"
"slices"
"sort"
"strconv"
"strings"
Expand All @@ -43,7 +44,6 @@ import (
"golang.org/x/tools/gopls/internal/util/immutable"
"golang.org/x/tools/gopls/internal/util/pathutil"
"golang.org/x/tools/gopls/internal/util/persistent"
"golang.org/x/tools/gopls/internal/util/slices"
"golang.org/x/tools/gopls/internal/vulncheck"
"golang.org/x/tools/internal/event"
"golang.org/x/tools/internal/event/label"
Expand Down
8 changes: 4 additions & 4 deletions gopls/internal/cache/view.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"path"
"path/filepath"
"regexp"
"slices"
"sort"
"strings"
"sync"
Expand All @@ -29,9 +30,8 @@ import (
"golang.org/x/tools/gopls/internal/file"
"golang.org/x/tools/gopls/internal/protocol"
"golang.org/x/tools/gopls/internal/settings"
"golang.org/x/tools/gopls/internal/util/maps"
"golang.org/x/tools/gopls/internal/util/moremaps"
"golang.org/x/tools/gopls/internal/util/pathutil"
"golang.org/x/tools/gopls/internal/util/slices"
"golang.org/x/tools/gopls/internal/vulncheck"
"golang.org/x/tools/internal/event"
"golang.org/x/tools/internal/gocommand"
Expand Down Expand Up @@ -253,7 +253,7 @@ func viewDefinitionsEqual(x, y *viewDefinition) bool {
if x.workspaceModFilesErr.Error() != y.workspaceModFilesErr.Error() {
return false
}
} else if !maps.SameKeys(x.workspaceModFiles, y.workspaceModFiles) {
} else if !moremaps.SameKeys(x.workspaceModFiles, y.workspaceModFiles) {
return false
}
if len(x.envOverlay) != len(y.envOverlay) {
Expand Down Expand Up @@ -698,7 +698,7 @@ func (s *Snapshot) initialize(ctx context.Context, firstAttempt bool) {
extractedDiags := s.extractGoCommandErrors(ctx, loadErr)
initialErr = &InitializationError{
MainError: loadErr,
Diagnostics: maps.Group(extractedDiags, byURI),
Diagnostics: moremaps.Group(extractedDiags, byURI),
}
case s.view.workspaceModFilesErr != nil:
initialErr = &InitializationError{
Expand Down
5 changes: 2 additions & 3 deletions gopls/internal/cache/xrefs/xrefs.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (
"golang.org/x/tools/gopls/internal/cache/parsego"
"golang.org/x/tools/gopls/internal/protocol"
"golang.org/x/tools/gopls/internal/util/frob"
"golang.org/x/tools/gopls/internal/util/typesutil"
)

// Index constructs a serializable index of outbound cross-references
Expand Down Expand Up @@ -93,8 +92,8 @@ func Index(files []*parsego.File, pkg *types.Package, info *types.Info) []byte {
case *ast.ImportSpec:
// Report a reference from each import path
// string to the imported package.
pkgname, ok := typesutil.ImportedPkgName(info, n)
if !ok {
pkgname := info.PkgNameOf(n)
if pkgname == nil {
return true // missing import
}
objects := getObjects(pkgname.Imported())
Expand Down
2 changes: 1 addition & 1 deletion gopls/internal/cmd/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ import (
"context"
"flag"
"fmt"
"slices"

"golang.org/x/tools/gopls/internal/protocol"
"golang.org/x/tools/gopls/internal/settings"
"golang.org/x/tools/gopls/internal/util/slices"
)

// check implements the check verb for gopls.
Expand Down
2 changes: 1 addition & 1 deletion gopls/internal/cmd/codeaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ import (
"flag"
"fmt"
"regexp"
"slices"
"strings"

"golang.org/x/tools/gopls/internal/protocol"
"golang.org/x/tools/gopls/internal/util/slices"
"golang.org/x/tools/internal/tool"
)

Expand Down
2 changes: 1 addition & 1 deletion gopls/internal/cmd/execute.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ import (
"fmt"
"log"
"os"
"slices"

"golang.org/x/tools/gopls/internal/protocol"
"golang.org/x/tools/gopls/internal/protocol/command"
"golang.org/x/tools/gopls/internal/server"
"golang.org/x/tools/gopls/internal/util/slices"
"golang.org/x/tools/internal/tool"
)

Expand Down
3 changes: 2 additions & 1 deletion gopls/internal/fuzzy/symbol_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@ func TestMatcherSimilarities(t *testing.T) {
idents := collectIdentifiers(t)
t.Logf("collected %d unique identifiers", len(idents))

// TODO: use go1.21 slices.MaxFunc.
// We can't use slices.MaxFunc because we want a custom
// scoring (not equivalence) function.
topMatch := func(score func(string) float64) string {
top := ""
topScore := 0.0
Expand Down
2 changes: 1 addition & 1 deletion gopls/internal/golang/codeaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"fmt"
"go/ast"
"go/types"
"slices"
"strings"

"golang.org/x/tools/go/ast/astutil"
Expand All @@ -23,7 +24,6 @@ import (
"golang.org/x/tools/gopls/internal/protocol/command"
"golang.org/x/tools/gopls/internal/settings"
"golang.org/x/tools/gopls/internal/util/bug"
"golang.org/x/tools/gopls/internal/util/slices"
"golang.org/x/tools/internal/event"
"golang.org/x/tools/internal/imports"
"golang.org/x/tools/internal/typesinternal"
Expand Down
12 changes: 3 additions & 9 deletions gopls/internal/golang/completion/completion.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
"go/token"
"go/types"
"math"
"reflect"
"slices"
"sort"
"strconv"
"strings"
Expand All @@ -39,7 +39,6 @@ import (
"golang.org/x/tools/gopls/internal/settings"
goplsastutil "golang.org/x/tools/gopls/internal/util/astutil"
"golang.org/x/tools/gopls/internal/util/safetoken"
"golang.org/x/tools/gopls/internal/util/slices"
"golang.org/x/tools/gopls/internal/util/typesutil"
"golang.org/x/tools/internal/aliases"
"golang.org/x/tools/internal/event"
Expand Down Expand Up @@ -198,7 +197,7 @@ type completer struct {

// goversion is the version of Go in force in the file, as
// defined by x/tools/internal/versions. Empty if unknown.
// TODO(adonovan): with go1.22+ it should always be known.
// Since go1.22 it should always be known.
goversion string

// (tokFile, pos) is the position at which the request was triggered.
Expand Down Expand Up @@ -1395,12 +1394,7 @@ func (c *completer) selector(ctx context.Context, sel *ast.SelectorExpr) error {
return nil
}

var goversion string
// TODO(adonovan): after go1.21, replace with:
// goversion = c.pkg.GetTypesInfo().FileVersions[c.file]
if v := reflect.ValueOf(c.pkg.TypesInfo()).Elem().FieldByName("FileVersions"); v.IsValid() {
goversion = v.Interface().(map[*ast.File]string)[c.file] // may be ""
}
goversion := c.pkg.TypesInfo().FileVersions[c.file]

// Extract the package-level candidates using a quick parse.
var g errgroup.Group
Expand Down
Loading

0 comments on commit 9d7d14e

Please sign in to comment.