Skip to content

fix reflect MakeFunc goroutine liveness#1900

Draft
cpunion wants to merge 2 commits into
xgo-dev:mainfrom
cpunion:codex/goroot-goroutine-reflect-coverage
Draft

fix reflect MakeFunc goroutine liveness#1900
cpunion wants to merge 2 commits into
xgo-dev:mainfrom
cpunion:codex/goroot-goroutine-reflect-coverage

Conversation

@cpunion
Copy link
Copy Markdown
Collaborator

@cpunion cpunion commented May 22, 2026

Summary

  • Keep reflect.MakeFunc libffi closure state (closure, Signature, callback data) reachable through the returned function environment.
  • Put goroutine startup records in scanned uncollectable runtime memory until the entry call returns, so reflect-generated function args stay visible while the new thread starts.
  • Add stable test/go coverage for reflect-generated functions launched as goroutines under a racing runtime.GC loop.
  • Remove only the now-passing fixedbugs/issue25897a.go xfails.

Notes

  • Full GOROOT CI is slow/disabled locally; I ran only the requested targeted GOROOT case.
  • Normal PR CI should run from the fork branch. I did not push anything to xgo-dev/llgo.

Focused tests

  • Reproduced before fix with xfail disabled:
    go test ./test/goroot -count=1 -run TestGoRootRunCases -args -goroot /opt/homebrew/Cellar/go@1.24/1.24.11/libexec -dirs fixedbugs -case '^fixedbugs/issue25897a\\.go$' -xfail /tmp/llgo-empty-xfail.yaml
  • go test ./test/go -run '^TestReflectMakeFuncGoroutineStartup$' -count=1
  • go test ./test/go -count=1
  • go run ./cmd/llgo test -a -run '^TestReflectMakeFuncGoroutineStartup$' ./test/go
  • go test ./ssa -run '^TestGoClosureStartupUsesGCManagedMemory$' -count=1
  • go test ./ssa -run 'TestGoClosureStartupUsesGCManagedMemory|TestMakeClosureWithCtx|TestClosure' -count=1
  • (cd runtime && go test ./... -count=1)
  • go test ./test/goroot -count=1 -run TestGoRootRunCases -args -goroot /opt/homebrew/Cellar/go@1.24/1.24.11/libexec -dirs fixedbugs -case '^fixedbugs/issue25897a\\.go$' -xfail /tmp/llgo-empty-xfail.yaml -llgo /tmp/llgo-dev
  • go test ./test/goroot -count=1 -run TestGoRootRunCases -args -goroot /opt/homebrew/Cellar/go@1.24/1.24.11/libexec -dirs fixedbugs -case '^fixedbugs/issue25897a\\.go$' -llgo /tmp/llgo-dev

@cpunion
Copy link
Copy Markdown
Collaborator Author

cpunion commented May 22, 2026

修复进展(head 1d04791cb280439c315bd568b2b20896152a3eb3):

根因:失败 job test (ubuntu-latest, 19) 的完整日志显示 go test -timeout 30m ./...clssaTestRunAndTestFromTestgo/goroutineselects FileCheck 失败。分支实现已把 goroutine startup record 从 AllocU 改为 AllocRoot,并在 routine 返回前 FreeRoot,但 cl/_testgo/goroutinecl/_testgo/selects 的旧 IR 期望仍匹配 AllocU

修复:更新 cl/_testgo/goroutine/in.gocl/_testgo/selects/in.go 的 CHECK 期望,匹配 AllocRoot,并在 goroutine routine 检查 FreeRoot。功能覆盖保留在 test/go/reflect_makefunc_goroutine_test.go,覆盖 reflect.MakeFunc 生成的函数在 goroutine + 强制 GC 下的 liveness。

本地测试:

  • go test ./cl -run 'TestRunAndTestFromTestgo/(goroutine|selects)$' -count=1
  • go test ./ssa -run 'TestFromTestgo/(goroutine|selects)$|TestGoClosureStartupUsesGCManagedMemory' -count=1
  • go test ./test/go -count=1
  • go test ./cl -run TestRunAndTestFromTestgo -count=1
  • go test ./ssa -run 'TestFromTestgo|TestGoClosureStartupUsesGCManagedMemory' -count=1
  • go test ./ssa -count=1

CI 状态:新 head CI 已触发,目前 checks 仍在 queued/in_progress,我会继续监控并按失败继续修。

@codecov-commenter
Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants