-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
runtime: run syscall/js finalizers on wasm without a manual GC #5545
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
deadprogram
merged 17 commits into
tinygo-org:dev
from
felipegenef:fix-syscall-js-finalizeref-pressure-gc
Aug 26, 2026
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
851d47e
runtime: run syscall/js finalizers on wasm without a manual GC
felipegenef 58898cd
runtime: address review feedback on finalizer idle GC
felipegenef ee59cd9
runtime: clear a finished task's args pointer so its arguments are co…
felipegenef d619b24
runtime: skip the finalizer scan with a per-block registration bit
felipegenef d456724
Merge remote-tracking branch 'upstream/dev' into fix-syscall-js-final…
felipegenef 45ce61c
runtime: guard the finalizer registration bitmap with gcLock
felipegenef 91d43ec
testdata: cover finalizer invariants on every scheduler
felipegenef 363b901
main_test: limit the finalizer scheduler variants to linux and darwin
felipegenef 69c945b
testdata: wait for the finalizer queue to drain before asserting
felipegenef 37e7097
testdata: make the finalizer counters atomic and wait for a known dra…
felipegenef a6e58da
runtime: add finalizer bookkeeping asserts under runtime_asserts
felipegenef fc0fe94
runtime: address finalizer GC review feedback
felipegenef abb41c2
testdata: strengthen blocked stack finalizer test
felipegenef 8a2f853
runtime: fix finalizer cleanup edge cases
felipegenef 9c0cecc
runtime: decouple wasm export scheduling from finalizers
felipegenef e2af231
runtime: avoid redundant wakeups for re-entrant wasm exports
felipegenef 214274a
runtime: simplify finalizer comments
felipegenef File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| package compileopts | ||
|
|
||
| import ( | ||
| "go/build/constraint" | ||
| "os" | ||
| "path/filepath" | ||
| "strings" | ||
| "testing" | ||
| ) | ||
|
|
||
| // TestFinalizerRunnerSchedulerCoverage verifies that each scheduler selects one runner file. | ||
| // It uses validSchedulerOptions so new schedulers are included. | ||
| func TestFinalizerRunnerSchedulerCoverage(t *testing.T) { | ||
| files := []string{ | ||
| "gc_finalizer_sched.go", | ||
| "gc_finalizer_sched_none.go", | ||
| "gc_finalizer_sched_other.go", | ||
| } | ||
| exprs := make([]constraint.Expr, len(files)) | ||
| for i, name := range files { | ||
| exprs[i] = readBuildConstraint(t, filepath.Join("..", "src", "runtime", name)) | ||
| } | ||
|
|
||
| for _, sched := range validSchedulerOptions { | ||
| // The finalizer table exists under block GCs. | ||
| // gc.conservative satisfies the GC condition in every constraint. | ||
| tags := map[string]bool{ | ||
| "gc.conservative": true, | ||
| "scheduler." + sched: true, | ||
| } | ||
| var matched []string | ||
| for i, expr := range exprs { | ||
| if expr.Eval(func(tag string) bool { return tags[tag] }) { | ||
| matched = append(matched, files[i]) | ||
| } | ||
| } | ||
| if len(matched) != 1 { | ||
| t.Errorf("scheduler.%s: spawnFinalizerRunner defined in %d files %v, want exactly 1", | ||
| sched, len(matched), matched) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| func readBuildConstraint(t *testing.T, path string) constraint.Expr { | ||
| t.Helper() | ||
| data, err := os.ReadFile(path) | ||
| if err != nil { | ||
| t.Fatal(err) | ||
| } | ||
| for _, line := range strings.Split(string(data), "\n") { | ||
| line = strings.TrimSpace(line) | ||
| if constraint.IsGoBuild(line) { | ||
| expr, err := constraint.Parse(line) | ||
| if err != nil { | ||
| t.Fatalf("%s: %v", path, err) | ||
| } | ||
| return expr | ||
| } | ||
| if line != "" && !strings.HasPrefix(line, "//") { | ||
| break // reached code before any //go:build line | ||
| } | ||
| } | ||
| t.Fatalf("%s: no //go:build line found", path) | ||
| return nil | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| //go:build scheduler.tasks | ||
|
|
||
| package task | ||
|
|
||
| // MarkFinishing does nothing for scheduler.tasks because it does not use asyncify heap stacks. | ||
| func MarkFinishing() {} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this might need
t.state.args = nil?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch, fixed. Added a testFinishedGoroutineArgs case in finalizeridle.go to cover it. Thanks!