Skip to content

wasm: the blob has no runtime error channel (needed for ConveyorTransitTooLong) #921

Closed

Description

@bpowers

Sub-issue of #884. Prerequisite for the conveyor belt pass (see the belt-pass issue).

Problem

The wasm blob has no runtime error channel at all. Nothing in the generated module can report a failure to the host: there is no error global, no exported getter, and run_to/run_initials have no early-return path.

That was fine until now, because the ordinary bytecode path has no per-step runtime errors (division by zero yields inf, a bad table index yields NaN, and so on), and the queue pass landed in d043434 has none either. The conveyor pass does.

Scope

Exactly one per-step runtime error exists in the whole conveyor/queue pass: ErrorCode::ConveyorTransitTooLong, raised when a belt's slat count exceeds conveyor::MAX_SLATS_PER_BELT (1e6). It is raised in two places:

  • conveyor_compile.rs:2797, inside init_belts
  • the mid-run growth path, when <sample> re-latches a larger transit time

Every other Err in queue_compile.rs (:271, :281, :470, :851, :931, :977, :984, :1156, :1178) is plan-build time and never executes inside the blob. So this is a narrow mechanism, not a general one.

Suggested shape

Two mutable i32 globals -- G_ERR_CODE (0 = ok, else the ErrorCode as i32) and G_ERR_BELT (index into the plan list) -- plus an exported getter. On error the pass sets both and unwinds; run_to and run_initials check and return early without saving a row.

The host reconstructs the message text from the plan rather than building strings in wasm. ConveyorPlan::name (conveyor_compile.rs:362-365) exists precisely to name the belt in this error, so the wasm-side message can be byte-identical to the VM's.

Note the queue pass's bump allocator currently traps (Unreachable) on a failed memory.grow, because no error channel existed when it was written (see the rustdoc on emit_alloc in src/wasmgen/passes.rs). Once this channel exists, consider whether an OOM should become a reportable error rather than a trap. A trap is defensible -- it is loud and contained -- so this is a judgment call, not an obligation.

Acceptance

  • A conveyor model whose transit time exceeds the slat bound reports ConveyorTransitTooLong from the wasm backend with the same message the VM produces, naming the same belt.
  • The blob stays self-contained: no host imports. The only new export is the error getter.
  • Use the test-only SlatBoundGuard override (conveyor.rs:69-86) with a tiny fixture. Do NOT build a 1e6-slat model to trip the production bound -- cargo test --workspace runs under a 3-minute cap.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions