Skip to content

Commit 28b92af

Browse files
adonovangopherbot
authored andcommitted
internal/typeparams: eliminate remainining compatibility shims
The nil checks in wrappers that had them were all redundant. Change-Id: Ide7296f2253610638b59dc4980b0487b9de72f0c Reviewed-on: https://go-review.googlesource.com/c/tools/+/549236 LUCI-TryBot-Result: Go LUCI <[email protected]> Auto-Submit: Alan Donovan <[email protected]> Reviewed-by: Robert Findley <[email protected]>
1 parent ee35f8e commit 28b92af

Some content is hidden

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

52 files changed

+126
-295
lines changed

go/analysis/passes/ifaceassert/parameterized.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ func (w *tpWalker) isParameterized(typ types.Type) (res bool) {
9595
return w.isParameterized(t.Elem())
9696

9797
case *types.Named:
98-
list := typeparams.NamedTypeArgs(t)
98+
list := t.TypeArgs()
9999
for i, n := 0, list.Len(); i < n; i++ {
100100
if w.isParameterized(list.At(i)) {
101101
return true

go/analysis/passes/tests/tests.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ import (
1717

1818
"golang.org/x/tools/go/analysis"
1919
"golang.org/x/tools/go/analysis/passes/internal/analysisutil"
20-
"golang.org/x/tools/internal/typeparams"
2120
)
2221

2322
//go:embed doc.go
@@ -391,7 +390,7 @@ func checkExampleName(pass *analysis.Pass, fn *ast.FuncDecl) {
391390
if results := fn.Type.Results; results != nil && len(results.List) != 0 {
392391
pass.Reportf(fn.Pos(), "%s should return nothing", fnName)
393392
}
394-
if tparams := typeparams.ForFuncType(fn.Type); tparams != nil && len(tparams.List) > 0 {
393+
if tparams := fn.Type.TypeParams; tparams != nil && len(tparams.List) > 0 {
395394
pass.Reportf(fn.Pos(), "%s should not have type params", fnName)
396395
}
397396

@@ -460,7 +459,7 @@ func checkTest(pass *analysis.Pass, fn *ast.FuncDecl, prefix string) {
460459
return
461460
}
462461

463-
if tparams := typeparams.ForFuncType(fn.Type); tparams != nil && len(tparams.List) > 0 {
462+
if tparams := fn.Type.TypeParams; tparams != nil && len(tparams.List) > 0 {
464463
// Note: cmd/go/internal/load also errors about TestXXX and BenchmarkXXX functions with type parameters.
465464
// We have currently decided to also warn before compilation/package loading. This can help users in IDEs.
466465
// TODO(adonovan): use ReportRangef(tparams).

go/analysis/unitchecker/unitchecker.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ import (
5050
"golang.org/x/tools/go/analysis"
5151
"golang.org/x/tools/go/analysis/internal/analysisflags"
5252
"golang.org/x/tools/internal/facts"
53-
"golang.org/x/tools/internal/typeparams"
5453
"golang.org/x/tools/internal/versions"
5554
)
5655

@@ -259,10 +258,10 @@ func run(fset *token.FileSet, cfg *Config, analyzers []*analysis.Analyzer) ([]re
259258
Defs: make(map[*ast.Ident]types.Object),
260259
Uses: make(map[*ast.Ident]types.Object),
261260
Implicits: make(map[ast.Node]types.Object),
261+
Instances: make(map[*ast.Ident]types.Instance),
262262
Scopes: make(map[ast.Node]*types.Scope),
263263
Selections: make(map[*ast.SelectorExpr]*types.Selection),
264264
}
265-
typeparams.InitInstanceInfo(info)
266265
versions.InitFileVersions(info)
267266

268267
pkg, err := tc.Check(cfg.ImportPath, fset, files, info)

go/ast/astutil/enclosing.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ import (
1111
"go/ast"
1212
"go/token"
1313
"sort"
14-
15-
"golang.org/x/tools/internal/typeparams"
1614
)
1715

1816
// PathEnclosingInterval returns the node that encloses the source
@@ -322,7 +320,7 @@ func childrenOf(n ast.Node) []ast.Node {
322320
children = append(children, n.Recv)
323321
}
324322
children = append(children, n.Name)
325-
if tparams := typeparams.ForFuncType(n.Type); tparams != nil {
323+
if tparams := n.Type.TypeParams; tparams != nil {
326324
children = append(children, tparams)
327325
}
328326
if n.Type.Params != nil {

go/ast/astutil/rewrite.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ import (
99
"go/ast"
1010
"reflect"
1111
"sort"
12-
13-
"golang.org/x/tools/internal/typeparams"
1412
)
1513

1614
// An ApplyFunc is invoked by Apply for each node n, even if n is nil,
@@ -293,7 +291,7 @@ func (a *application) apply(parent ast.Node, name string, iter *iterator, n ast.
293291
a.apply(n, "Fields", nil, n.Fields)
294292

295293
case *ast.FuncType:
296-
if tparams := typeparams.ForFuncType(n); tparams != nil {
294+
if tparams := n.TypeParams; tparams != nil {
297295
a.apply(n, "TypeParams", nil, tparams)
298296
}
299297
a.apply(n, "Params", nil, n.Params)
@@ -408,7 +406,7 @@ func (a *application) apply(parent ast.Node, name string, iter *iterator, n ast.
408406
case *ast.TypeSpec:
409407
a.apply(n, "Doc", nil, n.Doc)
410408
a.apply(n, "Name", nil, n.Name)
411-
if tparams := typeparams.ForTypeSpec(n); tparams != nil {
409+
if tparams := n.TypeParams; tparams != nil {
412410
a.apply(n, "TypeParams", nil, tparams)
413411
}
414412
a.apply(n, "Type", nil, n.Type)

go/callgraph/vta/graph.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -676,7 +676,7 @@ func (b *builder) multiconvert(c *ssa.MultiConvert) {
676676
// Common case.
677677
// Specializing the len=1 case to avoid a slice
678678
// had no measurable space/time benefit.
679-
terms = []*types.Term{typeparams.NewTerm(false, typ)}
679+
terms = []*types.Term{types.NewTerm(false, typ)}
680680
}
681681

682682
if err != nil {

go/loader/loader.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import (
2323

2424
"golang.org/x/tools/go/ast/astutil"
2525
"golang.org/x/tools/go/internal/cgo"
26-
"golang.org/x/tools/internal/typeparams"
2726
"golang.org/x/tools/internal/versions"
2827
)
2928

@@ -1034,13 +1033,13 @@ func (imp *importer) newPackageInfo(path, dir string) *PackageInfo {
10341033
Defs: make(map[*ast.Ident]types.Object),
10351034
Uses: make(map[*ast.Ident]types.Object),
10361035
Implicits: make(map[ast.Node]types.Object),
1036+
Instances: make(map[*ast.Ident]types.Instance),
10371037
Scopes: make(map[ast.Node]*types.Scope),
10381038
Selections: make(map[*ast.SelectorExpr]*types.Selection),
10391039
},
10401040
errorFunc: imp.conf.TypeChecker.Error,
10411041
dir: dir,
10421042
}
1043-
typeparams.InitInstanceInfo(&info.Info)
10441043
versions.InitFileVersions(&info.Info)
10451044

10461045
// Copy the types.Config so we can vary it across PackageInfos.

go/packages/packages.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ import (
2727
"golang.org/x/tools/go/gcexportdata"
2828
"golang.org/x/tools/internal/gocommand"
2929
"golang.org/x/tools/internal/packagesinternal"
30-
"golang.org/x/tools/internal/typeparams"
3130
"golang.org/x/tools/internal/typesinternal"
3231
"golang.org/x/tools/internal/versions"
3332
)
@@ -1015,10 +1014,10 @@ func (ld *loader) loadPackage(lpkg *loaderPackage) {
10151014
Defs: make(map[*ast.Ident]types.Object),
10161015
Uses: make(map[*ast.Ident]types.Object),
10171016
Implicits: make(map[ast.Node]types.Object),
1017+
Instances: make(map[*ast.Ident]types.Instance),
10181018
Scopes: make(map[ast.Node]*types.Scope),
10191019
Selections: make(map[*ast.SelectorExpr]*types.Selection),
10201020
}
1021-
typeparams.InitInstanceInfo(lpkg.TypesInfo)
10221021
versions.InitFileVersions(lpkg.TypesInfo)
10231022
lpkg.TypesSizes = ld.sizes
10241023

go/ssa/builder_test.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ import (
2626
"golang.org/x/tools/go/ssa"
2727
"golang.org/x/tools/go/ssa/ssautil"
2828
"golang.org/x/tools/internal/testenv"
29-
"golang.org/x/tools/internal/typeparams"
3029
"golang.org/x/tools/txtar"
3130
)
3231

@@ -689,10 +688,10 @@ func LoadPointer(addr *unsafe.Pointer) (val unsafe.Pointer)
689688
p := prog.Package(lprog.Package("p").Pkg)
690689
p.Build()
691690

692-
if load := p.Func("Load"); typeparams.ForSignature(load.Signature).Len() != 1 {
691+
if load := p.Func("Load"); load.Signature.TypeParams().Len() != 1 {
693692
t.Errorf("expected a single type param T for Load got %q", load.Signature)
694693
}
695-
if ptr := p.Type("Pointer"); typeparams.ForNamed(ptr.Type().(*types.Named)).Len() != 1 {
694+
if ptr := p.Type("Pointer"); ptr.Type().(*types.Named).TypeParams().Len() != 1 {
696695
t.Errorf("expected a single type param T for Pointer got %q", ptr.Type())
697696
}
698697
}

go/ssa/const_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import (
1515
"testing"
1616

1717
"golang.org/x/tools/go/ssa"
18-
"golang.org/x/tools/internal/typeparams"
1918
)
2019

2120
func TestConstString(t *testing.T) {
@@ -93,7 +92,7 @@ func TestConstString(t *testing.T) {
9392

9493
// Test type-param
9594
gen := pkg.Scope().Lookup("gen")
96-
tp := typeparams.ForSignature(gen.Type().(*types.Signature)).At(0)
95+
tp := gen.Type().(*types.Signature).TypeParams().At(0)
9796
if got, want := ssa.NewConst(nil, tp).String(), "0:T"; got != want {
9897
t.Errorf("ssa.NewConst(%v, %s).String() = %v, want %v", nil, tup, got, want)
9998
}

0 commit comments

Comments
 (0)