Skip to content

Commit

Permalink
go/ssa: use core type within (*builder).receiver
Browse files Browse the repository at this point in the history
Change-Id: I677d99a2aeb6c7c8fa5362a371d781652d45aa35
Reviewed-on: https://go-review.googlesource.com/c/tools/+/498599
Reviewed-by: Alan Donovan <adonovan@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Tim King <taking@google.com>
  • Loading branch information
timothy-king committed Jun 14, 2023
1 parent f394d45 commit 3b62e7e
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
9 changes: 4 additions & 5 deletions go/ssa/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -829,7 +829,7 @@ func (b *builder) expr0(fn *Function, e ast.Expr, tv types.TypeAndValue) Value {
// The result is a "bound".
obj := sel.obj.(*types.Func)
rt := fn.typ(recvType(obj))
_, wantAddr := deptr(rt)
_, wantAddr := deref(rt)
escaping := true
v := b.receiver(fn, e.X, wantAddr, escaping, sel)

Expand Down Expand Up @@ -956,9 +956,8 @@ func (b *builder) stmtList(fn *Function, list []ast.Stmt) {
//
// escaping is defined as per builder.addr().
func (b *builder) receiver(fn *Function, e ast.Expr, wantAddr, escaping bool, sel *selection) Value {

var v Value
if _, eptr := deptr(fn.typeOf(e)); wantAddr && !sel.indirect && !eptr {
if _, eptr := deref(fn.typeOf(e)); wantAddr && !sel.indirect && !eptr {
v = b.addr(fn, e, escaping).address(fn)
} else {
v = b.expr(fn, e)
Expand All @@ -967,7 +966,7 @@ func (b *builder) receiver(fn *Function, e ast.Expr, wantAddr, escaping bool, se
last := len(sel.index) - 1
// The position of implicit selection is the position of the inducing receiver expression.
v = emitImplicitSelections(fn, v, sel.index[:last], e.Pos())
if _, vptr := deptr(v.Type()); !wantAddr && vptr {
if _, vptr := deref(v.Type()); !wantAddr && vptr {
v = emitLoad(fn, v)
}
return v
Expand All @@ -986,7 +985,7 @@ func (b *builder) setCallFunc(fn *Function, e *ast.CallExpr, c *CallCommon) {
obj := sel.obj.(*types.Func)
recv := recvType(obj)

_, wantAddr := deptr(recv)
_, wantAddr := deref(recv)
escaping := true
v := b.receiver(fn, selector.X, wantAddr, escaping, sel)
if types.IsInterface(recv) {
Expand Down
20 changes: 20 additions & 0 deletions go/ssa/builder_generic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -690,6 +690,26 @@ func TestInstructionString(t *testing.T) {
func f13[A [3]int, PA *A](v PA) {
*v = A{7}
}
//@ instrs("f14", "*ssa.Call", "invoke t1.Set(0:int)")
func f14[T any, PT interface {
Set(int)
*T
}]() {
var t T
p := PT(&t)
p.Set(0)
}
//@ instrs("f15", "*ssa.MakeClosure", "make closure (interface{Set(int); *T}).Set$bound [t1]")
func f15[T any, PT interface {
Set(int)
*T
}]() func(int) {
var t T
p := PT(&t)
return p.Set
}
`

// Parse
Expand Down

0 comments on commit 3b62e7e

Please sign in to comment.