Skip to content

Commit

Permalink
test: go 1.23 testdata
Browse files Browse the repository at this point in the history
  • Loading branch information
jayantxie committed Sep 13, 2024
1 parent 71886b5 commit 28f4791
Show file tree
Hide file tree
Showing 4 changed files with 111 additions and 20 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
40 changes: 21 additions & 19 deletions pkg/proc/eval.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
38 changes: 38 additions & 0 deletions testdata/closure/main.go
Original file line number Diff line number Diff line change
@@ -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)
}
}
51 changes: 51 additions & 0 deletions testdata/rangeoverfunc/main.go
Original file line number Diff line number Diff line change
@@ -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)
}
}

0 comments on commit 28f4791

Please sign in to comment.