]> Cypherpunks repositories - gostls13.git/commitdiff
[dev.regabi] cmd/compile: replace NodeQueue with NameQueue
authorMatthew Dempsky <mdempsky@google.com>
Sun, 6 Dec 2020 20:29:42 +0000 (12:29 -0800)
committerMatthew Dempsky <mdempsky@google.com>
Sun, 6 Dec 2020 21:05:41 +0000 (21:05 +0000)
Similar to the previous CL, the only two users of NodeQueue only
needed it for tracking objects, not arbitrary AST nodes. So change
it's signature to use *Name instead of Node.

This does require a tweak to the nowritebarrierrec checker, because
previously it was pushing the ODCLFUNC *Func pointers into the queue,
whereas now we push the ONAME/PFUNC *Name pointers instead. However,
it's trivial and safe to flip between them.

Also, this changes a handful of export-related code from Node to
*Name, to avoid introducing type assertions within iexport.go.

Passes buildall w/ toolstash -cmp.

Updates #42982.

Change-Id: I867f9752121509fc3da753978c6a41d5015bc0ce
Reviewed-on: https://go-review.googlesource.com/c/go/+/275753
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Trust: Matthew Dempsky <mdempsky@google.com>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Go Bot <gobot@golang.org>

src/cmd/compile/internal/gc/dcl.go
src/cmd/compile/internal/gc/export.go
src/cmd/compile/internal/gc/go.go
src/cmd/compile/internal/gc/iexport.go
src/cmd/compile/internal/ir/node.go

index ce13f0bdfcc678f5102c40e2693864f1320a2061..56f8d1b9bf79d692233410025e1b6434efc82e7e 100644 (file)
@@ -931,7 +931,7 @@ func (c *nowritebarrierrecChecker) check() {
        // acts as the set of marks for the BFS of the call graph.
        funcs := make(map[ir.Node]nowritebarrierrecCall)
        // q is the queue of ODCLFUNC Nodes to visit in BFS order.
-       var q ir.NodeQueue
+       var q ir.NameQueue
 
        for _, n := range xtop {
                if n.Op() != ir.ODCLFUNC {
@@ -944,7 +944,7 @@ func (c *nowritebarrierrecChecker) check() {
                // Make nowritebarrierrec functions BFS roots.
                if fn.Pragma&ir.Nowritebarrierrec != 0 {
                        funcs[fn] = nowritebarrierrecCall{}
-                       q.PushRight(fn)
+                       q.PushRight(fn.Nname)
                }
                // Check go:nowritebarrier functions.
                if fn.Pragma&ir.Nowritebarrier != 0 && fn.WBPos.IsKnown() {
@@ -966,10 +966,10 @@ func (c *nowritebarrierrecChecker) check() {
 
                // Record the path.
                funcs[target] = nowritebarrierrecCall{target: src, lineno: pos}
-               q.PushRight(target)
+               q.PushRight(target.Nname)
        }
        for !q.Empty() {
-               fn := q.PopLeft().(*ir.Func)
+               fn := q.PopLeft().Func()
 
                // Check fn.
                if fn.WBPos.IsKnown() {
index 44fc70be037fe6b9781d7b6178a2a42f902a7b54..b632a15865d0a82442989295b1409f7fb67462b7 100644 (file)
@@ -24,7 +24,7 @@ func exportf(bout *bio.Writer, format string, args ...interface{}) {
 var asmlist []ir.Node
 
 // exportsym marks n for export (or reexport).
-func exportsym(n ir.Node) {
+func exportsym(n *ir.Name) {
        if n.Sym().OnExportList() {
                return
        }
@@ -41,7 +41,7 @@ func initname(s string) bool {
        return s == "init"
 }
 
-func autoexport(n ir.Node, ctxt ir.Class) {
+func autoexport(n *ir.Name, ctxt ir.Class) {
        if n.Sym().Pkg != ir.LocalPkg {
                return
        }
index c493165c7688a9b413fd523a23781f1ccea0f121..c4b9c185dcb377c22c682780c0156cd3954c21f5 100644 (file)
@@ -130,7 +130,7 @@ var (
 
 var xtop []ir.Node
 
-var exportlist []ir.Node
+var exportlist []*ir.Name
 
 var importlist []*ir.Func // imported functions and methods with inlinable bodies
 
index bb6f2b11e62e4b26f02321acddab2d7707d6bf6a..14614d8ab89ef162ee933f2619c1f5933344cbd3 100644 (file)
@@ -368,7 +368,7 @@ type iexporter struct {
        // main index.
        allPkgs map[*types.Pkg]bool
 
-       declTodo ir.NodeQueue
+       declTodo ir.NameQueue
 
        strings     intWriter
        stringIndex map[string]uint64
@@ -394,7 +394,7 @@ func (p *iexporter) stringOff(s string) uint64 {
 }
 
 // pushDecl adds n to the declaration work queue, if not already present.
-func (p *iexporter) pushDecl(n ir.Node) {
+func (p *iexporter) pushDecl(n *ir.Name) {
        if n.Sym() == nil || n.Sym().Def != n && n.Op() != ir.OTYPE {
                base.Fatalf("weird Sym: %v, %v", n, n.Sym())
        }
@@ -573,7 +573,7 @@ func (w *exportWriter) pkg(pkg *types.Pkg) {
 
 func (w *exportWriter) qualifiedIdent(n ir.Node) {
        // Ensure any referenced declarations are written out too.
-       w.p.pushDecl(n)
+       w.p.pushDecl(n.Name())
 
        s := n.Sym()
        w.string(s.Name)
index a0ee8aa0fecd182335998c01adc015bc091413e9..7fd02925ba34a4cdf76aa13fbf190f14faf53662 100644 (file)
@@ -539,25 +539,25 @@ func (n Nodes) Copy() Nodes {
        return c
 }
 
-// nodeQueue is a FIFO queue of *Node. The zero value of nodeQueue is
+// NameQueue is a FIFO queue of *Name. The zero value of NameQueue is
 // a ready-to-use empty queue.
-type NodeQueue struct {
-       ring       []Node
+type NameQueue struct {
+       ring       []*Name
        head, tail int
 }
 
-// empty reports whether q contains no Nodes.
-func (q *NodeQueue) Empty() bool {
+// Empty reports whether q contains no Names.
+func (q *NameQueue) Empty() bool {
        return q.head == q.tail
 }
 
-// pushRight appends n to the right of the queue.
-func (q *NodeQueue) PushRight(n Node) {
+// PushRight appends n to the right of the queue.
+func (q *NameQueue) PushRight(n *Name) {
        if len(q.ring) == 0 {
-               q.ring = make([]Node, 16)
+               q.ring = make([]*Name, 16)
        } else if q.head+len(q.ring) == q.tail {
                // Grow the ring.
-               nring := make([]Node, len(q.ring)*2)
+               nring := make([]*Name, len(q.ring)*2)
                // Copy the old elements.
                part := q.ring[q.head%len(q.ring):]
                if q.tail-q.head <= len(part) {
@@ -574,9 +574,9 @@ func (q *NodeQueue) PushRight(n Node) {
        q.tail++
 }
 
-// popLeft pops a node from the left of the queue. It panics if q is
+// PopLeft pops a Name from the left of the queue. It panics if q is
 // empty.
-func (q *NodeQueue) PopLeft() Node {
+func (q *NameQueue) PopLeft() *Name {
        if q.Empty() {
                panic("dequeue empty")
        }