internal/typeparams: use NewSignatureType, IsMethodSet, and Context

Update the internal/typeparams API proxy following CL 352615, CL
352616, and CL 353089.

Change-Id: Ib65a1876c7820945189e1dc953e1a82e98547a09
Reviewed-on: https://go-review.googlesource.com/c/tools/+/352852
Trust: Robert Findley <rfindley@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Robert Griesemer <gri@golang.org>
diff --git a/go/internal/gcimporter/iimport.go b/go/internal/gcimporter/iimport.go
index 1fcc87e..0c56eb2 100644
--- a/go/internal/gcimporter/iimport.go
+++ b/go/internal/gcimporter/iimport.go
@@ -352,8 +352,7 @@
 		if tag == 'G' {
 			tparams = r.tparamList()
 		}
-		sig := r.signature(nil)
-		typeparams.SetForSignature(sig, tparams)
+		sig := r.signature(nil, nil, tparams)
 		r.declare(types.NewFunc(pos, r.currPkg, name, sig))
 
 	case 'T', 'U':
@@ -377,12 +376,12 @@
 				mpos := r.pos()
 				mname := r.ident()
 				recv := r.param()
-				msig := r.signature(recv)
 
 				// If the receiver has any targs, set those as the
 				// rparams of the method (since those are the
 				// typeparams being used in the method sig/body).
-				targs := typeparams.NamedTypeArgs(baseType(msig.Recv().Type()))
+				targs := typeparams.NamedTypeArgs(baseType(recv.Type()))
+				var rparams []*typeparams.TypeParam
 				if targs.Len() > 0 {
 					rparams := make([]*typeparams.TypeParam, targs.Len())
 					for i := range rparams {
@@ -392,8 +391,8 @@
 						// library importer stricter.
 						rparams[i] = targs.At(i).(*typeparams.TypeParam)
 					}
-					typeparams.SetRecvTypeParams(msig, rparams)
 				}
+				msig := r.signature(recv, rparams, nil)
 
 				named.AddMethod(types.NewFunc(mpos, r.currPkg, mname, msig))
 			}
@@ -653,7 +652,7 @@
 		return types.NewMap(r.typ(), r.typ())
 	case signatureType:
 		r.currPkg = r.pkg()
-		return r.signature(nil)
+		return r.signature(nil, nil, nil)
 
 	case structType:
 		r.currPkg = r.pkg()
@@ -693,7 +692,7 @@
 				recv = types.NewVar(token.NoPos, r.currPkg, "", base)
 			}
 
-			msig := r.signature(recv)
+			msig := r.signature(recv, nil, nil)
 			methods[i] = types.NewFunc(mpos, r.currPkg, mname, msig)
 		}
 
@@ -750,11 +749,11 @@
 	return itag(r.uint64())
 }
 
-func (r *importReader) signature(recv *types.Var) *types.Signature {
+func (r *importReader) signature(recv *types.Var, rparams []*typeparams.TypeParam, tparams []*typeparams.TypeParam) *types.Signature {
 	params := r.paramList()
 	results := r.paramList()
 	variadic := params.Len() > 0 && r.bool()
-	return types.NewSignature(recv, params, results, variadic)
+	return typeparams.NewSignatureType(recv, rparams, tparams, params, results, variadic)
 }
 
 func (r *importReader) tparamList() []*typeparams.TypeParam {
diff --git a/internal/typeparams/typeparams_go117.go b/internal/typeparams/typeparams_go117.go
index ae153ab..2145b05 100644
--- a/internal/typeparams/typeparams_go117.go
+++ b/internal/typeparams/typeparams_go117.go
@@ -91,40 +91,35 @@
 	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
 }
 
-// SetForSignature panics if tparams is non-empty.
-func SetForSignature(_ *types.Signature, tparams []*TypeParam) {
-	if len(tparams) > 0 {
-		unsupported()
-	}
-}
-
 // RecvTypeParams returns a nil slice.
 func RecvTypeParams(sig *types.Signature) *TypeParamList {
 	return nil
 }
 
-// SetRecvTypeParams panics if rparams is non-empty.
-func SetRecvTypeParams(sig *types.Signature, rparams []*TypeParam) {
-	if len(rparams) > 0 {
-		unsupported()
-	}
-}
-
 // IsComparable returns false, as no interfaces are type-restricted at this Go
 // version.
 func IsComparable(*types.Interface) bool {
 	return false
 }
 
-// IsConstraint returns false, as no interfaces are type-restricted at this Go
+// IsMethodSet returns true, as no interfaces are type-restricted at this Go
 // version.
-func IsConstraint(*types.Interface) bool {
-	return false
+func IsMethodSet(*types.Interface) bool {
+	return true
 }
 
 // ForNamed returns an empty type parameter list, as type parameters are not
@@ -185,12 +180,12 @@
 // version.
 func GetInstance(*types.Info, *ast.Ident) (*TypeList, types.Type) { return nil, nil }
 
-// Environment is a placeholder type, as type parameters are not supported at
+// Context is a placeholder type, as type parameters are not supported at
 // this Go version.
-type Environment struct{}
+type Context struct{}
 
 // Instantiate is unsupported on this Go version, and panics.
-func Instantiate(env *Environment, typ types.Type, targs []types.Type, validate bool) (types.Type, error) {
+func Instantiate(ctxt *Context, typ types.Type, targs []types.Type, validate bool) (types.Type, error) {
 	unsupported()
 	return nil, nil
 }
diff --git a/internal/typeparams/typeparams_go118.go b/internal/typeparams/typeparams_go118.go
index aca937a..713efbb 100644
--- a/internal/typeparams/typeparams_go118.go
+++ b/internal/typeparams/typeparams_go118.go
@@ -96,34 +96,29 @@
 	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()
 }
 
-// SetForSignature calls sig.SetTypeParams(tparams)
-func SetForSignature(sig *types.Signature, tparams []*TypeParam) {
-	sig.SetTypeParams(tparams)
-}
-
 // RecvTypeParams returns sig.RecvTypeParams().
 func RecvTypeParams(sig *types.Signature) *TypeParamList {
 	return sig.RecvTypeParams()
 }
 
-// SetRecvTypeParams calls sig.SetRecvTypeParams(rparams).
-func SetRecvTypeParams(sig *types.Signature, rparams []*TypeParam) {
-	sig.SetRecvTypeParams(rparams)
-}
-
 // IsComparable calls iface.IsComparable().
 func IsComparable(iface *types.Interface) bool {
 	return iface.IsComparable()
 }
 
-// IsConstraint calls iface.IsConstraint().
-func IsConstraint(iface *types.Interface) bool {
-	return iface.IsConstraint()
+// IsMethodSet calls iface.IsMethodSet().
+func IsMethodSet(iface *types.Interface) bool {
+	return iface.IsMethodSet()
 }
 
 // ForNamed extracts the (possibly empty) type parameter object list from
@@ -181,10 +176,10 @@
 	return nil, nil
 }
 
-// Environment is an alias for types.Environment.
-type Environment = types.Environment
+// Context is an alias for types.Context.
+type Context = types.Context
 
 // Instantiate calls types.Instantiate.
-func Instantiate(env *Environment, typ types.Type, targs []types.Type, validate bool) (types.Type, error) {
-	return types.Instantiate(env, typ, targs, validate)
+func Instantiate(ctxt *Context, typ types.Type, targs []types.Type, validate bool) (types.Type, error) {
+	return types.Instantiate(ctxt, typ, targs, validate)
 }