]> Cypherpunks.ru repositories - gostls13.git/commit
[dev.regabi] cmd/compile: simplify inlining of closures
authorMatthew Dempsky <mdempsky@google.com>
Fri, 1 Jan 2021 10:39:00 +0000 (02:39 -0800)
committerMatthew Dempsky <mdempsky@google.com>
Fri, 1 Jan 2021 11:30:21 +0000 (11:30 +0000)
commitfad9a8b52864da738037163565e8eacc958baaa8
treef6c90c6a4257ef17bd47eaf27a2442e434be24ec
parent7d55669847389b8d2e490400226f272023da8605
[dev.regabi] cmd/compile: simplify inlining of closures

Closures have their own ONAMEs for captured variables, which their
function bodies refer to. So during inlining, we need to account for
this and ensure the references still work.

The previous inlining handled this by actually declaring the variables
and then either copying the original value or creating a pointer to
them, as appropriate for variables captured by value or by reference.

But this is needlessly complicated. When inlining the function body,
we need to rewrite all variable references anyway. We can just detect
closure variables and change them to directly point to the enclosing
function's version of this variable. No need for copying or further
indirection.

Does not pass toolstash -cmp. Presumably because we're able to
generate better code in some circumstances.

Change-Id: I8f0ccf7b098f39b8cd33f3bcefb875c8132d2c62
Reviewed-on: https://go-review.googlesource.com/c/go/+/280996
Trust: Matthew Dempsky <mdempsky@google.com>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
TryBot-Result: Go Bot <gobot@golang.org>
src/cmd/compile/internal/inline/inl.go