[dev.unified] cmd/compile: add method expressions to dictionaries

This CL changes method expressions that use derived-type receiver
parameters to use dictionary lookups.

Change-Id: Iacd09b6d77a2d3000438ec8bc9b5af2a0b068aa7
Reviewed-on: https://go-review.googlesource.com/c/go/+/419455
Reviewed-by: David Chase <drchase@google.com>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
This commit is contained in:
Matthew Dempsky 2022-07-23 23:54:15 -07:00
parent f48fa643f1
commit fc72b7705d
3 changed files with 93 additions and 15 deletions

View file

@ -154,6 +154,8 @@ type readerDict struct {
funcsObj []ir.Node
itabs []itabInfo2
methodExprs []ir.Node
}
type itabInfo2 struct {
@ -776,6 +778,14 @@ func (pr *pkgReader) objDictIdx(sym *types.Sym, idx pkgbits.Index, implicits, ex
dict.itabs[i] = itabInfo2{typ: typ, lsym: lsym}
}
dict.methodExprs = make([]ir.Node, r.Len())
for i := range dict.methodExprs {
recv := pr.typIdx(typeInfo{idx: pkgbits.Index(r.Len()), derived: true}, &dict, true)
_, sym := r.selector()
dict.methodExprs[i] = typecheck.Expr(ir.NewSelectorExpr(src.NoXPos, ir.OXDOT, ir.TypeNode(recv), sym))
}
return &dict
}
@ -1696,15 +1706,13 @@ func (r *reader) expr() (res ir.Node) {
case exprSelector:
var x ir.Node
if r.Bool() { // MethodExpr
x = r.exprType(false)
// Method expression with derived receiver type.
if x.Op() == ir.ODYNAMICTYPE {
// TODO(mdempsky): Handle with runtime dictionary lookup.
n := ir.TypeNode(x.Type())
n.SetTypecheck(1)
x = n
if r.Bool() {
return r.dict.methodExprs[r.Len()]
}
n := ir.TypeNode(r.typ())
n.SetTypecheck(1)
x = n
} else { // FieldVal, MethodVal
x = r.expr()
}