moonbit: async runtime redesign and coverage expansion#1556
Draft
peter-jerry-ye wants to merge 61 commits intobytecodealliance:mainfrom
Draft
moonbit: async runtime redesign and coverage expansion#1556peter-jerry-ye wants to merge 61 commits intobytecodealliance:mainfrom
peter-jerry-ye wants to merge 61 commits intobytecodealliance:mainfrom
Conversation
Move file writing to each stage to simplify the data structure
Previously we had them all in the pkg that does the exportation, but it made the code generator too complex. Now we move them away to simplify this As a side effect, there's no unified return_area. The return_area will be freed with each post_return
- Add direction field to FunctionBindgen for proper type resolution - Add type_name_for_lowering function to use OutFuture/OutStream instead of FutureR/StreamR for exports - Add sig_string_with_direction for export stub generation - Pass Direction::Import/Export to FunctionBindgen::new calls appropriately
- Add () to FFI function declarations with no parameters - Use [export] prefix for lowering intrinsic module names - Change reinterpret_as_int() to to_int() for handle conversion - Add let _ = before spawn call to suppress unused result warning
- Make write and close functions async in StreamW generation - Make spawn function public in coroutine.mbt for test usage - Make OutStream struct public for test usage
- Change function signatures from async with out parameter to returning OutFuture/OutStream - Update runner.rs to use new API and handle end-of-stream properly - Fix stream test to use StreamResult::Complete for end-of-stream detection
- Add task_group parameter to async export function signatures - Wrap async export calls with @async.with_task_group - Add async_ field to FunctionBindgen for context tracking - Update tests to use task_group.spawn_bg for background tasks This allows exported async functions to spawn background tasks that will be properly awaited before the function returns.
- Fix MoonBit codegen/runtime for futures/streams\n- Adjust runtime-async MoonBit tests and Rust runner
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.
Summary
This PR redesigns MoonBit async support in
wit-bindgento align generated bindings/runtime behavior with component-model async semantics, and adds broad runtime coverage for MoonBit async paths.What Changed
1. MoonBit async runtime foundation
2. Generator changes for async imports/exports
with_waitablesetandwith_task_group.task_groupparameter.3. MoonBit test toolchain integration updates
4. Runtime and codegen coverage expansion
tests/runtime-async/async/**(new.mbtrunner/test coverage)Design Notes (Intentional)
with_task_groupchild task to model MoonBit structured concurrency.task_group : @async.TaskGroup[Unit]as an umbrella concurrency/cancellation context, not as a direct encoding of function return payload type.Verification
Tested with latest toolchain:
wasmtime 43.0.0wasm-toolsfrommainCommands used:
cargo run test --languages moonbit tests/codegen --artifacts target/artifacts --rust-wit-bindgen-path ./crates/guest-rust --test-threads 1PATH="target/tools/bin:$PATH" cargo run test --languages rust,moonbit tests/runtime-async --artifacts target/artifacts --rust-wit-bindgen-path ./crates/guest-rust --runner "wasmtime -W component-model-async"rust-lowered-sendping-pong