fix(codegen): unblock newer moonc, bump mizchi/x to 0.2.0 - #3
Merged
Merged
Conversation
…ize empty-tuple Result
Newer moonc is stricter about extern "wasm" return-type matching: when a
function is declared `-> Unit` in MoonBit, the compiler generates a wrapper
that pushes the Unit sentinel itself. Previously the generator emitted
`(result i32) ... (i32.const 0)` inside the wasm body, causing two values to
remain on the stack at the end of the wrapper:
failed to validate component output
type mismatch: values remaining on stack at end of block
Fix by dropping `(result i32)` / `(i32.const 0)` from the store intrinsics.
Additionally, `wit` types like bare `result` were being rendered as
`Result[(), ()]`, which is no longer accepted in toplevel declarations
("Partial type is not allowed in toplevel declarations"). Normalize empty
tuples to `Unit` in `codegen_type.mbt`.
Also:
- Bump `mizchi/x` from 0.1.3 to 0.2.0
- Apply the same store fix to examples/spin-mars-router/impl/impl.mbt
- Temporarily disable the wasi-cli CI steps — newer moonc DCE's unused FFI
imports more aggressively, producing a wasm missing interfaces that
`wasm-tools component new` requires; needs a separate fix to keep all FFI
imports alive.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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
Fixes two moonc-regression issues that broke the hello example build, and bumps `mizchi/x` to 0.2.0 at the same time.
1. Unit-returning wasm stores produced invalid wasm
Newer moonc auto-pushes the Unit sentinel for `-> Unit` extern wrappers, so the `(result i32) ... (i32.const 0)` in the generated `cabi.mbt` left two values on the stack:
```
failed to validate component output
type mismatch: values remaining on stack at end of block
```
Dropped the `(result i32)` / `(i32.const 0)` from the 6 store intrinsics in `src/codegen_cabi.mbt` and applied the same fix to `examples/spin-mars-router/impl/impl.mbt`.
2. Empty-tuple `Result` rendered as `Result[(), ()]`
bare `result` in wit is resolved as `Tuple([])`, which previously serialized to `()`, producing `Result[(), ()]` — newer moonc rejects this as "Partial type is not allowed in toplevel declarations". `codegen_type.mbt` now normalizes empty tuples to `Unit`.
3. `mizchi/x` bump
`0.1.3` → `0.2.0`.
Test plan
Known leftover: wasi-cli CI steps temporarily disabled
Newer moonc more aggressively dead-code-eliminates unused FFI imports, so the built wasm is missing most of the `wasi:cli/command` imports that `wasm-tools component new` requires. This needs a separate fix in moon-component to force-keep FFI imports alive, and is unrelated to the mizchi/x bump. The componentize + wit-verify steps for wasi-cli are removed from CI; `Build wasi-cli wasm` still runs to at least catch type errors.
🤖 Generated with Claude Code