You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
ADR-015 S6a: WIT export lifting for WASI command components (#343)
## Summary
Implements ADR-015 S6a (WIT export lifting) to enable AffineScript
programs to be invoked as WASI commands via `wasmtime run` and other
WASI 0.2 hosts. When a parameter-less `fn main()` is present, the
compiler now auto-emits a `_start : () -> ()` shim that calls `main` and
drops its result, allowing the command adapter to lift this into a
`wasi:cli/run` export.
## Key Changes
**Compiler (lib/codegen.ml)**
- Auto-emit `_start : () -> ()` shim whenever a parameter-less `fn
main()` is present
- Shim calls `main` and drops its i32 result via `Drop` instructions
- Purely additive: existing reactor consumers, game-loop hooks, and
`__indirect_function_table` exports are byte-unchanged
- Skips if `_start` already exists or `main` has parameters
**Toolchain (tools/provision-component-toolchain.sh)**
- Provision both reactor and command adapters from wasmtime v44.0.1
- Add `ADAPTER_COMMAND_URL` and `ADAPTER_COMMAND_SHA256`
(8ff2ea78d31179f12d6fb1d2cadc0ab83356cd049f362d5a8d94a4070c7a15bd)
- Refactor adapter fetching into reusable `fetch_adapter()` function
- Maintain backward-compatibility aliases (`ADAPTER_URL`,
`ADAPTER_SHA256`, `ADAPTER_PATH`) pointing to reactor
**Componentizer (tools/componentize.sh)**
- Add `--command` and `--reactor` mode flags (reactor is default)
- Select appropriate adapter based on mode
- Validate `_start` export presence in command mode (fail-fast with
pointer to codegen contract)
- Post-componentization, assert `wasi:cli/run` export exists in command
mode (catches adapter/lift regressions)
- Updated usage and error messages to reflect both modes
**Testing (tests/componentize/command_smoke.sh)**
- New end-to-end smoke test for S6a contract
- Compiles fixture with parameter-less `main`, componentizes with
`--command`
- Asserts: valid WASI-0.2 component, `wasi:cli/run` export, `wasmtime
run` invocation succeeds (exit 0), ownership section survives
- SKIP-safe when toolchain or wasmtime not provisioned
**Documentation**
- Updated ECOSYSTEM.adoc and TECH-DEBT.adoc to reflect S6a completion
- Updated SETTLED-DECISIONS.adoc with S6a details and remaining
sub-slices (S5, S6b, S6c)
- Updated .machine_readable/6a2/META.a2ml with S6a ledger entry and
staged plan breakdown
## Implementation Details
- The `_start` shim is inserted as a new function in the module's
function list, with its index recorded in the exports
- Type interning ensures the `() -> ()` type is reused if it already
exists
- The shim's body is a single `Call` to `main` followed by `Drop`
instructions for each result type
- Command mode validation uses `wasm-tools print` to check for `_start`
export and `wasm-tools component wit` to verify the lift
- All adapter fetches are checksum-verified with fail-closed semantics
https://claude.ai/code/session_01NK8KaMbWEwJZfvmrq8Nm8X
Co-authored-by: Claude <noreply@anthropic.com>
0 commit comments