diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index e693316..7748567 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -6,7 +6,7 @@ jobs: unit-benchmark-test: strategy: matrix: - go: [ "1.21", "1.22" ] + go: [ "1.21", "1.22", "1.23" ] os: [ X64 ] runs-on: ${{ matrix.os }} steps: diff --git a/pkg/proc/eval.go b/pkg/proc/eval.go index cd15e40..59f1253 100644 --- a/pkg/proc/eval.go +++ b/pkg/proc/eval.go @@ -48,28 +48,30 @@ func (scope *myEvalScope) Locals(t *proc.Target, g *proc.G, threadID int, mds [] if err != nil { return nil, err } - if rpn := rangeParentName(scope.Fn.Name); rpn == "" { - return vars, nil - } - - rangeFrames, err := rangeFuncStackTrace(t, g) - if err != nil { - return vars, nil - } - rangeFrames = rangeFrames[2:] // skip the first frame and its return frame - enclosingRangeScopes := make([]*myEvalScope, len(rangeFrames)/2) - - for i, scope2 := range enclosingRangeScopes { - if scope2 == nil { - scope2 := &myEvalScope{EvalScope: *proc.FrameToScope(t, t.Memory(), g, threadID, rangeFrames[2*i:]...)} - enclosingRangeScopes[i] = scope2 + /* + if rpn := rangeParentName(scope.Fn.Name); rpn == "" { + return vars, nil } - vars2, err := scope2.simpleLocals(mds) + + rangeFrames, err := rangeFuncStackTrace(t, g) if err != nil { - continue + return vars, nil } - vars = append(vars, vars2...) - } + rangeFrames = rangeFrames[2:] // skip the first frame and its return frame + enclosingRangeScopes := make([]*myEvalScope, len(rangeFrames)/2) + + for i, scope2 := range enclosingRangeScopes { + if scope2 == nil { + scope2 := &myEvalScope{EvalScope: *proc.FrameToScope(t, t.Memory(), g, threadID, rangeFrames[2*i:]...)} + enclosingRangeScopes[i] = scope2 + } + vars2, err := scope2.simpleLocals(mds) + if err != nil { + continue + } + vars = append(vars, vars2...) + } + */ return vars, nil } diff --git a/testdata/closure/main.go b/testdata/closure/main.go new file mode 100644 index 0000000..edfe41e --- /dev/null +++ b/testdata/closure/main.go @@ -0,0 +1,38 @@ +package main + +import ( + "sync" + "time" +) + +type ctx struct { + a []byte + b *int64 + c *string +} + +func main() { + cf := getFunc() + var wg sync.WaitGroup + wg.Add(1) + go func() { + defer wg.Done() + time.Sleep(100 * time.Second) + cf() + }() + wg.Wait() +} + +func getFunc() func() { + a := make([]byte, 1024) + b := int64(123) + c := string(a) + myctx := &ctx{ + a: a, + b: &b, + c: &c, + } + return func() { + println(myctx) + } +} diff --git a/testdata/rangeoverfunc/main.go b/testdata/rangeoverfunc/main.go new file mode 100644 index 0000000..80252ee --- /dev/null +++ b/testdata/rangeoverfunc/main.go @@ -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) + } +}