From 72bb8185b5fb2fe84ee7cfdc8e9605f2c81b32fe Mon Sep 17 00:00:00 2001 From: Alessandro Arzilli Date: Wed, 25 Aug 2021 10:08:07 +0200 Subject: cmd/compile: emit DWARF info about dictionary entries When emitting the DIE of the instantiation of a generic function also emit one DW_TAG_typedef_type entry for each dictionary entry in use, referencing the shape type and having a custom attribute containing the index inside the dictionary. When emitting the DIE of variables that have an instantiated parametric type, instead of referencing the shape type directly go through the DW_TAG_typedef_type entry emitted for the dictionary entry describing the real type of the variable. Change-Id: Ia45d157ecd4c25e2b60300469e43bbb27a663582 Reviewed-on: https://go-review.googlesource.com/c/go/+/344929 Run-TryBot: Alessandro Arzilli Run-TryBot: Dan Scales TryBot-Result: Go Bot Reviewed-by: Dan Scales Reviewed-by: Than McIntosh Trust: Dan Scales Trust: Jeremy Faller --- src/cmd/compile/internal/noder/stencil.go | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) (limited to 'src/cmd/compile/internal/noder') diff --git a/src/cmd/compile/internal/noder/stencil.go b/src/cmd/compile/internal/noder/stencil.go index 5069db9fe1..6c990c1828 100644 --- a/src/cmd/compile/internal/noder/stencil.go +++ b/src/cmd/compile/internal/noder/stencil.go @@ -779,6 +779,7 @@ func (subst *subster) localvar(name *ir.Name) *ir.Name { m.Func = name.Func subst.ts.Vars[name] = m m.SetTypecheck(1) + m.DictIndex = name.DictIndex if name.Defn != nil { if name.Defn.Op() == ir.ONAME { // This is a closure variable, so its Defn is the outer @@ -1268,14 +1269,18 @@ func (subst *subster) node(n ir.Node) ir.Node { // function info.gfInfo. This will indicate the dictionary entry with the // correct concrete type for the associated instantiated function. func findDictType(info *instInfo, t *types.Type) int { - for i, dt := range info.gfInfo.tparams { + return info.gfInfo.findDictType(t) +} + +func (gfInfo *gfInfo) findDictType(t *types.Type) int { + for i, dt := range gfInfo.tparams { if dt == t { return i } } - for i, dt := range info.gfInfo.derivedTypes { + for i, dt := range gfInfo.derivedTypes { if types.Identical(dt, t) { - return i + len(info.gfInfo.tparams) + return i + len(gfInfo.tparams) } } return -1 @@ -1736,6 +1741,7 @@ func (g *irgen) getGfInfo(gn *ir.Name) *gfInfo { for _, n := range gf.Dcl { addType(&info, n, n.Type()) + n.DictIndex = uint16(info.findDictType(n.Type()) + 1) } if infoPrintMode { @@ -1805,9 +1811,13 @@ func (g *irgen) getGfInfo(gn *ir.Name) *gfInfo { // Visit the closure body and add all relevant entries to the // dictionary of the outer function (closure will just use // the dictionary of the outer function). - for _, n1 := range n.(*ir.ClosureExpr).Func.Body { + cfunc := n.(*ir.ClosureExpr).Func + for _, n1 := range cfunc.Body { ir.Visit(n1, visitFunc) } + for _, n := range cfunc.Dcl { + n.DictIndex = uint16(info.findDictType(n.Type()) + 1) + } } if n.Op() == ir.OSWITCH && n.(*ir.SwitchStmt).Tag != nil && n.(*ir.SwitchStmt).Tag.Op() == ir.OTYPESW && !n.(*ir.SwitchStmt).Tag.(*ir.TypeSwitchGuard).X.Type().IsEmptyInterface() { for _, cc := range n.(*ir.SwitchStmt).Cases { -- cgit v1.3-5-g9baa