aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/compile/internal/types2/signature.go
diff options
context:
space:
mode:
authorRobert Griesemer <gri@golang.org>2021-07-28 15:29:19 -0700
committerRobert Griesemer <gri@golang.org>2021-07-29 21:05:45 +0000
commit27552e9172c5a9f7bbd8428c6e30eac14bb5e0b0 (patch)
tree725803dfd6ba089389abe0a83f9c83e0eeff6f6e /src/cmd/compile/internal/types2/signature.go
parentaf903261e7e6af8ce932433cf87a60381781bfb9 (diff)
downloadgo-27552e9172c5a9f7bbd8428c6e30eac14bb5e0b0.tar.gz
go-27552e9172c5a9f7bbd8428c6e30eac14bb5e0b0.zip
[dev.typeparams] cmd/compile: set type parameter indices when they are bound
This is a port of CL 336249 with adjustments due to slightly different handling of type parameter declaration in types2. The CL also contains adjustments to the compiler front-end. With this change it is not necessary to export type parameter indices. Filed issue #47451 so we don't forget. Change-Id: I2834f7be313fcb4763dff2a9058f1983ee6a81b3 Reviewed-on: https://go-review.googlesource.com/c/go/+/338192 Trust: Robert Griesemer <gri@golang.org> Run-TryBot: Robert Griesemer <gri@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Robert Findley <rfindley@google.com>
Diffstat (limited to 'src/cmd/compile/internal/types2/signature.go')
-rw-r--r--src/cmd/compile/internal/types2/signature.go31
1 files changed, 16 insertions, 15 deletions
diff --git a/src/cmd/compile/internal/types2/signature.go b/src/cmd/compile/internal/types2/signature.go
index fa5c3f7a9b..832f37a6af 100644
--- a/src/cmd/compile/internal/types2/signature.go
+++ b/src/cmd/compile/internal/types2/signature.go
@@ -19,8 +19,8 @@ type Signature struct {
// and store it in the Func Object) because when type-checking a function
// literal we call the general type checker which returns a general Type.
// We then unpack the *Signature and use the scope for the literal body.
- rparams []*TypeName // receiver type parameters from left to right; or nil
- tparams []*TypeName // type parameters from left to right; or nil
+ rparams *TypeParams // receiver type parameters from left to right, or nil
+ tparams *TypeParams // type parameters from left to right, or nil
scope *Scope // function scope, present for package-local signatures
recv *Var // nil if not a method
params *Tuple // (incoming) parameters from left to right; or nil
@@ -54,16 +54,16 @@ func NewSignature(recv *Var, params, results *Tuple, variadic bool) *Signature {
func (s *Signature) Recv() *Var { return s.recv }
// TParams returns the type parameters of signature s, or nil.
-func (s *Signature) TParams() []*TypeName { return s.tparams }
-
-// RParams returns the receiver type params of signature s, or nil.
-func (s *Signature) RParams() []*TypeName { return s.rparams }
+func (s *Signature) TParams() *TypeParams { return s.tparams }
// SetTParams sets the type parameters of signature s.
-func (s *Signature) SetTParams(tparams []*TypeName) { s.tparams = tparams }
+func (s *Signature) SetTParams(tparams []*TypeName) { s.tparams = bindTParams(tparams) }
+
+// RParams returns the receiver type parameters of signature s, or nil.
+func (s *Signature) RParams() *TypeParams { return s.rparams }
// SetRParams sets the receiver type params of signature s.
-func (s *Signature) SetRParams(rparams []*TypeName) { s.rparams = rparams }
+func (s *Signature) SetRParams(rparams []*TypeName) { s.rparams = bindTParams(rparams) }
// Params returns the parameters of signature s, or nil.
func (s *Signature) Params() *Tuple { return s.params }
@@ -119,10 +119,11 @@ func (check *Checker) funcType(sig *Signature, recvPar *syntax.Field, tparams []
// blank identifiers were found => use rewritten receiver type
recvTyp = isubst(recvPar.Type, smap)
}
- sig.rparams = make([]*TypeName, len(rparams))
+ rlist := make([]*TypeName, len(rparams))
for i, rparam := range rparams {
- sig.rparams[i] = check.declareTypeParam(i, rparam)
+ rlist[i] = check.declareTypeParam(rparam)
}
+ sig.rparams = bindTParams(rlist)
// determine receiver type to get its type parameters
// and the respective type parameter bounds
var recvTParams []*TypeName
@@ -132,19 +133,19 @@ func (check *Checker) funcType(sig *Signature, recvPar *syntax.Field, tparams []
// again when we type-check the signature.
// TODO(gri) maybe the receiver should be marked as invalid instead?
if recv := asNamed(check.genericType(rname, false)); recv != nil {
- recvTParams = recv.TParams()
+ recvTParams = recv.TParams().list()
}
}
// provide type parameter bounds
// - only do this if we have the right number (otherwise an error is reported elsewhere)
- if len(sig.rparams) == len(recvTParams) {
+ if sig.RParams().Len() == len(recvTParams) {
// We have a list of *TypeNames but we need a list of Types.
- list := make([]Type, len(sig.rparams))
- for i, t := range sig.rparams {
+ list := make([]Type, sig.RParams().Len())
+ for i, t := range sig.RParams().list() {
list[i] = t.typ
}
smap := makeSubstMap(recvTParams, list)
- for i, tname := range sig.rparams {
+ for i, tname := range sig.RParams().list() {
bound := recvTParams[i].typ.(*TypeParam).bound
// bound is (possibly) parameterized in the context of the
// receiver type declaration. Substitute parameters for the