Repository navigation
Enable NativeAOT finalization on WASM and WASI - #136682
Conversation
|
Azure Pipelines: Successfully started running 3 pipeline(s). 12 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
|
Tagging subscribers to this area: @agocke, @dotnet/ilc-contrib |
d9ca808 to
de3e3b3
Compare
de3e3b3 to
bdf2e79
Compare
bdf2e79 to
0b22ad3
Compare
0b22ad3 to
beef4b3
Compare
Mirror CoreCLR's host scheduling and conditional structure, with synchronous WASM finalizer waits and separate persistent-worker and callback iteration entry points. Co-authored-by: Copilot <[email protected]> Copilot-Session: 8c7bee32-d29d-4640-ac49-ec1c6ee6e8b5
beef4b3 to
624c058
Compare
|
Still draft? |
There was a problem hiding this comment.
🟡 Changes recommended
Critical finalizer scheduling gaps can indefinitely block WASI finalization and let multithreaded WASM shutdown finish without delivering ProcessExit.
5 open issues
Drain pending finalizers before the WASI event loop polls · New Wake and join the finalizer worker during WASM shutdown · New Restore execution and synchronization contexts after finalization · New Guard against reentry from callback-driven finalizers · New Add WASI coverage for callback-driven finalizer draining · New
What changed in this PR
This PR enables NativeAOT finalization on WASM/WASI using host callbacks and synchronous queue draining, while aligning CoreCLR’s finalizer behavior with threading support.
Changes:
- Includes NativeAOT’s managed finalizer implementation in WASM builds and separates persistent-worker and single-iteration entry points.
- Adds WASI pending-finalization scheduling, browser callback hooks, and synchronous finalizer waits for single-threaded builds.
- Replaces selected CoreCLR WASM-specific guards with
FEATURE_MULTITHREADINGchecks.
| File | Description |
|---|---|
src/coreclr/vm/finalizerthread.cpp |
Selects finalizer signaling and waiting behavior by threading support. |
src/coreclr/nativeaot/System.Private.CoreLib/src/System.Private.CoreLib.csproj |
Includes the managed finalizer implementation on WASM. |
src/coreclr/nativeaot/Runtime/FinalizerHelpers.cpp |
Adds host scheduling, callback entry points, and synchronous draining. |
src/coreclr/nativeaot/Runtime.Base/src/System/Runtime/__Finalizer.cs |
Extracts a shared finalizer iteration and exposes a WASM callback entry point. |
Review effort: Balanced
Co-authored-by: Copilot <[email protected]> Copilot-Session: a5403e73-fcf9-4278-b9d0-4b1dc55ca703
|
Tagging subscribers to 'arch-wasm': @lewing, @pavelsavara |
I wasn't sure about the dead TARGET_BROWSER code. The task I gave to copilot was to mirror what CoreCLR does including ifdefs (that's why it was also not using MULTITHREADING you asked about). I removed the dead TARGET_BROWSER code from this in the last commit and pulled out of draft. I'm not sure what to do with the copilot feedback here. It's pointing out issues in the WASI CoreCLR implementation that this just mirrors. We either extend the scope of this and fix it on CoreCLR too, or file that that feedback off as a bug to be looked at in both implementations. |
This reverts commit 43a7d6f.
Oh so we do build for TARGET_BROWSER, I just never looked if any of it makes sense. My bad, reverted that. |
|
All CoreCLR Wasm is single threaded currently. I do not think any of the feedback is actionable in this PR - I would just fix the few ifdefs for consistency. It may be nice to open an issue about the bugs in the CoreCLR implementation. |
Co-authored-by: Copilot <[email protected]> Copilot-Session: 1d482a30-02fe-42a3-99c9-5d133801a665



Mirror CoreCLR's host scheduling and conditional structure, with synchronous WASM finalizer waits and separate persistent-worker and callback iteration entry points.
This also has hooks for TARGET_BROWSER, but I could pull them out.
Co-authored-by: Copilot [email protected]
Copilot-Session: 8c7bee32-d29d-4640-ac49-ec1c6ee6e8b5
Stack created with GitHub Stacks CLI • Give Feedback 💬