diff options
| author | Dan Scales <danscales@google.com> | 2022-01-18 12:55:17 -0800 |
|---|---|---|
| committer | Dan Scales <danscales@google.com> | 2022-01-21 00:39:55 +0000 |
| commit | 32636cd1ffc6cd9ef81d09b8320d2aaad4a21117 (patch) | |
| tree | 76ef77c1dc05ceb0eef3b7c279d3f0b971e4b100 /src/cmd/compile/internal/noder | |
| parent | 2c2e08144f79d8746384c2a483bf03532dc0c443 (diff) | |
| download | go-32636cd1ffc6cd9ef81d09b8320d2aaad4a21117.tar.xz | |
cmd/compile: make sure multiple blank typeparams remain unique
In a method declaration "func (f *Foo[_, _]) String() string { ... }",
the two blank typeparams have the same name, but our current design with
types1 needs unique names for type params. Similarly, for export/import,
we need unique names to keep the type params straight in generic types
and connect the proper type param with the proper constraint. We make
blank type params unique by changing them to $1, $2, etc in noder.typ0()
via typecheck.TparamExportName(). We then revert $<num> back to _ during
type2 import via typecheck.TparamName(). We similarly revert
during gcimporter import. We don't need/want to revert in the types1
importer, since we want unique names for type params.
Rob Findley has made a similar change to x/tools (and we tried to make
the source code changes similar for the gcimporter and types2 importer
changes).
Fixes #50419
Change-Id: I855cc3d90d06bcf59541ed0c879e9a0e4ede45bb
Reviewed-on: https://go-review.googlesource.com/c/go/+/379194
Reviewed-by: Robert Griesemer <gri@golang.org>
Trust: Dan Scales <danscales@google.com>
Diffstat (limited to 'src/cmd/compile/internal/noder')
| -rw-r--r-- | src/cmd/compile/internal/noder/types.go | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/src/cmd/compile/internal/noder/types.go b/src/cmd/compile/internal/noder/types.go index 3f3c9566ca..e7ce4c1089 100644 --- a/src/cmd/compile/internal/noder/types.go +++ b/src/cmd/compile/internal/noder/types.go @@ -239,10 +239,13 @@ func (g *irgen) typ0(typ types2.Type) *types.Type { // Save the name of the type parameter in the sym of the type. // Include the types2 subscript in the sym name pkg := g.tpkg(typ) - // Create the unique types1 name for a type param, using its context with a - // function, type, or method declaration. + // Create the unique types1 name for a type param, using its context + // with a function, type, or method declaration. Also, map blank type + // param names to a unique name based on their type param index. The + // unique blank names will be exported, but will be reverted during + // types2 and gcimporter import. assert(g.curDecl != "") - nm := g.curDecl + "." + typ.Obj().Name() + nm := typecheck.TparamExportName(g.curDecl, typ.Obj().Name(), typ.Index()) sym := pkg.Lookup(nm) if sym.Def != nil { // Make sure we use the same type param type for the same |
