mirror of
https://github.com/golang/go.git
synced 2025-05-18 22:04:38 +00: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:
parent
4927b9a9ff
commit
3d90378df5
@ -195,12 +195,12 @@ func autotmpname(n int) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// make a new Node off the books
|
// make a new Node off the books
|
||||||
func tempname(nn *Node, t *Type) {
|
func tempnamel(pos src.XPos, curfn *Node, nn *Node, t *Type) {
|
||||||
if Curfn == nil {
|
if curfn == nil {
|
||||||
Fatalf("no curfn for tempname")
|
Fatalf("no curfn for tempname")
|
||||||
}
|
}
|
||||||
if Curfn.Func.Closure != nil && Curfn.Op == OCLOSURE {
|
if curfn.Func.Closure != nil && curfn.Op == OCLOSURE {
|
||||||
Dump("tempname", Curfn)
|
Dump("tempname", curfn)
|
||||||
Fatalf("adding tempname to wrong closure function")
|
Fatalf("adding tempname to wrong closure function")
|
||||||
}
|
}
|
||||||
if t == nil {
|
if t == nil {
|
||||||
@ -208,17 +208,17 @@ func tempname(nn *Node, t *Type) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
s := &Sym{
|
s := &Sym{
|
||||||
Name: autotmpname(len(Curfn.Func.Dcl)),
|
Name: autotmpname(len(curfn.Func.Dcl)),
|
||||||
Pkg: localpkg,
|
Pkg: localpkg,
|
||||||
}
|
}
|
||||||
n := newname(s)
|
n := newnamel(pos, s)
|
||||||
s.Def = n
|
s.Def = n
|
||||||
n.Type = t
|
n.Type = t
|
||||||
n.Class = PAUTO
|
n.Class = PAUTO
|
||||||
n.Esc = EscNever
|
n.Esc = EscNever
|
||||||
n.Name.Curfn = Curfn
|
n.Name.Curfn = curfn
|
||||||
n.Name.SetAutoTemp(true)
|
n.Name.SetAutoTemp(true)
|
||||||
Curfn.Func.Dcl = append(Curfn.Func.Dcl, n)
|
curfn.Func.Dcl = append(curfn.Func.Dcl, n)
|
||||||
|
|
||||||
dowidth(t)
|
dowidth(t)
|
||||||
*nn = *n
|
*nn = *n
|
||||||
@ -226,16 +226,14 @@ func tempname(nn *Node, t *Type) {
|
|||||||
|
|
||||||
func temp(t *Type) *Node {
|
func temp(t *Type) *Node {
|
||||||
var n Node
|
var n Node
|
||||||
tempname(&n, t)
|
tempnamel(lineno, Curfn, &n, t)
|
||||||
n.Sym.Def.SetUsed(true)
|
n.Sym.Def.SetUsed(true)
|
||||||
return n.Orig
|
return n.Orig
|
||||||
}
|
}
|
||||||
|
|
||||||
func tempAt(pos src.XPos, curfn *Node, t *Type) *Node {
|
func tempAt(pos src.XPos, curfn *Node, t *Type) *Node {
|
||||||
// TODO(mdempsky/josharian): Remove all reads and writes of lineno and Curfn.
|
var n Node
|
||||||
lineno = pos
|
tempnamel(pos, curfn, &n, t)
|
||||||
Curfn = curfn
|
n.Sym.Def.SetUsed(true)
|
||||||
n := temp(t)
|
return n.Orig
|
||||||
Curfn = nil
|
|
||||||
return n
|
|
||||||
}
|
}
|
||||||
|
@ -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.
|
// newname returns a new ONAME Node associated with symbol s.
|
||||||
func newname(s *Sym) *Node {
|
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 {
|
if s == nil {
|
||||||
Fatalf("newname nil")
|
Fatalf("newnamel nil")
|
||||||
}
|
}
|
||||||
|
|
||||||
var x struct {
|
var x struct {
|
||||||
@ -379,8 +387,7 @@ func newname(s *Sym) *Node {
|
|||||||
n.Name.Param = &x.Param
|
n.Name.Param = &x.Param
|
||||||
|
|
||||||
n.Op = ONAME
|
n.Op = ONAME
|
||||||
n.Pos = lineno
|
n.Pos = pos
|
||||||
n.Name.Curfn = Curfn
|
|
||||||
n.Orig = n
|
n.Orig = n
|
||||||
|
|
||||||
n.Sym = s
|
n.Sym = s
|
||||||
|
Loading…
x
Reference in New Issue
Block a user