proc: for optimized functions allow .closureptr to not exist (#3808)

* proc: flag variables correctly when range-over-func stmts are used

Argument variables of a range-over-func body closure should be returned
flagged as normal local variables, not as function arguments.

Updates #3806

* proc: for optimized functions allow .closureptr to not exist

For optimized functions .closureptr is sometimes omitted from DWARF,
allow it to be 0 and try to recover the range-over-func stack by best
effort.

Fixes #3806
This commit is contained in:
Alessandro Arzilli
2024-09-18 23:16:34 +02:00
committed by GitHub
parent b9fadbae9b
commit 582305a813
6 changed files with 143 additions and 13 deletions

51
_fixtures/setiterator.go Normal file
View File

@ -0,0 +1,51 @@
package main
import (
"fmt"
"iter"
"strconv"
"time"
)
func main() {
set := New[string]()
for i := 10; i < 100; i++ {
set.Add(strconv.Itoa(i))
}
PrintAllElements[string](set)
}
// Set holds a set of elements.
type Set[E comparable] struct {
m map[E]struct{}
}
// New returns a new [Set].
func New[E comparable]() *Set[E] {
return &Set[E]{m: make(map[E]struct{})}
}
// All is an iterator over the elements of s.
func (s *Set[E]) All() iter.Seq[E] {
return func(yield func(E) bool) {
for v := range s.m {
tmp := make([]byte, 1024)
str := string(tmp)
if !yield(v) {
return
}
go func() { println(str) }()
}
}
}
func (s *Set[E]) Add(v E) {
s.m[v] = struct{}{}
}
func PrintAllElements[E comparable](s *Set[E]) {
for v := range s.All() {
time.Sleep(100 * time.Second)
fmt.Println(v)
}
}