]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile/internal/types2: implement TypeList.String (debugging support)
authorRobert Griesemer <gri@golang.org>
Thu, 26 Aug 2021 18:56:52 +0000 (11:56 -0700)
committerRobert Griesemer <gri@golang.org>
Thu, 26 Aug 2021 20:39:50 +0000 (20:39 +0000)
Change-Id: Iaa203def3dac94a7d5ff6120e89315c3d7977ee1
Reviewed-on: https://go-review.googlesource.com/c/go/+/345471
Trust: Robert Griesemer <gri@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
src/cmd/compile/internal/types2/instantiate.go
src/cmd/compile/internal/types2/subst.go
src/cmd/compile/internal/types2/typelists.go

index f9cde24dfc803b9ba154fd08c7fa6bcf183e2845..4113d248b8f0fb5a41195ae00c803bf2a177bb95 100644 (file)
@@ -75,7 +75,7 @@ func Instantiate(env *Environment, typ Type, targs []Type, validate bool) (Type,
 func (check *Checker) instantiate(pos syntax.Pos, typ Type, targs []Type, posList []syntax.Pos) (res Type) {
        assert(check != nil)
        if check.conf.Trace {
-               check.trace(pos, "-- instantiating %s with %s", typ, typeListString(targs))
+               check.trace(pos, "-- instantiating %s with %s", typ, NewTypeList(targs))
                check.indent++
                defer func() {
                        check.indent--
index ff8dd13b6d717cac35f32b6368c5f8703011568a..7c33e7ade4095fcb3814836e4691f6882e308532 100644 (file)
@@ -281,12 +281,6 @@ func instantiatedHash(typ *Named, targs []Type) string {
        return string(res[:i])
 }
 
-func typeListString(list []Type) string {
-       var buf bytes.Buffer
-       writeTypeList(&buf, list, nil, nil)
-       return buf.String()
-}
-
 // typOrNil is like typ but if the argument is nil it is replaced with Typ[Invalid].
 // A nil type may appear in pathological cases such as type T[P any] []func(_ T([]_))
 // where an array/slice element is accessed before it is set up.
index 3258a5e9f87301809fd4227bf6ce992afbfb3ee1..c3befb077fc79d245d2a1aacd3526f92cc8ce46a 100644 (file)
@@ -4,6 +4,8 @@
 
 package types2
 
+import "bytes"
+
 // TParamList holds a list of type parameters.
 type TParamList struct{ tparams []*TypeParam }
 
@@ -52,6 +54,17 @@ func (l *TypeList) list() []Type {
        return l.types
 }
 
+func (l *TypeList) String() string {
+       if l == nil || len(l.types) == 0 {
+               return "[]"
+       }
+       var buf bytes.Buffer
+       buf.WriteByte('[')
+       writeTypeList(&buf, l.types, nil, nil)
+       buf.WriteByte(']')
+       return buf.String()
+}
+
 // ----------------------------------------------------------------------------
 // Implementation