Skip to content

Commit 9d7d14e

Browse files
adonovangopherbot
authored andcommitted
x/tools/gopls: delete code obsoleted by go1.23
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 <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: Robert Findley <[email protected]>
1 parent 4bcf6a3 commit 9d7d14e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+135
-310
lines changed

gopls/doc/generate/generate.go

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,13 @@ import (
2323
"go/ast"
2424
"go/token"
2525
"go/types"
26+
"maps"
2627
"os"
2728
"os/exec"
2829
"path/filepath"
2930
"reflect"
3031
"regexp"
32+
"slices"
3133
"sort"
3234
"strconv"
3335
"strings"
@@ -41,7 +43,6 @@ import (
4143
"golang.org/x/tools/gopls/internal/golang"
4244
"golang.org/x/tools/gopls/internal/mod"
4345
"golang.org/x/tools/gopls/internal/settings"
44-
"golang.org/x/tools/gopls/internal/util/maps"
4546
"golang.org/x/tools/gopls/internal/util/safetoken"
4647
)
4748

@@ -56,14 +57,6 @@ func main() {
5657
// - if write, it updates them;
5758
// - if !write, it reports whether they would change.
5859
func doMain(write bool) (bool, error) {
59-
// TODO(adonovan): when we can rely on go1.23,
60-
// switch to gotypesalias=1 behavior.
61-
//
62-
// (Since this program is run by 'go run',
63-
// the gopls/go.mod file's go 1.19 directive doesn't
64-
// have its usual effect of setting gotypesalias=0.)
65-
os.Setenv("GODEBUG", "gotypesalias=0")
66-
6760
api, err := loadAPI()
6861
if err != nil {
6962
return false, err
@@ -472,9 +465,7 @@ func loadLenses(settingsPkg *packages.Package, defaults map[settings.CodeLensSou
472465
// Build list of Lens descriptors.
473466
var lenses []*doc.Lens
474467
addAll := func(sources map[settings.CodeLensSource]cache.CodeLensSourceFunc, fileType string) error {
475-
slice := maps.Keys(sources)
476-
sort.Slice(slice, func(i, j int) bool { return slice[i] < slice[j] })
477-
for _, source := range slice {
468+
for _, source := range slices.Sorted(maps.Keys(sources)) {
478469
docText, ok := enumDoc[string(source)]
479470
if !ok {
480471
return fmt.Errorf("missing CodeLensSource declaration for %s", source)

gopls/internal/analysis/simplifycompositelit/simplifycompositelit.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import (
1919
"golang.org/x/tools/go/analysis"
2020
"golang.org/x/tools/go/analysis/passes/inspect"
2121
"golang.org/x/tools/go/ast/inspector"
22-
"golang.org/x/tools/gopls/internal/util/astutil"
2322
"golang.org/x/tools/internal/analysisinternal"
2423
)
2524

@@ -38,7 +37,7 @@ func run(pass *analysis.Pass) (interface{}, error) {
3837
// Gather information whether file is generated or not
3938
generated := make(map[*token.File]bool)
4039
for _, file := range pass.Files {
41-
if astutil.IsGenerated(file) {
40+
if ast.IsGenerated(file) {
4241
generated[pass.Fset.File(file.Pos())] = true
4342
}
4443
}

gopls/internal/analysis/simplifyrange/simplifyrange.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import (
1414
"golang.org/x/tools/go/analysis"
1515
"golang.org/x/tools/go/analysis/passes/inspect"
1616
"golang.org/x/tools/go/ast/inspector"
17-
"golang.org/x/tools/gopls/internal/util/astutil"
1817
"golang.org/x/tools/internal/analysisinternal"
1918
)
2019

@@ -33,7 +32,7 @@ func run(pass *analysis.Pass) (interface{}, error) {
3332
// Gather information whether file is generated or not
3433
generated := make(map[*token.File]bool)
3534
for _, file := range pass.Files {
36-
if astutil.IsGenerated(file) {
35+
if ast.IsGenerated(file) {
3736
generated[pass.Fset.File(file.Pos())] = true
3837
}
3938
}

gopls/internal/analysis/simplifyrange/simplifyrange_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ package simplifyrange_test
66

77
import (
88
"go/build"
9+
"slices"
910
"testing"
1011

1112
"golang.org/x/tools/go/analysis/analysistest"
1213
"golang.org/x/tools/gopls/internal/analysis/simplifyrange"
13-
"golang.org/x/tools/gopls/internal/util/slices"
1414
)
1515

1616
func Test(t *testing.T) {

gopls/internal/analysis/simplifyslice/simplifyslice.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import (
1515
"golang.org/x/tools/go/analysis"
1616
"golang.org/x/tools/go/analysis/passes/inspect"
1717
"golang.org/x/tools/go/ast/inspector"
18-
"golang.org/x/tools/gopls/internal/util/astutil"
1918
"golang.org/x/tools/internal/analysisinternal"
2019
)
2120

@@ -42,7 +41,7 @@ func run(pass *analysis.Pass) (interface{}, error) {
4241
// Gather information whether file is generated or not
4342
generated := make(map[*token.File]bool)
4443
for _, file := range pass.Files {
45-
if astutil.IsGenerated(file) {
44+
if ast.IsGenerated(file) {
4645
generated[pass.Fset.File(file.Pos())] = true
4746
}
4847
}

gopls/internal/analysis/unusedparams/unusedparams.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import (
1313
"golang.org/x/tools/go/analysis"
1414
"golang.org/x/tools/go/analysis/passes/inspect"
1515
"golang.org/x/tools/go/ast/inspector"
16-
"golang.org/x/tools/gopls/internal/util/slices"
16+
"golang.org/x/tools/gopls/internal/util/moreslices"
1717
"golang.org/x/tools/internal/analysisinternal"
1818
)
1919

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

200200
if fn == nil && id.Name == "_" {

gopls/internal/cache/analysis.go

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
"reflect"
2525
"runtime"
2626
"runtime/debug"
27+
"slices"
2728
"sort"
2829
"strings"
2930
"sync"
@@ -43,8 +44,7 @@ import (
4344
"golang.org/x/tools/gopls/internal/util/astutil"
4445
"golang.org/x/tools/gopls/internal/util/bug"
4546
"golang.org/x/tools/gopls/internal/util/frob"
46-
"golang.org/x/tools/gopls/internal/util/maps"
47-
"golang.org/x/tools/gopls/internal/util/slices"
47+
"golang.org/x/tools/gopls/internal/util/moremaps"
4848
"golang.org/x/tools/internal/analysisinternal"
4949
"golang.org/x/tools/internal/event"
5050
"golang.org/x/tools/internal/facts"
@@ -769,11 +769,7 @@ func (an *analysisNode) cacheKey() [sha256.Size]byte {
769769
}
770770

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

gopls/internal/cache/check.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
"go/types"
1616
"regexp"
1717
"runtime"
18+
"slices"
1819
"sort"
1920
"strings"
2021
"sync"
@@ -32,7 +33,6 @@ import (
3233
"golang.org/x/tools/gopls/internal/protocol"
3334
"golang.org/x/tools/gopls/internal/util/bug"
3435
"golang.org/x/tools/gopls/internal/util/safetoken"
35-
"golang.org/x/tools/gopls/internal/util/slices"
3636
"golang.org/x/tools/internal/analysisinternal"
3737
"golang.org/x/tools/internal/event"
3838
"golang.org/x/tools/internal/gcimporter"

gopls/internal/cache/load.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"errors"
1111
"fmt"
1212
"path/filepath"
13+
"slices"
1314
"sort"
1415
"strings"
1516
"sync/atomic"
@@ -23,7 +24,6 @@ import (
2324
"golang.org/x/tools/gopls/internal/util/bug"
2425
"golang.org/x/tools/gopls/internal/util/immutable"
2526
"golang.org/x/tools/gopls/internal/util/pathutil"
26-
"golang.org/x/tools/gopls/internal/util/slices"
2727
"golang.org/x/tools/internal/event"
2828
"golang.org/x/tools/internal/gocommand"
2929
"golang.org/x/tools/internal/packagesinternal"

gopls/internal/cache/session.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"fmt"
1111
"os"
1212
"path/filepath"
13+
"slices"
1314
"sort"
1415
"strconv"
1516
"strings"
@@ -24,7 +25,6 @@ import (
2425
"golang.org/x/tools/gopls/internal/protocol"
2526
"golang.org/x/tools/gopls/internal/util/bug"
2627
"golang.org/x/tools/gopls/internal/util/persistent"
27-
"golang.org/x/tools/gopls/internal/util/slices"
2828
"golang.org/x/tools/gopls/internal/vulncheck"
2929
"golang.org/x/tools/internal/event"
3030
"golang.org/x/tools/internal/event/keys"

gopls/internal/cache/snapshot.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
"path/filepath"
2020
"regexp"
2121
"runtime"
22+
"slices"
2223
"sort"
2324
"strconv"
2425
"strings"
@@ -43,7 +44,6 @@ import (
4344
"golang.org/x/tools/gopls/internal/util/immutable"
4445
"golang.org/x/tools/gopls/internal/util/pathutil"
4546
"golang.org/x/tools/gopls/internal/util/persistent"
46-
"golang.org/x/tools/gopls/internal/util/slices"
4747
"golang.org/x/tools/gopls/internal/vulncheck"
4848
"golang.org/x/tools/internal/event"
4949
"golang.org/x/tools/internal/event/label"

gopls/internal/cache/view.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"path"
2121
"path/filepath"
2222
"regexp"
23+
"slices"
2324
"sort"
2425
"strings"
2526
"sync"
@@ -29,9 +30,8 @@ import (
2930
"golang.org/x/tools/gopls/internal/file"
3031
"golang.org/x/tools/gopls/internal/protocol"
3132
"golang.org/x/tools/gopls/internal/settings"
32-
"golang.org/x/tools/gopls/internal/util/maps"
33+
"golang.org/x/tools/gopls/internal/util/moremaps"
3334
"golang.org/x/tools/gopls/internal/util/pathutil"
34-
"golang.org/x/tools/gopls/internal/util/slices"
3535
"golang.org/x/tools/gopls/internal/vulncheck"
3636
"golang.org/x/tools/internal/event"
3737
"golang.org/x/tools/internal/gocommand"
@@ -253,7 +253,7 @@ func viewDefinitionsEqual(x, y *viewDefinition) bool {
253253
if x.workspaceModFilesErr.Error() != y.workspaceModFilesErr.Error() {
254254
return false
255255
}
256-
} else if !maps.SameKeys(x.workspaceModFiles, y.workspaceModFiles) {
256+
} else if !moremaps.SameKeys(x.workspaceModFiles, y.workspaceModFiles) {
257257
return false
258258
}
259259
if len(x.envOverlay) != len(y.envOverlay) {
@@ -698,7 +698,7 @@ func (s *Snapshot) initialize(ctx context.Context, firstAttempt bool) {
698698
extractedDiags := s.extractGoCommandErrors(ctx, loadErr)
699699
initialErr = &InitializationError{
700700
MainError: loadErr,
701-
Diagnostics: maps.Group(extractedDiags, byURI),
701+
Diagnostics: moremaps.Group(extractedDiags, byURI),
702702
}
703703
case s.view.workspaceModFilesErr != nil:
704704
initialErr = &InitializationError{

gopls/internal/cache/xrefs/xrefs.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import (
1818
"golang.org/x/tools/gopls/internal/cache/parsego"
1919
"golang.org/x/tools/gopls/internal/protocol"
2020
"golang.org/x/tools/gopls/internal/util/frob"
21-
"golang.org/x/tools/gopls/internal/util/typesutil"
2221
)
2322

2423
// Index constructs a serializable index of outbound cross-references
@@ -93,8 +92,8 @@ func Index(files []*parsego.File, pkg *types.Package, info *types.Info) []byte {
9392
case *ast.ImportSpec:
9493
// Report a reference from each import path
9594
// string to the imported package.
96-
pkgname, ok := typesutil.ImportedPkgName(info, n)
97-
if !ok {
95+
pkgname := info.PkgNameOf(n)
96+
if pkgname == nil {
9897
return true // missing import
9998
}
10099
objects := getObjects(pkgname.Imported())

gopls/internal/cmd/check.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ import (
88
"context"
99
"flag"
1010
"fmt"
11+
"slices"
1112

1213
"golang.org/x/tools/gopls/internal/protocol"
1314
"golang.org/x/tools/gopls/internal/settings"
14-
"golang.org/x/tools/gopls/internal/util/slices"
1515
)
1616

1717
// check implements the check verb for gopls.

gopls/internal/cmd/codeaction.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ import (
99
"flag"
1010
"fmt"
1111
"regexp"
12+
"slices"
1213
"strings"
1314

1415
"golang.org/x/tools/gopls/internal/protocol"
15-
"golang.org/x/tools/gopls/internal/util/slices"
1616
"golang.org/x/tools/internal/tool"
1717
)
1818

gopls/internal/cmd/execute.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ import (
1111
"fmt"
1212
"log"
1313
"os"
14+
"slices"
1415

1516
"golang.org/x/tools/gopls/internal/protocol"
1617
"golang.org/x/tools/gopls/internal/protocol/command"
1718
"golang.org/x/tools/gopls/internal/server"
18-
"golang.org/x/tools/gopls/internal/util/slices"
1919
"golang.org/x/tools/internal/tool"
2020
)
2121

gopls/internal/fuzzy/symbol_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,8 @@ func TestMatcherSimilarities(t *testing.T) {
100100
idents := collectIdentifiers(t)
101101
t.Logf("collected %d unique identifiers", len(idents))
102102

103-
// TODO: use go1.21 slices.MaxFunc.
103+
// We can't use slices.MaxFunc because we want a custom
104+
// scoring (not equivalence) function.
104105
topMatch := func(score func(string) float64) string {
105106
top := ""
106107
topScore := 0.0

gopls/internal/golang/codeaction.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"fmt"
1111
"go/ast"
1212
"go/types"
13+
"slices"
1314
"strings"
1415

1516
"golang.org/x/tools/go/ast/astutil"
@@ -23,7 +24,6 @@ import (
2324
"golang.org/x/tools/gopls/internal/protocol/command"
2425
"golang.org/x/tools/gopls/internal/settings"
2526
"golang.org/x/tools/gopls/internal/util/bug"
26-
"golang.org/x/tools/gopls/internal/util/slices"
2727
"golang.org/x/tools/internal/event"
2828
"golang.org/x/tools/internal/imports"
2929
"golang.org/x/tools/internal/typesinternal"

gopls/internal/golang/completion/completion.go

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import (
1818
"go/token"
1919
"go/types"
2020
"math"
21-
"reflect"
21+
"slices"
2222
"sort"
2323
"strconv"
2424
"strings"
@@ -39,7 +39,6 @@ import (
3939
"golang.org/x/tools/gopls/internal/settings"
4040
goplsastutil "golang.org/x/tools/gopls/internal/util/astutil"
4141
"golang.org/x/tools/gopls/internal/util/safetoken"
42-
"golang.org/x/tools/gopls/internal/util/slices"
4342
"golang.org/x/tools/gopls/internal/util/typesutil"
4443
"golang.org/x/tools/internal/aliases"
4544
"golang.org/x/tools/internal/event"
@@ -198,7 +197,7 @@ type completer struct {
198197

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

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

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

14051399
// Extract the package-level candidates using a quick parse.
14061400
var g errgroup.Group

0 commit comments

Comments
 (0)