mirror of
https://github.com/golang/go
synced 2024-11-22 19:14:53 -07:00
[dev.regabi] cmd/compile: replace NodeQueue with NameQueue
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>
This commit is contained in:
parent
6c5967e528
commit
1b5eed8982
@ -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() {
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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
|
||||
|
||||
|
@ -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)
|
||||
|
@ -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")
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user