Commit 2197321d authored by Matthew Dempsky's avatar Matthew Dempsky

cmd/compile: split n.Noescape() into separate uses

n.Noescape() was overloaded for two uses: (1) to indicate a function
was annotated with //go:noescape, and (2) to indicate that certain
temporary allocations don't outlive the current statement.

The first use case is redundant with n.Func.Pragma&Noescape!=0, which
is the convention we use for checking other function-level pragmas.

The second use case is better served by renaming "Noescape" to
"Transient".

Passes toolstash-check.

Change-Id: I0f09d2d5767513894b7bf49da9cdabd04aa4a05e
Reviewed-on: https://go-review.googlesource.com/c/go/+/199822
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: default avatarCherry Zhang <cherryyz@google.com>
parent 5650a53d
...@@ -369,7 +369,7 @@ func (e *Escape) paramTag(fn *Node, narg int, f *types.Field) string { ...@@ -369,7 +369,7 @@ func (e *Escape) paramTag(fn *Node, narg int, f *types.Field) string {
// External functions are assumed unsafe, unless // External functions are assumed unsafe, unless
// //go:noescape is given before the declaration. // //go:noescape is given before the declaration.
if fn.Noescape() { if fn.Func.Pragma&Noescape != 0 {
if Debug['m'] != 0 && f.Sym != nil { if Debug['m'] != 0 && f.Sym != nil {
Warnl(f.Pos, "%v does not escape", name()) Warnl(f.Pos, "%v does not escape", name())
} }
......
...@@ -1293,7 +1293,7 @@ func (e *Escape) finish(fns []*Node) { ...@@ -1293,7 +1293,7 @@ func (e *Escape) finish(fns []*Node) {
} }
n.Esc = EscNone n.Esc = EscNone
if loc.transient { if loc.transient {
n.SetNoescape(true) n.SetTransient(true)
} }
} }
} }
......
...@@ -495,7 +495,6 @@ func (p *noder) funcDecl(fun *syntax.FuncDecl) *Node { ...@@ -495,7 +495,6 @@ func (p *noder) funcDecl(fun *syntax.FuncDecl) *Node {
pragma := fun.Pragma pragma := fun.Pragma
f.Func.Pragma = fun.Pragma f.Func.Pragma = fun.Pragma
f.SetNoescape(pragma&Noescape != 0)
if pragma&Systemstack != 0 && pragma&Nosplit != 0 { if pragma&Systemstack != 0 && pragma&Nosplit != 0 {
yyerrorl(f.Pos, "go:nosplit and go:systemstack cannot be combined") yyerrorl(f.Pos, "go:nosplit and go:systemstack cannot be combined")
} }
...@@ -507,7 +506,7 @@ func (p *noder) funcDecl(fun *syntax.FuncDecl) *Node { ...@@ -507,7 +506,7 @@ func (p *noder) funcDecl(fun *syntax.FuncDecl) *Node {
p.funcBody(f, fun.Body) p.funcBody(f, fun.Body)
if fun.Body != nil { if fun.Body != nil {
if f.Noescape() { if f.Func.Pragma&Noescape != 0 {
yyerrorl(f.Pos, "can only use //go:noescape with external func implementations") yyerrorl(f.Pos, "can only use //go:noescape with external func implementations")
} }
} else { } else {
......
...@@ -1174,7 +1174,7 @@ func (o *Order) expr(n, lhs *Node) *Node { ...@@ -1174,7 +1174,7 @@ func (o *Order) expr(n, lhs *Node) *Node {
} }
case OCLOSURE: case OCLOSURE:
if n.Noescape() && n.Func.Closure.Func.Cvars.Len() > 0 { if n.Transient() && n.Func.Closure.Func.Cvars.Len() > 0 {
prealloc[n] = o.newTemp(closureType(n), false) prealloc[n] = o.newTemp(closureType(n), false)
} }
...@@ -1183,7 +1183,7 @@ func (o *Order) expr(n, lhs *Node) *Node { ...@@ -1183,7 +1183,7 @@ func (o *Order) expr(n, lhs *Node) *Node {
n.Right = o.expr(n.Right, nil) n.Right = o.expr(n.Right, nil)
o.exprList(n.List) o.exprList(n.List)
o.exprList(n.Rlist) o.exprList(n.Rlist)
if n.Noescape() { if n.Transient() {
var t *types.Type var t *types.Type
switch n.Op { switch n.Op {
case OSLICELIT: case OSLICELIT:
...@@ -1195,7 +1195,7 @@ func (o *Order) expr(n, lhs *Node) *Node { ...@@ -1195,7 +1195,7 @@ func (o *Order) expr(n, lhs *Node) *Node {
} }
case ODDDARG: case ODDDARG:
if n.Noescape() { if n.Transient() {
// The ddd argument does not live beyond the call it is created for. // The ddd argument does not live beyond the call it is created for.
// Allocate a temporary that will be cleaned up when this statement // Allocate a temporary that will be cleaned up when this statement
// completes. We could be more aggressive and try to arrange for it // completes. We could be more aggressive and try to arrange for it
......
...@@ -151,7 +151,7 @@ const ( ...@@ -151,7 +151,7 @@ const (
_, nodeDiag // already printed error about this _, nodeDiag // already printed error about this
_, nodeColas // OAS resulting from := _, nodeColas // OAS resulting from :=
_, nodeNonNil // guaranteed to be non-nil _, nodeNonNil // guaranteed to be non-nil
_, nodeNoescape // func arguments do not escape; TODO(rsc): move Noescape to Func struct (see CL 7360) _, nodeTransient // storage can be reused immediately after this statement
_, nodeBounded // bounds check unnecessary _, nodeBounded // bounds check unnecessary
_, nodeAddable // addressable _, nodeAddable // addressable
_, nodeHasCall // expression contains a function call _, nodeHasCall // expression contains a function call
...@@ -179,7 +179,7 @@ func (n *Node) IsDDD() bool { return n.flags&nodeIsDDD != 0 } ...@@ -179,7 +179,7 @@ func (n *Node) IsDDD() bool { return n.flags&nodeIsDDD != 0 }
func (n *Node) Diag() bool { return n.flags&nodeDiag != 0 } func (n *Node) Diag() bool { return n.flags&nodeDiag != 0 }
func (n *Node) Colas() bool { return n.flags&nodeColas != 0 } func (n *Node) Colas() bool { return n.flags&nodeColas != 0 }
func (n *Node) NonNil() bool { return n.flags&nodeNonNil != 0 } func (n *Node) NonNil() bool { return n.flags&nodeNonNil != 0 }
func (n *Node) Noescape() bool { return n.flags&nodeNoescape != 0 } func (n *Node) Transient() bool { return n.flags&nodeTransient != 0 }
func (n *Node) Bounded() bool { return n.flags&nodeBounded != 0 } func (n *Node) Bounded() bool { return n.flags&nodeBounded != 0 }
func (n *Node) Addable() bool { return n.flags&nodeAddable != 0 } func (n *Node) Addable() bool { return n.flags&nodeAddable != 0 }
func (n *Node) HasCall() bool { return n.flags&nodeHasCall != 0 } func (n *Node) HasCall() bool { return n.flags&nodeHasCall != 0 }
...@@ -206,7 +206,7 @@ func (n *Node) SetIsDDD(b bool) { n.flags.set(nodeIsDDD, b) } ...@@ -206,7 +206,7 @@ func (n *Node) SetIsDDD(b bool) { n.flags.set(nodeIsDDD, b) }
func (n *Node) SetDiag(b bool) { n.flags.set(nodeDiag, b) } func (n *Node) SetDiag(b bool) { n.flags.set(nodeDiag, b) }
func (n *Node) SetColas(b bool) { n.flags.set(nodeColas, b) } func (n *Node) SetColas(b bool) { n.flags.set(nodeColas, b) }
func (n *Node) SetNonNil(b bool) { n.flags.set(nodeNonNil, b) } func (n *Node) SetNonNil(b bool) { n.flags.set(nodeNonNil, b) }
func (n *Node) SetNoescape(b bool) { n.flags.set(nodeNoescape, b) } func (n *Node) SetTransient(b bool) { n.flags.set(nodeTransient, b) }
func (n *Node) SetBounded(b bool) { n.flags.set(nodeBounded, b) } func (n *Node) SetBounded(b bool) { n.flags.set(nodeBounded, b) }
func (n *Node) SetAddable(b bool) { n.flags.set(nodeAddable, b) } func (n *Node) SetAddable(b bool) { n.flags.set(nodeAddable, b) }
func (n *Node) SetHasCall(b bool) { n.flags.set(nodeHasCall, b) } func (n *Node) SetHasCall(b bool) { n.flags.set(nodeHasCall, b) }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment