Skip to content

Refactor module loading API using Config-based entrypoint#30

Merged
chaploud merged 4 commits intoclojurewasm:mainfrom
jtakakura:refactor/module-instantiation-api
Apr 21, 2026
Merged

Refactor module loading API using Config-based entrypoint#30
chaploud merged 4 commits intoclojurewasm:mainfrom
jtakakura:refactor/module-instantiation-api

Conversation

@jtakakura
Copy link
Copy Markdown
Contributor

Summary

This PR refactors the WasmModule loading API to consolidate various loading parameters into a single Config structure, as proposed in #29. This change simplifies the API surface and ensures that all resource limits are applied consistently before module execution.

Major Changes

  • Unified Loading API: Introduced WasmModule.Config and loadWithOptions in src/types.zig. This replaces multiple specialized load functions with a single, extensible entry point.
  • Pre-execution Resource Limits: VM settings such as fuel, timeout, and memory limits are now applied before the module's start function or instantiation logic runs.
  • C API Expansion: Added zwasm_config_t setter functions for fuel, timeout, and memory limits, allowing C users to configure VM constraints before module creation.
  • Internal Migration: Updated the CLI and internal component logic to use the new unified API.

Rationale

The previous loading API was becoming complex as more configuration options were added. By moving parameters into a Config struct, we provide a cleaner interface for embedders and a more robust foundation for future features, such as execution cancellation.

This refactoring is a prerequisite for the cancellation mechanism currently in draft at #28.

Related Issue
Closes #29

@jtakakura jtakakura force-pushed the refactor/module-instantiation-api branch 9 times, most recently from 6313723 to 003c710 Compare April 16, 2026 03:49
@jtakakura jtakakura force-pushed the refactor/module-instantiation-api branch from 003c710 to 3f25c04 Compare April 16, 2026 07:16
@jtakakura jtakakura marked this pull request as ready for review April 16, 2026 08:57
@chaploud chaploud merged commit cc87f59 into clojurewasm:main Apr 21, 2026
5 checks passed
@chaploud
Copy link
Copy Markdown
Contributor

Thanks for the clean refactor, @jtakakura! Merged into main as cc87f59.

Before merging I ran the full Commit Gate on both platforms plus a downstream regression check, since this PR touches the loading surface that several of our embedders depend on. Sharing the details for transparency:

Mac (arm64)

  • zig build test — pass
  • spec tests — 62263/62263
  • e2e — 796/796
  • FFI (test/c_api/run_ffi_test.sh) — 69/69
  • realworld — PASS=50 FAIL=0 CRASH=0
  • minimal build (-Djit=false -Dcomponent=false -Dwat=false) — pass
  • stripped binary size — 1.22 MB (≤1.5 MB ceiling)
  • fib bench — 46.6 ms vs 48.5 ms baseline (-4%, no regression)

Ubuntu x86_64 (all items above, same commands) — all green

Downstream regression checkClojureWasm pinned locally to this branch:

  • zig build test — PASS
  • cljw test (83 namespaces, upstream Clojure regression) — PASS (0 failures)
  • e2e (wasm) — PASS
  • deps.edn e2e — PASS

A few behavioral changes worth noting for the release notes at tag time:

  1. Fuel now persists (decrements) across invocations — this aligns the impl with the existing /// Persistent fuel budget. doc comment; previous behavior was per-invoke reset.
  2. Resource limits (fuel / timeout / max_memory / force_interpreter) now apply during the start function, since loadCore installs them on Vm before instantiation.
  3. CLI --link retry-without-imports is now scoped to ImportNotFound rather than any error — stricter and more predictable.

Also nice incidental fixes I noticed: store.deinit() on decode/instantiate failure in loadLinked, and the errdefer allocator.destroy(self.vm). Good catches.

Thanks again — this makes the path for future Config additions (cancellation, allocator hooks, etc.) much cleaner.

@jtakakura jtakakura deleted the refactor/module-instantiation-api branch April 21, 2026 11:52
@jtakakura
Copy link
Copy Markdown
Contributor Author

@chaploud Thanks for the deep-dive testing and the regression checks! It’s great to see the incidental fixes and fuel persistence aligned with your expectations. Really glad this helps clear the path for the next features. Looking forward to it 👍

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.

Centralize WasmModule parameters into a Config struct

2 participants