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