cmd/compile/internal/noder: prune unified IR's dictionary logic

Unified IR uses static dictionaries for some itabs and function/method
expressions, and they're roughly the right idea. But at the same time,
they're actually somewhat brittle and I need to reorganize some ideas
anyway to get shaped-based stenciling working. So this CL just rips
them out entirely.

Note: the code for emitting runtime dictionaries with *runtime._type
symbols is still present, and continues to demonstrate that basic
runtime dictionary handling is working.

Change-Id: I44eb1c7974fb397909ad5db12987659e7505c2ad
Reviewed-on: https://go-review.googlesource.com/c/go/+/421819
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Reviewed-by: Than McIntosh <thanm@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
This commit is contained in:
Matthew Dempsky 2022-08-06 15:27:30 -07:00
parent 88635b3862
commit 29b07037b1
2 changed files with 25 additions and 201 deletions

View file

@ -164,18 +164,6 @@ type readerDict struct {
derived []derivedInfo // reloc index of the derived type's descriptor
derivedTypes []*types.Type // slice of previously computed derived types
funcs []objInfo
funcsObj []ir.Node
itabs []itabInfo2
methodExprs []ir.Node
}
type itabInfo2 struct {
typ *types.Type
lsym *obj.LSym
}
func setType(n ir.Node, typ *types.Type) {
@ -744,41 +732,6 @@ func (pr *pkgReader) objDictIdx(sym *types.Sym, idx pkgbits.Index, implicits, ex
dict.derived[i] = derivedInfo{r.Reloc(pkgbits.RelocType), r.Bool()}
}
dict.funcs = make([]objInfo, r.Len())
dict.funcsObj = make([]ir.Node, len(dict.funcs))
for i := range dict.funcs {
objIdx := r.Reloc(pkgbits.RelocObj)
targs := make([]typeInfo, r.Len())
for j := range targs {
targs[j] = r.typInfo()
}
dict.funcs[i] = objInfo{idx: objIdx, explicits: targs}
}
dict.itabs = make([]itabInfo2, r.Len())
for i := range dict.itabs {
typ := pr.typIdx(typeInfo{idx: pkgbits.Index(r.Len()), derived: true}, &dict, true)
ifaceInfo := r.typInfo()
var lsym *obj.LSym
if typ.IsInterface() {
lsym = reflectdata.TypeLinksym(typ)
} else {
iface := pr.typIdx(ifaceInfo, &dict, true)
lsym = reflectdata.ITabLsym(typ, iface)
}
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
}
@ -1844,22 +1797,6 @@ func (r *reader) expr() (res ir.Node) {
return typecheck.Callee(r.obj())
case exprFuncInst:
if r.Bool() {
idx := r.Len()
obj := r.dict.funcsObj[idx]
if obj == nil {
fn := r.dict.funcs[idx]
targs := make([]*types.Type, len(fn.explicits))
for i, targ := range fn.explicits {
targs[i] = r.p.typIdx(targ, r.dict, true)
}
obj = r.p.objIdx(fn.idx, nil, targs)
assert(r.dict.funcsObj[idx] == nil)
r.dict.funcsObj[idx] = obj
}
return obj
}
return r.obj()
case exprConst:
@ -1906,10 +1843,6 @@ func (r *reader) expr() (res ir.Node) {
return n
case exprMethodExpr:
if r.Bool() {
return r.dict.methodExprs[r.Len()]
}
typ := r.typ()
pos := r.pos()
_, sym := r.selector()
@ -2259,9 +2192,19 @@ func (r *reader) rtypeInfo(pos src.XPos, info typeInfo) ir.Node {
typ := r.p.typIdx(info, r.dict, true)
return reflectdata.TypePtrAt(pos, typ)
}
assert(r.dict.derived[info.idx].needed)
return typecheck.Expr(ir.NewConvExpr(pos, ir.OCONVNOP, types.NewPtr(types.Types[types.TUINT8]), r.dictWord(pos, int64(info.idx))))
}
// itabInfo returns an expression of type *runtime.itab representing
// the itab for the given decoded type and interface reference pair.
func (r *reader) itabInfo(pos src.XPos, typInfo, ifaceInfo typeInfo) ir.Node {
typ := r.p.typIdx(typInfo, r.dict, true)
iface := r.p.typIdx(ifaceInfo, r.dict, true)
lsym := reflectdata.ITabLsym(typ, iface)
return typecheck.LinksymAddr(pos, lsym, types.Types[types.TUINT8])
}
// convRTTI returns expressions appropriate for populating an
// ir.ConvExpr's TypeWord and SrcRType fields, respectively.
func (r *reader) convRTTI(pos src.XPos) (typeWord, srcRType ir.Node) {
@ -2283,7 +2226,7 @@ func (r *reader) convRTTI(pos src.XPos) (typeWord, srcRType ir.Node) {
typeWord = r.rtypeInfo(pos, srcInfo) // direct eface construction
}
case !src.IsInterface():
typeWord = reflectdata.ITabAddrAt(pos, src, dst) // direct iface construction
typeWord = r.itabInfo(pos, srcInfo, dstInfo) // direct iface construction
default:
typeWord = r.rtypeInfo(pos, dstInfo) // convI2I
}
@ -2302,35 +2245,28 @@ func (r *reader) exprType() ir.Node {
pos := r.pos()
setBasePos(pos)
lsymPtr := func(lsym *obj.LSym) ir.Node {
return typecheck.Expr(typecheck.NodAddrAt(pos, ir.NewLinksymExpr(pos, lsym, types.Types[types.TUINT8])))
}
var typ *types.Type
var rtype, itab ir.Node
if r.Bool() {
info := r.dict.itabs[r.Len()]
typ = info.typ
typInfo := r.typInfo()
typ := r.p.typIdx(typInfo, r.dict, true)
if r.Bool() {
ifaceInfo := r.typInfo()
// TODO(mdempsky): Populate rtype unconditionally?
if typ.IsInterface() {
rtype = lsymPtr(info.lsym)
rtype = r.rtypeInfo(pos, typInfo)
} else {
itab = lsymPtr(info.lsym)
itab = r.itabInfo(pos, typInfo, ifaceInfo)
}
} else {
info := r.typInfo()
typ = r.p.typIdx(info, r.dict, true)
if !info.derived {
if !typInfo.derived {
// TODO(mdempsky): ir.TypeNode should probably return a typecheck'd node.
n := ir.TypeNode(typ)
n.SetTypecheck(1)
return n
}
rtype = r.rtypeInfo(pos, info)
rtype = r.rtypeInfo(pos, typInfo)
}
dt := ir.NewDynamicType(pos, rtype)