]> Cypherpunks repositories - gostls13.git/commitdiff
[dev.regabi] cmd/compile: address some ir TODOs
authorMatthew Dempsky <mdempsky@google.com>
Tue, 29 Dec 2020 01:06:43 +0000 (17:06 -0800)
committerMatthew Dempsky <mdempsky@google.com>
Tue, 29 Dec 2020 02:49:00 +0000 (02:49 +0000)
Previously, ODOTTYPE/ODOTTYPE2 were forced to reuse some available
Node fields for storing pointers to runtime type descriptors. This
resulted in awkward field types for TypeAssertExpr and AddrExpr.

This CL gives TypeAssertExpr proper fields for the runtime type
descriptors, and also tightens the field types as
possible/appropriate.

Passes toolstash -cmp.

Change-Id: I521ee7a1462affc5459de33a0de6c68a7d6416ba
Reviewed-on: https://go-review.googlesource.com/c/go/+/280637
Trust: Matthew Dempsky <mdempsky@google.com>
Trust: Dan Scales <danscales@google.com>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Dan Scales <danscales@google.com>
src/cmd/compile/internal/ir/expr.go
src/cmd/compile/internal/ir/node_gen.go
src/cmd/compile/internal/ssagen/ssa.go
src/cmd/compile/internal/typecheck/expr.go
src/cmd/compile/internal/walk/expr.go

