From 67611a11a1be5466d372eba4e925d97290929ef4 Mon Sep 17 00:00:00 2001 From: Alan Donovan Date: Tue, 12 Dec 2023 13:04:59 -0500 Subject: [PATCH] internal/typeparams: eliminate type aliases Change-Id: I660520bbb1dae855e52bf92492045bb3b16eff8d Reviewed-on: https://go-review.googlesource.com/c/tools/+/549119 Reviewed-by: Robert Findley LUCI-TryBot-Result: Go LUCI --- go/analysis/passes/composite/composite.go | 4 +- go/analysis/passes/copylock/copylock.go | 2 +- .../passes/ifaceassert/parameterized.go | 2 +- go/analysis/passes/nilfunc/nilfunc.go | 2 +- go/analysis/passes/printf/types.go | 2 +- go/analysis/passes/shift/shift.go | 2 +- go/analysis/passes/stringintconv/string.go | 2 +- go/analysis/passes/testinggoroutine/util.go | 2 +- go/analysis/passes/unmarshal/unmarshal.go | 3 +- go/ast/astutil/enclosing.go | 4 +- go/ast/astutil/rewrite.go | 2 +- go/ast/inspector/inspector_test.go | 9 ++-- go/ast/inspector/typeof.go | 4 +- go/callgraph/vta/graph.go | 10 ++-- go/ssa/builder.go | 4 +- go/ssa/const.go | 2 +- go/ssa/coretype.go | 10 ++-- go/ssa/create.go | 2 +- go/ssa/methods.go | 2 +- go/ssa/parameterized.go | 2 +- go/ssa/print.go | 3 +- go/ssa/ssa.go | 21 ++++---- go/ssa/subst.go | 28 +++++----- go/ssa/util.go | 2 +- go/types/objectpath/objectpath.go | 10 ++-- go/types/typeutil/callee.go | 2 +- go/types/typeutil/map.go | 16 +++--- go/types/typeutil/map_test.go | 2 +- godoc/linkify.go | 4 +- godoc/server.go | 3 +- .../analysis/fillstruct/fillstruct.go | 3 +- .../lsp/cache/methodsets/methodsets.go | 2 +- gopls/internal/lsp/cache/typerefs/refs.go | 2 +- .../lsp/source/completion/completion.go | 8 +-- .../internal/lsp/source/completion/literal.go | 12 ++--- gopls/internal/lsp/source/hover.go | 4 +- .../internal/lsp/source/invertifcondition.go | 3 +- gopls/internal/lsp/source/rename.go | 2 +- gopls/internal/lsp/source/types_format.go | 6 +-- gopls/internal/lsp/source/util.go | 3 +- gopls/internal/server/semantic.go | 9 ++-- gopls/internal/util/astutil/util.go | 2 +- internal/facts/imports.go | 4 +- internal/gcimporter/bexport_test.go | 8 +-- internal/gcimporter/iexport.go | 12 ++--- internal/gcimporter/iimport.go | 20 +++---- internal/typeparams/common.go | 8 +-- internal/typeparams/common_test.go | 2 +- internal/typeparams/coretype.go | 8 +-- internal/typeparams/normalize.go | 18 +++---- internal/typeparams/typeparams_go118.go | 52 +++++-------------- refactor/satisfy/find.go | 2 +- 52 files changed, 157 insertions(+), 196 deletions(-) diff --git a/go/analysis/passes/composite/composite.go b/go/analysis/passes/composite/composite.go index c7a49776fe5..847063bb326 100644 --- a/go/analysis/passes/composite/composite.go +++ b/go/analysis/passes/composite/composite.go @@ -72,7 +72,7 @@ func run(pass *analysis.Pass) (interface{}, error) { } var structuralTypes []types.Type switch typ := typ.(type) { - case *typeparams.TypeParam: + case *types.TypeParam: terms, err := typeparams.StructuralTerms(typ) if err != nil { return // invalid type @@ -163,7 +163,7 @@ func isLocalType(pass *analysis.Pass, typ types.Type) bool { case *types.Named: // names in package foo are local to foo_test too return strings.TrimSuffix(x.Obj().Pkg().Path(), "_test") == strings.TrimSuffix(pass.Pkg.Path(), "_test") - case *typeparams.TypeParam: + case *types.TypeParam: return strings.TrimSuffix(x.Obj().Pkg().Path(), "_test") == strings.TrimSuffix(pass.Pkg.Path(), "_test") } return false diff --git a/go/analysis/passes/copylock/copylock.go b/go/analysis/passes/copylock/copylock.go index 2eeb0a330ac..6cbbc7e8140 100644 --- a/go/analysis/passes/copylock/copylock.go +++ b/go/analysis/passes/copylock/copylock.go @@ -255,7 +255,7 @@ func lockPath(tpkg *types.Package, typ types.Type, seen map[types.Type]bool) typ } seen[typ] = true - if tpar, ok := typ.(*typeparams.TypeParam); ok { + if tpar, ok := typ.(*types.TypeParam); ok { terms, err := typeparams.StructuralTerms(tpar) if err != nil { return nil // invalid type diff --git a/go/analysis/passes/ifaceassert/parameterized.go b/go/analysis/passes/ifaceassert/parameterized.go index b84577fcf85..1fdd30c917a 100644 --- a/go/analysis/passes/ifaceassert/parameterized.go +++ b/go/analysis/passes/ifaceassert/parameterized.go @@ -102,7 +102,7 @@ func (w *tpWalker) isParameterized(typ types.Type) (res bool) { } } - case *typeparams.TypeParam: + case *types.TypeParam: return true default: diff --git a/go/analysis/passes/nilfunc/nilfunc.go b/go/analysis/passes/nilfunc/nilfunc.go index 6df134399a3..778f7f1f8f9 100644 --- a/go/analysis/passes/nilfunc/nilfunc.go +++ b/go/analysis/passes/nilfunc/nilfunc.go @@ -62,7 +62,7 @@ func run(pass *analysis.Pass) (interface{}, error) { obj = pass.TypesInfo.Uses[v] case *ast.SelectorExpr: obj = pass.TypesInfo.Uses[v.Sel] - case *ast.IndexExpr, *typeparams.IndexListExpr: + case *ast.IndexExpr, *ast.IndexListExpr: // Check generic functions such as "f[T1,T2]". x, _, _, _ := typeparams.UnpackIndexExpr(v) if id, ok := x.(*ast.Ident); ok { diff --git a/go/analysis/passes/printf/types.go b/go/analysis/passes/printf/types.go index 7cbb0bdbf5f..ab98e569980 100644 --- a/go/analysis/passes/printf/types.go +++ b/go/analysis/passes/printf/types.go @@ -72,7 +72,7 @@ func (m *argMatcher) match(typ types.Type, topLevel bool) bool { return true } - if typ, _ := typ.(*typeparams.TypeParam); typ != nil { + if typ, _ := typ.(*types.TypeParam); typ != nil { // Avoid infinite recursion through type parameters. if m.seen[typ] { return true diff --git a/go/analysis/passes/shift/shift.go b/go/analysis/passes/shift/shift.go index bafb9112e17..e272df709f3 100644 --- a/go/analysis/passes/shift/shift.go +++ b/go/analysis/passes/shift/shift.go @@ -99,7 +99,7 @@ func checkLongShift(pass *analysis.Pass, node ast.Node, x, y ast.Expr) { } var structuralTypes []types.Type switch t := t.(type) { - case *typeparams.TypeParam: + case *types.TypeParam: terms, err := typeparams.StructuralTerms(t) if err != nil { return // invalid type diff --git a/go/analysis/passes/stringintconv/string.go b/go/analysis/passes/stringintconv/string.go index bb04dae6269..b2591ccff55 100644 --- a/go/analysis/passes/stringintconv/string.go +++ b/go/analysis/passes/stringintconv/string.go @@ -195,7 +195,7 @@ func run(pass *analysis.Pass) (interface{}, error) { func structuralTypes(t types.Type) ([]types.Type, error) { var structuralTypes []types.Type switch t := t.(type) { - case *typeparams.TypeParam: + case *types.TypeParam: terms, err := typeparams.StructuralTerms(t) if err != nil { return nil, err diff --git a/go/analysis/passes/testinggoroutine/util.go b/go/analysis/passes/testinggoroutine/util.go index 805ccf49e4e..d156851db17 100644 --- a/go/analysis/passes/testinggoroutine/util.go +++ b/go/analysis/passes/testinggoroutine/util.go @@ -57,7 +57,7 @@ func isMethodNamed(f *types.Func, pkgPath string, names ...string) bool { func funcIdent(fun ast.Expr) *ast.Ident { switch fun := astutil.Unparen(fun).(type) { - case *ast.IndexExpr, *typeparams.IndexListExpr: + case *ast.IndexExpr, *ast.IndexListExpr: x, _, _, _ := typeparams.UnpackIndexExpr(fun) // necessary? id, _ := x.(*ast.Ident) return id diff --git a/go/analysis/passes/unmarshal/unmarshal.go b/go/analysis/passes/unmarshal/unmarshal.go index 7043baa899b..f4e73528b43 100644 --- a/go/analysis/passes/unmarshal/unmarshal.go +++ b/go/analysis/passes/unmarshal/unmarshal.go @@ -14,7 +14,6 @@ import ( "golang.org/x/tools/go/analysis/passes/internal/analysisutil" "golang.org/x/tools/go/ast/inspector" "golang.org/x/tools/go/types/typeutil" - "golang.org/x/tools/internal/typeparams" ) //go:embed doc.go @@ -92,7 +91,7 @@ func run(pass *analysis.Pass) (interface{}, error) { t := pass.TypesInfo.Types[call.Args[argidx]].Type switch t.Underlying().(type) { - case *types.Pointer, *types.Interface, *typeparams.TypeParam: + case *types.Pointer, *types.Interface, *types.TypeParam: return } diff --git a/go/ast/astutil/enclosing.go b/go/ast/astutil/enclosing.go index 9fa5aa192c2..c05873a8b94 100644 --- a/go/ast/astutil/enclosing.go +++ b/go/ast/astutil/enclosing.go @@ -377,7 +377,7 @@ func childrenOf(n ast.Node) []ast.Node { tok(n.Lbrack, len("[")), tok(n.Rbrack, len("]"))) - case *typeparams.IndexListExpr: + case *ast.IndexListExpr: children = append(children, tok(n.Lbrack, len("[")), tok(n.Rbrack, len("]"))) @@ -588,7 +588,7 @@ func NodeDescription(n ast.Node) string { return "decrement statement" case *ast.IndexExpr: return "index expression" - case *typeparams.IndexListExpr: + case *ast.IndexListExpr: return "index list expression" case *ast.InterfaceType: return "interface type" diff --git a/go/ast/astutil/rewrite.go b/go/ast/astutil/rewrite.go index f430b21b9b9..94bc887dc20 100644 --- a/go/ast/astutil/rewrite.go +++ b/go/ast/astutil/rewrite.go @@ -252,7 +252,7 @@ func (a *application) apply(parent ast.Node, name string, iter *iterator, n ast. a.apply(n, "X", nil, n.X) a.apply(n, "Index", nil, n.Index) - case *typeparams.IndexListExpr: + case *ast.IndexListExpr: a.apply(n, "X", nil, n.X) a.applyList(n, "Indices") diff --git a/go/ast/inspector/inspector_test.go b/go/ast/inspector/inspector_test.go index 4b26ff6715a..57a2293c0cd 100644 --- a/go/ast/inspector/inspector_test.go +++ b/go/ast/inspector/inspector_test.go @@ -17,7 +17,6 @@ import ( "testing" "golang.org/x/tools/go/ast/inspector" - "golang.org/x/tools/internal/typeparams" ) var netFiles []*ast.File @@ -94,7 +93,7 @@ var _ i13[i14, i15] inspect := inspector.New([]*ast.File{f}) found := make([]bool, 16) - indexListExprs := make(map[*typeparams.IndexListExpr]bool) + indexListExprs := make(map[*ast.IndexListExpr]bool) // Verify that we reach all i* identifiers, and collect IndexListExpr nodes. inspect.Preorder(nil, func(n ast.Node) { @@ -107,7 +106,7 @@ var _ i13[i14, i15] } found[index] = true } - case *typeparams.IndexListExpr: + case *ast.IndexListExpr: indexListExprs[n] = false } }) @@ -122,8 +121,8 @@ var _ i13[i14, i15] if len(indexListExprs) == 0 { t.Fatal("no index list exprs found") } - inspect.Preorder([]ast.Node{&typeparams.IndexListExpr{}}, func(n ast.Node) { - ix := n.(*typeparams.IndexListExpr) + inspect.Preorder([]ast.Node{&ast.IndexListExpr{}}, func(n ast.Node) { + ix := n.(*ast.IndexListExpr) indexListExprs[ix] = true }) for ix, v := range indexListExprs { diff --git a/go/ast/inspector/typeof.go b/go/ast/inspector/typeof.go index 703c8139544..2a872f89d47 100644 --- a/go/ast/inspector/typeof.go +++ b/go/ast/inspector/typeof.go @@ -12,8 +12,6 @@ package inspector import ( "go/ast" "math" - - "golang.org/x/tools/internal/typeparams" ) const ( @@ -171,7 +169,7 @@ func typeOf(n ast.Node) uint64 { return 1 << nIncDecStmt case *ast.IndexExpr: return 1 << nIndexExpr - case *typeparams.IndexListExpr: + case *ast.IndexListExpr: return 1 << nIndexListExpr case *ast.InterfaceType: return 1 << nInterfaceType diff --git a/go/callgraph/vta/graph.go b/go/callgraph/vta/graph.go index 4d1d5254c6e..987859c023a 100644 --- a/go/callgraph/vta/graph.go +++ b/go/callgraph/vta/graph.go @@ -661,14 +661,14 @@ func addReturnFlows(b *builder, r *ssa.Return, site ssa.Value) { func (b *builder) multiconvert(c *ssa.MultiConvert) { // TODO(zpavlinovic): decide what to do on MultiConvert long term. // TODO(zpavlinovic): add unit tests. - typeSetOf := func(typ types.Type) []*typeparams.Term { + typeSetOf := func(typ types.Type) []*types.Term { // This is a adaptation of x/exp/typeparams.NormalTerms which x/tools cannot depend on. - var terms []*typeparams.Term + var terms []*types.Term var err error switch typ := typ.(type) { - case *typeparams.TypeParam: + case *types.TypeParam: terms, err = typeparams.StructuralTerms(typ) - case *typeparams.Union: + case *types.Union: terms, err = typeparams.UnionTermSet(typ) case *types.Interface: terms, err = typeparams.InterfaceTermSet(typ) @@ -676,7 +676,7 @@ func (b *builder) multiconvert(c *ssa.MultiConvert) { // Common case. // Specializing the len=1 case to avoid a slice // had no measurable space/time benefit. - terms = []*typeparams.Term{typeparams.NewTerm(false, typ)} + terms = []*types.Term{typeparams.NewTerm(false, typ)} } if err != nil { diff --git a/go/ssa/builder.go b/go/ssa/builder.go index 92465b8dcd6..0d6716c4296 100644 --- a/go/ssa/builder.go +++ b/go/ssa/builder.go @@ -802,7 +802,7 @@ func (b *builder) expr0(fn *Function, e ast.Expr, tv types.TypeAndValue) Value { if types.IsInterface(rt) { // If v may be an interface type I (after instantiating), // we must emit a check that v is non-nil. - if recv, ok := sel.recv.(*typeparams.TypeParam); ok { + if recv, ok := sel.recv.(*types.TypeParam); ok { // Emit a nil check if any possible instantiation of the // type parameter is an interface type. if typeSetOf(recv).Len() > 0 { @@ -848,7 +848,7 @@ func (b *builder) expr0(fn *Function, e ast.Expr, tv types.TypeAndValue) Value { panic("unexpected expression-relative selector") - case *typeparams.IndexListExpr: + case *ast.IndexListExpr: // f[X, Y] must be a generic function if !instance(fn.info, e.X) { panic("unexpected expression-could not match index list to instantiation") diff --git a/go/ssa/const.go b/go/ssa/const.go index 4a51a2cb4bb..2a6ac5882a0 100644 --- a/go/ssa/const.go +++ b/go/ssa/const.go @@ -125,7 +125,7 @@ func zeroString(t types.Type, from *types.Package) string { components[i] = zeroString(t.At(i).Type(), from) } return "(" + strings.Join(components, ", ") + ")" - case *typeparams.TypeParam: + case *types.TypeParam: return "*new(" + relType(t, from) + ")" } panic(fmt.Sprint("zeroString: unexpected ", t)) diff --git a/go/ssa/coretype.go b/go/ssa/coretype.go index 128d61e4267..957696bcdbd 100644 --- a/go/ssa/coretype.go +++ b/go/ssa/coretype.go @@ -40,19 +40,19 @@ func isBytestring(T types.Type) bool { } // termList is a list of types. -type termList []*typeparams.Term // type terms of the type set +type termList []*types.Term // type terms of the type set func (s termList) Len() int { return len(s) } func (s termList) At(i int) types.Type { return s[i].Type() } // typeSetOf returns the type set of typ. Returns an empty typeset on an error. func typeSetOf(typ types.Type) termList { // This is a adaptation of x/exp/typeparams.NormalTerms which x/tools cannot depend on. - var terms []*typeparams.Term + var terms []*types.Term var err error switch typ := typ.(type) { - case *typeparams.TypeParam: + case *types.TypeParam: terms, err = typeparams.StructuralTerms(typ) - case *typeparams.Union: + case *types.Union: terms, err = typeparams.UnionTermSet(typ) case *types.Interface: terms, err = typeparams.InterfaceTermSet(typ) @@ -60,7 +60,7 @@ func typeSetOf(typ types.Type) termList { // Common case. // Specializing the len=1 case to avoid a slice // had no measurable space/time benefit. - terms = []*typeparams.Term{typeparams.NewTerm(false, typ)} + terms = []*types.Term{typeparams.NewTerm(false, typ)} } if err != nil { diff --git a/go/ssa/create.go b/go/ssa/create.go index 653ce2e5c3d..c5f952df399 100644 --- a/go/ssa/create.go +++ b/go/ssa/create.go @@ -117,7 +117,7 @@ func createFunction(prog *Program, obj *types.Func, name string, syntax ast.Node sig := obj.Type().(*types.Signature) // Collect type parameters. - var tparams *typeparams.TypeParamList + var tparams *types.TypeParamList if rtparams := typeparams.RecvTypeParams(sig); rtparams.Len() > 0 { tparams = rtparams // method of generic type } else if sigparams := typeparams.ForSignature(sig); sigparams.Len() > 0 { diff --git a/go/ssa/methods.go b/go/ssa/methods.go index 03ef62521d9..4797b39286c 100644 --- a/go/ssa/methods.go +++ b/go/ssa/methods.go @@ -261,7 +261,7 @@ func forEachReachable(msets *typeutil.MethodSetCache, T types.Type, f func(types visit(T.At(i).Type(), false) } - case *typeparams.TypeParam, *typeparams.Union: + case *types.TypeParam, *types.Union: // forEachReachable must not be called on parameterized types. panic(T) diff --git a/go/ssa/parameterized.go b/go/ssa/parameterized.go index 656417ac8e1..63160b4e49b 100644 --- a/go/ssa/parameterized.go +++ b/go/ssa/parameterized.go @@ -117,7 +117,7 @@ func (w *tpWalker) isParameterizedLocked(typ types.Type) (res bool) { } return w.isParameterizedLocked(t.Underlying()) // recurse for types local to parameterized functions - case *typeparams.TypeParam: + case *types.TypeParam: return true default: diff --git a/go/ssa/print.go b/go/ssa/print.go index 7f34a7b58b7..727a7350265 100644 --- a/go/ssa/print.go +++ b/go/ssa/print.go @@ -17,7 +17,6 @@ import ( "strings" "golang.org/x/tools/go/types/typeutil" - "golang.org/x/tools/internal/typeparams" ) // relName returns the name of v relative to i. @@ -51,7 +50,7 @@ func relType(t types.Type, from *types.Package) string { return s } -func relTerm(term *typeparams.Term, from *types.Package) string { +func relTerm(term *types.Term, from *types.Package) string { s := relType(term.Type(), from) if term.Tilde() { return "~" + s diff --git a/go/ssa/ssa.go b/go/ssa/ssa.go index 58a641a1fdb..30bf4bc6777 100644 --- a/go/ssa/ssa.go +++ b/go/ssa/ssa.go @@ -27,8 +27,8 @@ type Program struct { mode BuilderMode // set of mode bits for SSA construction MethodSets typeutil.MethodSetCache // cache of type-checker's method-sets - canon *canonizer // type canonicalization map - ctxt *typeparams.Context // cache for type checking instantiations + canon *canonizer // type canonicalization map + ctxt *types.Context // cache for type checking instantiations methodsMu sync.Mutex methodSets typeutil.Map // maps type to its concrete *methodSet @@ -339,10 +339,10 @@ type Function struct { referrers []Instruction // referring instructions (iff Parent() != nil) anonIdx int32 // position of a nested function in parent's AnonFuncs. fn.Parent()!=nil => fn.Parent().AnonFunc[fn.anonIdx] == fn. - typeparams *typeparams.TypeParamList // type parameters of this function. typeparams.Len() > 0 => generic or instance of generic function - typeargs []types.Type // type arguments that instantiated typeparams. len(typeargs) > 0 => instance of generic function - topLevelOrigin *Function // the origin function if this is an instance of a source function. nil if Parent()!=nil. - generic *generic // instances of this function, if generic + typeparams *types.TypeParamList // type parameters of this function. typeparams.Len() > 0 => generic or instance of generic function + typeargs []types.Type // type arguments that instantiated typeparams. len(typeargs) > 0 => instance of generic function + topLevelOrigin *Function // the origin function if this is an instance of a source function. nil if Parent()!=nil. + generic *generic // instances of this function, if generic // The following fields are cleared after building. currentBlock *BasicBlock // where to emit code @@ -690,8 +690,8 @@ type Convert struct { type MultiConvert struct { register X Value - from []*typeparams.Term - to []*typeparams.Term + from []*types.Term + to []*types.Term } // ChangeInterface constructs a value of one interface type from a @@ -1539,10 +1539,7 @@ func (v *Function) Referrers() *[]Instruction { // TypeParams are the function's type parameters if generic or the // type parameters that were instantiated if fn is an instantiation. -// -// TODO(taking): declare result type as *types.TypeParamList -// after we drop support for go1.17. -func (fn *Function) TypeParams() *typeparams.TypeParamList { +func (fn *Function) TypeParams() *types.TypeParamList { return fn.typeparams } diff --git a/go/ssa/subst.go b/go/ssa/subst.go index 23d19ae7383..ae8718daee7 100644 --- a/go/ssa/subst.go +++ b/go/ssa/subst.go @@ -18,11 +18,11 @@ import ( // // Not concurrency-safe. type subster struct { - replacements map[*typeparams.TypeParam]types.Type // values should contain no type params - cache map[types.Type]types.Type // cache of subst results - ctxt *typeparams.Context // cache for instantiation - scope *types.Scope // *types.Named declared within this scope can be substituted (optional) - debug bool // perform extra debugging checks + replacements map[*types.TypeParam]types.Type // values should contain no type params + cache map[types.Type]types.Type // cache of subst results + ctxt *types.Context // cache for instantiation + scope *types.Scope // *types.Named declared within this scope can be substituted (optional) + debug bool // perform extra debugging checks // TODO(taking): consider adding Pos // TODO(zpavlinovic): replacements can contain type params // when generating instances inside of a generic function body. @@ -31,11 +31,11 @@ type subster struct { // Returns a subster that replaces tparams[i] with targs[i]. Uses ctxt as a cache. // targs should not contain any types in tparams. // scope is the (optional) lexical block of the generic function for which we are substituting. -func makeSubster(ctxt *typeparams.Context, scope *types.Scope, tparams *typeparams.TypeParamList, targs []types.Type, debug bool) *subster { +func makeSubster(ctxt *types.Context, scope *types.Scope, tparams *types.TypeParamList, targs []types.Type, debug bool) *subster { assert(tparams.Len() == len(targs), "makeSubster argument count must match") subst := &subster{ - replacements: make(map[*typeparams.TypeParam]types.Type, tparams.Len()), + replacements: make(map[*types.TypeParam]types.Type, tparams.Len()), cache: make(map[types.Type]types.Type), ctxt: ctxt, scope: scope, @@ -82,7 +82,7 @@ func (subst *subster) typ(t types.Type) (res types.Type) { // fall through if result r will be identical to t, types.Identical(r, t). switch t := t.(type) { - case *typeparams.TypeParam: + case *types.TypeParam: r := subst.replacements[t] assert(r != nil, "type param without replacement encountered") return r @@ -131,7 +131,7 @@ func (subst *subster) typ(t types.Type) (res types.Type) { case *types.Signature: return subst.signature(t) - case *typeparams.Union: + case *types.Union: return subst.union(t) case *types.Interface: @@ -220,14 +220,14 @@ func (subst *subster) var_(v *types.Var) *types.Var { return v } -func (subst *subster) union(u *typeparams.Union) *typeparams.Union { - var out []*typeparams.Term // nil => no updates +func (subst *subster) union(u *types.Union) *types.Union { + var out []*types.Term // nil => no updates for i, n := 0, u.Len(); i < n; i++ { t := u.Term(i) r := subst.typ(t.Type()) if r != t.Type() && out == nil { - out = make([]*typeparams.Term, n) + out = make([]*types.Term, n) for j := 0; j < i; j++ { out[j] = u.Term(j) } @@ -422,7 +422,7 @@ func reaches(t types.Type, c map[types.Type]bool) (res bool) { }() switch t := t.(type) { - case *typeparams.TypeParam, *types.Basic: + case *types.TypeParam, *types.Basic: return false case *types.Array: return reaches(t.Elem(), c) @@ -451,7 +451,7 @@ func reaches(t types.Type, c map[types.Type]bool) (res bool) { return true } return reaches(t.Params(), c) || reaches(t.Results(), c) - case *typeparams.Union: + case *types.Union: for i := 0; i < t.Len(); i++ { if reaches(t.Term(i).Type(), c) { return true diff --git a/go/ssa/util.go b/go/ssa/util.go index 63fbbc1282a..dd6ff19da28 100644 --- a/go/ssa/util.go +++ b/go/ssa/util.go @@ -352,7 +352,7 @@ func (m *typeListMap) hash(ts []types.Type) uint32 { } // instantiateMethod instantiates m with targs and returns a canonical representative for this method. -func (canon *canonizer) instantiateMethod(m *types.Func, targs []types.Type, ctxt *typeparams.Context) *types.Func { +func (canon *canonizer) instantiateMethod(m *types.Func, targs []types.Type, ctxt *types.Context) *types.Func { recv := recvType(m) if p, ok := recv.(*types.Pointer); ok { recv = p.Elem() diff --git a/go/types/objectpath/objectpath.go b/go/types/objectpath/objectpath.go index e742ecc4644..86f89836d80 100644 --- a/go/types/objectpath/objectpath.go +++ b/go/types/objectpath/objectpath.go @@ -223,7 +223,7 @@ func (enc *Encoder) For(obj types.Object) (Path, error) { // Reject obviously non-viable cases. switch obj := obj.(type) { case *types.TypeName: - if _, ok := obj.Type().(*typeparams.TypeParam); !ok { + if _, ok := obj.Type().(*types.TypeParam); !ok { // With the exception of type parameters, only package-level type names // have a path. return "", fmt.Errorf("no path for %v", obj) @@ -505,7 +505,7 @@ func find(obj types.Object, T types.Type, path []byte, seen map[*types.TypeName] } } return nil - case *typeparams.TypeParam: + case *types.TypeParam: name := T.Obj() if name == obj { return append(path, opObj) @@ -525,7 +525,7 @@ func find(obj types.Object, T types.Type, path []byte, seen map[*types.TypeName] panic(T) } -func findTypeParam(obj types.Object, list *typeparams.TypeParamList, path []byte, seen map[*types.TypeName]bool) []byte { +func findTypeParam(obj types.Object, list *types.TypeParamList, path []byte, seen map[*types.TypeName]bool) []byte { for i := 0; i < list.Len(); i++ { tparam := list.At(i) path2 := appendOpArg(path, opTypeParam, i) @@ -562,7 +562,7 @@ func Object(pkg *types.Package, p Path) (types.Object, error) { } // abstraction of *types.{Named,Signature} type hasTypeParams interface { - TypeParams() *typeparams.TypeParamList + TypeParams() *types.TypeParamList } // abstraction of *types.{Named,TypeParam} type hasObj interface { @@ -664,7 +664,7 @@ func Object(pkg *types.Package, p Path) (types.Object, error) { t = tparams.At(index) case opConstraint: - tparam, ok := t.(*typeparams.TypeParam) + tparam, ok := t.(*types.TypeParam) if !ok { return nil, fmt.Errorf("cannot apply %q to %s (got %T, want type parameter)", code, t, t) } diff --git a/go/types/typeutil/callee.go b/go/types/typeutil/callee.go index 90b3ab0e21c..90dc541adfe 100644 --- a/go/types/typeutil/callee.go +++ b/go/types/typeutil/callee.go @@ -22,7 +22,7 @@ func Callee(info *types.Info, call *ast.CallExpr) types.Object { // Look through type instantiation if necessary. isInstance := false switch fun.(type) { - case *ast.IndexExpr, *typeparams.IndexListExpr: + case *ast.IndexExpr, *ast.IndexListExpr: // When extracting the callee from an *IndexExpr, we need to check that // it is a *types.Func and not a *types.Var. // Example: Don't match a slice m within the expression `m[0]()`. diff --git a/go/types/typeutil/map.go b/go/types/typeutil/map.go index 7bd2fdb38be..6b67ca882ec 100644 --- a/go/types/typeutil/map.go +++ b/go/types/typeutil/map.go @@ -219,7 +219,7 @@ type Hasher struct { // generic types or functions, and instantiated signatures do not have type // parameter lists, we should never encounter a second non-empty type // parameter list when hashing a generic signature. - sigTParams *typeparams.TypeParamList + sigTParams *types.TypeParamList } // MakeHasher returns a new Hasher instance. @@ -318,7 +318,7 @@ func (h Hasher) hashFor(t types.Type) uint32 { return hash + 3*h.hashTuple(t.Params()) + 5*h.hashTuple(t.Results()) - case *typeparams.Union: + case *types.Union: return h.hashUnion(t) case *types.Interface: @@ -361,7 +361,7 @@ func (h Hasher) hashFor(t types.Type) uint32 { } return hash - case *typeparams.TypeParam: + case *types.TypeParam: return h.hashTypeParam(t) case *types.Tuple: @@ -381,7 +381,7 @@ func (h Hasher) hashTuple(tuple *types.Tuple) uint32 { return hash } -func (h Hasher) hashUnion(t *typeparams.Union) uint32 { +func (h Hasher) hashUnion(t *types.Union) uint32 { // Hash type restrictions. terms, err := typeparams.UnionTermSet(t) // if err != nil t has invalid type restrictions. Fall back on a non-zero @@ -392,7 +392,7 @@ func (h Hasher) hashUnion(t *typeparams.Union) uint32 { return h.hashTermSet(terms) } -func (h Hasher) hashTermSet(terms []*typeparams.Term) uint32 { +func (h Hasher) hashTermSet(terms []*types.Term) uint32 { hash := 9157 + 2*uint32(len(terms)) for _, term := range terms { // term order is not significant. @@ -416,7 +416,7 @@ func (h Hasher) hashTermSet(terms []*typeparams.Term) uint32 { // are not identical. // // Otherwise the hash of t depends only on t's pointer identity. -func (h Hasher) hashTypeParam(t *typeparams.TypeParam) uint32 { +func (h Hasher) hashTypeParam(t *types.TypeParam) uint32 { if h.sigTParams != nil { i := t.Index() if i >= 0 && i < h.sigTParams.Len() && t == h.sigTParams.At(i) { @@ -489,7 +489,7 @@ func (h Hasher) shallowHash(t types.Type) uint32 { case *types.Pointer: return 4393139 - case *typeparams.Union: + case *types.Union: return 562448657 case *types.Interface: @@ -504,7 +504,7 @@ func (h Hasher) shallowHash(t types.Type) uint32 { case *types.Named: return h.hashPtr(t.Obj()) - case *typeparams.TypeParam: + case *types.TypeParam: return h.hashPtr(t.Obj()) } panic(fmt.Sprintf("shallowHash: %T: %v", t, t)) diff --git a/go/types/typeutil/map_test.go b/go/types/typeutil/map_test.go index 4197b69fe76..5d875cecf9c 100644 --- a/go/types/typeutil/map_test.go +++ b/go/types/typeutil/map_test.go @@ -277,7 +277,7 @@ var Issue56048b = Issue56048_Ib.m CI = C.Underlying().(*types.Interface) I = scope.Lookup("I").Type() II = I.Underlying().(*types.Interface) - U = CI.EmbeddedType(0).(*typeparams.Union) + U = CI.EmbeddedType(0).(*types.Union) Fa1 = scope.Lookup("Fa1").Type().(*types.Signature) Fa2 = scope.Lookup("Fa2").Type().(*types.Signature) Fa1P = typeparams.ForSignature(Fa1).At(0) diff --git a/godoc/linkify.go b/godoc/linkify.go index cf266d01f1d..ad773b8410b 100644 --- a/godoc/linkify.go +++ b/godoc/linkify.go @@ -17,8 +17,6 @@ import ( "go/token" "io" "strconv" - - "golang.org/x/tools/internal/typeparams" ) // LinkifyText HTML-escapes source text and writes it to w. @@ -116,7 +114,7 @@ func linksFor(node ast.Node) (links []link) { if ident, _ := x.Index.(*ast.Ident); ident != nil { typeParams[ident.Name] = true } - case *typeparams.IndexListExpr: + case *ast.IndexListExpr: for _, index := range x.Indices { if ident, _ := index.(*ast.Ident); ident != nil { typeParams[ident.Name] = true diff --git a/godoc/server.go b/godoc/server.go index a6df6d74e68..afb28e2e187 100644 --- a/godoc/server.go +++ b/godoc/server.go @@ -29,7 +29,6 @@ import ( "golang.org/x/tools/godoc/analysis" "golang.org/x/tools/godoc/util" "golang.org/x/tools/godoc/vfs" - "golang.org/x/tools/internal/typeparams" ) // handlerServer is a migration from an old godoc http Handler type. @@ -471,7 +470,7 @@ func addNames(names map[string]bool, decl ast.Decl) { typeName = x.Name case *ast.IndexExpr: typeName = x.X.(*ast.Ident).Name - case *typeparams.IndexListExpr: + case *ast.IndexListExpr: typeName = x.X.(*ast.Ident).Name } name = typeName + "_" + name diff --git a/gopls/internal/analysis/fillstruct/fillstruct.go b/gopls/internal/analysis/fillstruct/fillstruct.go index 4b1bb4aa4b0..b7bb17b0665 100644 --- a/gopls/internal/analysis/fillstruct/fillstruct.go +++ b/gopls/internal/analysis/fillstruct/fillstruct.go @@ -29,7 +29,6 @@ import ( "golang.org/x/tools/gopls/internal/util/safetoken" "golang.org/x/tools/internal/analysisinternal" "golang.org/x/tools/internal/fuzzy" - "golang.org/x/tools/internal/typeparams" ) const Doc = `note incomplete struct initializations @@ -493,7 +492,7 @@ func populateValue(f *ast.File, pkg *types.Package, typ types.Type) ast.Expr { } case *types.Interface: - if param, ok := typ.(*typeparams.TypeParam); ok { + if param, ok := typ.(*types.TypeParam); ok { // *new(T) is the zero value of a type parameter T. // TODO(adonovan): one could give a more specific zero // value if the type has a core type that is, say, diff --git a/gopls/internal/lsp/cache/methodsets/methodsets.go b/gopls/internal/lsp/cache/methodsets/methodsets.go index 5199400749b..ca51409e309 100644 --- a/gopls/internal/lsp/cache/methodsets/methodsets.go +++ b/gopls/internal/lsp/cache/methodsets/methodsets.go @@ -434,7 +434,7 @@ func fingerprint(method *types.Func) (string, bool) { buf.WriteString("interface{...}") } - case *typeparams.TypeParam: + case *types.TypeParam: tricky = true // TODO(adonovan): refine this by adding a numeric suffix // indicating the index among the receiver type's parameters. diff --git a/gopls/internal/lsp/cache/typerefs/refs.go b/gopls/internal/lsp/cache/typerefs/refs.go index 95c47960219..878f53da86a 100644 --- a/gopls/internal/lsp/cache/typerefs/refs.go +++ b/gopls/internal/lsp/cache/typerefs/refs.go @@ -523,7 +523,7 @@ func visitExpr(expr ast.Expr, f refVisitor) { visitExpr(n.X, f) visitExpr(n.Index, f) // may affect type for instantiations - case *typeparams.IndexListExpr: + case *ast.IndexListExpr: visitExpr(n.X, f) for _, index := range n.Indices { visitExpr(index, f) // may affect the type for instantiations diff --git a/gopls/internal/lsp/source/completion/completion.go b/gopls/internal/lsp/source/completion/completion.go index a9f52d43a33..6b1665fe7b1 100644 --- a/gopls/internal/lsp/source/completion/completion.go +++ b/gopls/internal/lsp/source/completion/completion.go @@ -2345,7 +2345,7 @@ Nodes: } } return inf - case *typeparams.IndexListExpr: + case *ast.IndexListExpr: if node.Lbrack < c.pos && c.pos <= node.Rbrack { if tv, ok := c.pkg.GetTypesInfo().Types[node.X]; ok { if ct := expectedConstraint(tv.Type, exprAtPos(c.pos, node.Indices)); ct != nil { @@ -2438,7 +2438,7 @@ func (c *completer) expectedCallParamType(inf candidateInference, node *ast.Call // If our expected type is an uninstantiated generic type param, // swap to the constraint which will do a decent job filtering // candidates. - if tp, _ := inf.objType.(*typeparams.TypeParam); tp != nil { + if tp, _ := inf.objType.(*types.TypeParam); tp != nil { inf.objType = tp.Constraint() } @@ -2446,7 +2446,7 @@ func (c *completer) expectedCallParamType(inf candidateInference, node *ast.Call } func expectedConstraint(t types.Type, idx int) types.Type { - var tp *typeparams.TypeParamList + var tp *types.TypeParamList if named, _ := t.(*types.Named); named != nil { tp = typeparams.ForNamed(named) } else if sig, _ := t.Underlying().(*types.Signature); sig != nil { @@ -2960,7 +2960,7 @@ func considerTypeConversion(from, to types.Type, path []types.Object) bool { return false } - if _, ok := from.(*typeparams.TypeParam); ok { + if _, ok := from.(*types.TypeParam); ok { return false } diff --git a/gopls/internal/lsp/source/completion/literal.go b/gopls/internal/lsp/source/completion/literal.go index 440e41abea4..fe97269baef 100644 --- a/gopls/internal/lsp/source/completion/literal.go +++ b/gopls/internal/lsp/source/completion/literal.go @@ -194,7 +194,7 @@ func (c *completer) functionLiteral(ctx context.Context, sig *types.Signature, m name = p.Name() ) - if tp, _ := p.Type().(*typeparams.TypeParam); tp != nil && !c.typeParamInScope(tp) { + if tp, _ := p.Type().(*types.TypeParam); tp != nil && !c.typeParamInScope(tp) { hasTypeParams = true } @@ -285,7 +285,7 @@ func (c *completer) functionLiteral(ctx context.Context, sig *types.Signature, m typeStr = strings.Replace(typeStr, "[]", "...", 1) } - if tp, _ := p.Type().(*typeparams.TypeParam); tp != nil && !c.typeParamInScope(tp) { + if tp, _ := p.Type().(*types.TypeParam); tp != nil && !c.typeParamInScope(tp) { snip.WritePlaceholder(func(snip *snippet.Builder) { snip.WriteText(typeStr) }) @@ -306,7 +306,7 @@ func (c *completer) functionLiteral(ctx context.Context, sig *types.Signature, m var resultHasTypeParams bool for i := 0; i < results.Len(); i++ { - if tp, _ := results.At(i).Type().(*typeparams.TypeParam); tp != nil && !c.typeParamInScope(tp) { + if tp, _ := results.At(i).Type().(*types.TypeParam); tp != nil && !c.typeParamInScope(tp) { resultHasTypeParams = true } } @@ -339,7 +339,7 @@ func (c *completer) functionLiteral(ctx context.Context, sig *types.Signature, m } return } - if tp, _ := r.Type().(*typeparams.TypeParam); tp != nil && !c.typeParamInScope(tp) { + if tp, _ := r.Type().(*types.TypeParam); tp != nil && !c.typeParamInScope(tp) { snip.WritePlaceholder(func(snip *snippet.Builder) { snip.WriteText(text) }) @@ -558,7 +558,7 @@ func (c *completer) fullyInstantiated(t *types.Named) bool { for i := 0; i < tas.Len(); i++ { switch ta := tas.At(i).(type) { - case *typeparams.TypeParam: + case *types.TypeParam: // A *TypeParam only counts as specified if it is currently in // scope (i.e. we are in a generic definition). if !c.typeParamInScope(ta) { @@ -576,7 +576,7 @@ func (c *completer) fullyInstantiated(t *types.Named) bool { // typeParamInScope returns whether tp's object is in scope at c.pos. // This tells you whether you are in a generic definition and can // assume tp has been specified. -func (c *completer) typeParamInScope(tp *typeparams.TypeParam) bool { +func (c *completer) typeParamInScope(tp *types.TypeParam) bool { obj := tp.Obj() if obj == nil { return false diff --git a/gopls/internal/lsp/source/hover.go b/gopls/internal/lsp/source/hover.go index 7e3efef3c02..9e9f5ddd806 100644 --- a/gopls/internal/lsp/source/hover.go +++ b/gopls/internal/lsp/source/hover.go @@ -224,7 +224,7 @@ func hover(ctx context.Context, snapshot *cache.Snapshot, fh file.Handle, pp pro // // TODO(adonovan): this logic belongs in objectString. _, isTypeName := obj.(*types.TypeName) - _, isTypeParam := obj.Type().(*typeparams.TypeParam) + _, isTypeParam := obj.Type().(*types.TypeParam) if isTypeName && !isTypeParam { spec, ok := spec.(*ast.TypeSpec) if !ok { @@ -799,7 +799,7 @@ func objectString(obj types.Object, qf types.Qualifier, declPos token.Pos, file // TODO(rfindley): there appears to be zero(!) tests for this functionality. func HoverDocForObject(ctx context.Context, snapshot *cache.Snapshot, fset *token.FileSet, obj types.Object) (*ast.CommentGroup, error) { if _, isTypeName := obj.(*types.TypeName); isTypeName { - if _, isTypeParam := obj.Type().(*typeparams.TypeParam); isTypeParam { + if _, isTypeParam := obj.Type().(*types.TypeParam); isTypeParam { return nil, nil } } diff --git a/gopls/internal/lsp/source/invertifcondition.go b/gopls/internal/lsp/source/invertifcondition.go index 81882653159..cd19344fb46 100644 --- a/gopls/internal/lsp/source/invertifcondition.go +++ b/gopls/internal/lsp/source/invertifcondition.go @@ -14,7 +14,6 @@ import ( "golang.org/x/tools/go/analysis" "golang.org/x/tools/go/ast/astutil" "golang.org/x/tools/gopls/internal/util/safetoken" - "golang.org/x/tools/internal/typeparams" ) // invertIfCondition is a singleFileFixFunc that inverts an if/else statement @@ -131,7 +130,7 @@ func invertCondition(fset *token.FileSet, cond ast.Expr, src []byte) ([]byte, er oldText := string(src[condStart.Offset:condEnd.Offset]) switch expr := cond.(type) { - case *ast.Ident, *ast.ParenExpr, *ast.CallExpr, *ast.StarExpr, *ast.IndexExpr, *typeparams.IndexListExpr, *ast.SelectorExpr: + case *ast.Ident, *ast.ParenExpr, *ast.CallExpr, *ast.StarExpr, *ast.IndexExpr, *ast.IndexListExpr, *ast.SelectorExpr: newText := "!" + oldText if oldText == "true" { newText = "false" diff --git a/gopls/internal/lsp/source/rename.go b/gopls/internal/lsp/source/rename.go index c87302d3688..adc3ce98dc1 100644 --- a/gopls/internal/lsp/source/rename.go +++ b/gopls/internal/lsp/source/rename.go @@ -353,7 +353,7 @@ func renameOrdinary(ctx context.Context, snapshot *cache.Snapshot, f file.Handle // of the type parameters, unlike methods). switch obj.(type) { // avoid "obj :=" since cases reassign the var case *types.TypeName: - if _, ok := obj.Type().(*typeparams.TypeParam); ok { + if _, ok := obj.Type().(*types.TypeParam); ok { // As with capitalized function parameters below, type parameters are // local. goto skipObjectPath diff --git a/gopls/internal/lsp/source/types_format.go b/gopls/internal/lsp/source/types_format.go index 4cc699b0b96..ecb33c66612 100644 --- a/gopls/internal/lsp/source/types_format.go +++ b/gopls/internal/lsp/source/types_format.go @@ -182,7 +182,7 @@ func formatFieldList(ctx context.Context, fset *token.FileSet, list *ast.FieldLi // FormatTypeParams turns TypeParamList into its Go representation, such as: // [T, Y]. Note that it does not print constraints as this is mainly used for // formatting type params in method receivers. -func FormatTypeParams(tparams *typeparams.TypeParamList) string { +func FormatTypeParams(tparams *types.TypeParamList) string { if tparams == nil || tparams.Len() == 0 { return "" } @@ -430,12 +430,12 @@ func qualifyTypeExpr(expr ast.Expr, qf func(string) string) ast.Expr { Rbrack: expr.Rbrack, } - case *typeparams.IndexListExpr: + case *ast.IndexListExpr: indices := make([]ast.Expr, len(expr.Indices)) for i, idx := range expr.Indices { indices[i] = qualifyTypeExpr(idx, qf) } - return &typeparams.IndexListExpr{ + return &ast.IndexListExpr{ X: qualifyTypeExpr(expr.X, qf), Lbrack: expr.Lbrack, Indices: indices, diff --git a/gopls/internal/lsp/source/util.go b/gopls/internal/lsp/source/util.go index 5745994b9ba..1d588968faf 100644 --- a/gopls/internal/lsp/source/util.go +++ b/gopls/internal/lsp/source/util.go @@ -22,7 +22,6 @@ import ( "golang.org/x/tools/gopls/internal/util/safetoken" "golang.org/x/tools/gopls/internal/util/typesutil" "golang.org/x/tools/internal/tokeninternal" - "golang.org/x/tools/internal/typeparams" ) // IsGenerated gets and reads the file denoted by uri and reports @@ -423,7 +422,7 @@ func embeddedIdent(x ast.Expr) *ast.Ident { switch ix := x.(type) { // check for instantiated receivers case *ast.IndexExpr: x = ix.X - case *typeparams.IndexListExpr: + case *ast.IndexListExpr: x = ix.X } switch x := x.(type) { diff --git a/gopls/internal/server/semantic.go b/gopls/internal/server/semantic.go index 08776907fed..1421e9bda9c 100644 --- a/gopls/internal/server/semantic.go +++ b/gopls/internal/server/semantic.go @@ -373,7 +373,7 @@ func (e *encoded) inspector(n ast.Node) bool { case *ast.IncDecStmt: e.token(x.TokPos, len(x.Tok.String()), tokOperator, nil) case *ast.IndexExpr: - case *typeparams.IndexListExpr: + case *ast.IndexListExpr: case *ast.InterfaceType: e.token(x.Interface, len("interface"), tokKeyword, nil) case *ast.KeyValueExpr: @@ -509,7 +509,7 @@ func (e *encoded) ident(x *ast.Ident) { var mods []string if _, ok := y.Type().(*types.Basic); ok { mods = []string{"defaultLibrary"} - } else if _, ok := y.Type().(*typeparams.TypeParam); ok { + } else if _, ok := y.Type().(*types.TypeParam); ok { tok(x.Pos(), len(x.String()), tokTypeParam, mods) break } @@ -593,9 +593,8 @@ func (e *encoded) unkIdent(x *ast.Ident) (tokenType, []string) { *ast.ReturnStmt, *ast.ChanType, *ast.SendStmt, *ast.ForStmt, // possibly incomplete *ast.IfStmt, /* condition */ - *ast.KeyValueExpr: // either key or value - return tokVariable, nil - case *typeparams.IndexListExpr: + *ast.KeyValueExpr, // either key or value + *ast.IndexListExpr: return tokVariable, nil case *ast.Ellipsis: return tokType, nil diff --git a/gopls/internal/util/astutil/util.go b/gopls/internal/util/astutil/util.go index d975c5a3824..4fc313535b9 100644 --- a/gopls/internal/util/astutil/util.go +++ b/gopls/internal/util/astutil/util.go @@ -35,7 +35,7 @@ L: // unpack receiver type // unpack type parameters, if any switch rtyp.(type) { - case *ast.IndexExpr, *typeparams.IndexListExpr: + case *ast.IndexExpr, *ast.IndexListExpr: var indices []ast.Expr rtyp, _, indices, _ = typeparams.UnpackIndexExpr(rtyp) for _, arg := range indices { diff --git a/internal/facts/imports.go b/internal/facts/imports.go index f64695ea520..5c69b75072a 100644 --- a/internal/facts/imports.go +++ b/internal/facts/imports.go @@ -108,11 +108,11 @@ func importMap(imports []*types.Package) map[string]*types.Package { for i := 0; i < T.NumEmbeddeds(); i++ { addType(T.EmbeddedType(i)) // walk Embedded for implicits } - case *typeparams.Union: + case *types.Union: for i := 0; i < T.Len(); i++ { addType(T.Term(i).Type()) } - case *typeparams.TypeParam: + case *types.TypeParam: if !typs[T] { typs[T] = true addObj(T.Obj()) diff --git a/internal/gcimporter/bexport_test.go b/internal/gcimporter/bexport_test.go index 978c46e1932..f722d0084c3 100644 --- a/internal/gcimporter/bexport_test.go +++ b/internal/gcimporter/bexport_test.go @@ -184,8 +184,8 @@ func equalType(x, y types.Type) error { return fmt.Errorf("tuple element %d: %s", i, err) } } - case *typeparams.TypeParam: - y := y.(*typeparams.TypeParam) + case *types.TypeParam: + y := y.(*types.TypeParam) if x.String() != y.String() { return fmt.Errorf("unequal named types: %s vs %s", x, y) } @@ -266,7 +266,7 @@ func makeExplicit(typ types.Type) types.Type { return typ } -func equalTypeArgs(x, y *typeparams.TypeList) error { +func equalTypeArgs(x, y *types.TypeList) error { if x.Len() != y.Len() { return fmt.Errorf("unequal lengths: %d vs %d", x.Len(), y.Len()) } @@ -278,7 +278,7 @@ func equalTypeArgs(x, y *typeparams.TypeList) error { return nil } -func equalTypeParams(x, y *typeparams.TypeParamList) error { +func equalTypeParams(x, y *types.TypeParamList) error { if x.Len() != y.Len() { return fmt.Errorf("unequal lengths: %d vs %d", x.Len(), y.Len()) } diff --git a/internal/gcimporter/iexport.go b/internal/gcimporter/iexport.go index 6103dd7102b..828f5550979 100644 --- a/internal/gcimporter/iexport.go +++ b/internal/gcimporter/iexport.go @@ -507,7 +507,7 @@ func (p *iexporter) doDecl(obj types.Object) { case *types.TypeName: t := obj.Type() - if tparam, ok := t.(*typeparams.TypeParam); ok { + if tparam, ok := t.(*types.TypeParam); ok { w.tag('P') w.pos(obj.Pos()) constraint := tparam.Constraint() @@ -752,7 +752,7 @@ func (w *exportWriter) doTyp(t types.Type, pkg *types.Package) { w.startType(definedType) w.qualifiedType(t.Obj()) - case *typeparams.TypeParam: + case *types.TypeParam: w.startType(typeParamType) w.qualifiedType(t.Obj()) @@ -868,7 +868,7 @@ func (w *exportWriter) doTyp(t types.Type, pkg *types.Package) { w.signature(sig) } - case *typeparams.Union: + case *types.Union: w.startType(unionType) nt := t.Len() w.uint64(uint64(nt)) @@ -948,14 +948,14 @@ func (w *exportWriter) signature(sig *types.Signature) { } } -func (w *exportWriter) typeList(ts *typeparams.TypeList, pkg *types.Package) { +func (w *exportWriter) typeList(ts *types.TypeList, pkg *types.Package) { w.uint64(uint64(ts.Len())) for i := 0; i < ts.Len(); i++ { w.typ(ts.At(i), pkg) } } -func (w *exportWriter) tparamList(prefix string, list *typeparams.TypeParamList, pkg *types.Package) { +func (w *exportWriter) tparamList(prefix string, list *types.TypeParamList, pkg *types.Package) { ll := uint64(list.Len()) w.uint64(ll) for i := 0; i < list.Len(); i++ { @@ -973,7 +973,7 @@ const blankMarker = "$" // differs from its actual object name: it is prefixed with a qualifier, and // blank type parameter names are disambiguated by their index in the type // parameter list. -func tparamExportName(prefix string, tparam *typeparams.TypeParam) string { +func tparamExportName(prefix string, tparam *types.TypeParam) string { assert(prefix != "") name := tparam.Obj().Name() if name == "_" { diff --git a/internal/gcimporter/iimport.go b/internal/gcimporter/iimport.go index 8e64cf644fc..391764f9ee2 100644 --- a/internal/gcimporter/iimport.go +++ b/internal/gcimporter/iimport.go @@ -339,7 +339,7 @@ func iimportCommon(fset *token.FileSet, getPackages GetPackagesFunc, data []byte } type setConstraintArgs struct { - t *typeparams.TypeParam + t *types.TypeParam constraint types.Type } @@ -549,7 +549,7 @@ func (r *importReader) obj(name string) { r.declare(types.NewConst(pos, r.currPkg, name, typ, val)) case 'F', 'G': - var tparams []*typeparams.TypeParam + var tparams []*types.TypeParam if tag == 'G' { tparams = r.tparamList() } @@ -584,11 +584,11 @@ func (r *importReader) obj(name string) { base := baseType(recv.Type()) assert(base != nil) targs := typeparams.NamedTypeArgs(base) - var rparams []*typeparams.TypeParam + var rparams []*types.TypeParam if targs.Len() > 0 { - rparams = make([]*typeparams.TypeParam, targs.Len()) + rparams = make([]*types.TypeParam, targs.Len()) for i := range rparams { - rparams[i] = targs.At(i).(*typeparams.TypeParam) + rparams[i] = targs.At(i).(*types.TypeParam) } } msig := r.signature(recv, rparams, nil) @@ -976,7 +976,7 @@ func (r *importReader) doType(base *types.Named) (res types.Type) { if r.p.version < iexportVersionGenerics { errorf("unexpected instantiation type") } - terms := make([]*typeparams.Term, r.uint64()) + terms := make([]*types.Term, r.uint64()) for i := range terms { terms[i] = typeparams.NewTerm(r.bool(), r.typ()) } @@ -1008,23 +1008,23 @@ func (r *importReader) objectPathObject() types.Object { return obj } -func (r *importReader) signature(recv *types.Var, rparams []*typeparams.TypeParam, tparams []*typeparams.TypeParam) *types.Signature { +func (r *importReader) signature(recv *types.Var, rparams []*types.TypeParam, tparams []*types.TypeParam) *types.Signature { params := r.paramList() results := r.paramList() variadic := params.Len() > 0 && r.bool() return typeparams.NewSignatureType(recv, rparams, tparams, params, results, variadic) } -func (r *importReader) tparamList() []*typeparams.TypeParam { +func (r *importReader) tparamList() []*types.TypeParam { n := r.uint64() if n == 0 { return nil } - xs := make([]*typeparams.TypeParam, n) + xs := make([]*types.TypeParam, n) for i := range xs { // Note: the standard library importer is tolerant of nil types here, // though would panic in SetTypeParams. - xs[i] = r.typ().(*typeparams.TypeParam) + xs[i] = r.typ().(*types.TypeParam) } return xs } diff --git a/internal/typeparams/common.go b/internal/typeparams/common.go index d0d0649fe2a..ae7e5c5c988 100644 --- a/internal/typeparams/common.go +++ b/internal/typeparams/common.go @@ -42,7 +42,7 @@ func UnpackIndexExpr(n ast.Node) (x ast.Expr, lbrack token.Pos, indices []ast.Ex switch e := n.(type) { case *ast.IndexExpr: return e.X, e.Lbrack, []ast.Expr{e.Index}, e.Rbrack - case *IndexListExpr: + case *ast.IndexListExpr: return e.X, e.Lbrack, e.Indices, e.Rbrack } return nil, token.NoPos, nil, token.NoPos @@ -63,7 +63,7 @@ func PackIndexExpr(x ast.Expr, lbrack token.Pos, indices []ast.Expr, rbrack toke Rbrack: rbrack, } default: - return &IndexListExpr{ + return &ast.IndexListExpr{ X: x, Lbrack: lbrack, Indices: indices, @@ -74,7 +74,7 @@ func PackIndexExpr(x ast.Expr, lbrack token.Pos, indices []ast.Expr, rbrack toke // IsTypeParam reports whether t is a type parameter. func IsTypeParam(t types.Type) bool { - _, ok := t.(*TypeParam) + _, ok := t.(*types.TypeParam) return ok } @@ -157,7 +157,7 @@ func OriginMethod(fn *types.Func) *types.Func { // // In this case, GenericAssignableTo reports that instantiations of Container // are assignable to the corresponding instantiation of Interface. -func GenericAssignableTo(ctxt *Context, V, T types.Type) bool { +func GenericAssignableTo(ctxt *types.Context, V, T types.Type) bool { // If V and T are not both named, or do not have matching non-empty type // parameter lists, fall back on types.AssignableTo. diff --git a/internal/typeparams/common_test.go b/internal/typeparams/common_test.go index d1f13fa7f53..b6f355cc5d7 100644 --- a/internal/typeparams/common_test.go +++ b/internal/typeparams/common_test.go @@ -19,7 +19,7 @@ func TestGetIndexExprData(t *testing.T) { x := &ast.Ident{} i := &ast.Ident{} - want := &IndexListExpr{X: x, Lbrack: 1, Indices: []ast.Expr{i}, Rbrack: 2} + want := &ast.IndexListExpr{X: x, Lbrack: 1, Indices: []ast.Expr{i}, Rbrack: 2} tests := map[ast.Node]bool{ &ast.IndexExpr{X: x, Lbrack: 1, Index: i, Rbrack: 2}: true, want: true, diff --git a/internal/typeparams/coretype.go b/internal/typeparams/coretype.go index 71248209ee5..c2dc8e2982e 100644 --- a/internal/typeparams/coretype.go +++ b/internal/typeparams/coretype.go @@ -108,15 +108,15 @@ func CoreType(T types.Type) types.Type { // // _NormalTerms makes no guarantees about the order of terms, except that it // is deterministic. -func _NormalTerms(typ types.Type) ([]*Term, error) { +func _NormalTerms(typ types.Type) ([]*types.Term, error) { switch typ := typ.(type) { - case *TypeParam: + case *types.TypeParam: return StructuralTerms(typ) - case *Union: + case *types.Union: return UnionTermSet(typ) case *types.Interface: return InterfaceTermSet(typ) default: - return []*Term{NewTerm(false, typ)}, nil + return []*types.Term{NewTerm(false, typ)}, nil } } diff --git a/internal/typeparams/normalize.go b/internal/typeparams/normalize.go index 9c631b6512d..d88efa509a3 100644 --- a/internal/typeparams/normalize.go +++ b/internal/typeparams/normalize.go @@ -60,7 +60,7 @@ var ErrEmptyTypeSet = errors.New("empty type set") // // StructuralTerms makes no guarantees about the order of terms, except that it // is deterministic. -func StructuralTerms(tparam *TypeParam) ([]*Term, error) { +func StructuralTerms(tparam *types.TypeParam) ([]*types.Term, error) { constraint := tparam.Constraint() if constraint == nil { return nil, fmt.Errorf("%s has nil constraint", tparam) @@ -78,7 +78,7 @@ func StructuralTerms(tparam *TypeParam) ([]*Term, error) { // // See the documentation of StructuralTerms for more information on // normalization. -func InterfaceTermSet(iface *types.Interface) ([]*Term, error) { +func InterfaceTermSet(iface *types.Interface) ([]*types.Term, error) { return computeTermSet(iface) } @@ -88,11 +88,11 @@ func InterfaceTermSet(iface *types.Interface) ([]*Term, error) { // // See the documentation of StructuralTerms for more information on // normalization. -func UnionTermSet(union *Union) ([]*Term, error) { +func UnionTermSet(union *types.Union) ([]*types.Term, error) { return computeTermSet(union) } -func computeTermSet(typ types.Type) ([]*Term, error) { +func computeTermSet(typ types.Type) ([]*types.Term, error) { tset, err := computeTermSetInternal(typ, make(map[types.Type]*termSet), 0) if err != nil { return nil, err @@ -103,7 +103,7 @@ func computeTermSet(typ types.Type) ([]*Term, error) { if tset.terms.isAll() { return nil, nil } - var terms []*Term + var terms []*types.Term for _, term := range tset.terms { terms = append(terms, NewTerm(term.tilde, term.typ)) } @@ -162,7 +162,7 @@ func computeTermSetInternal(t types.Type, seen map[types.Type]*termSet, depth in tset.terms = allTermlist for i := 0; i < u.NumEmbeddeds(); i++ { embedded := u.EmbeddedType(i) - if _, ok := embedded.Underlying().(*TypeParam); ok { + if _, ok := embedded.Underlying().(*types.TypeParam); ok { return nil, fmt.Errorf("invalid embedded type %T", embedded) } tset2, err := computeTermSetInternal(embedded, seen, depth+1) @@ -171,7 +171,7 @@ func computeTermSetInternal(t types.Type, seen map[types.Type]*termSet, depth in } tset.terms = tset.terms.intersect(tset2.terms) } - case *Union: + case *types.Union: // The term set of a union is the union of term sets of its terms. tset.terms = nil for i := 0; i < u.Len(); i++ { @@ -184,7 +184,7 @@ func computeTermSetInternal(t types.Type, seen map[types.Type]*termSet, depth in return nil, err } terms = tset2.terms - case *TypeParam, *Union: + case *types.TypeParam, *types.Union: // A stand-alone type parameter or union is not permitted as union // term. return nil, fmt.Errorf("invalid union term %T", t) @@ -199,7 +199,7 @@ func computeTermSetInternal(t types.Type, seen map[types.Type]*termSet, depth in return nil, fmt.Errorf("exceeded max term count %d", maxTermCount) } } - case *TypeParam: + case *types.TypeParam: panic("unreachable") default: // For all other types, the term set is just a single non-tilde term diff --git a/internal/typeparams/typeparams_go118.go b/internal/typeparams/typeparams_go118.go index 0bda83dd59b..54e8e9711d9 100644 --- a/internal/typeparams/typeparams_go118.go +++ b/internal/typeparams/typeparams_go118.go @@ -9,10 +9,7 @@ import ( "go/types" ) -// TODO(adonovan): melt the aliases away. - -// IndexListExpr is an alias for ast.IndexListExpr. -type IndexListExpr = ast.IndexListExpr +// TODO(adonovan): melt the trivial functions away. // ForTypeSpec returns n.TypeParams. func ForTypeSpec(n *ast.TypeSpec) *ast.FieldList { @@ -30,37 +27,28 @@ func ForFuncType(n *ast.FuncType) *ast.FieldList { return n.TypeParams } -// TypeParam is an alias for types.TypeParam -type TypeParam = types.TypeParam - -// TypeParamList is an alias for types.TypeParamList -type TypeParamList = types.TypeParamList - -// TypeList is an alias for types.TypeList -type TypeList = types.TypeList - // NewTypeParam calls types.NewTypeParam. -func NewTypeParam(name *types.TypeName, constraint types.Type) *TypeParam { +func NewTypeParam(name *types.TypeName, constraint types.Type) *types.TypeParam { return types.NewTypeParam(name, constraint) } // SetTypeParamConstraint calls tparam.SetConstraint(constraint). -func SetTypeParamConstraint(tparam *TypeParam, constraint types.Type) { +func SetTypeParamConstraint(tparam *types.TypeParam, constraint types.Type) { tparam.SetConstraint(constraint) } // NewSignatureType calls types.NewSignatureType. -func NewSignatureType(recv *types.Var, recvTypeParams, typeParams []*TypeParam, params, results *types.Tuple, variadic bool) *types.Signature { +func NewSignatureType(recv *types.Var, recvTypeParams, typeParams []*types.TypeParam, params, results *types.Tuple, variadic bool) *types.Signature { return types.NewSignatureType(recv, recvTypeParams, typeParams, params, results, variadic) } // ForSignature returns sig.TypeParams() -func ForSignature(sig *types.Signature) *TypeParamList { +func ForSignature(sig *types.Signature) *types.TypeParamList { return sig.TypeParams() } // RecvTypeParams returns sig.RecvTypeParams(). -func RecvTypeParams(sig *types.Signature) *TypeParamList { +func RecvTypeParams(sig *types.Signature) *types.TypeParamList { return sig.RecvTypeParams() } @@ -86,18 +74,18 @@ func MarkImplicit(iface *types.Interface) { // ForNamed extracts the (possibly empty) type parameter object list from // named. -func ForNamed(named *types.Named) *TypeParamList { +func ForNamed(named *types.Named) *types.TypeParamList { return named.TypeParams() } // SetForNamed sets the type params tparams on n. Each tparam must be of // dynamic type *types.TypeParam. -func SetForNamed(n *types.Named, tparams []*TypeParam) { +func SetForNamed(n *types.Named, tparams []*types.TypeParam) { n.SetTypeParams(tparams) } // NamedTypeArgs returns named.TypeArgs(). -func NamedTypeArgs(named *types.Named) *TypeList { +func NamedTypeArgs(named *types.Named) *types.TypeList { return named.TypeArgs() } @@ -106,19 +94,13 @@ func NamedTypeOrigin(named *types.Named) *types.Named { return named.Origin() } -// Term is an alias for types.Term. -type Term = types.Term - // NewTerm calls types.NewTerm. -func NewTerm(tilde bool, typ types.Type) *Term { +func NewTerm(tilde bool, typ types.Type) *types.Term { return types.NewTerm(tilde, typ) } -// Union is an alias for types.Union -type Union = types.Union - // NewUnion calls types.NewUnion. -func NewUnion(terms []*Term) *Union { +func NewUnion(terms []*types.Term) *types.Union { return types.NewUnion(terms) } @@ -128,23 +110,17 @@ func InitInstanceInfo(info *types.Info) { info.Instances = make(map[*ast.Ident]types.Instance) } -// Instance is an alias for types.Instance. -type Instance = types.Instance - // GetInstances returns info.Instances. -func GetInstances(info *types.Info) map[*ast.Ident]Instance { +func GetInstances(info *types.Info) map[*ast.Ident]types.Instance { return info.Instances } -// Context is an alias for types.Context. -type Context = types.Context - // NewContext calls types.NewContext. -func NewContext() *Context { +func NewContext() *types.Context { return types.NewContext() } // Instantiate calls types.Instantiate. -func Instantiate(ctxt *Context, typ types.Type, targs []types.Type, validate bool) (types.Type, error) { +func Instantiate(ctxt *types.Context, typ types.Type, targs []types.Type, validate bool) (types.Type, error) { return types.Instantiate(ctxt, typ, targs, validate) } diff --git a/refactor/satisfy/find.go b/refactor/satisfy/find.go index 9e60af3b618..19cf4722c57 100644 --- a/refactor/satisfy/find.go +++ b/refactor/satisfy/find.go @@ -411,7 +411,7 @@ func (f *Finder) expr(e ast.Expr) types.Type { } } - case *typeparams.IndexListExpr: + case *ast.IndexListExpr: // f[X, Y] -- generic instantiation case *ast.SliceExpr: