go/internal/gcimporter: remove support for type parameters subscripts
Now that the compiler no longer includes subscripts in its export data,
we can remove support for parsing them in the gcimporter.
Make this change, as well as add support for exporting the new names to
iexport.go (tests fail if these changes are made in separate CLs). This
proved a bit tricky to debug, so along the way add some hooks for easier
tracing of import/export.
Fix a bug in iimport.go where rparams were being shadowed, and fix the
export tests to actually compare methods.
Change-Id: Ie08aa5e5ee971d357d352b8f4a4673f6d2a38779
Reviewed-on: https://go-review.googlesource.com/c/tools/+/356534
Trust: Robert Findley <rfindley@google.com>
Trust: Dan Scales <danscales@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Dan Scales <danscales@google.com>
diff --git a/go/internal/gcimporter/bexport_test.go b/go/internal/gcimporter/bexport_test.go
index 7300ba8..8a80427 100644
--- a/go/internal/gcimporter/bexport_test.go
+++ b/go/internal/gcimporter/bexport_test.go
@@ -15,6 +15,7 @@
"path/filepath"
"reflect"
"runtime"
+ "sort"
"strings"
"testing"
@@ -242,6 +243,32 @@
if err := equalTypeArgs(typeparams.NamedTypeArgs(x), typeparams.NamedTypeArgs(y)); err != nil {
return fmt.Errorf("type arguments: %s", err)
}
+ if x.NumMethods() != y.NumMethods() {
+ return fmt.Errorf("unequal methods: %d vs %d",
+ x.NumMethods(), y.NumMethods())
+ }
+ // Unfortunately method sorting is not canonical, so sort before comparing.
+ var xms, yms []*types.Func
+ for i := 0; i < x.NumMethods(); i++ {
+ xms = append(xms, x.Method(i))
+ yms = append(yms, y.Method(i))
+ }
+ for _, ms := range [][]*types.Func{xms, yms} {
+ sort.Slice(ms, func(i, j int) bool {
+ return ms[i].Name() < ms[j].Name()
+ })
+ }
+ for i, xm := range xms {
+ ym := yms[i]
+ if xm.Name() != ym.Name() {
+ return fmt.Errorf("mismatched %dth method: %s vs %s", i, xm, ym)
+ }
+ // Calling equalType here leads to infinite recursion, so just compare
+ // strings.
+ if sanitizeName(xm.String()) != sanitizeName(ym.String()) {
+ return fmt.Errorf("unequal methods: %s vs %s", x, y)
+ }
+ }
case *types.Pointer:
y := y.(*types.Pointer)
if err := equalType(x.Elem(), y.Elem()); err != nil {