[dev.regabi] cmd/compile: implement copy for nodes

Put each node in charge of making copies of its own slices.
This removes a generic use of Body, SetBody, and so on
in func Copy, heading toward removing those even from
being used in package ir.

Passes buildall w/ toolstash -cmp.

Change-Id: I249b7fe54cf72e9d2f0467b10f3f257abf9b29b9
Reviewed-on: https://go-review.googlesource.com/c/go/+/275374
Trust: Russ Cox <rsc@golang.org>
Run-TryBot: Russ Cox <rsc@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
This commit is contained in:
Russ Cox 2020-12-03 18:43:18 -05:00
parent d855b30fe4
commit 18f2df7e81
7 changed files with 532 additions and 281 deletions

View file

@ -27,8 +27,8 @@ type Node interface {
Pos() src.XPos
SetPos(x src.XPos)
// For making copies. Mainly used by Copy and SepCopy.
rawCopy() Node
// For making copies. For Copy and SepCopy.
copy() Node
// Abstract graph structure, for generic traversals.
Op() Op
@ -521,6 +521,21 @@ func (n *Nodes) AppendNodes(n2 *Nodes) {
n2.slice = nil
}
// Copy returns a copy of the content of the slice.
func (n Nodes) Copy() Nodes {
var c Nodes
if n.slice == nil {
return c
}
c.slice = new([]Node)
if *n.slice == nil {
return c
}
*c.slice = make([]Node, n.Len())
copy(*c.slice, n.Slice())
return c
}
// nodeQueue is a FIFO queue of *Node. The zero value of nodeQueue is
// a ready-to-use empty queue.
type NodeQueue struct {