index 872f81a447862f8e0f7bc9e994d20c1f71d70950..825d4ace78548128883b0875c6ff72094f190f21 100644 (file)
@@ -109,7 +109,7 @@ func NewAddStringExpr(pos src.XPos, list []Node) *AddStringExpr {
 type AddrExpr struct {
        miniExpr
        X     Node
-       Alloc Node // preallocated storage if any
+       Alloc *Name // preallocated storage if any
 }
 
 func NewAddrExpr(pos src.XPos, x Node) *AddrExpr {
@@ -660,8 +660,13 @@ func (n *StarExpr) SetOTYPE(t *types.Type) {
 type TypeAssertExpr struct {
        miniExpr
        X     Node
-       Ntype Node  // TODO: Should be Ntype, but reused as address of type structure
-       Itab  Nodes // Itab[0] is itab
+       Ntype Ntype
+
+       // Runtime type information provided by walkDotType.
+       // Caution: These aren't always populated; see walkDotType.
+       SrcType *AddrExpr // *runtime._type for X's type
+       DstType *AddrExpr // *runtime._type for Type
+       Itab    *AddrExpr // *runtime.itab for Type implementing X's type
 }
 
 func NewTypeAssertExpr(pos src.XPos, x Node, typ Ntype) *TypeAssertExpr {
index a1ce9a4e9dddb647b72b9969879fd524963d65ad..1d24904a3f34c8b719702b2cf56bfd49d2adcd5b 100644 (file)
@@ -32,13 +32,11 @@ func (n *AddrExpr) doChildren(do func(Node) error) error {
        var err error
        err = maybeDoList(n.init, err, do)
        err = maybeDo(n.X, err, do)
-       err = maybeDo(n.Alloc, err, do)
        return err
 }
 func (n *AddrExpr) editChildren(edit func(Node) Node) {
        editList(n.init, edit)
        n.X = maybeEdit(n.X, edit)
-       n.Alloc = maybeEdit(n.Alloc, edit)
 }
 
 func (n *ArrayType) Format(s fmt.State, verb rune) { FmtNode(n, s, verb) }
@@ -954,7 +952,6 @@ func (n *TypeAssertExpr) Format(s fmt.State, verb rune) { FmtNode(n, s, verb) }
 func (n *TypeAssertExpr) copy() Node {
        c := *n
        c.init = c.init.Copy()
-       c.Itab = c.Itab.Copy()
        return &c
 }
 func (n *TypeAssertExpr) doChildren(do func(Node) error) error {
@@ -962,14 +959,12 @@ func (n *TypeAssertExpr) doChildren(do func(Node) error) error {
        err = maybeDoList(n.init, err, do)
        err = maybeDo(n.X, err, do)
        err = maybeDo(n.Ntype, err, do)
-       err = maybeDoList(n.Itab, err, do)
        return err
 }
 func (n *TypeAssertExpr) editChildren(edit func(Node) Node) {
        editList(n.init, edit)
        n.X = maybeEdit(n.X, edit)
-       n.Ntype = maybeEdit(n.Ntype, edit)
-       editList(n.Itab, edit)
+       n.Ntype = toNtype(maybeEdit(n.Ntype, edit))
 }
 
 func (n *TypeSwitchGuard) Format(s fmt.State, verb rune) { FmtNode(n, s, verb) }
index 0da6ab3272aec645e45e42ae8f4f7658b2e9e607..509d53f8c9b90195864f6635f445dc91fc437187 100644 (file)
@@ -5978,8 +5978,8 @@ func (s *state) floatToUint(cvttab *f2uCvtTab, n ir.Node, x *ssa.Value, ft, tt *
 // commaok indicates whether to panic or return a bool.
 // If commaok is false, resok will be nil.
 func (s *state) dottype(n *ir.TypeAssertExpr, commaok bool) (res, resok *ssa.Value) {
-       iface := s.expr(n.X)      // input interface
-       target := s.expr(n.Ntype) // target type
+       iface := s.expr(n.X)        // input interface
+       target := s.expr(n.DstType) // target type
        byteptr := s.f.Config.Types.BytePtr
 
        if n.Type().IsInterface() {
@@ -6086,7 +6086,7 @@ func (s *state) dottype(n *ir.TypeAssertExpr, commaok bool) (res, resok *ssa.Val
                targetITab = target
        } else {
                // Looking for pointer to itab for target type and source interface.
-               targetITab = s.expr(n.Itab[0])
+               targetITab = s.expr(n.Itab)
        }
 
        var tmp ir.Node     // temporary for use with large types
@@ -6113,7 +6113,7 @@ func (s *state) dottype(n *ir.TypeAssertExpr, commaok bool) (res, resok *ssa.Val
        if !commaok {
                // on failure, panic by calling panicdottype
                s.startBlock(bFail)
-               taddr := s.expr(n.Ntype.(*ir.AddrExpr).Alloc)
+               taddr := s.expr(n.SrcType)
                if n.X.Type().IsEmptyInterface() {
                        s.rtcall(ir.Syms.PanicdottypeE, false, nil, itab, target, taddr)
                } else {
index 0682548c273679f630d18c3d5546e7460277c588..29d7a080114d71ab1d1887b23efe7cde531b6e85 100644 (file)
@@ -649,7 +649,7 @@ func tcDotType(n *ir.TypeAssertExpr) ir.Node {
        }
 
        if n.Ntype != nil {
-               n.Ntype = typecheck(n.Ntype, ctxType)
+               n.Ntype = typecheckNtype(n.Ntype)
                n.SetType(n.Ntype.Type())
                n.Ntype = nil
                if n.Type() == nil {
index 7cc67580248b5196908c15caa44818fa965938d9..f40aa6adb5de598bdf86e4b35c6ea56374601bfc 100644 (file)
@@ -639,12 +639,13 @@ func walkDot(n *ir.SelectorExpr, init *ir.Nodes) ir.Node {
 func walkDotType(n *ir.TypeAssertExpr, init *ir.Nodes) ir.Node {
        n.X = walkExpr(n.X, init)
        // Set up interface type addresses for back end.
-       n.Ntype = reflectdata.TypePtr(n.Type())
+
+       n.DstType = reflectdata.TypePtr(n.Type())
        if n.Op() == ir.ODOTTYPE {
-               n.Ntype.(*ir.AddrExpr).Alloc = reflectdata.TypePtr(n.X.Type())
+               n.SrcType = reflectdata.TypePtr(n.X.Type())
        }
        if !n.Type().IsInterface() && !n.X.Type().IsEmptyInterface() {
-               n.Itab = []ir.Node{reflectdata.ITabAddr(n.Type(), n.X.Type())}
+               n.Itab = reflectdata.ITabAddr(n.Type(), n.X.Type())
        }
        return n
 }