-
Notifications
You must be signed in to change notification settings - Fork 17.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
cmd/compile: inaccurate escape to heap message #45269
Comments
what should we expect to see a copy of a escapes to heap |
From logic, a should not escape to heap. And this gets verified by the fact that the compiler doesn't report escape for line 7. Maybe nothing needs to change here. The message |
It looks escape analysis misses a package main
func main() {
x := new(int) // new(int) escapes to heap
c := make(chan bool) // (missing)
s := make([]int, 5) // make([]int, 5) escapes to heap
m := make(map[int]int) // make(map[int]int) escapes to heap
go func() {
*x = 1
s[0] = 1
m[1] = 1
close(c)
}()
<-c
println(*x)
println(x)
println(s[0])
println(m[1])
} |
Channels can't be allocated on the stack, so I don't think there's value in tracking their escapiness. |
Reasonable, mainly for sorting purpose in select blocks? Will a channel used as a FIFO queue in a single goroutine be allocated on heap? |
That would be one complication of stack allocation, yes.
Yes, currently. |
And this? It looks package main
const N = 100 * 1024 * 1024
var i interface{}
func bar() {
i = [N]byte{} // [104857600]byte{} escapes to heap
}
func main() {
run := func(f func(), c chan struct{}) {
defer close(c)
var x int
println(&x) // <address 1>
f()
println(&x) // <address 2>
}
c2 := make(chan struct{})
go run(bar, c2)
<-c2
} |
It is stack allocating a big byte array. Not sure why that escape message is there - maybe it refers to the copy that is the backing store for the interface? |
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes.
What did you do?
What did you expect to see?
What did you see instead?
The text was updated successfully, but these errors were encountered: