Merge pull request #2211 from containers/renovate/golang.org-x-exp-digest

fix(deps): update golang.org/x/exp digest to 1b97071
This commit is contained in:
Miloslav Trmač 2024-02-01 19:43:02 +01:00 committed by GitHub
commit d39f17c995
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
19 changed files with 162 additions and 518 deletions

4
go.mod
View File

@ -16,7 +16,7 @@ require (
github.com/spf13/pflag v1.0.5 github.com/spf13/pflag v1.0.5
github.com/stretchr/testify v1.8.4 github.com/stretchr/testify v1.8.4
github.com/syndtr/gocapability v0.0.0-20200815063812-42c35b437635 github.com/syndtr/gocapability v0.0.0-20200815063812-42c35b437635
golang.org/x/exp v0.0.0-20231226003508-02704c960a9b golang.org/x/exp v0.0.0-20240119083558-1b970713d09a
golang.org/x/term v0.16.0 golang.org/x/term v0.16.0
gopkg.in/yaml.v3 v3.0.1 gopkg.in/yaml.v3 v3.0.1
) )
@ -126,7 +126,7 @@ require (
golang.org/x/sync v0.6.0 // indirect golang.org/x/sync v0.6.0 // indirect
golang.org/x/sys v0.16.0 // indirect golang.org/x/sys v0.16.0 // indirect
golang.org/x/text v0.14.0 // indirect golang.org/x/text v0.14.0 // indirect
golang.org/x/tools v0.16.0 // indirect golang.org/x/tools v0.17.0 // indirect
google.golang.org/appengine v1.6.8 // indirect google.golang.org/appengine v1.6.8 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20230920204549-e6e6cdab5c13 // indirect google.golang.org/genproto/googleapis/rpc v0.0.0-20230920204549-e6e6cdab5c13 // indirect
google.golang.org/grpc v1.59.0 // indirect google.golang.org/grpc v1.59.0 // indirect

8
go.sum
View File

@ -432,8 +432,8 @@ golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d/go.mod h1:IxCIyHEi3zRg3s0
golang.org/x/crypto v0.18.0 h1:PGVlW0xEltQnzFZ55hkuX5+KLyrMYhHld1YHO4AKcdc= golang.org/x/crypto v0.18.0 h1:PGVlW0xEltQnzFZ55hkuX5+KLyrMYhHld1YHO4AKcdc=
golang.org/x/crypto v0.18.0/go.mod h1:R0j02AL6hcrfOiy9T4ZYp/rcWeMxM3L6QYxlOuEG1mg= golang.org/x/crypto v0.18.0/go.mod h1:R0j02AL6hcrfOiy9T4ZYp/rcWeMxM3L6QYxlOuEG1mg=
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/exp v0.0.0-20231226003508-02704c960a9b h1:kLiC65FbiHWFAOu+lxwNPujcsl8VYyTYYEZnsOO1WK4= golang.org/x/exp v0.0.0-20240119083558-1b970713d09a h1:Q8/wZp0KX97QFTc2ywcOE0YRjZPVIx+MXInMzdvQqcA=
golang.org/x/exp v0.0.0-20231226003508-02704c960a9b/go.mod h1:iRJReGqOEeBhDZGkGbynYwcHlctCvnjTYIamk7uXpHI= golang.org/x/exp v0.0.0-20240119083558-1b970713d09a/go.mod h1:idGWGoKP1toJGkd5/ig9ZLuPcZBC3ewk7SzmH0uou08=
golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU= golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU=
golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
@ -516,8 +516,8 @@ golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtn
golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE=
golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
golang.org/x/tools v0.16.0 h1:GO788SKMRunPIBCXiQyo2AaexLstOrVhuAL5YwsckQM= golang.org/x/tools v0.17.0 h1:FvmRgNOcs3kOa+T20R1uhfP9F6HgG2mfxDv1vrx1Htc=
golang.org/x/tools v0.16.0/go.mod h1:kYVVN6I1mBNoB1OX+noeBjbRk4IUEPa7JJ+TJMEooJ0= golang.org/x/tools v0.17.0/go.mod h1:xsh6VxdV005rRVaS6SSAf9oiAqljS7UZUacMZ8Bnsps=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=

View File

@ -209,25 +209,37 @@ func Insert[S ~[]E, E any](s S, i int, v ...E) S {
return s return s
} }
// Delete removes the elements s[i:j] from s, returning the modified slice. // clearSlice sets all elements up to the length of s to the zero value of E.
// Delete panics if s[i:j] is not a valid slice of s. // We may use the builtin clear func instead, and remove clearSlice, when upgrading
// Delete is O(len(s)-j), so if many items must be deleted, it is better to // to Go 1.21+.
// make a single call deleting them all together than to delete one at a time. func clearSlice[S ~[]E, E any](s S) {
// Delete might not modify the elements s[len(s)-(j-i):len(s)]. If those var zero E
// elements contain pointers you might consider zeroing those elements so that for i := range s {
// objects they reference can be garbage collected. s[i] = zero
func Delete[S ~[]E, E any](s S, i, j int) S { }
_ = s[i:j] // bounds check }
return append(s[:i], s[j:]...) // Delete removes the elements s[i:j] from s, returning the modified slice.
// Delete panics if j > len(s) or s[i:j] is not a valid slice of s.
// Delete is O(len(s)-i), so if many items must be deleted, it is better to
// make a single call deleting them all together than to delete one at a time.
// Delete zeroes the elements s[len(s)-(j-i):len(s)].
func Delete[S ~[]E, E any](s S, i, j int) S {
_ = s[i:j:len(s)] // bounds check
if i == j {
return s
}
oldlen := len(s)
s = append(s[:i], s[j:]...)
clearSlice(s[len(s):oldlen]) // zero/nil out the obsolete elements, for GC
return s
} }
// DeleteFunc removes any elements from s for which del returns true, // DeleteFunc removes any elements from s for which del returns true,
// returning the modified slice. // returning the modified slice.
// When DeleteFunc removes m elements, it might not modify the elements // DeleteFunc zeroes the elements between the new length and the original length.
// s[len(s)-m:len(s)]. If those elements contain pointers you might consider
// zeroing those elements so that objects they reference can be garbage
// collected.
func DeleteFunc[S ~[]E, E any](s S, del func(E) bool) S { func DeleteFunc[S ~[]E, E any](s S, del func(E) bool) S {
i := IndexFunc(s, del) i := IndexFunc(s, del)
if i == -1 { if i == -1 {
@ -240,11 +252,13 @@ func DeleteFunc[S ~[]E, E any](s S, del func(E) bool) S {
i++ i++
} }
} }
clearSlice(s[i:]) // zero/nil out the obsolete elements, for GC
return s[:i] return s[:i]
} }
// Replace replaces the elements s[i:j] by the given v, and returns the // Replace replaces the elements s[i:j] by the given v, and returns the
// modified slice. Replace panics if s[i:j] is not a valid slice of s. // modified slice. Replace panics if s[i:j] is not a valid slice of s.
// When len(v) < (j-i), Replace zeroes the elements between the new length and the original length.
func Replace[S ~[]E, E any](s S, i, j int, v ...E) S { func Replace[S ~[]E, E any](s S, i, j int, v ...E) S {
_ = s[i:j] // verify that i:j is a valid subslice _ = s[i:j] // verify that i:j is a valid subslice
@ -272,6 +286,7 @@ func Replace[S ~[]E, E any](s S, i, j int, v ...E) S {
if i+len(v) != j { if i+len(v) != j {
copy(r[i+len(v):], s[j:]) copy(r[i+len(v):], s[j:])
} }
clearSlice(s[tot:]) // zero/nil out the obsolete elements, for GC
return r return r
} }
@ -345,9 +360,7 @@ func Clone[S ~[]E, E any](s S) S {
// This is like the uniq command found on Unix. // This is like the uniq command found on Unix.
// Compact modifies the contents of the slice s and returns the modified slice, // Compact modifies the contents of the slice s and returns the modified slice,
// which may have a smaller length. // which may have a smaller length.
// When Compact discards m elements in total, it might not modify the elements // Compact zeroes the elements between the new length and the original length.
// s[len(s)-m:len(s)]. If those elements contain pointers you might consider
// zeroing those elements so that objects they reference can be garbage collected.
func Compact[S ~[]E, E comparable](s S) S { func Compact[S ~[]E, E comparable](s S) S {
if len(s) < 2 { if len(s) < 2 {
return s return s
@ -361,11 +374,13 @@ func Compact[S ~[]E, E comparable](s S) S {
i++ i++
} }
} }
clearSlice(s[i:]) // zero/nil out the obsolete elements, for GC
return s[:i] return s[:i]
} }
// CompactFunc is like [Compact] but uses an equality function to compare elements. // CompactFunc is like [Compact] but uses an equality function to compare elements.
// For runs of elements that compare equal, CompactFunc keeps the first one. // For runs of elements that compare equal, CompactFunc keeps the first one.
// CompactFunc zeroes the elements between the new length and the original length.
func CompactFunc[S ~[]E, E any](s S, eq func(E, E) bool) S { func CompactFunc[S ~[]E, E any](s S, eq func(E, E) bool) S {
if len(s) < 2 { if len(s) < 2 {
return s return s
@ -379,6 +394,7 @@ func CompactFunc[S ~[]E, E any](s S, eq func(E, E) bool) S {
i++ i++
} }
} }
clearSlice(s[i:]) // zero/nil out the obsolete elements, for GC
return s[:i] return s[:i]
} }

