cmd/compile: more nodeSeq conversions

Found by temporarily flipping fields from *NodeList to Nodes and fixing
all the compilation errors.  This CL does not actually change any
fields.

Passes toolstash -cmp.

Update #14473.

Change-Id: Ib98fa37e8752f96358224c973a743618a6a0e736
Reviewed-on: https://go-review.googlesource.com/20320
Run-TryBot: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
diff --git a/src/cmd/compile/internal/gc/walk.go b/src/cmd/compile/internal/gc/walk.go
index 9e5e26b..a34f4b2 100644
--- a/src/cmd/compile/internal/gc/walk.go
+++ b/src/cmd/compile/internal/gc/walk.go
@@ -89,13 +89,17 @@
 	}
 }
 
-func samelist(a *NodeList, b *NodeList) bool {
-	for ; a != nil && b != nil; a, b = a.Next, b.Next {
-		if a.N != b.N {
+func samelist(a nodesOrNodeList, b nodesOrNodeList) bool {
+	ita := nodeSeqIterate(a)
+	itb := nodeSeqIterate(b)
+	for !ita.Done() && !itb.Done() {
+		if ita.N() != itb.N() {
 			return false
 		}
+		ita.Next()
+		itb.Next()
 	}
-	return a == b
+	return ita.Done() == itb.Done()
 }
 
 func paramoutheap(fn *Node) bool {
@@ -651,7 +655,7 @@
 			// transformclosure already did all preparation work.
 
 			// Prepend captured variables to argument list.
-			setNodeSeq(&n.List, concat(n.Left.Func.Enter.NodeList(), n.List))
+			setNodeSeq(&n.List, append(n.Left.Func.Enter.Slice(), nodeSeqSlice(n.List)...))
 
 			n.Left.Func.Enter.Set(nil)
 
@@ -1659,33 +1663,35 @@
 	return convas(n, init)
 }
 
-func ascompatee(op Op, nl *NodeList, nr *NodeList, init nodesOrNodeListPtr) *NodeList {
+func ascompatee(op Op, nl nodesOrNodeList, nr nodesOrNodeList, init nodesOrNodeListPtr) *NodeList {
 	// check assign expression list to
 	// a expression list. called in
 	//	expr-list = expr-list
 
 	// ensure order of evaluation for function calls
-	for ll := nl; ll != nil; ll = ll.Next {
-		ll.N = safeexpr(ll.N, init)
+	for nlit := nodeSeqIterate(nl); !nlit.Done(); nlit.Next() {
+		*nlit.P() = safeexpr(nlit.N(), init)
 	}
-	for lr := nr; lr != nil; lr = lr.Next {
-		lr.N = safeexpr(lr.N, init)
+	for nrit := nodeSeqIterate(nr); !nrit.Done(); nrit.Next() {
+		*nrit.P() = safeexpr(nrit.N(), init)
 	}
 
 	var nn *NodeList
-	ll := nl
-	lr := nr
-	for ; ll != nil && lr != nil; ll, lr = ll.Next, lr.Next {
+	nlit := nodeSeqIterate(nl)
+	nrit := nodeSeqIterate(nr)
+	for ; !nlit.Done() && !nrit.Done(); nlit.Next() {
 		// Do not generate 'x = x' during return. See issue 4014.
-		if op == ORETURN && ll.N == lr.N {
+		if op == ORETURN && nlit.N() == nrit.N() {
+			nrit.Next()
 			continue
 		}
-		nn = list(nn, ascompatee1(op, ll.N, lr.N, init))
+		nn = list(nn, ascompatee1(op, nlit.N(), nrit.N(), init))
+		nrit.Next()
 	}
 
 	// cannot happen: caller checked that lists had same length
-	if ll != nil || lr != nil {
-		Yyerror("error in shape across %v %v %v / %d %d [%s]", Hconv(nl, obj.FmtSign), Oconv(op, 0), Hconv(nr, obj.FmtSign), count(nl), count(nr), Curfn.Func.Nname.Sym.Name)
+	if !nlit.Done() || !nrit.Done() {
+		Yyerror("error in shape across %v %v %v / %d %d [%s]", Hconv(nl, obj.FmtSign), Oconv(op, 0), Hconv(nr, obj.FmtSign), nodeSeqLen(nl), nodeSeqLen(nr), Curfn.Func.Nname.Sym.Name)
 	}
 	return nn
 }
@@ -1708,11 +1714,10 @@
 	return true
 }
 
-func ascompatet(op Op, nl *NodeList, nr **Type, fp int, init nodesOrNodeListPtr) *NodeList {
+func ascompatet(op Op, nl nodesOrNodeList, nr **Type, fp int, init nodesOrNodeListPtr) *NodeList {
 	var l *Node
 	var tmp *Node
 	var a *Node
-	var ll *NodeList
 	var saver Iter
 
 	// check assign type list to
@@ -1723,11 +1728,12 @@
 	var nn *NodeList
 	var mm *NodeList
 	ucount := 0
-	for ll = nl; ll != nil; ll = ll.Next {
+	it := nodeSeqIterate(nl)
+	for ; !it.Done(); it.Next() {
 		if r == nil {
 			break
 		}
-		l = ll.N
+		l = it.N()
 		if isblank(l) {
 			r = structnext(&saver)
 			continue
@@ -1757,8 +1763,8 @@
 		r = structnext(&saver)
 	}
 
-	if ll != nil || r != nil {
-		Yyerror("ascompatet: assignment count mismatch: %d = %d", count(nl), structcount(*nr))
+	if !it.Done() || r != nil {
+		Yyerror("ascompatet: assignment count mismatch: %d = %d", nodeSeqLen(nl), structcount(*nr))
 	}
 
 	if ucount != 0 {
@@ -2947,7 +2953,7 @@
 //   }
 //   s
 func walkappend(n *Node, init nodesOrNodeListPtr, dst *Node) *Node {
-	if !samesafeexpr(dst, n.List.N) {
+	if !samesafeexpr(dst, nodeSeqFirst(n.List)) {
 		it := nodeSeqIterate(n.List)
 		*it.P() = safeexpr(it.N(), init)
 		walkexpr(it.P(), init)