Skip to content

feat(module): pluggable module providers and a host module prelude - #87

Merged
ecto merged 1 commit into
mainfrom
claude/module-providers
Jul 26, 2026
Merged

feat(module): pluggable module providers and a host module prelude#87
ecto merged 1 commit into
mainfrom
claude/module-providers

Conversation

@ecto

@ecto ecto commented Jul 26, 2026

Copy link
Copy Markdown
Owner

Why

The module system assumed a filesystem, so an embedder without one — WASM in a browser — could not use [use ...] at all. vcad hit this building a two-repo CAD project where a shared interface must have a single source of truth: its browser kernel and its MCP server both evaluate loon, and neither could reach the module system, so multi-file projects needed an external concatenation step that defeats pub, cannot alias, and has no real cycle detection.

Threading a base_dir further would only fix the native path. The resolver, not the path, is the thing to abstract.

What changed

  • trait ModuleProvider { fetch(module_path, from_dir) -> Result<Option<String>, String> }, consulted ahead of path resolution. Returning Ok(None) declines and resolution falls through, so path deps, manifests, lockfiles and remote deps are untouched — a provider is purely additive.
  • MapProvider, a provider over an in-memory name -> source map (also accepts <name>.loon / <name>.oo keys so a caller can key by filename).
  • ModuleCache::{with_provider, set_provider, set_prelude}, and interp::eval_program_with_modules(exprs, base_dir, provider, module_prelude); eval_program_with_base_dir delegates to it, so existing callers are unchanged.
  • Provider modules share the eval path with filesystem ones via a new eval_module, keyed by a <provider>/<name> sentinel. Cycle detection (Loading/Loaded), nested [use], aliasing, selective import and pub behave identically whatever the origin.
  • set_prelude evaluates a host stdlib into every module's env — vcad needs its CAD vocabulary visible inside imported modules.

Behavior change worth a look

The implicit "no pub declared → export everything" fallback previously excluded only builtins, so it also exported prelude names (Option, Result, …) under mod.Name. It now excludes everything defined before the module body — the prelude and any host prelude — so such a module exports only its own definitions. loon-lang's 415 tests pass unchanged.

Consumer

Required by ecto/vcad#715, which supplies an in-memory map on the WASM side and the vcad stdlib as the module prelude. That PR's Rust jobs fail until this lands on main, since vcad's CI clones loon at its default branch.

🤖 Generated with Claude Code

The module system assumed a filesystem, so embedders without one (WASM
in a browser) could not use [use ...] at all. Add a ModuleProvider trait
consulted ahead of path resolution — declining with Ok(None) falls
through, so package/manifest/lockfile resolution is unchanged — plus a
MapProvider over an in-memory name -> source map.

Provider modules share the eval path with filesystem ones via
eval_module, so cycle detection, nested [use], and pub exports behave
identically whatever the origin.

set_prelude lets an embedder evaluate a host stdlib into every module's
env (vcad needs its CAD vocabulary there). Names defined before the
module body are now excluded from the implicit "export everything"
fallback, so a module without pub exports only its own definitions
rather than the prelude's as well.
@cursor

cursor Bot commented Jul 26, 2026

Copy link
Copy Markdown

Bugbot is not enabled for your account, so this pull request was not reviewed.

Enable Bugbot in the Cursor dashboard to get automatic reviews on future PRs.

@chojiai

chojiai Bot commented Jul 26, 2026

Copy link
Copy Markdown

Choji has used up today's reviews

Your team has reached the free plan's limit of 5 reviews per day, so Choji stepped aside on this pull request. That's a plan limit, not a reflection of the change itself.

Your free reviews reset tomorrow. To have Choji review every push without waiting, upgrade to Pro for unlimited reviews.

You're on the free plan · 5 reviews/day.

@vercel

vercel Bot commented Jul 26, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
loon Ready Ready Preview, Comment Jul 26, 2026 12:56am

Request Review

@ecto
ecto merged commit f4b9b9a into main Jul 26, 2026
6 checks passed
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.

1 participant