]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: add newnamel, use in tempAt
authorJosh Bleecher Snyder <josharian@gmail.com>
Fri, 31 Mar 2017 18:10:01 +0000 (11:10 -0700)
committerJosh Bleecher Snyder <josharian@gmail.com>
Fri, 31 Mar 2017 20:05:20 +0000 (20:05 +0000)
newnamel is newname but with no dependency on lineno or Curfn.
This makes it suitable for use in a concurrent back end.
Use it now to make tempAt global-free.

The decision to push the assignment to n.Name.Curfn
to the caller of newnamel is based on mdempsky's
comments in #19683 that he'd like to do that
for callers of newname as well.

Passes toolstash-check. No compiler performance impact.

Updates #19683
Updates #15756

Change-Id: Idc461a1716916d268c9ff323129830d9a6e4a4d9
Reviewed-on: https://go-review.googlesource.com/39191
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
src/cmd/compile/internal/gc/gen.go
src/cmd/compile/internal/gc/subr.go

index 0429c0c9e7278c17ff47bc0961d15c52eb72ab2d..b0689b22cae1a757dcd365a55df8f050e41e7c4d 100644 (file)
@@ -195,12 +195,12 @@ func autotmpname(n int) string {
 }
 
 // make a new Node off the books
-func tempname(nn *Node, t *Type) {
-       if Curfn == nil {
+func tempnamel(pos src.XPos, curfn *Node, nn *Node, t *Type) {
+       if curfn == nil {
                Fatalf("no curfn for tempname")
        }
-       if Curfn.Func.Closure != nil && Curfn.Op == OCLOSURE {
-               Dump("tempname", Curfn)
+       if curfn.Func.Closure != nil && curfn.Op == OCLOSURE {
+               Dump("tempname", curfn)
                Fatalf("adding tempname to wrong closure function")
        }
        if t == nil {
@@ -208,17 +208,17 @@ func tempname(nn *Node, t *Type) {
        }
 
        s := &Sym{
-               Name: autotmpname(len(Curfn.Func.Dcl)),
+               Name: autotmpname(len(curfn.Func.Dcl)),
                Pkg:  localpkg,
        }
-       n := newname(s)
+       n := newnamel(pos, s)
        s.Def = n
        n.Type = t
        n.Class = PAUTO
        n.Esc = EscNever
-       n.Name.Curfn = Curfn
+       n.Name.Curfn = curfn
        n.Name.SetAutoTemp(true)
-       Curfn.Func.Dcl = append(Curfn.Func.Dcl, n)
+       curfn.Func.Dcl = append(curfn.Func.Dcl, n)
 
        dowidth(t)
        *nn = *n
@@ -226,16 +226,14 @@ func tempname(nn *Node, t *Type) {
 
 func temp(t *Type) *Node {
        var n Node
-       tempname(&n, t)
+       tempnamel(lineno, Curfn, &n, t)
        n.Sym.Def.SetUsed(true)
        return n.Orig
 }
 
 func tempAt(pos src.XPos, curfn *Node, t *Type) *Node {
-       // TODO(mdempsky/josharian): Remove all reads and writes of lineno and Curfn.
-       lineno = pos
-       Curfn = curfn
-       n := temp(t)
-       Curfn = nil
-       return n
+       var n Node
+       tempnamel(pos, curfn, &n, t)
+       n.Sym.Def.SetUsed(true)
+       return n.Orig
 }
index a61f339a1bb048bc26355d10b77e76a572fd40fb..9bdecec5ce7573ad4315e6ea0e4aa70999727a4c 100644 (file)
@@ -365,8 +365,16 @@ func nodl(pos src.XPos, op Op, nleft, nright *Node) *Node {
 
 // newname returns a new ONAME Node associated with symbol s.
 func newname(s *Sym) *Node {
+       n := newnamel(lineno, s)
+       n.Name.Curfn = Curfn
+       return n
+}
+
+// newname returns a new ONAME Node associated with symbol s at position pos.
+// The caller is responsible for setting n.Name.Curfn.
+func newnamel(pos src.XPos, s *Sym) *Node {
        if s == nil {
-               Fatalf("newname nil")
+               Fatalf("newnamel nil")
        }
 
        var x struct {
@@ -379,8 +387,7 @@ func newname(s *Sym) *Node {
        n.Name.Param = &x.Param
 
        n.Op = ONAME
-       n.Pos = lineno
-       n.Name.Curfn = Curfn
+       n.Pos = pos
        n.Orig = n
 
        n.Sym = s