Re: [go-nuts] Re: Local variable escapes to heap

2020-11-23 Thread jfcg...@gmail.com
I found this in runtime/chan.go: // Sends and receives on unbuffered or empty-buffered channels are the // only operations where one running goroutine writes to the stack of // another running goroutine. The GC assumes that stack writes only // happen when the goroutine is running and are only don

Re: [go-nuts] Re: Local variable escapes to heap

2020-11-21 Thread jake...@gmail.com
For me, the example you gave of sorty is a strong argument against adding go:local. If I understand correctly, using go:local, if a variable marked this way actually does escape it would cause undefined behavior, possibly in unrelated code. This is the type of bug that is very, very hard to find

Re: [go-nuts] Re: Local variable escapes to heap

2020-11-21 Thread jfcg...@gmail.com
In sorty (commit e4fb296daf1d90037d) I see: $ go build -gcflags -m |& grep -i heap ./sortyI8.go:319:2: moved to heap: sv ./sortyU8.go:319:2: moved to heap: sv ./sortyF4.go:319:2: moved to heap: sv ./sortyF8.go:319:2: moved to heap: sv ./sortyI4.go:319:2: moved to he

Re: [go-nuts] Re: Local variable escapes to heap

2020-11-21 Thread Ian Lance Taylor
On Sat, Nov 21, 2020 at 12:11 AM jfcg...@gmail.com wrote: > > I have the following: > > package myf > > func F1(x *int, ch chan bool) { > *x += 1 > ch <- false > } > > func F2() { > var x int > ch := make(chan bool) // or with buffer > go F1(&x, ch) > <-ch > } > > I get thi

[go-nuts] Re: Local variable escapes to heap

2020-11-21 Thread jfcg...@gmail.com
Hi, I have the following: package myf func F1(x *int, ch chan bool) { *x += 1 ch <- false } func F2() { var x int ch := make(chan bool) // or with buffer go F1(&x, ch) <-ch } I get this when I build with go 1.15.5 via go build -gcflags '-m -m' : 3:6: can inline F1 with

[go-nuts] Re: Local variable escapes to heap

2018-09-19 Thread Dave Cheney
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: f