View File

@ -5,12 +5,32 @@
/* /*
Package packages loads Go packages for inspection and analysis. Package packages loads Go packages for inspection and analysis.
The Load function takes as input a list of patterns and return a list of Package The [Load] function takes as input a list of patterns and returns a
structs describing individual packages matched by those patterns. list of [Package] values describing individual packages matched by those
The LoadMode controls the amount of detail in the loaded packages. patterns.
A [Config] specifies configuration options, the most important of which is
the [LoadMode], which controls the amount of detail in the loaded packages.
Load passes most patterns directly to the underlying build tool, Load passes most patterns directly to the underlying build tool.
but all patterns with the prefix "query=", where query is a The default build tool is the go command.
Its supported patterns are described at
https://pkg.go.dev/cmd/go#hdr-Package_lists_and_patterns.
Load may be used in Go projects that use alternative build systems, by
installing an appropriate "driver" program for the build system and
specifying its location in the GOPACKAGESDRIVER environment variable.
For example,
https://github.com/bazelbuild/rules_go/wiki/Editor-and-tool-integration
explains how to use the driver for Bazel.
The driver program is responsible for interpreting patterns in its
preferred notation and reporting information about the packages that
they identify.
(See driverRequest and driverResponse types for the JSON
schema used by the protocol.
Though the protocol is supported, these types are currently unexported;
see #64608 for a proposal to publish them.)
Regardless of driver, all patterns with the prefix "query=", where query is a
non-empty string of letters from [a-z], are reserved and may be non-empty string of letters from [a-z], are reserved and may be
interpreted as query operators. interpreted as query operators.
@ -64,7 +84,7 @@ reported about the loaded packages. See the documentation for type LoadMode
for details. for details.
Most tools should pass their command-line arguments (after any flags) Most tools should pass their command-line arguments (after any flags)
uninterpreted to the loader, so that the loader can interpret them uninterpreted to [Load], so that it can interpret them
according to the conventions of the underlying build system. according to the conventions of the underlying build system.
See the Example function for typical usage. See the Example function for typical usage.
*/ */

View File

@ -27,7 +27,6 @@ import (
"golang.org/x/tools/go/gcexportdata" "golang.org/x/tools/go/gcexportdata"
"golang.org/x/tools/internal/gocommand" "golang.org/x/tools/internal/gocommand"
"golang.org/x/tools/internal/packagesinternal" "golang.org/x/tools/internal/packagesinternal"
"golang.org/x/tools/internal/typeparams"
"golang.org/x/tools/internal/typesinternal" "golang.org/x/tools/internal/typesinternal"
"golang.org/x/tools/internal/versions" "golang.org/x/tools/internal/versions"
) )
@ -1015,10 +1014,10 @@ func (ld *loader) loadPackage(lpkg *loaderPackage) {
Defs: make(map[*ast.Ident]types.Object), Defs: make(map[*ast.Ident]types.Object),
Uses: make(map[*ast.Ident]types.Object), Uses: make(map[*ast.Ident]types.Object),
Implicits: make(map[ast.Node]types.Object), Implicits: make(map[ast.Node]types.Object),
Instances: make(map[*ast.Ident]types.Instance),
Scopes: make(map[ast.Node]*types.Scope), Scopes: make(map[ast.Node]*types.Scope),
Selections: make(map[*ast.SelectorExpr]*types.Selection), Selections: make(map[*ast.SelectorExpr]*types.Selection),
} }
typeparams.InitInstanceInfo(lpkg.TypesInfo)
versions.InitFileVersions(lpkg.TypesInfo) versions.InitFileVersions(lpkg.TypesInfo)
lpkg.TypesSizes = ld.sizes lpkg.TypesSizes = ld.sizes

