panic(fmt.Sprintf("iter %d: maxI = %d, len(m) = %d",iter,maxI,len(m)))// ERROR "iter escapes to heap$" "len\(m\) escapes to heap$" "500 escapes to heap$" "... argument does not escape$" "fmt.Sprintf\(.*\) escapes to heap"
}
}
functest2(iterint){
constmaxI=500
m:=make(map[int][]int)// ERROR "make\(map\[int\]\[\]int\) does not escape$"
// var fn func()
fori:=0;i<maxI;i++{
varfnfunc()// this makes it work, because fn stays off heap
j:=0
fn=func(){// ERROR "func literal does not escape$"
panic(fmt.Sprintf("iter %d: maxI = %d, len(m) = %d",iter,maxI,len(m)))// ERROR "iter escapes to heap$" "len\(m\) escapes to heap$" "500 escapes to heap$" "... argument does not escape$" "fmt.Sprintf\(.*\) escapes to heap"
}
}
functest3(iterint){
constmaxI=500
varxint// ERROR "moved to heap: x$"
m:=&x
varfnfunc()// ERROR "moved to heap: fn$"
fori:=0;i<maxI;i++{
// var fn func() // this makes it work, because fn stays off heap
j:=0// ERROR "moved to heap: j$"
fn=func(){// ERROR "func literal escapes to heap$"
ifj<100{
j++
fn()
}else{
*m=*m+1
}
}
fn()
}
if*m!=maxI{
panic(fmt.Sprintf("iter %d: maxI = %d, *m = %d",iter,maxI,*m))// ERROR "\*m escapes to heap$" "iter escapes to heap$" "500 escapes to heap$" "... argument does not escape$" "fmt.Sprintf\(.*\) escapes to heap"
}
}
functest4(iterint){
constmaxI=500
varxint
m:=&x
// var fn func()
fori:=0;i<maxI;i++{
varfnfunc()// this makes it work, because fn stays off heap
j:=0
fn=func(){// ERROR "func literal does not escape$"
ifj<100{
j++
fn()
}else{
*m=*m+1
}
}
fn()
}
if*m!=maxI{
panic(fmt.Sprintf("iter %d: maxI = %d, *m = %d",iter,maxI,*m))// ERROR "\*m escapes to heap$" "iter escapes to heap$" "500 escapes to heap$" "... argument does not escape$" "fmt.Sprintf\(.*\) escapes to heap"
}
}
typestrstruct{
m*int
}
funcrecur1(jint,s*str){// ERROR "s does not escape"
ifj<100{
j++
recur1(j,s)
}else{
*s.m++
}
}
functest5(iterint){
constmaxI=500
varxint// ERROR "moved to heap: x$"
m:=&x
varfn*str
fori:=0;i<maxI;i++{
// var fn *str // this makes it work, because fn stays off heap
fn=&str{m}// ERROR "&str{...} escapes to heap"
recur1(0,fn)
}
if*m!=maxI{
panic(fmt.Sprintf("iter %d: maxI = %d, *m = %d",iter,maxI,*m))// ERROR "\*m escapes to heap$" "iter escapes to heap$" "500 escapes to heap$" "... argument does not escape$" "fmt.Sprintf\(.*\) escapes to heap"
}
}
functest6(iterint){
constmaxI=500
varxint
m:=&x
// var fn *str
fori:=0;i<maxI;i++{
varfn*str// this makes it work, because fn stays off heap
fn=&str{m}// ERROR "&str{...} does not escape"
recur1(0,fn)
}
if*m!=maxI{
panic(fmt.Sprintf("iter %d: maxI = %d, *m = %d",iter,maxI,*m))// ERROR "\*m escapes to heap$" "iter escapes to heap$" "500 escapes to heap$" "... argument does not escape$" "fmt.Sprintf\(.*\) escapes to heap"