Skip to content

Commit 67611a1

Browse files
committed
internal/typeparams: eliminate type aliases
Change-Id: I660520bbb1dae855e52bf92492045bb3b16eff8d Reviewed-on: https://go-review.googlesource.com/c/tools/+/549119 Reviewed-by: Robert Findley <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]>
1 parent 23c86e8 commit 67611a1

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

+157
-196
lines changed

go/analysis/passes/composite/composite.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ func run(pass *analysis.Pass) (interface{}, error) {
7272
}
7373
var structuralTypes []types.Type
7474
switch typ := typ.(type) {
75-
case *typeparams.TypeParam:
75+
case *types.TypeParam:
7676
terms, err := typeparams.StructuralTerms(typ)
7777
if err != nil {
7878
return // invalid type
@@ -163,7 +163,7 @@ func isLocalType(pass *analysis.Pass, typ types.Type) bool {
163163
case *types.Named:
164164
// names in package foo are local to foo_test too
165165
return strings.TrimSuffix(x.Obj().Pkg().Path(), "_test") == strings.TrimSuffix(pass.Pkg.Path(), "_test")
166-
case *typeparams.TypeParam:
166+
case *types.TypeParam:
167167
return strings.TrimSuffix(x.Obj().Pkg().Path(), "_test") == strings.TrimSuffix(pass.Pkg.Path(), "_test")
168168
}
169169
return false

go/analysis/passes/copylock/copylock.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ func lockPath(tpkg *types.Package, typ types.Type, seen map[types.Type]bool) typ
255255
}
256256
seen[typ] = true
257257

258-
if tpar, ok := typ.(*typeparams.TypeParam); ok {
258+
if tpar, ok := typ.(*types.TypeParam); ok {
259259
terms, err := typeparams.StructuralTerms(tpar)
260260
if err != nil {
261261
return nil // invalid type

go/analysis/passes/ifaceassert/parameterized.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ func (w *tpWalker) isParameterized(typ types.Type) (res bool) {
102102
}
103103
}
104104

105-
case *typeparams.TypeParam:
105+
case *types.TypeParam:
106106
return true
107107

108108
default:

go/analysis/passes/nilfunc/nilfunc.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ func run(pass *analysis.Pass) (interface{}, error) {
6262
obj = pass.TypesInfo.Uses[v]
6363
case *ast.SelectorExpr:
6464
obj = pass.TypesInfo.Uses[v.Sel]
65-
case *ast.IndexExpr, *typeparams.IndexListExpr:
65+
case *ast.IndexExpr, *ast.IndexListExpr:
6666
// Check generic functions such as "f[T1,T2]".
6767
x, _, _, _ := typeparams.UnpackIndexExpr(v)
6868
if id, ok := x.(*ast.Ident); ok {

go/analysis/passes/printf/types.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ func (m *argMatcher) match(typ types.Type, topLevel bool) bool {
7272
return true
7373
}
7474

75-
if typ, _ := typ.(*typeparams.TypeParam); typ != nil {
75+
if typ, _ := typ.(*types.TypeParam); typ != nil {
7676
// Avoid infinite recursion through type parameters.
7777
if m.seen[typ] {
7878
return true

go/analysis/passes/shift/shift.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ func checkLongShift(pass *analysis.Pass, node ast.Node, x, y ast.Expr) {
9999
}
100100
var structuralTypes []types.Type
101101
switch t := t.(type) {
102-
case *typeparams.TypeParam:
102+
case *types.TypeParam:
103103
terms, err := typeparams.StructuralTerms(t)
104104
if err != nil {
105105
return // invalid type

go/analysis/passes/stringintconv/string.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ func run(pass *analysis.Pass) (interface{}, error) {
195195
func structuralTypes(t types.Type) ([]types.Type, error) {
196196
var structuralTypes []types.Type
197197
switch t := t.(type) {
198-
case *typeparams.TypeParam:
198+
case *types.TypeParam:
199199
terms, err := typeparams.StructuralTerms(t)
200200
if err != nil {
201201
return nil, err

go/analysis/passes/testinggoroutine/util.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ func isMethodNamed(f *types.Func, pkgPath string, names ...string) bool {
5757

5858
func funcIdent(fun ast.Expr) *ast.Ident {
5959
switch fun := astutil.Unparen(fun).(type) {
60-
case *ast.IndexExpr, *typeparams.IndexListExpr:
60+
case *ast.IndexExpr, *ast.IndexListExpr:
6161
x, _, _, _ := typeparams.UnpackIndexExpr(fun) // necessary?
6262
id, _ := x.(*ast.Ident)
6363
return id

go/analysis/passes/unmarshal/unmarshal.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import (
1414
"golang.org/x/tools/go/analysis/passes/internal/analysisutil"
1515
"golang.org/x/tools/go/ast/inspector"
1616
"golang.org/x/tools/go/types/typeutil"
17-
"golang.org/x/tools/internal/typeparams"
1817
)
1918

2019
//go:embed doc.go
@@ -92,7 +91,7 @@ func run(pass *analysis.Pass) (interface{}, error) {
9291

9392
t := pass.TypesInfo.Types[call.Args[argidx]].Type
9493
switch t.Underlying().(type) {
95-
case *types.Pointer, *types.Interface, *typeparams.TypeParam:
94+
case *types.Pointer, *types.Interface, *types.TypeParam:
9695
return
9796
}
9897

go/ast/astutil/enclosing.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,7 @@ func childrenOf(n ast.Node) []ast.Node {
377377
tok(n.Lbrack, len("[")),
378378
tok(n.Rbrack, len("]")))
379379

380-
case *typeparams.IndexListExpr:
380+
case *ast.IndexListExpr:
381381
children = append(children,
382382
tok(n.Lbrack, len("[")),
383383
tok(n.Rbrack, len("]")))
@@ -588,7 +588,7 @@ func NodeDescription(n ast.Node) string {
588588
return "decrement statement"
589589
case *ast.IndexExpr:
590590
return "index expression"
591-
case *typeparams.IndexListExpr:
591+
case *ast.IndexListExpr:
592592
return "index list expression"
593593
case *ast.InterfaceType:
594594
return "interface type"

go/ast/astutil/rewrite.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ func (a *application) apply(parent ast.Node, name string, iter *iterator, n ast.
252252
a.apply(n, "X", nil, n.X)
253253
a.apply(n, "Index", nil, n.Index)
254254

255-
case *typeparams.IndexListExpr:
255+
case *ast.IndexListExpr:
256256
a.apply(n, "X", nil, n.X)
257257
a.applyList(n, "Indices")
258258

go/ast/inspector/inspector_test.go

+4-5
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ import (
1717
"testing"
1818

1919
"golang.org/x/tools/go/ast/inspector"
20-
"golang.org/x/tools/internal/typeparams"
2120
)
2221

2322
var netFiles []*ast.File
@@ -94,7 +93,7 @@ var _ i13[i14, i15]
9493
inspect := inspector.New([]*ast.File{f})
9594
found := make([]bool, 16)
9695

97-
indexListExprs := make(map[*typeparams.IndexListExpr]bool)
96+
indexListExprs := make(map[*ast.IndexListExpr]bool)
9897

9998
// Verify that we reach all i* identifiers, and collect IndexListExpr nodes.
10099
inspect.Preorder(nil, func(n ast.Node) {
@@ -107,7 +106,7 @@ var _ i13[i14, i15]
107106
}
108107
found[index] = true
109108
}
110-
case *typeparams.IndexListExpr:
109+
case *ast.IndexListExpr:
111110
indexListExprs[n] = false
112111
}
113112
})
@@ -122,8 +121,8 @@ var _ i13[i14, i15]
122121
if len(indexListExprs) == 0 {
123122
t.Fatal("no index list exprs found")
124123
}
125-
inspect.Preorder([]ast.Node{&typeparams.IndexListExpr{}}, func(n ast.Node) {
126-
ix := n.(*typeparams.IndexListExpr)
124+
inspect.Preorder([]ast.Node{&ast.IndexListExpr{}}, func(n ast.Node) {
125+
ix := n.(*ast.IndexListExpr)
127126
indexListExprs[ix] = true
128127
})
129128
for ix, v := range indexListExprs {

go/ast/inspector/typeof.go

+1-3
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ package inspector
1212
import (
1313
"go/ast"
1414
"math"
15-
16-
"golang.org/x/tools/internal/typeparams"
1715
)
1816

1917
const (
@@ -171,7 +169,7 @@ func typeOf(n ast.Node) uint64 {
171169
return 1 << nIncDecStmt
172170
case *ast.IndexExpr:
173171
return 1 << nIndexExpr
174-
case *typeparams.IndexListExpr:
172+
case *ast.IndexListExpr:
175173
return 1 << nIndexListExpr
176174
case *ast.InterfaceType:
177175
return 1 << nInterfaceType

go/callgraph/vta/graph.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -661,22 +661,22 @@ func addReturnFlows(b *builder, r *ssa.Return, site ssa.Value) {
661661
func (b *builder) multiconvert(c *ssa.MultiConvert) {
662662
// TODO(zpavlinovic): decide what to do on MultiConvert long term.
663663
// TODO(zpavlinovic): add unit tests.
664-
typeSetOf := func(typ types.Type) []*typeparams.Term {
664+
typeSetOf := func(typ types.Type) []*types.Term {
665665
// This is a adaptation of x/exp/typeparams.NormalTerms which x/tools cannot depend on.
666-
var terms []*typeparams.Term
666+
var terms []*types.Term
667667
var err error
668668
switch typ := typ.(type) {
669-
case *typeparams.TypeParam:
669+
case *types.TypeParam:
670670
terms, err = typeparams.StructuralTerms(typ)
671-
case *typeparams.Union:
671+
case *types.Union:
672672
terms, err = typeparams.UnionTermSet(typ)
673673
case *types.Interface:
674674
terms, err = typeparams.InterfaceTermSet(typ)
675675
default:
676676
// Common case.
677677
// Specializing the len=1 case to avoid a slice
678678
// had no measurable space/time benefit.
679-
terms = []*typeparams.Term{typeparams.NewTerm(false, typ)}
679+
terms = []*types.Term{typeparams.NewTerm(false, typ)}
680680
}
681681

682682
if err != nil {

go/ssa/builder.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -802,7 +802,7 @@ func (b *builder) expr0(fn *Function, e ast.Expr, tv types.TypeAndValue) Value {
802802
if types.IsInterface(rt) {
803803
// If v may be an interface type I (after instantiating),
804804
// we must emit a check that v is non-nil.
805-
if recv, ok := sel.recv.(*typeparams.TypeParam); ok {
805+
if recv, ok := sel.recv.(*types.TypeParam); ok {
806806
// Emit a nil check if any possible instantiation of the
807807
// type parameter is an interface type.
808808
if typeSetOf(recv).Len() > 0 {
@@ -848,7 +848,7 @@ func (b *builder) expr0(fn *Function, e ast.Expr, tv types.TypeAndValue) Value {
848848

849849
panic("unexpected expression-relative selector")
850850

851-
case *typeparams.IndexListExpr:
851+
case *ast.IndexListExpr:
852852
// f[X, Y] must be a generic function
853853
if !instance(fn.info, e.X) {
854854
panic("unexpected expression-could not match index list to instantiation")

go/ssa/const.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ func zeroString(t types.Type, from *types.Package) string {
125125
components[i] = zeroString(t.At(i).Type(), from)
126126
}
127127
return "(" + strings.Join(components, ", ") + ")"
128-
case *typeparams.TypeParam:
128+
case *types.TypeParam:
129129
return "*new(" + relType(t, from) + ")"
130130
}
131131
panic(fmt.Sprint("zeroString: unexpected ", t))

go/ssa/coretype.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -40,27 +40,27 @@ func isBytestring(T types.Type) bool {
4040
}
4141

4242
// termList is a list of types.
43-
type termList []*typeparams.Term // type terms of the type set
43+
type termList []*types.Term // type terms of the type set
4444
func (s termList) Len() int { return len(s) }
4545
func (s termList) At(i int) types.Type { return s[i].Type() }
4646

4747
// typeSetOf returns the type set of typ. Returns an empty typeset on an error.
4848
func typeSetOf(typ types.Type) termList {
4949
// This is a adaptation of x/exp/typeparams.NormalTerms which x/tools cannot depend on.
50-
var terms []*typeparams.Term
50+
var terms []*types.Term
5151
var err error
5252
switch typ := typ.(type) {
53-
case *typeparams.TypeParam:
53+
case *types.TypeParam:
5454
terms, err = typeparams.StructuralTerms(typ)
55-
case *typeparams.Union:
55+
case *types.Union:
5656
terms, err = typeparams.UnionTermSet(typ)
5757
case *types.Interface:
5858
terms, err = typeparams.InterfaceTermSet(typ)
5959
default:
6060
// Common case.
6161
// Specializing the len=1 case to avoid a slice
6262
// had no measurable space/time benefit.
63-
terms = []*typeparams.Term{typeparams.NewTerm(false, typ)}
63+
terms = []*types.Term{typeparams.NewTerm(false, typ)}
6464
}
6565

6666
if err != nil {

go/ssa/create.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ func createFunction(prog *Program, obj *types.Func, name string, syntax ast.Node
117117
sig := obj.Type().(*types.Signature)
118118

119119
// Collect type parameters.
120-
var tparams *typeparams.TypeParamList
120+
var tparams *types.TypeParamList
121121
if rtparams := typeparams.RecvTypeParams(sig); rtparams.Len() > 0 {
122122
tparams = rtparams // method of generic type
123123
} else if sigparams := typeparams.ForSignature(sig); sigparams.Len() > 0 {

go/ssa/methods.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ func forEachReachable(msets *typeutil.MethodSetCache, T types.Type, f func(types
261261
visit(T.At(i).Type(), false)
262262
}
263263

264-
case *typeparams.TypeParam, *typeparams.Union:
264+
case *types.TypeParam, *types.Union:
265265
// forEachReachable must not be called on parameterized types.
266266
panic(T)
267267

go/ssa/parameterized.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ func (w *tpWalker) isParameterizedLocked(typ types.Type) (res bool) {
117117
}
118118
return w.isParameterizedLocked(t.Underlying()) // recurse for types local to parameterized functions
119119

120-
case *typeparams.TypeParam:
120+
case *types.TypeParam:
121121
return true
122122

123123
default:

go/ssa/print.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ import (
1717
"strings"
1818

1919
"golang.org/x/tools/go/types/typeutil"
20-
"golang.org/x/tools/internal/typeparams"
2120
)
2221

2322
// relName returns the name of v relative to i.
@@ -51,7 +50,7 @@ func relType(t types.Type, from *types.Package) string {
5150
return s
5251
}
5352

54-
func relTerm(term *typeparams.Term, from *types.Package) string {
53+
func relTerm(term *types.Term, from *types.Package) string {
5554
s := relType(term.Type(), from)
5655
if term.Tilde() {
5756
return "~" + s

go/ssa/ssa.go

+9-12
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ type Program struct {
2727
mode BuilderMode // set of mode bits for SSA construction
2828
MethodSets typeutil.MethodSetCache // cache of type-checker's method-sets
2929

30-
canon *canonizer // type canonicalization map
31-
ctxt *typeparams.Context // cache for type checking instantiations
30+
canon *canonizer // type canonicalization map
31+
ctxt *types.Context // cache for type checking instantiations
3232

3333
methodsMu sync.Mutex
3434
methodSets typeutil.Map // maps type to its concrete *methodSet
@@ -339,10 +339,10 @@ type Function struct {
339339
referrers []Instruction // referring instructions (iff Parent() != nil)
340340
anonIdx int32 // position of a nested function in parent's AnonFuncs. fn.Parent()!=nil => fn.Parent().AnonFunc[fn.anonIdx] == fn.
341341

342-
typeparams *typeparams.TypeParamList // type parameters of this function. typeparams.Len() > 0 => generic or instance of generic function
343-
typeargs []types.Type // type arguments that instantiated typeparams. len(typeargs) > 0 => instance of generic function
344-
topLevelOrigin *Function // the origin function if this is an instance of a source function. nil if Parent()!=nil.
345-
generic *generic // instances of this function, if generic
342+
typeparams *types.TypeParamList // type parameters of this function. typeparams.Len() > 0 => generic or instance of generic function
343+
typeargs []types.Type // type arguments that instantiated typeparams. len(typeargs) > 0 => instance of generic function
344+
topLevelOrigin *Function // the origin function if this is an instance of a source function. nil if Parent()!=nil.
345+
generic *generic // instances of this function, if generic
346346

347347
// The following fields are cleared after building.
348348
currentBlock *BasicBlock // where to emit code
@@ -690,8 +690,8 @@ type Convert struct {
690690
type MultiConvert struct {
691691
register
692692
X Value
693-
from []*typeparams.Term
694-
to []*typeparams.Term
693+
from []*types.Term
694+
to []*types.Term
695695
}
696696

697697
// ChangeInterface constructs a value of one interface type from a
@@ -1539,10 +1539,7 @@ func (v *Function) Referrers() *[]Instruction {
15391539

15401540
// TypeParams are the function's type parameters if generic or the
15411541
// type parameters that were instantiated if fn is an instantiation.
1542-
//
1543-
// TODO(taking): declare result type as *types.TypeParamList
1544-
// after we drop support for go1.17.
1545-
func (fn *Function) TypeParams() *typeparams.TypeParamList {
1542+
func (fn *Function) TypeParams() *types.TypeParamList {
15461543
return fn.typeparams
15471544
}
15481545

0 commit comments

Comments
 (0)