View File

@ -223,7 +223,7 @@ func (enc *Encoder) For(obj types.Object) (Path, error) {
// Reject obviously non-viable cases. // Reject obviously non-viable cases.
switch obj := obj.(type) { switch obj := obj.(type) {
case *types.TypeName: 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 // With the exception of type parameters, only package-level type names
// have a path. // have a path.
return "", fmt.Errorf("no path for %v", obj) return "", fmt.Errorf("no path for %v", obj)
@ -283,7 +283,7 @@ func (enc *Encoder) For(obj types.Object) (Path, error) {
} }
} else { } else {
if named, _ := T.(*types.Named); named != nil { if named, _ := T.(*types.Named); named != nil {
if r := findTypeParam(obj, typeparams.ForNamed(named), path, nil); r != nil { if r := findTypeParam(obj, named.TypeParams(), path, nil); r != nil {
// generic named type // generic named type
return Path(r), nil return Path(r), nil
} }
@ -462,7 +462,7 @@ func find(obj types.Object, T types.Type, path []byte, seen map[*types.TypeName]
} }
return find(obj, T.Elem(), append(path, opElem), seen) return find(obj, T.Elem(), append(path, opElem), seen)
case *types.Signature: case *types.Signature:
if r := findTypeParam(obj, typeparams.ForSignature(T), path, seen); r != nil { if r := findTypeParam(obj, T.TypeParams(), path, seen); r != nil {
return r return r
} }
if r := find(obj, T.Params(), append(path, opParams), seen); r != nil { if r := find(obj, T.Params(), append(path, opParams), seen); r != nil {
@ -505,7 +505,7 @@ func find(obj types.Object, T types.Type, path []byte, seen map[*types.TypeName]
} }
} }
return nil return nil
case *typeparams.TypeParam: case *types.TypeParam:
name := T.Obj() name := T.Obj()
if name == obj { if name == obj {
return append(path, opObj) return append(path, opObj)
@ -525,7 +525,7 @@ func find(obj types.Object, T types.Type, path []byte, seen map[*types.TypeName]
panic(T) 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++ { for i := 0; i < list.Len(); i++ {
tparam := list.At(i) tparam := list.At(i)
path2 := appendOpArg(path, opTypeParam, 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} // abstraction of *types.{Named,Signature}
type hasTypeParams interface { type hasTypeParams interface {
TypeParams() *typeparams.TypeParamList TypeParams() *types.TypeParamList
} }
// abstraction of *types.{Named,TypeParam} // abstraction of *types.{Named,TypeParam}
type hasObj interface { type hasObj interface {
@ -664,7 +664,7 @@ func Object(pkg *types.Package, p Path) (types.Object, error) {
t = tparams.At(index) t = tparams.At(index)
case opConstraint: case opConstraint:
tparam, ok := t.(*typeparams.TypeParam) tparam, ok := t.(*types.TypeParam)
if !ok { if !ok {
return nil, fmt.Errorf("cannot apply %q to %s (got %T, want type parameter)", code, t, t) return nil, fmt.Errorf("cannot apply %q to %s (got %T, want type parameter)", code, t, t)
} }

21
vendor/golang.org/x/tools/internal/event/keys/util.go generated vendored Normal file
View File

@ -0,0 +1,21 @@
// Copyright 2023 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package keys
import (
"sort"
"strings"
)
// Join returns a canonical join of the keys in S:
// a sorted comma-separated string list.
func Join[S ~[]T, T ~string](s S) string {
strs := make([]string, 0, len(s))
for _, v := range s {
strs = append(strs, string(v))
}
sort.Strings(strs)
return strings.Join(strs, ",")
}

View File

@ -24,7 +24,6 @@ import (
"golang.org/x/tools/go/types/objectpath" "golang.org/x/tools/go/types/objectpath"
"golang.org/x/tools/internal/tokeninternal" "golang.org/x/tools/internal/tokeninternal"
"golang.org/x/tools/internal/typeparams"
) )
// IExportShallow encodes "shallow" export data for the specified package. // IExportShallow encodes "shallow" export data for the specified package.
@ -481,7 +480,7 @@ func (p *iexporter) doDecl(obj types.Object) {
} }
// Function. // Function.
if typeparams.ForSignature(sig).Len() == 0 { if sig.TypeParams().Len() == 0 {
w.tag('F') w.tag('F')
} else { } else {
w.tag('G') w.tag('G')
@ -494,7 +493,7 @@ func (p *iexporter) doDecl(obj types.Object) {
// //
// While importing the type parameters, tparamList computes and records // While importing the type parameters, tparamList computes and records
// their export name, so that it can be later used when writing the index. // their export name, so that it can be later used when writing the index.
if tparams := typeparams.ForSignature(sig); tparams.Len() > 0 { if tparams := sig.TypeParams(); tparams.Len() > 0 {
w.tparamList(obj.Name(), tparams, obj.Pkg()) w.tparamList(obj.Name(), tparams, obj.Pkg())
} }
w.signature(sig) w.signature(sig)
@ -507,14 +506,14 @@ func (p *iexporter) doDecl(obj types.Object) {
case *types.TypeName: case *types.TypeName:
t := obj.Type() t := obj.Type()
if tparam, ok := t.(*typeparams.TypeParam); ok { if tparam, ok := t.(*types.TypeParam); ok {
w.tag('P') w.tag('P')
w.pos(obj.Pos()) w.pos(obj.Pos())
constraint := tparam.Constraint() constraint := tparam.Constraint()
if p.version >= iexportVersionGo1_18 { if p.version >= iexportVersionGo1_18 {
implicit := false implicit := false
if iface, _ := constraint.(*types.Interface); iface != nil { if iface, _ := constraint.(*types.Interface); iface != nil {
implicit = typeparams.IsImplicit(iface) implicit = iface.IsImplicit()
} }
w.bool(implicit) w.bool(implicit)
} }
@ -535,17 +534,17 @@ func (p *iexporter) doDecl(obj types.Object) {
panic(internalErrorf("%s is not a defined type", t)) panic(internalErrorf("%s is not a defined type", t))
} }
if typeparams.ForNamed(named).Len() == 0 { if named.TypeParams().Len() == 0 {
w.tag('T') w.tag('T')
} else { } else {
w.tag('U') w.tag('U')
} }
w.pos(obj.Pos()) w.pos(obj.Pos())
if typeparams.ForNamed(named).Len() > 0 { if named.TypeParams().Len() > 0 {
// While importing the type parameters, tparamList computes and records // While importing the type parameters, tparamList computes and records
// their export name, so that it can be later used when writing the index. // their export name, so that it can be later used when writing the index.
w.tparamList(obj.Name(), typeparams.ForNamed(named), obj.Pkg()) w.tparamList(obj.Name(), named.TypeParams(), obj.Pkg())
} }
underlying := obj.Type().Underlying() underlying := obj.Type().Underlying()
@ -565,7 +564,7 @@ func (p *iexporter) doDecl(obj types.Object) {
// Receiver type parameters are type arguments of the receiver type, so // Receiver type parameters are type arguments of the receiver type, so
// their name must be qualified before exporting recv. // their name must be qualified before exporting recv.
if rparams := typeparams.RecvTypeParams(sig); rparams.Len() > 0 { if rparams := sig.RecvTypeParams(); rparams.Len() > 0 {
prefix := obj.Name() + "." + m.Name() prefix := obj.Name() + "." + m.Name()
for i := 0; i < rparams.Len(); i++ { for i := 0; i < rparams.Len(); i++ {
rparam := rparams.At(i) rparam := rparams.At(i)
@ -740,19 +739,19 @@ func (w *exportWriter) doTyp(t types.Type, pkg *types.Package) {
} }
switch t := t.(type) { switch t := t.(type) {
case *types.Named: case *types.Named:
if targs := typeparams.NamedTypeArgs(t); targs.Len() > 0 { if targs := t.TypeArgs(); targs.Len() > 0 {
w.startType(instanceType) w.startType(instanceType)
// TODO(rfindley): investigate if this position is correct, and if it // TODO(rfindley): investigate if this position is correct, and if it
// matters. // matters.
w.pos(t.Obj().Pos()) w.pos(t.Obj().Pos())
w.typeList(targs, pkg) w.typeList(targs, pkg)
w.typ(typeparams.NamedTypeOrigin(t), pkg) w.typ(t.Origin(), pkg)
return return
} }
w.startType(definedType) w.startType(definedType)
w.qualifiedType(t.Obj()) w.qualifiedType(t.Obj())
case *typeparams.TypeParam: case *types.TypeParam:
w.startType(typeParamType) w.startType(typeParamType)
w.qualifiedType(t.Obj()) w.qualifiedType(t.Obj())
@ -868,7 +867,7 @@ func (w *exportWriter) doTyp(t types.Type, pkg *types.Package) {
w.signature(sig) w.signature(sig)
} }
case *typeparams.Union: case *types.Union:
w.startType(unionType) w.startType(unionType)
nt := t.Len() nt := t.Len()
w.uint64(uint64(nt)) w.uint64(uint64(nt))
@ -948,14 +947,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())) w.uint64(uint64(ts.Len()))
for i := 0; i < ts.Len(); i++ { for i := 0; i < ts.Len(); i++ {
w.typ(ts.At(i), pkg) 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()) ll := uint64(list.Len())
w.uint64(ll) w.uint64(ll)
for i := 0; i < list.Len(); i++ { for i := 0; i < list.Len(); i++ {
@ -973,7 +972,7 @@ const blankMarker = "$"
// differs from its actual object name: it is prefixed with a qualifier, and // 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 // blank type parameter names are disambiguated by their index in the type
// parameter list. // parameter list.
func tparamExportName(prefix string, tparam *typeparams.TypeParam) string { func tparamExportName(prefix string, tparam *types.TypeParam) string {
assert(prefix != "") assert(prefix != "")
name := tparam.Obj().Name() name := tparam.Obj().Name()
if name == "_" { if name == "_" {

View File

@ -22,7 +22,6 @@ import (
"strings" "strings"
"golang.org/x/tools/go/types/objectpath" "golang.org/x/tools/go/types/objectpath"
"golang.org/x/tools/internal/typeparams"
) )
type intReader struct { type intReader struct {
@ -321,7 +320,7 @@ func iimportCommon(fset *token.FileSet, getPackages GetPackagesFunc, data []byte
// Therefore, we defer calling SetConstraint there, and call it here instead // Therefore, we defer calling SetConstraint there, and call it here instead
// after all types are complete. // after all types are complete.
for _, d := range p.later { for _, d := range p.later {
typeparams.SetTypeParamConstraint(d.t, d.constraint) d.t.SetConstraint(d.constraint)
} }
for _, typ := range p.interfaceList { for _, typ := range p.interfaceList {
@ -339,7 +338,7 @@ func iimportCommon(fset *token.FileSet, getPackages GetPackagesFunc, data []byte
} }
type setConstraintArgs struct { type setConstraintArgs struct {
t *typeparams.TypeParam t *types.TypeParam
constraint types.Type constraint types.Type
} }
@ -549,7 +548,7 @@ func (r *importReader) obj(name string) {
r.declare(types.NewConst(pos, r.currPkg, name, typ, val)) r.declare(types.NewConst(pos, r.currPkg, name, typ, val))
case 'F', 'G': case 'F', 'G':
var tparams []*typeparams.TypeParam var tparams []*types.TypeParam
if tag == 'G' { if tag == 'G' {
tparams = r.tparamList() tparams = r.tparamList()
} }
@ -566,7 +565,7 @@ func (r *importReader) obj(name string) {
r.declare(obj) r.declare(obj)
if tag == 'U' { if tag == 'U' {
tparams := r.tparamList() tparams := r.tparamList()
typeparams.SetForNamed(named, tparams) named.SetTypeParams(tparams)
} }
underlying := r.p.typAt(r.uint64(), named).Underlying() underlying := r.p.typAt(r.uint64(), named).Underlying()
@ -583,12 +582,12 @@ func (r *importReader) obj(name string) {
// typeparams being used in the method sig/body). // typeparams being used in the method sig/body).
base := baseType(recv.Type()) base := baseType(recv.Type())
assert(base != nil) assert(base != nil)
targs := typeparams.NamedTypeArgs(base) targs := base.TypeArgs()
var rparams []*typeparams.TypeParam var rparams []*types.TypeParam
if targs.Len() > 0 { if targs.Len() > 0 {
rparams = make([]*typeparams.TypeParam, targs.Len()) rparams = make([]*types.TypeParam, targs.Len())
for i := range rparams { for i := range rparams {
rparams[i] = targs.At(i).(*typeparams.TypeParam) rparams[i] = targs.At(i).(*types.TypeParam)
} }
} }
msig := r.signature(recv, rparams, nil) msig := r.signature(recv, rparams, nil)
@ -606,7 +605,7 @@ func (r *importReader) obj(name string) {
} }
name0 := tparamName(name) name0 := tparamName(name)
tn := types.NewTypeName(pos, r.currPkg, name0, nil) tn := types.NewTypeName(pos, r.currPkg, name0, nil)
t := typeparams.NewTypeParam(tn, nil) t := types.NewTypeParam(tn, nil)
// To handle recursive references to the typeparam within its // To handle recursive references to the typeparam within its
// bound, save the partial type in tparamIndex before reading the bounds. // bound, save the partial type in tparamIndex before reading the bounds.
@ -622,7 +621,7 @@ func (r *importReader) obj(name string) {
if iface == nil { if iface == nil {
errorf("non-interface constraint marked implicit") errorf("non-interface constraint marked implicit")
} }
typeparams.MarkImplicit(iface) iface.MarkImplicit()
} }
// The constraint type may not be complete, if we // The constraint type may not be complete, if we
// are in the middle of a type recursion involving type // are in the middle of a type recursion involving type
@ -966,7 +965,7 @@ func (r *importReader) doType(base *types.Named) (res types.Type) {
// The imported instantiated type doesn't include any methods, so // The imported instantiated type doesn't include any methods, so
// we must always use the methods of the base (orig) type. // we must always use the methods of the base (orig) type.
// TODO provide a non-nil *Environment // TODO provide a non-nil *Environment
t, _ := typeparams.Instantiate(nil, baseType, targs, false) t, _ := types.Instantiate(nil, baseType, targs, false)
// Workaround for golang/go#61561. See the doc for instanceList for details. // Workaround for golang/go#61561. See the doc for instanceList for details.
r.p.instanceList = append(r.p.instanceList, t) r.p.instanceList = append(r.p.instanceList, t)
@ -976,11 +975,11 @@ func (r *importReader) doType(base *types.Named) (res types.Type) {
if r.p.version < iexportVersionGenerics { if r.p.version < iexportVersionGenerics {
errorf("unexpected instantiation type") errorf("unexpected instantiation type")
} }
terms := make([]*typeparams.Term, r.uint64()) terms := make([]*types.Term, r.uint64())
for i := range terms { for i := range terms {
terms[i] = typeparams.NewTerm(r.bool(), r.typ()) terms[i] = types.NewTerm(r.bool(), r.typ())
} }
return typeparams.NewUnion(terms) return types.NewUnion(terms)
} }
} }
@ -1008,23 +1007,23 @@ func (r *importReader) objectPathObject() types.Object {
return obj 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() params := r.paramList()
results := r.paramList() results := r.paramList()
variadic := params.Len() > 0 && r.bool() variadic := params.Len() > 0 && r.bool()
return typeparams.NewSignatureType(recv, rparams, tparams, params, results, variadic) return types.NewSignatureType(recv, rparams, tparams, params, results, variadic)
} }
func (r *importReader) tparamList() []*typeparams.TypeParam { func (r *importReader) tparamList() []*types.TypeParam {
n := r.uint64() n := r.uint64()
if n == 0 { if n == 0 {
return nil return nil
} }
xs := make([]*typeparams.TypeParam, n) xs := make([]*types.TypeParam, n)
for i := range xs { for i := range xs {
// Note: the standard library importer is tolerant of nil types here, // Note: the standard library importer is tolerant of nil types here,
// though would panic in SetTypeParams. // though would panic in SetTypeParams.
xs[i] = r.typ().(*typeparams.TypeParam) xs[i] = r.typ().(*types.TypeParam)
} }
return xs return xs
} }

View File

@ -42,7 +42,7 @@ func UnpackIndexExpr(n ast.Node) (x ast.Expr, lbrack token.Pos, indices []ast.Ex
switch e := n.(type) { switch e := n.(type) {
case *ast.IndexExpr: case *ast.IndexExpr:
return e.X, e.Lbrack, []ast.Expr{e.Index}, e.Rbrack 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 e.X, e.Lbrack, e.Indices, e.Rbrack
} }
return nil, token.NoPos, nil, token.NoPos 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, Rbrack: rbrack,
} }
default: default:
return &IndexListExpr{ return &ast.IndexListExpr{
X: x, X: x,
Lbrack: lbrack, Lbrack: lbrack,
Indices: indices, 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. // IsTypeParam reports whether t is a type parameter.
func IsTypeParam(t types.Type) bool { func IsTypeParam(t types.Type) bool {
_, ok := t.(*TypeParam) _, ok := t.(*types.TypeParam)
return ok return ok
} }
@ -100,11 +100,11 @@ func OriginMethod(fn *types.Func) *types.Func {
// Receiver is a *types.Interface. // Receiver is a *types.Interface.
return fn return fn
} }
if ForNamed(named).Len() == 0 { if named.TypeParams().Len() == 0 {
// Receiver base has no type parameters, so we can avoid the lookup below. // Receiver base has no type parameters, so we can avoid the lookup below.
return fn return fn
} }
orig := NamedTypeOrigin(named) orig := named.Origin()
gfn, _, _ := types.LookupFieldOrMethod(orig, true, fn.Pkg(), fn.Name()) gfn, _, _ := types.LookupFieldOrMethod(orig, true, fn.Pkg(), fn.Name())
// This is a fix for a gopls crash (#60628) due to a go/types bug (#60634). In: // This is a fix for a gopls crash (#60628) due to a go/types bug (#60634). In:
@ -157,7 +157,7 @@ func OriginMethod(fn *types.Func) *types.Func {
// //
// In this case, GenericAssignableTo reports that instantiations of Container // In this case, GenericAssignableTo reports that instantiations of Container
// are assignable to the corresponding instantiation of Interface. // 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 // If V and T are not both named, or do not have matching non-empty type
// parameter lists, fall back on types.AssignableTo. // parameter lists, fall back on types.AssignableTo.
@ -167,9 +167,9 @@ func GenericAssignableTo(ctxt *Context, V, T types.Type) bool {
return types.AssignableTo(V, T) return types.AssignableTo(V, T)
} }
vtparams := ForNamed(VN) vtparams := VN.TypeParams()
ttparams := ForNamed(TN) ttparams := TN.TypeParams()
if vtparams.Len() == 0 || vtparams.Len() != ttparams.Len() || NamedTypeArgs(VN).Len() != 0 || NamedTypeArgs(TN).Len() != 0 { if vtparams.Len() == 0 || vtparams.Len() != ttparams.Len() || VN.TypeArgs().Len() != 0 || TN.TypeArgs().Len() != 0 {
return types.AssignableTo(V, T) return types.AssignableTo(V, T)
} }
@ -182,7 +182,7 @@ func GenericAssignableTo(ctxt *Context, V, T types.Type) bool {
// Minor optimization: ensure we share a context across the two // Minor optimization: ensure we share a context across the two
// instantiations below. // instantiations below.
if ctxt == nil { if ctxt == nil {
ctxt = NewContext() ctxt = types.NewContext()
} }
var targs []types.Type var targs []types.Type
@ -190,12 +190,12 @@ func GenericAssignableTo(ctxt *Context, V, T types.Type) bool {
targs = append(targs, vtparams.At(i)) targs = append(targs, vtparams.At(i))
} }
vinst, err := Instantiate(ctxt, V, targs, true) vinst, err := types.Instantiate(ctxt, V, targs, true)
if err != nil { if err != nil {
panic("type parameters should satisfy their own constraints") panic("type parameters should satisfy their own constraints")
} }
tinst, err := Instantiate(ctxt, T, targs, true) tinst, err := types.Instantiate(ctxt, T, targs, true)
if err != nil { if err != nil {
return false return false
} }

View File

@ -108,15 +108,15 @@ func CoreType(T types.Type) types.Type {
// //
// _NormalTerms makes no guarantees about the order of terms, except that it // _NormalTerms makes no guarantees about the order of terms, except that it
// is deterministic. // is deterministic.
func _NormalTerms(typ types.Type) ([]*Term, error) { func _NormalTerms(typ types.Type) ([]*types.Term, error) {
switch typ := typ.(type) { switch typ := typ.(type) {
case *TypeParam: case *types.TypeParam:
return StructuralTerms(typ) return StructuralTerms(typ)
case *Union: case *types.Union:
return UnionTermSet(typ) return UnionTermSet(typ)
case *types.Interface: case *types.Interface:
return InterfaceTermSet(typ) return InterfaceTermSet(typ)
default: default:
return []*Term{NewTerm(false, typ)}, nil return []*types.Term{types.NewTerm(false, typ)}, nil
} }
} }

View File

@ -1,12 +0,0 @@
// Copyright 2021 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build !go1.18
// +build !go1.18
package typeparams
// Enabled reports whether type parameters are enabled in the current build
// environment.
const Enabled = false

View File

@ -1,15 +0,0 @@
// Copyright 2021 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build go1.18
// +build go1.18
package typeparams
// Note: this constant is in a separate file as this is the only acceptable
// diff between the <1.18 API of this package and the 1.18 API.
// Enabled reports whether type parameters are enabled in the current build
// environment.
const Enabled = true

View File

@ -60,7 +60,7 @@ var ErrEmptyTypeSet = errors.New("empty type set")
// //
// StructuralTerms makes no guarantees about the order of terms, except that it // StructuralTerms makes no guarantees about the order of terms, except that it
// is deterministic. // is deterministic.
func StructuralTerms(tparam *TypeParam) ([]*Term, error) { func StructuralTerms(tparam *types.TypeParam) ([]*types.Term, error) {
constraint := tparam.Constraint() constraint := tparam.Constraint()
if constraint == nil { if constraint == nil {
return nil, fmt.Errorf("%s has nil constraint", tparam) 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 // See the documentation of StructuralTerms for more information on
// normalization. // normalization.
func InterfaceTermSet(iface *types.Interface) ([]*Term, error) { func InterfaceTermSet(iface *types.Interface) ([]*types.Term, error) {
return computeTermSet(iface) return computeTermSet(iface)
} }
@ -88,11 +88,11 @@ func InterfaceTermSet(iface *types.Interface) ([]*Term, error) {
// //
// See the documentation of StructuralTerms for more information on // See the documentation of StructuralTerms for more information on
// normalization. // normalization.
func UnionTermSet(union *Union) ([]*Term, error) { func UnionTermSet(union *types.Union) ([]*types.Term, error) {
return computeTermSet(union) 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) tset, err := computeTermSetInternal(typ, make(map[types.Type]*termSet), 0)
if err != nil { if err != nil {
return nil, err return nil, err
@ -103,9 +103,9 @@ func computeTermSet(typ types.Type) ([]*Term, error) {
if tset.terms.isAll() { if tset.terms.isAll() {
return nil, nil return nil, nil
} }
var terms []*Term var terms []*types.Term
for _, term := range tset.terms { for _, term := range tset.terms {
terms = append(terms, NewTerm(term.tilde, term.typ)) terms = append(terms, types.NewTerm(term.tilde, term.typ))
} }
return terms, nil return terms, nil
} }
@ -162,7 +162,7 @@ func computeTermSetInternal(t types.Type, seen map[types.Type]*termSet, depth in
tset.terms = allTermlist tset.terms = allTermlist
for i := 0; i < u.NumEmbeddeds(); i++ { for i := 0; i < u.NumEmbeddeds(); i++ {
embedded := u.EmbeddedType(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) return nil, fmt.Errorf("invalid embedded type %T", embedded)
} }
tset2, err := computeTermSetInternal(embedded, seen, depth+1) 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) 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. // The term set of a union is the union of term sets of its terms.
tset.terms = nil tset.terms = nil
for i := 0; i < u.Len(); i++ { 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 return nil, err
} }
terms = tset2.terms terms = tset2.terms
case *TypeParam, *Union: case *types.TypeParam, *types.Union:
// A stand-alone type parameter or union is not permitted as union // A stand-alone type parameter or union is not permitted as union
// term. // term.
return nil, fmt.Errorf("invalid union term %T", t) 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) return nil, fmt.Errorf("exceeded max term count %d", maxTermCount)
} }
} }
case *TypeParam: case *types.TypeParam:
panic("unreachable") panic("unreachable")
default: default:
// For all other types, the term set is just a single non-tilde term // For all other types, the term set is just a single non-tilde term

View File

@ -1,197 +0,0 @@
// Copyright 2021 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build !go1.18
// +build !go1.18
package typeparams
import (
"go/ast"
"go/token"
"go/types"
)
func unsupported() {
panic("type parameters are unsupported at this go version")
}
// IndexListExpr is a placeholder type, as type parameters are not supported at
// this Go version. Its methods panic on use.
type IndexListExpr struct {
ast.Expr
X ast.Expr // expression
Lbrack token.Pos // position of "["
Indices []ast.Expr // index expressions
Rbrack token.Pos // position of "]"
}
// ForTypeSpec returns an empty field list, as type parameters on not supported
// at this Go version.
func ForTypeSpec(*ast.TypeSpec) *ast.FieldList {
return nil
}
// ForFuncType returns an empty field list, as type parameters are not
// supported at this Go version.
func ForFuncType(*ast.FuncType) *ast.FieldList {
return nil
}
// TypeParam is a placeholder type, as type parameters are not supported at
// this Go version. Its methods panic on use.
type TypeParam struct{ types.Type }
func (*TypeParam) Index() int { unsupported(); return 0 }
func (*TypeParam) Constraint() types.Type { unsupported(); return nil }
func (*TypeParam) Obj() *types.TypeName { unsupported(); return nil }
// TypeParamList is a placeholder for an empty type parameter list.
type TypeParamList struct{}
func (*TypeParamList) Len() int { return 0 }
func (*TypeParamList) At(int) *TypeParam { unsupported(); return nil }
// TypeList is a placeholder for an empty type list.
type TypeList struct{}
func (*TypeList) Len() int { return 0 }
func (*TypeList) At(int) types.Type { unsupported(); return nil }
// NewTypeParam is unsupported at this Go version, and panics.
func NewTypeParam(name *types.TypeName, constraint types.Type) *TypeParam {
unsupported()
return nil
}
// SetTypeParamConstraint is unsupported at this Go version, and panics.
func SetTypeParamConstraint(tparam *TypeParam, constraint types.Type) {
unsupported()
}
// NewSignatureType calls types.NewSignature, panicking if recvTypeParams or
// typeParams is non-empty.
func NewSignatureType(recv *types.Var, recvTypeParams, typeParams []*TypeParam, params, results *types.Tuple, variadic bool) *types.Signature {
if len(recvTypeParams) != 0 || len(typeParams) != 0 {
panic("signatures cannot have type parameters at this Go version")
}
return types.NewSignature(recv, params, results, variadic)
}
// ForSignature returns an empty slice.
func ForSignature(*types.Signature) *TypeParamList {
return nil
}
// RecvTypeParams returns a nil slice.
func RecvTypeParams(sig *types.Signature) *TypeParamList {
return nil
}
// IsComparable returns false, as no interfaces are type-restricted at this Go
// version.
func IsComparable(*types.Interface) bool {
return false
}
// IsMethodSet returns true, as no interfaces are type-restricted at this Go
// version.
func IsMethodSet(*types.Interface) bool {
return true
}
// IsImplicit returns false, as no interfaces are implicit at this Go version.
func IsImplicit(*types.Interface) bool {
return false
}
// MarkImplicit does nothing, because this Go version does not have implicit
// interfaces.
func MarkImplicit(*types.Interface) {}
// ForNamed returns an empty type parameter list, as type parameters are not
// supported at this Go version.
func ForNamed(*types.Named) *TypeParamList {
return nil
}
// SetForNamed panics if tparams is non-empty.
func SetForNamed(_ *types.Named, tparams []*TypeParam) {
if len(tparams) > 0 {
unsupported()
}
}
// NamedTypeArgs returns nil.
func NamedTypeArgs(*types.Named) *TypeList {
return nil
}
// NamedTypeOrigin is the identity method at this Go version.
func NamedTypeOrigin(named *types.Named) *types.Named {
return named
}
// Term holds information about a structural type restriction.
type Term struct {
tilde bool
typ types.Type
}
func (m *Term) Tilde() bool { return m.tilde }
func (m *Term) Type() types.Type { return m.typ }
func (m *Term) String() string {
pre := ""
if m.tilde {
pre = "~"
}
return pre + m.typ.String()
}
// NewTerm is unsupported at this Go version, and panics.
func NewTerm(tilde bool, typ types.Type) *Term {
return &Term{tilde, typ}
}
// Union is a placeholder type, as type parameters are not supported at this Go
// version. Its methods panic on use.
type Union struct{ types.Type }
func (*Union) Len() int { return 0 }
func (*Union) Term(i int) *Term { unsupported(); return nil }
// NewUnion is unsupported at this Go version, and panics.
func NewUnion(terms []*Term) *Union {
unsupported()
return nil
}
// InitInstanceInfo is a noop at this Go version.
func InitInstanceInfo(*types.Info) {}
// Instance is a placeholder type, as type parameters are not supported at this
// Go version.
type Instance struct {
TypeArgs *TypeList
Type types.Type
}
// GetInstances returns a nil map, as type parameters are not supported at this
// Go version.
func GetInstances(info *types.Info) map[*ast.Ident]Instance { return nil }
// Context is a placeholder type, as type parameters are not supported at
// this Go version.
type Context struct{}
// NewContext returns a placeholder Context instance.
func NewContext() *Context {
return &Context{}
}
// Instantiate is unsupported on this Go version, and panics.
func Instantiate(ctxt *Context, typ types.Type, targs []types.Type, validate bool) (types.Type, error) {
unsupported()
return nil, nil
}

View File

@ -1,151 +0,0 @@
// Copyright 2021 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build go1.18
// +build go1.18
package typeparams
import (
"go/ast"
"go/types"
)
// IndexListExpr is an alias for ast.IndexListExpr.
type IndexListExpr = ast.IndexListExpr
// ForTypeSpec returns n.TypeParams.
func ForTypeSpec(n *ast.TypeSpec) *ast.FieldList {
if n == nil {
return nil
}
return n.TypeParams
}
// ForFuncType returns n.TypeParams.
func ForFuncType(n *ast.FuncType) *ast.FieldList {
if n == nil {
return nil
}
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 {
return types.NewTypeParam(name, constraint)
}
// SetTypeParamConstraint calls tparam.SetConstraint(constraint).
func SetTypeParamConstraint(tparam *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 {
return types.NewSignatureType(recv, recvTypeParams, typeParams, params, results, variadic)
}
// ForSignature returns sig.TypeParams()
func ForSignature(sig *types.Signature) *TypeParamList {
return sig.TypeParams()
}
// RecvTypeParams returns sig.RecvTypeParams().
func RecvTypeParams(sig *types.Signature) *TypeParamList {
return sig.RecvTypeParams()
}
// IsComparable calls iface.IsComparable().
func IsComparable(iface *types.Interface) bool {
return iface.IsComparable()
}
// IsMethodSet calls iface.IsMethodSet().
func IsMethodSet(iface *types.Interface) bool {
return iface.IsMethodSet()
}
// IsImplicit calls iface.IsImplicit().
func IsImplicit(iface *types.Interface) bool {
return iface.IsImplicit()
}
// MarkImplicit calls iface.MarkImplicit().
func MarkImplicit(iface *types.Interface) {
iface.MarkImplicit()
}
// ForNamed extracts the (possibly empty) type parameter object list from
// named.
func ForNamed(named *types.Named) *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) {
n.SetTypeParams(tparams)
}
// NamedTypeArgs returns named.TypeArgs().
func NamedTypeArgs(named *types.Named) *TypeList {
return named.TypeArgs()
}
// NamedTypeOrigin returns named.Orig().
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 {
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 {
return types.NewUnion(terms)
}
// InitInstanceInfo initializes info to record information about type and
// function instances.
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 {
return info.Instances
}
// Context is an alias for types.Context.
type Context = types.Context
// NewContext calls types.NewContext.
func NewContext() *Context {
return types.NewContext()
}
// Instantiate calls types.Instantiate.
func Instantiate(ctxt *Context, typ types.Type, targs []types.Type, validate bool) (types.Type, error) {
return types.Instantiate(ctxt, typ, targs, validate)
}

View File

@ -2,11 +2,14 @@
// Use of this source code is governed by a BSD-style // Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
//go:build !go1.22
// +build !go1.22
package versions package versions
// Note: If we use build tags to use go/versions when go >=1.22,
// we run into go.dev/issue/53737. Under some operations users would see an
// import of "go/versions" even if they would not compile the file.
// For example, during `go get -u ./...` (go.dev/issue/64490) we do not try to include
// For this reason, this library just a clone of go/versions for the moment.
// Lang returns the Go language version for version x. // Lang returns the Go language version for version x.
// If x is not a valid version, Lang returns the empty string. // If x is not a valid version, Lang returns the empty string.
// For example: // For example:

View File

@ -1,38 +0,0 @@
// Copyright 2023 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build go1.22
// +build go1.22
package versions
import (
"go/version"
)
// Lang returns the Go language version for version x.
// If x is not a valid version, Lang returns the empty string.
// For example:
//
// Lang("go1.21rc2") = "go1.21"
// Lang("go1.21.2") = "go1.21"
// Lang("go1.21") = "go1.21"
// Lang("go1") = "go1"
// Lang("bad") = ""
// Lang("1.21") = ""
func Lang(x string) string { return version.Lang(x) }
// Compare returns -1, 0, or +1 depending on whether
// x < y, x == y, or x > y, interpreted as Go versions.
// The versions x and y must begin with a "go" prefix: "go1.21" not "1.21".
// Invalid versions, including the empty string, compare less than
// valid versions and equal to each other.
// The language version "go1.21" compares less than the
// release candidate and eventual releases "go1.21rc1" and "go1.21.0".
// Custom toolchain suffixes are ignored during comparison:
// "go1.21.0" and "go1.21.0-bigcorp" are equal.
func Compare(x, y string) int { return version.Compare(x, y) }
// IsValid reports whether the version x is valid.
func IsValid(x string) bool { return version.IsValid(x) }

4
vendor/modules.txt vendored
View File

@ -631,7 +631,7 @@ golang.org/x/crypto/pbkdf2
golang.org/x/crypto/salsa20/salsa golang.org/x/crypto/salsa20/salsa
golang.org/x/crypto/scrypt golang.org/x/crypto/scrypt
golang.org/x/crypto/sha3 golang.org/x/crypto/sha3
# golang.org/x/exp v0.0.0-20231226003508-02704c960a9b # golang.org/x/exp v0.0.0-20240119083558-1b970713d09a
## explicit; go 1.20 ## explicit; go 1.20
golang.org/x/exp/constraints golang.org/x/exp/constraints
golang.org/x/exp/maps golang.org/x/exp/maps
@ -672,7 +672,7 @@ golang.org/x/text/secure/bidirule
golang.org/x/text/transform golang.org/x/text/transform
golang.org/x/text/unicode/bidi golang.org/x/text/unicode/bidi
golang.org/x/text/unicode/norm golang.org/x/text/unicode/norm
# golang.org/x/tools v0.16.0 # golang.org/x/tools v0.17.0
## explicit; go 1.18 ## explicit; go 1.18
golang.org/x/tools/cmd/stringer golang.org/x/tools/cmd/stringer
golang.org/x/tools/go/gcexportdata golang.org/x/tools/go/gcexportdata