If you pass more -m's to the compiler it will explain why

Daves-MacBook-Pro(~/src) % go build -gcflags=-m=2 buffer.go
# command-line-arguments
./buffer.go:12:6: cannot inline main: function too complex: cost 108 
exceeds budget 80
./buffer.go:15:21: buffer escapes to heap
./buffer.go:15:21:      from Builder literal (struct literal element) at 
./buffer.go:15:14
./buffer.go:15:21:      from b (assigned) at ./buffer.go:15:4
./buffer.go:15:21:      from b.meta.Index() (receiver in indirect call) at 
./buffer.go:18:15
./buffer.go:13:6: moved to heap: buffer
<autogenerated>:1: leaking param: .this
<autogenerated>:1:      from .this.Index() (receiver in indirect call) at 
<autogenerated>:1

I recommend raising a bug https://golang.org/issue/new if you feel the 
compiler could prove that main.buffer did not escape.

On Thursday, 20 September 2018 12:39:33 UTC+10, Alex Bahdanau wrote:
>
> Hi all,
>
> I've read a lot about escape analysis in golang, but still couldn't find 
> an answer to this question
> here is the sample <https://play.golang.org/p/GWotXWY0ksC>:
>
> package main
>
> type IMeta interface {
>     Index() int
> }
>
> type Builder struct {
>     buf  []byte
>     meta IMeta
> }
>
> func main() {
>     var buffer [512]byte
>
>     b := Builder{buffer[:0], nil}
>
>     if b.meta != nil {
>         b.meta.Index()
>     }
> }
>
> escape analyzer says:
> .\main.go:15:21: buffer escapes to heap
> .\main.go:13:6: moved to heap: buffer
> <autogenerated>:1:0: leaking param: .this
>
> Could anyone please clarify why local buffer escapes here?
>
> Thx in advance
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to