Repository navigation
C# async fixes - #1747
Merged
alexcrichton merged 4 commits intoOct 15, 2026
Merged
C# async fixes#1747
Conversation
wasi-sdk 34's wasm-ld puts the stack first by default, which needs the data to start above the stack, but the ILCompiler sets a global base of 1024, so every C# test failed to link. Put the stack after the data instead: raising the global base to the stack size links, but breaks the runtime's exception unwinding. Also reference the ILCompiler runtime package for the host architecture rather than always x64, so the tests run on aarch64 Linux.
- Declare an async function returning `result` without payloads as `Task`, not `Task<void>`. - Await the export in the async-lift wrapper and wrap its value in the Result, instead of calling it unawaited and awaiting the Result. - Call async imports through the interface's interop class rather than a nonexistent `IImportsInterop`. - Number futures and streams together, in signature order, in the `[future-*-N]` / `[stream-*-N]` intrinsic names, as the canonical ABI does. A function with a stream parameter and a future result (such as `wasi:cli/stdout.write-via-stream`) produced an invalid component. - Name and number futures and streams in an async import's result after the function, instead of an empty function name. - Pin only primitive future/stream buffers. Other payloads, such as `Result<,>`, hold references or differ from the canonical ABI layout, so they go through native memory and the vtable's Lift. Size native buffers for the whole read, and don't call a missing Lift. - Rethrow an async export's failure before its first suspension instead of reporting a NullReferenceException, fail fast on a later failure, and explain an export waiting on something that is not a waitable. - Fully qualify Task, List, Action and TaskContinuationOptions so the generated code compiles without ImplicitUsings. Adds runtime tests for async exports returning results and for a stream parameter with a future result.
Member
|
Thanks! We don't have a ton of active C# reviewers at this time and I don't know enough myself to be able to review this personally. That being said at a skim this all seems fine, and it's ok to land code like this in this repo in general. While you're at it though, would you be up for helping out figuring out how to get C# re-enabled in CI? |
- Size the buffer an async import writes its result into from the result type's canonical ABI layout. It was 4 bytes for any result, so a string or record result overran it, and larger flat results hit a todo!() in the generator. - Free that buffer with AlignedFree once the call's task completes. It was freed with Free right after starting the call, so a call that was still pending wrote and lifted its result from freed memory. - Don't throw from LiftingTaskCompletionSource after setting a result. - Pass the number of values read to a stream's Lift and lift each of them, instead of only the first. - Release a primitive stream read's pinned buffer after a successful read; it took the faulted branch and skipped its cleanups. Adds a runtime test with async imports that return a string and a record while still pending, and a multi-value stream<string> read.
C# was removed from the test matrix when moving it from wasi-sdk 29 to 34, whose linker rejected the ILCompiler's memory layout; the test harness now links with --no-stack-first. Also install .NET 10, which the generated test projects target. Fix the one C# codegen test failure, issue1703.wit, added while C# was out of CI: a variant case named `tag` or `tags` generated a factory method clashing with the variant's `Tag` field or `Tags` class. Those cases now get the same `_` suffix as a case named after its variant.
Contributor
Author
|
@alexcrichton I just noticed this PR was accidentally created, but thanks for looking at it. I've added a couple of other fixes since your review and enabled the CI as you've requested :) |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fixes the following issues: