[dev.typeparams] cmd/compile: create .dict Param in the package of the instantiated function

The instantiated functions are created in the source package of the
generic function, so all lookups of symbols should be relative to that
package, so all symbols are consistently in the source package.

Fixes #46575

Change-Id: Iba67b2ba8014a630c5d4e032c0f2f2fbaaedce65
Reviewed-on: https://go-review.googlesource.com/c/go/+/325529
Reviewed-by: Keith Randall <khr@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
This commit is contained in:
Dan Scales 2021-06-04 18:17:49 -07:00
parent 7c8a5be2d6
commit 201d55e637
4 changed files with 31 additions and 1 deletions

View file

@ -558,7 +558,7 @@ func (g *irgen) genericSubst(newsym *types.Sym, nameNode *ir.Name, targs []*type
oldt := nameNode.Type()
// We also transform a generic method type to the corresponding
// instantiated function type where the dictionary is the first parameter.
dictionarySym := types.LocalPkg.Lookup(".dict")
dictionarySym := newsym.Pkg.Lookup(".dict")
dictionaryType := types.Types[types.TUINTPTR]
dictionaryName := ir.NewNameAt(gf.Pos(), dictionarySym)
typed(dictionaryType, dictionaryName)

View file

@ -0,0 +1,11 @@
// Copyright 2021 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package a
type X int
func (x X) M() X { return x }
func F[T interface{ M() U }, U interface{ M() T }]() {}
func G() { F[X, X]() }

View file

@ -0,0 +1,12 @@
// Copyright 2021 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package b
import "./a"
func H() {
a.F[a.X, a.X]()
a.G()
}

View file

@ -0,0 +1,7 @@
// compiledir -G=3
// Copyright 2021 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package ignored