From 1d9a1f67d537309f80740b16ef619500fb55db16 Mon Sep 17 00:00:00 2001 From: Matthew Dempsky Date: Fri, 25 Dec 2020 00:12:15 -0800 Subject: [PATCH] [dev.regabi] cmd/compile: don't emit reflect data for method types Within the compiler, we represent the type of methods as a special "method" type, where the receiver parameter type is kept separate from the other parameters. This is convenient for operations like testing whether a type implements an interface, where we want to ignore the receiver type. These method types don't properly exist within the Go language though: there are only "function" types. E.g., method expressions (expressions of the form Type.Method) are simply functions with the receiver parameter prepended to the regular parameter list. However, the compiler backend is currently a little sloppy in its handling of these types, which results in temporary variables being declared as having "method" type, which then end up in DWARF data. This is probably harmless in practice, but it's still wrong. The proper solution is to fix the backend code so that we use correct types everywhere, and the next CL does exactly this. But as it fixes the DWARF output, so it fails toolstash -cmp. So this prelim CL bandages over the issue in a way that generates the same output as that proper fix. Change-Id: I37a127bc8365c3a79ce513bdb3cfccb945912762 Reviewed-on: https://go-review.googlesource.com/c/go/+/280293 Trust: Matthew Dempsky Run-TryBot: Matthew Dempsky TryBot-Result: Go Bot Reviewed-by: Cuong Manh Le --- src/cmd/compile/internal/reflectdata/reflect.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/cmd/compile/internal/reflectdata/reflect.go b/src/cmd/compile/internal/reflectdata/reflect.go index 3fbf6f337f..27ee09ade2 100644 --- a/src/cmd/compile/internal/reflectdata/reflect.go +++ b/src/cmd/compile/internal/reflectdata/reflect.go @@ -835,6 +835,10 @@ func TypeSym(t *types.Type) *types.Sym { if t == nil || (t.IsPtr() && t.Elem() == nil) || t.IsUntyped() { base.Fatalf("typenamesym %v", t) } + if t.Kind() == types.TFUNC && t.Recv() != nil { + // TODO(mdempsky): Fix callers and make fatal. + t = typecheck.NewMethodType(t, t.Recv().Type) + } s := types.TypeSym(t) signatmu.Lock() NeedRuntimeType(t) -- 2.50.0