Wado

WEP: Effect Reconstruction from CM Component Imports

Status: Implemented (v1, synchronous value-type surface)

Guest effects cross the Component Model boundary in both directions, under one rule. A consumer's effect obligations are reconstructed from a dependency's real host-leaf imports rather than from the mere presence of a function-bearing interface (the consuming direction). A Wado library, symmetrically, turns a guest effect it leaves unhandled into a CM import that a consumer satisfies (the producing direction): by holding the underlying capability, by handling it with a with handler, or by supplying a provider component composed in as a fused sibling.

Async import/export (stream<T> / future<T>) is out of scope for v1.

Context

Wado's model is interface = effect = CM import/export (Design Philosophy), and Wasm CM Component Import maps an imported component's interface onto an effectful Wado interface, like WASI.

That over-applies to pure components. package-marl (Markdown → HTML, string→string, no I/O) exports an interface carrying no host capability, yet calling Marl::render(src) as a compiled component required with Marl, and that requirement propagated through the whole call tree — ceremony with no capability behind it.

Two observations sharpen it:

Rejected: generalize #[benign]

Silencing an imported interface's effect with #[benign] (now #[ambient]) asserts a purity the compiler cannot check — the unsafe pattern reborn, admitting unnoticed non-determinism. The point is to derive purity, not trust it.

Decision

One rule spans both directions:

An interface is an effect iff, in the final composed component, it bottoms out as a host import. Satisfied by a fused sibling component instead, it is a transparent namespace whose effectfulness forwards to that sibling's own imports, recursively.

This is composition-relative: the same WIT interface is an effect when host-satisfied and a namespace when sibling-satisfied. The distinction is computed at link/compose time, not intrinsic to the declaration.

Consuming — reconstruct a dependency's obligations

Calling into an imported component requires the union of that component's own host-leaf imports, mapped to the underlying Wado effects (wasi:clocks/monotonic-clock → MonotonicClock), not a with Marl token. A truly pure component reconstructs to no effect — derived, not asserted.

Because CM imports are explicit in the artifact, the reconstructed set is a sound over-approximation by construction: it can over-include an unused capability but never miss one. Hidden non-determinism is surfaced, not silenced — a component that secretly reads the clock forces with MonotonicClock on its callers.

An import only #[ambient] code reaches is the exception, as it is for a source dependency: an assertion's message on wasi:cli/stderr demands nothing of a caller. A Wado library lists in its custom section org.wado-lang.demanded-imports the wasi:* interfaces some export fn holds by what it declares, and reconstruction leaves out the wasi:* imports the list does not name. The consumer still forwards every import, so the host answers it. The payload's first line is its format version. A component without a section of the version the compiler reads, one not built by Wado or stripped of custom sections, demands every import, and a missing-effect error that this causes says so.

The substitution unit moves with the rule: a consumer mocks the underlying capabilities a dependency uses (MonotonicClock), not "Marl". A pure component has nothing to substitute.

Producing — an unhandled guest effect becomes a CM import

A library may declare its own interface effect and leave it unhandled at the boundary. Compiled as a component, that effect lowers to a CM import of a synthesized interface — the mirror of reconstruction. marl can thus perform a RenderHook effect it does not implement, leaving the choice to consumers. An effect handled inside the library stays internal and imports nothing.

Satisfying — hold the capability, handle it, or compose a provider

A reconstructed guest effect (a non-WASI import) materializes in the consumer's scope as an impl-able effect and is required like any other; using the dependency without providing it is a missing-effect error. Three ways to provide it:

A provider is a static link-time choice; a handler is a per-call dynamic one.

A handler links the two components in a cycle: the consumer calls into the dependency, and the dependency calls back into the consumer. Neither can be instantiated first, so the consumer's component nests the dependency and links it by donut wrapping (Linking.md):

The dependency calling back while the consumer's own call into it is still on the stack is reentrance, which the Component Model permits since WebAssembly/component-model#705 removed may_enter. The dependency's other imports (wasi:*, or a guest effect the consumer leaves open) are forwarded from the consumer's own imports, which carry every function the dependency needs. A types-only interface (wasi:clocks/types) has nothing to run, so the consumer defines its types itself rather than importing it. Where one of the consumer's own imports reaches a type of it, the consumer imports it anyway, so that import can alias the type, and the dependency is handed that import too. Such an interface declares no operation, so it is no effect either.

Where no handler is installed at run time, an operation falls back as any effect operation does: to the consumer's own import of the interface when the effect is open at the consumer's boundary, and to a trap otherwise.

Research: Callbacks across the CM Boundary surveys the alternatives (a host effect pump, first-class function values).

Scope

The rule covers the synchronous value-type surface. Consuming attributes to each export the union of the component's demanded imports — sound, and exact for a well-factored pure package, over-approximating only where one component mixes pure and impure exports. Producing is the mirror: a guest effect left unhandled at a library boundary lowers to a CM import for a handler or a provider to satisfy.

Not covered yet:

Resources ride the same rule with no special path: a host-provided resource (wasi:*, Stream / Future) bottoms out at the host and stays an effect; a guest-implemented resource imported through fusion reconstructs like any other interface. The unit is "host-leaf import vs fused-component export," not "interface vs resource."

Consequences

Discoverability

The requirement is statically known at import time; tooling surfaces it — hover prints the reconstructed signature (... with MonotonicClock), and effect-error diagnostics name the full set with a provenance chain (Diagnostic Reason Chains): "render requires MonotonicClock — marl.wasm imports wasi:clocks/monotonic-clock."

Costs (the price of honesty)

Both are the flip side of "no hidden effects": surfacing MonotonicClock is correct; with Marl was cheap because it was dishonest.

Consistency wins

Supersedes

Each supersession is scoped — host-satisfied (WASI) interfaces and host-provided resources are unchanged.

References