]> Cypherpunks repositories - gostls13.git/commitdiff
[dev.typeparams] go/types: use the TParams API consistently
authorRob Findley <rfindley@google.com>
Wed, 21 Jul 2021 15:26:00 +0000 (11:26 -0400)
committerRobert Findley <rfindley@google.com>
Thu, 22 Jul 2021 17:24:27 +0000 (17:24 +0000)
Even internally to the type checker, we should use the TParams and
RParams methods instead of accessing fields directly, as TParams may be
lazily expanded, and in the future we may want to pack receiver and
function type parameters into a single field on Signature.

We should also not differentiate a nil *TParamList from an empty
*TParamList.

Change-Id: I85c616e6c708a89b6a5eb1e69fe0b014276eda90
Reviewed-on: https://go-review.googlesource.com/c/go/+/336251
Trust: Robert Findley <rfindley@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
Reviewed-by: Robert Griesemer <gri@golang.org>
src/go/types/call.go
src/go/types/decl.go
src/go/types/subst.go
src/go/types/typestring.go

index 96d0429af95237d0f2e6efa48c44523e033ddd86..16b8e4eb7c43f6f865b756998c90d1fef8c10f90 100644 (file)
@@ -61,7 +61,7 @@ func (check *Checker) funcInst(x *operand, ix *typeparams.IndexExpr) {
 
        // instantiate function signature
        res := check.Instantiate(x.Pos(), sig, targs, poslist, true).(*Signature)
-       assert(res.tparams == nil) // signature is not generic anymore
+       assert(res.TParams().Len() == 0) // signature is not generic anymore
        if inferred {
                check.recordInferred(ix.Orig, targs, res)
        }
@@ -334,7 +334,7 @@ func (check *Checker) arguments(call *ast.CallExpr, sig *Signature, targs []Type
 
                // compute result signature
                rsig = check.Instantiate(call.Pos(), sig, targs, nil, true).(*Signature)
-               assert(rsig.tparams == nil) // signature is not generic anymore
+               assert(rsig.TParams().Len() == 0) // signature is not generic anymore
                check.recordInferred(call, targs, rsig)
 
                // Optimization: Only if the parameter list was adjusted do we
index be7753d9d18744276c52536a13ee69f195584172..ad88c302820ace75d83f079fff34369a4430f442 100644 (file)
@@ -625,7 +625,7 @@ func (check *Checker) typeDecl(obj *TypeName, tdecl *ast.TypeSpec, def *Named) {
        named.underlying = under(named)
 
        // If the RHS is a type parameter, it must be from this type declaration.
-       if tpar, _ := named.underlying.(*TypeParam); tpar != nil && tparamIndex(named.tparams.list(), tpar) < 0 {
+       if tpar, _ := named.underlying.(*TypeParam); tpar != nil && tparamIndex(named.TParams().list(), tpar) < 0 {
                check.errorf(tdecl.Type, _Todo, "cannot use function type parameter %s as RHS in type declaration", tpar)
                named.underlying = Typ[Invalid]
        }
index 197d79b6a8da7820045fb2199e4f9d22cfdf402a..60fc7ae8192e4b4108ba201f5c8712c1d3db6594 100644 (file)
@@ -193,7 +193,7 @@ func (subst *subster) typ(typ Type) Type {
                        }
                }
 
-               if t.TParams() == nil {
+               if t.TParams().Len() == 0 {
                        dump(">>> %s is not parameterized", t)
                        return t // type is not parameterized
                }
index 18c436e3efb0f9f53a8b12103d07ceef1228447d..6a9e7f2ac89424375d09bf542cbc6d44fb87e4c4 100644 (file)
@@ -276,7 +276,7 @@ func writeType(buf *bytes.Buffer, typ Type, qf Qualifier, visited []Type) {
                        buf.WriteByte('[')
                        writeTypeList(buf, t.targs, qf, visited)
                        buf.WriteByte(']')
-               } else if t.TParams() != nil {
+               } else if t.TParams().Len() != 0 {
                        // parameterized type
                        writeTParamList(buf, t.TParams().list(), qf, visited)
                }
@@ -424,7 +424,7 @@ func WriteSignature(buf *bytes.Buffer, sig *Signature, qf Qualifier) {
 }
 
 func writeSignature(buf *bytes.Buffer, sig *Signature, qf Qualifier, visited []Type) {
-       if sig.tparams != nil {
+       if sig.TParams().Len() != 0 {
                writeTParamList(buf, sig.TParams().list(), qf, visited)
        }