1
0
mirror of https://github.com/golang/go synced 2024-11-18 06:34:53 -07:00

cmd/compile: add newnamel, use in tempAt

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>
This commit is contained in:
Josh Bleecher Snyder 2017-03-31 11:10:01 -07:00
parent 4927b9a9ff
commit 3d90378df5
2 changed files with 23 additions and 18 deletions

View 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
}

View 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