mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
cmd/compile: wrap/desugar defer calls for register abi
Adds code to the compiler's "order" phase to rewrite go and defer
statements to always be argument-less. E.g.
defer f(x,y) => x1, y1 := x, y
defer func() { f(x1, y1) }
This transformation is not beneficial on its own, but it helps
simplify runtime defer handling for the new register ABI (when
invoking deferred functions on the panic path, the runtime doesn't
need to manage the complexity of determining which args to pass in
register vs memory).
This feature is currently enabled by default if GOEXPERIMENT=regabi or
GOEXPERIMENT=regabidefer is in effect.
Included in this CL are some workarounds in the runtime to insure that
"go" statement targets in the runtime are argument-less already (since
wrapping them can potentially introduce heap-allocated closures, which
are currently not allowed). The expectation is that these workarounds
will be temporary, and can go away once we either A) change the rules
about heap-allocated closures, or B) implement some other scheme for
handling go statements.
Change-Id: I01060d79a6b140c6f0838d6e6813f807ccdca319
Reviewed-on: https://go-review.googlesource.com/c/go/+/298669
Trust: Than McIntosh <thanm@google.com>
Run-TryBot: Than McIntosh <thanm@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
Reviewed-by: David Chase <drchase@google.com>
This commit is contained in:
parent
4e27aa6cd2
commit
769d4b68ef
12 changed files with 344 additions and 41 deletions
|
|
@ -37,6 +37,14 @@ func directClosureCall(n *ir.CallExpr) {
|
|||
return // leave for walkClosure to handle
|
||||
}
|
||||
|
||||
// If wrapGoDefer() in the order phase has flagged this call,
|
||||
// avoid eliminating the closure even if there is a direct call to
|
||||
// (the closure is needed to simplify the register ABI). See
|
||||
// wrapGoDefer for more details.
|
||||
if n.PreserveClosure {
|
||||
return
|
||||
}
|
||||
|
||||
// We are going to insert captured variables before input args.
|
||||
var params []*types.Field
|
||||
var decls []*ir.Name
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue