Skip to content

AOT: defer .wasm imports to throw-on-use stubs (shared notice + strict) so the build proceeds #5235

Closed

Description

@proggeramlug

Context: after #5230 (defer dynamic import), compiling opencode's real source reaches a .wasm import — @silvia-odwyer/photon-node/photon_rs_bg.wasm (a transitive image dep). perry reads the .wasm as UTF-8 and hard-fails:

Error: Failed to read .../photon_rs_bg.wasm: stream did not contain valid UTF-8

Proposal (defer, matching #5206/#5230)

When an import resolves to a .wasm file, don't read it as UTF-8/TS. Instead:

Reuse: the text-asset synthesis path (#5223) as the file-handling model, and the deferred-site sink + notice + strict from #5230. Build proceeds; the wasm feature degrades unless reached.

Why

Keeps real apps compiling past peripheral .wasm deps (leaf features), consistent with the eval/dynamic-import deferral policy. Full instantiation that makes the wasm actually run is the companion #5234.

Wall chain: new Function ✅ → @/ ✅ → require ✅ → text ✅ → dynamic import ✅ → .wasm (this: defer; #5234: real).

Activity

  1. proggeramlug commented on Jul 13, 2026

    @proggeramlug
    ContributorAuthor

    Shipped in #5236 (5258a6073). Verified end-to-end against the issue's own base64 add.wasm:

    • the .wasm export section is parsed (id-7 binary walk) and named exports become throw-on-call stubs — importing is fine, only calling throws
    • the site is recorded in the shared deferred-AOT notice: notice: 1 ahead-of-time-unsupported site compiled to a deferred runtime error
    • --strict-dynamic-import / perry.strict makes it a hard compile-time error
    • the throw message points at the companion issue: "wasm module add.wasm cannot run in an ahead-of-time compiled binary — full .wasm ESM instantiation is tracked in AOT: instantiate .wasm ES module imports (import * as wasm from './x.wasm') and expose its exports #5234"

    Full .wasm ESM instantiation remains tracked in #5234 (which is the half that did not ship — worth noting, since the two are easy to confuse).

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

    enhancementNew capability or improvement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions