aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/compile/internal/typecheck/iimport.go
diff options
context:
space:
mode:
authorDan Scales <danscales@google.com>2021-08-22 08:58:24 -0700
committerDan Scales <danscales@google.com>2021-08-24 18:30:13 +0000
commit5b64381155a779d5392f015e08111906c6e35738 (patch)
tree9085a1a8fcdeaf7f1f144ba1521258abc8f24620 /src/cmd/compile/internal/typecheck/iimport.go
parent4a9f0cec2918c855a23d5581c0b1da95eb11dd17 (diff)
downloadgo-5b64381155a779d5392f015e08111906c6e35738.tar.gz
go-5b64381155a779d5392f015e08111906c6e35738.zip
cmd/compile: fix naming of types inside instantiations
Issues 47713 and 47877 were both due to problems with the names used for instantiated functions/methods, which must be in sync with the names used by types2. - Switched to using NameString() for writing out type arguments in instantiation names. This ensures that we are always adding the package to type names even for the local package. Previously, we were explicitly adding the package name for local packages, but that doesn't handle the case when the local type is embedded inside a pointer or slice type. By switching to NameString(), we fix #47713. - types1 and types2 write out 'interface {' differently (vs. 'interface{') and we were already handling that. But we needed to add similar code to handle 'struct {' vs 'struct{'. This fixes issue #47877. While fixing these bugs, I also moved some duplicated code (which include some of the changes above) into a common function addTargs(). I also moved InstType() name to subr.go, and renamed: MakeInstName -> MakeFuncInstSym and MakeDictName -> MakeDictSym. Also removed a couple of ".inst..inst." prefix checks which are irrelvant now, since we don't add ".inst." anymore to function instantiations. Fixes #47713 Fixes #47877 Fixes #47922 Change-Id: I19e9a073451f3ababd8ec31b6608cd79ba8cba36 Reviewed-on: https://go-review.googlesource.com/c/go/+/344613 Trust: Dan Scales <danscales@google.com> Reviewed-by: Keith Randall <khr@golang.org>
Diffstat (limited to 'src/cmd/compile/internal/typecheck/iimport.go')
-rw-r--r--src/cmd/compile/internal/typecheck/iimport.go29
1 files changed, 1 insertions, 28 deletions
diff --git a/src/cmd/compile/internal/typecheck/iimport.go b/src/cmd/compile/internal/typecheck/iimport.go
index 2e3fdbc1bc..a1a3ac3e8a 100644
--- a/src/cmd/compile/internal/typecheck/iimport.go
+++ b/src/cmd/compile/internal/typecheck/iimport.go
@@ -8,7 +8,6 @@
package typecheck
import (
- "bytes"
"encoding/binary"
"fmt"
"go/constant"
@@ -1751,32 +1750,6 @@ func builtinCall(pos src.XPos, op ir.Op) *ir.CallExpr {
return ir.NewCallExpr(pos, ir.OCALL, ir.NewIdent(base.Pos, types.BuiltinPkg.Lookup(ir.OpNames[op])), nil)
}
-// InstTypeName creates a name for an instantiated type, based on the name of the
-// generic type and the type args.
-func InstTypeName(name string, targs []*types.Type) string {
- b := bytes.NewBufferString(name)
- b.WriteByte('[')
- for i, targ := range targs {
- if i > 0 {
- b.WriteByte(',')
- }
- // WriteString() does not include the package name for the local
- // package, but we want it to make sure type arguments (including
- // type params) are uniquely specified.
- if targ.Sym() != nil && targ.Sym().Pkg == types.LocalPkg {
- b.WriteString(targ.Sym().Pkg.Name)
- b.WriteByte('.')
- }
- // types1 uses "interface {" and types2 uses "interface{" - convert
- // to consistent types2 format.
- tstring := targ.String()
- tstring = strings.Replace(tstring, "interface {", "interface{", -1)
- b.WriteString(tstring)
- }
- b.WriteByte(']')
- return b.String()
-}
-
// NewIncompleteNamedType returns a TFORW type t with name specified by sym, such
// that t.nod and sym.Def are set correctly.
func NewIncompleteNamedType(pos src.XPos, sym *types.Sym) *types.Type {
@@ -1879,7 +1852,7 @@ func substInstType(t *types.Type, baseType *types.Type, targs []*types.Type) {
}
t2 := msubst.Typ(f.Type)
oldsym := f.Nname.Sym()
- newsym := MakeInstName(oldsym, targs, true)
+ newsym := MakeFuncInstSym(oldsym, targs, true)
var nname *ir.Name
if newsym.Def != nil {
nname = newsym.Def.(*ir.Name)