]> Cypherpunks repositories - gostls13.git/commit
cmd/compile: more precise analysis of method values
authorMatthew Dempsky <mdempsky@google.com>
Mon, 20 Apr 2020 18:14:36 +0000 (11:14 -0700)
committerMatthew Dempsky <mdempsky@google.com>
Tue, 21 Apr 2020 20:49:34 +0000 (20:49 +0000)
commit2a2423bd05da85dc7d0f8e7d12531623b69036a0
tree0d92bc832877e14b3653f924cdc4f39c9ce11270
parent181153369534c6987306c47630f9e4fbf07b467f
cmd/compile: more precise analysis of method values

Previously for a method value "x.M", we always flowed x directly to
the heap, which led to the receiver argument generally needing to be
heap allocated.

This CL changes it to flow x to the closure and M's receiver
parameter. This allows receiver arguments to be stack allocated as
long as (1) the closure never escapes, *and* (2) method doesn't leak
its receiver parameter.

Within the standard library, this allows a handful of objects to be
stack allocated instead. Listed here are diagnostics that were
previously emitted by "go build -gcflags=-m std cmd" that are no
longer emitted:

archive/tar/writer.go:118:6: moved to heap: f
archive/tar/writer.go:208:6: moved to heap: f
archive/tar/writer.go:248:6: moved to heap: f
cmd/compile/internal/gc/initorder.go:252:2: moved to heap: d
cmd/compile/internal/gc/initorder.go:75:2: moved to heap: s
cmd/go/internal/generate/generate.go:206:7: &Generator literal escapes to heap
cmd/internal/obj/arm64/asm7.go:910:2: moved to heap: c
cmd/internal/obj/mips/asm0.go:415:2: moved to heap: c
cmd/internal/obj/pcln.go:294:22: new(pcinlineState) escapes to heap
cmd/internal/obj/s390x/asmz.go:459:2: moved to heap: c
crypto/tls/handshake_server.go:56:2: moved to heap: hs

Thanks to Cuong Manh Le for help coming up with this solution.

Fixes #27557.

Change-Id: I8c85d671d07fb9b53e11d2dd05949a34dbbd7e17
Reviewed-on: https://go-review.googlesource.com/c/go/+/228263
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
src/cmd/compile/internal/gc/closure.go
src/cmd/compile/internal/gc/escape.go
src/cmd/compile/internal/gc/scc.go
test/escape2.go
test/escape2n.go
test/fixedbugs/issue21709.go
test/fixedbugs/issue27557.go