]> Cypherpunks.ru repositories - gostls13.git/commit
[dev.regabi] cmd/compile: reimplement capture analysis
authorMatthew Dempsky <mdempsky@google.com>
Tue, 5 Jan 2021 02:05:34 +0000 (18:05 -0800)
committerMatthew Dempsky <mdempsky@google.com>
Tue, 5 Jan 2021 21:11:38 +0000 (21:11 +0000)
commitfd43831f4476dc9a3ba83aa3a2e4117ed0b8596e
tree47f90a423a1c796d925ac5564dd0a7d58e641cb0
parentfb69c67cad4d554dab8281786b7e1e2707fc3346
[dev.regabi] cmd/compile: reimplement capture analysis

Currently we rely on the type-checker to do some basic data-flow
analysis to help decide whether function literals should capture
variables by value or reference. However, this analysis isn't done by
go/types, and escape analysis already has a better framework for doing
this more precisely.

This CL extends escape analysis to recalculate the same "byval" as
CaptureVars and check that it matches. A future CL will remove
CaptureVars in favor of escape analysis's calculation.

Notably, escape analysis happens after deadcode removes obviously
unreachable code, so it sees the AST without any unreachable
assignments. (Also without unreachable addrtakens, but
ComputeAddrtaken already happens after deadcode too.) There are two
test cases where a variable is only reassigned on certain CPUs. This
CL changes them to reassign the variables unconditionally (as no-op
reassignments that avoid triggering cmd/vet's self-assignment check),
at least until we remove CaptureVars.

Passes toolstash -cmp.

Change-Id: I7162619739fedaf861b478fb8d506f96a6ac21f3
Reviewed-on: https://go-review.googlesource.com/c/go/+/281535
Trust: Matthew Dempsky <mdempsky@google.com>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
src/cmd/compile/internal/escape/escape.go
src/cmd/compile/internal/logopt/logopt_test.go
test/chancap.go
test/fixedbugs/issue4085b.go