mirror of https://github.com/golang/go.git
[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.
|
// acts as the set of marks for the BFS of the call graph.
|
||||||
funcs := make(map[ir.Node]nowritebarrierrecCall)
|
funcs := make(map[ir.Node]nowritebarrierrecCall)
|
||||||
// q is the queue of ODCLFUNC Nodes to visit in BFS order.
|
// q is the queue of ODCLFUNC Nodes to visit in BFS order.
|
||||||
var q ir.NodeQueue
|
var q ir.NameQueue
|
||||||
|
|
||||||
for _, n := range xtop {
|
for _, n := range xtop {
|
||||||
if n.Op() != ir.ODCLFUNC {
|
if n.Op() != ir.ODCLFUNC {
|
||||||
|
|
@ -944,7 +944,7 @@ func (c *nowritebarrierrecChecker) check() {
|
||||||
// Make nowritebarrierrec functions BFS roots.
|
// Make nowritebarrierrec functions BFS roots.
|
||||||
if fn.Pragma&ir.Nowritebarrierrec != 0 {
|
if fn.Pragma&ir.Nowritebarrierrec != 0 {
|
||||||
funcs[fn] = nowritebarrierrecCall{}
|
funcs[fn] = nowritebarrierrecCall{}
|
||||||
q.PushRight(fn)
|
q.PushRight(fn.Nname)
|
||||||
}
|
}
|
||||||
// Check go:nowritebarrier functions.
|
// Check go:nowritebarrier functions.
|
||||||
if fn.Pragma&ir.Nowritebarrier != 0 && fn.WBPos.IsKnown() {
|
if fn.Pragma&ir.Nowritebarrier != 0 && fn.WBPos.IsKnown() {
|
||||||
|
|
@ -966,10 +966,10 @@ func (c *nowritebarrierrecChecker) check() {
|
||||||
|
|
||||||
// Record the path.
|
// Record the path.
|
||||||
funcs[target] = nowritebarrierrecCall{target: src, lineno: pos}
|
funcs[target] = nowritebarrierrecCall{target: src, lineno: pos}
|
||||||
q.PushRight(target)
|
q.PushRight(target.Nname)
|
||||||
}
|
}
|
||||||
for !q.Empty() {
|
for !q.Empty() {
|
||||||
fn := q.PopLeft().(*ir.Func)
|
fn := q.PopLeft().Func()
|
||||||
|
|
||||||
// Check fn.
|
// Check fn.
|
||||||
if fn.WBPos.IsKnown() {
|
if fn.WBPos.IsKnown() {
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,7 @@ func exportf(bout *bio.Writer, format string, args ...interface{}) {
|
||||||
var asmlist []ir.Node
|
var asmlist []ir.Node
|
||||||
|
|
||||||
// exportsym marks n for export (or reexport).
|
// exportsym marks n for export (or reexport).
|
||||||
func exportsym(n ir.Node) {
|
func exportsym(n *ir.Name) {
|
||||||
if n.Sym().OnExportList() {
|
if n.Sym().OnExportList() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
@ -41,7 +41,7 @@ func initname(s string) bool {
|
||||||
return s == "init"
|
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 {
|
if n.Sym().Pkg != ir.LocalPkg {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -130,7 +130,7 @@ var (
|
||||||
|
|
||||||
var xtop []ir.Node
|
var xtop []ir.Node
|
||||||
|
|
||||||
var exportlist []ir.Node
|
var exportlist []*ir.Name
|
||||||
|
|
||||||
var importlist []*ir.Func // imported functions and methods with inlinable bodies
|
var importlist []*ir.Func // imported functions and methods with inlinable bodies
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -368,7 +368,7 @@ type iexporter struct {
|
||||||
// main index.
|
// main index.
|
||||||
allPkgs map[*types.Pkg]bool
|
allPkgs map[*types.Pkg]bool
|
||||||
|
|
||||||
declTodo ir.NodeQueue
|
declTodo ir.NameQueue
|
||||||
|
|
||||||
strings intWriter
|
strings intWriter
|
||||||
stringIndex map[string]uint64
|
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.
|
// 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 {
|
if n.Sym() == nil || n.Sym().Def != n && n.Op() != ir.OTYPE {
|
||||||
base.Fatalf("weird Sym: %v, %v", n, n.Sym())
|
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) {
|
func (w *exportWriter) qualifiedIdent(n ir.Node) {
|
||||||
// Ensure any referenced declarations are written out too.
|
// Ensure any referenced declarations are written out too.
|
||||||
w.p.pushDecl(n)
|
w.p.pushDecl(n.Name())
|
||||||
|
|
||||||
s := n.Sym()
|
s := n.Sym()
|
||||||
w.string(s.Name)
|
w.string(s.Name)
|
||||||
|
|
|
||||||
|
|
@ -539,25 +539,25 @@ func (n Nodes) Copy() Nodes {
|
||||||
return c
|
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.
|
// a ready-to-use empty queue.
|
||||||
type NodeQueue struct {
|
type NameQueue struct {
|
||||||
ring []Node
|
ring []*Name
|
||||||
head, tail int
|
head, tail int
|
||||||
}
|
}
|
||||||
|
|
||||||
// empty reports whether q contains no Nodes.
|
// Empty reports whether q contains no Names.
|
||||||
func (q *NodeQueue) Empty() bool {
|
func (q *NameQueue) Empty() bool {
|
||||||
return q.head == q.tail
|
return q.head == q.tail
|
||||||
}
|
}
|
||||||
|
|
||||||
// pushRight appends n to the right of the queue.
|
// PushRight appends n to the right of the queue.
|
||||||
func (q *NodeQueue) PushRight(n Node) {
|
func (q *NameQueue) PushRight(n *Name) {
|
||||||
if len(q.ring) == 0 {
|
if len(q.ring) == 0 {
|
||||||
q.ring = make([]Node, 16)
|
q.ring = make([]*Name, 16)
|
||||||
} else if q.head+len(q.ring) == q.tail {
|
} else if q.head+len(q.ring) == q.tail {
|
||||||
// Grow the ring.
|
// Grow the ring.
|
||||||
nring := make([]Node, len(q.ring)*2)
|
nring := make([]*Name, len(q.ring)*2)
|
||||||
// Copy the old elements.
|
// Copy the old elements.
|
||||||
part := q.ring[q.head%len(q.ring):]
|
part := q.ring[q.head%len(q.ring):]
|
||||||
if q.tail-q.head <= len(part) {
|
if q.tail-q.head <= len(part) {
|
||||||
|
|
@ -574,9 +574,9 @@ func (q *NodeQueue) PushRight(n Node) {
|
||||||
q.tail++
|
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.
|
// empty.
|
||||||
func (q *NodeQueue) PopLeft() Node {
|
func (q *NameQueue) PopLeft() *Name {
|
||||||
if q.Empty() {
|
if q.Empty() {
|
||||||
panic("dequeue empty")
|
panic("dequeue empty")
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue