Skip to content

fix(codegen): unblock newer moonc, bump mizchi/x to 0.2.0 - #3

Merged
mizchi merged 1 commit into
mainfrom
bump/x-0.2.0
Apr 10, 2026
Merged

mizchi merged 1 commit into
mainfrom
bump/x-0.2.0

Conversation

@mizchi

@mizchi mizchi commented Apr 10, 2026

Copy link
Copy Markdown
Owner

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

  • `moon test --target native` 68/68 pass
  • Hello example: `moon-component generate` + `moon build --target wasm --release` + `wasm-tools component new` produces a valid component

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

…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>
@mizchi
mizchi merged commit 02335dd into main Apr 10, 2026
2 checks passed
@mizchi
mizchi deleted the bump/x-0.2.0 branch April 10, 2026 18:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant