Skip to content

Build and run check on wasm32-wasip1 (six gated sites) #494

Open

Description

@humuhumu33

Request

Let lexlean check build and run on wasm32-wasip1, so it can run in a browser worker over a file system held in memory. No feature flag and no new API are needed: six sites, each gated on target_family = "wasm", leave native code as it is.

Why

A browser tool that authors LexLean specs can then check them with LexLean's own code, with no server and without sending the spec anywhere.

Measured with the patch below, on LexLean 0.3.0 as vendored in PrismPM 35e9f01d5415ed4b0b64c152238f291546957ec4, Rust 1.97.1:

  • On 17 files (4 real specs and 13 with one planted fault each) the WebAssembly build gives the same verdict, codes, messages, lines and columns as lexlean check --all in the SDK image built from that commit.
  • It reports the same compiler-semantics ID and writes the same lexlean.lock, byte for byte.
  • A check of an edited module takes about 50 ms in a Chrome worker.

What blocks it today

Found by building and running, in this order:

  1. fs4 does not compile for WASI (9 errors, cannot find module sys). Used at one site, api.rs acquire_lock. check never takes that lock.
  2. verify/lifeline.rs defines end_leader for Unix and Windows only: a compile error on any other target.
  3. link.rs check_project runs the pipeline on a new thread. WASI has none: LLS8001 cannot spawn the compile thread.
  4. lib.rs embedded_digest reads the embedded tree on scoped threads. The process aborts, even for --version.
  5. same-file compiles for WASI and refuses at run time: same-file is not supported on this platform, once per source file.
  6. backend/core.rs on_stack_for spawns a thread as in 3 (build path, not check).

The change

59 lines added, 14 removed, 7 files:

  1. Cargo.toml: fs4 and same-file become dependencies of non-wasm targets.
  2. api.rs acquire_lock: no lock_exclusive on wasm. An instance owns its whole file system and runs one command.
  3. project.rs all_modules: no same-file identity on wasm. Symlinks are still rejected.
  4. link.rs check_project, backend/core.rs on_stack_for: on wasm without threads, run on the one stack, which the embedder sizes at link time (-zstack-size).
  5. lib.rs embedded_digest: on wasm without threads, read the files on the one thread. The loop body becomes a closure shared by both paths.
  6. verify/lifeline.rs: an end_leader for hosts that are neither Unix nor Windows. It reports failure; no child is ever started there.

To decide

  • Whether dropping the same-file check (LLC0104) on wasm is acceptable, given a host file system without hard links, or whether it should wait for WASI's device and inode in stable std.
  • Whether deep nesting on wasm should be bounded by a depth the build declares, so it stays LLS8002 and never a trap of the instance.

Not tested

  • The crate's own test suite on a native target with the patch applied (it compiles).
  • Any LexLean newer than 0.3.0. The patch is against the 0.3.0 sources; the sites may have moved.
  • Browsers other than Chrome.

Related, separate

For language 1.2 every process reads the 31 MB embedded preservation library to compute the compiler-semantics ID. On wasm that is 0.8 to 1.3 s at start. A check-only build with the ID as a checked-in constant would make the module 15 MB instead of 47 MB. I can open that as its own issue.

The patch (applies to PrismPM 35e9f01d, vendor/lexlean)
diff --git a/vendor/lexlean/Cargo.toml b/vendor/lexlean/Cargo.toml
index 74503e0c..508c464f 100644
--- a/vendor/lexlean/Cargo.toml
+++ b/vendor/lexlean/Cargo.toml
@@ -77,13 +77,6 @@ version = "1.2"
 version = "4.5"
 features = ["derive"]
 
-[dependencies.fs4]
-version = "0.13"
-features = ["sync"]
-
-[dependencies.same-file]
-version = "1.0"
-
 [dependencies.semver]
 version = "1.0"
 
@@ -113,6 +106,13 @@ version = "2"
 [dev-dependencies.proptest]
 version = "1.6"
 
+[target.'cfg(not(target_family = "wasm"))'.dependencies.fs4]
+version = "0.13"
+features = ["sync"]
+
+[target.'cfg(not(target_family = "wasm"))'.dependencies.same-file]
+version = "1.0"
+
 [target."cfg(unix)".dependencies.rustix]
 version = "1"
 features = [
diff --git a/vendor/lexlean/src/api.rs b/vendor/lexlean/src/api.rs
index 2fac21e5..56d6c51b 100644
--- a/vendor/lexlean/src/api.rs
+++ b/vendor/lexlean/src/api.rs
@@ -529,6 +529,7 @@ pub(crate) struct MutationGuard {
 /// Acquire the project mutation lock at `<build_root>/.lock` (§21.8). The
 /// build root's components are checked for symlinks first (§25.1).
 fn acquire_lock(project: &Project) -> Result<MutationGuard, LexLeanError> {
+    #[cfg(not(target_family = "wasm"))]
     use fs4::fs_std::FileExt;
     let build_root = project
         .confined_creatable(&project.config.build_root)
@@ -549,6 +550,10 @@ fn acquire_lock(project: &Project) -> Result<MutationGuard, LexLeanError> {
         .write(true)
         .open(lock_path.as_std_path())
         .map_err(|io_error| host_failure(format!("{lock_relative}: {io_error}")))?;
+    // A WebAssembly instance owns its whole file system and runs one
+    // command, so there is no second writer to exclude and no host lock to
+    // take; every other host keeps the exclusive lock (§21.8).
+    #[cfg(not(target_family = "wasm"))]
     file.lock_exclusive()
         .map_err(|io_error| host_failure(format!("{lock_relative}: {io_error}")))?;
     Ok(MutationGuard { _file: file })
diff --git a/vendor/lexlean/src/backend/core.rs b/vendor/lexlean/src/backend/core.rs
index 63143257..7762c667 100644
--- a/vendor/lexlean/src/backend/core.rs
+++ b/vendor/lexlean/src/backend/core.rs
@@ -1481,6 +1481,14 @@ fn on_stack_for<T: Send>(depth: u64, work: impl FnOnce() -> T + Send) -> Result<
         .unwrap_or(usize::MAX)
         .saturating_mul(48 << 10)
         .saturating_add(1 << 20);
+    // As in `link::check_project`: without threads the one linked stack
+    // hosts the work, and an overflow traps the instance.
+    #[cfg(all(target_family = "wasm", not(target_feature = "atomics")))]
+    {
+        let _ = bytes;
+        return Ok(work());
+    }
+    #[cfg(not(all(target_family = "wasm", not(target_feature = "atomics"))))]
     std::thread::scope(|scope| {
         let handle = std::thread::Builder::new()
             .stack_size(bytes)
diff --git a/vendor/lexlean/src/lib.rs b/vendor/lexlean/src/lib.rs
index 6ebb25d1..59360533 100644
--- a/vendor/lexlean/src/lib.rs
+++ b/vendor/lexlean/src/lib.rs
@@ -230,15 +230,24 @@ fn embedded_digest(keep: impl Fn(&str) -> bool) -> Sha256Digest {
     let workers = std::thread::available_parallelism()
         .map_or(1, usize::from)
         .min(8);
+    let read = || loop {
+        let at = next.fetch_add(1, std::sync::atomic::Ordering::Relaxed);
+        let Some((path, bytes)) = selected.get(at) else {
+            break;
+        };
+        let _ = slots[at].set(identity_bytes(path, bytes));
+    };
+    // A WebAssembly target without threads reads the files on its one
+    // thread; the rows and so the digest are the same.
+    #[cfg(all(target_family = "wasm", not(target_feature = "atomics")))]
+    {
+        let _ = workers;
+        read();
+    }
+    #[cfg(not(all(target_family = "wasm", not(target_feature = "atomics"))))]
     std::thread::scope(|scope| {
         for _ in 0..workers {
-            scope.spawn(|| loop {
-                let at = next.fetch_add(1, std::sync::atomic::Ordering::Relaxed);
-                let Some((path, bytes)) = selected.get(at) else {
-                    break;
-                };
-                let _ = slots[at].set(identity_bytes(path, bytes));
-            });
+            scope.spawn(&read);
         }
     });
     let rows: Vec<(&str, std::borrow::Cow<'static, [u8]>)> = selected
diff --git a/vendor/lexlean/src/link.rs b/vendor/lexlean/src/link.rs
index 50bbbb81..0b90f676 100644
--- a/vendor/lexlean/src/link.rs
+++ b/vendor/lexlean/src/link.rs
@@ -364,6 +364,12 @@ pub fn check_project(
     lock: &Lock,
     packages: Vec<LexiconPackage>,
 ) -> Result<CheckedProject, LexLeanError> {
+    // A WebAssembly target without threads cannot host the compile thread.
+    // Its one stack is fixed when the module is linked, so the build sizes
+    // it instead, and an overflow traps the instance.
+    #[cfg(all(target_family = "wasm", not(target_feature = "atomics")))]
+    return check_project_inline(project, selection, lock, packages);
+    #[cfg(not(all(target_family = "wasm", not(target_feature = "atomics"))))]
     std::thread::scope(|scope| {
         let handle = std::thread::Builder::new()
             .name("lexlean-compile".to_owned())
diff --git a/vendor/lexlean/src/project.rs b/vendor/lexlean/src/project.rs
index c1fb0eea..c68d58ad 100644
--- a/vendor/lexlean/src/project.rs
+++ b/vendor/lexlean/src/project.rs
@@ -422,6 +422,7 @@ impl Project {
     pub fn all_modules(&self) -> Result<BTreeMap<String, String>, Vec<Diagnostic>> {
         let mut diagnostics = Vec::new();
         let mut modules: BTreeMap<String, String> = BTreeMap::new();
+        #[cfg(not(target_family = "wasm"))]
         let mut identities: Vec<(same_file::Handle, String)> = Vec::new();
         for root in &self.config.source_roots {
             let absolute_root = match self.confined(root, Expect::Creatable) {
@@ -484,6 +485,12 @@ impl Project {
                     continue;
                 }
                 let relative = self.display(&path);
+                // A WebAssembly host gives no stable identity of a file
+                // (`same-file` has no implementation there), so two names of
+                // one file cannot be told apart by it: such a host must
+                // supply a file system without hard links. Symlinks are
+                // rejected above on every host.
+                #[cfg(not(target_family = "wasm"))]
                 match same_file::Handle::from_path(path.as_std_path()) {
                     Ok(handle) => {
                         if let Some((_, existing)) = identities
diff --git a/vendor/lexlean/src/verify/lifeline.rs b/vendor/lexlean/src/verify/lifeline.rs
index 841038b7..b3ccca93 100644
--- a/vendor/lexlean/src/verify/lifeline.rs
+++ b/vendor/lexlean/src/verify/lifeline.rs
@@ -419,6 +419,16 @@ pub(crate) fn group_members(group: i32) -> Option<Vec<Member>> {
     Some(members)
 }
 
+/// A host with neither process groups nor a process tree starts no child
+/// (`verify` is refused there before one is spawned), so there is never a
+/// leader to end; being asked to end one is reported, never taken for success.
+#[cfg(not(any(unix, windows)))]
+pub(crate) fn end_leader(id: u32) -> GroupEnd {
+    GroupEnd::Failed(format!(
+        "process {id} cannot be ended: this host runs no child processes"
+    ))
+}
+
 /// End the tree rooted at `id` on windows, and report a `taskkill` that
 /// failed like a group that could not be ended (the one place a tree is
 /// ended; see the unix function of the same name).

Activity

  1. afflom commented on Nov 12, 2026

    @afflom
    Member

    Bounded maintainer scope review: retain the17-file/Chrome/vendored0.3.0 results as historical evidence; they do not establish current-release support or authorize dropping native guarantees.

    The smallest design decision is an explicit supported-host contract. target_family="wasm" alone does not imply a private filesystem, no hardlinks, one writer or a sufficient stack; atomics alone does not establish thread support. Disabling locking and LLC0104 for the whole target family therefore needs a narrower, enforceable capability boundary. The single-stack path also needs a stated supported depth/error contract: a trap cannot silently replace the documented typed failure. Check-only status must remain distinct from verification and production capability.

    Please resolve those boundaries in the proposal before selecting implementation scope; keep native behavior and existing error guarantees intact. No new run of the historical demonstration is requested. This review does not schedule implementation, alter a milestone, or create a prerequisite for #468.

  2. humuhumu33 commented on Nov 13, 2026

    @humuhumu33
    ContributorAuthor

    Thank you for the review. Draft pull request #503 resolves each boundary in the specification before scope is chosen; nothing in it relies on the 0.3.0 demonstration, and native behavior and error guarantees are unchanged.

    • Host boundary. Every gate is target_os = "wasi", and the claim is wasm32-wasip1 alone, written into SPEC §8.3 and registered as CL-25. Neither target_family = "wasm" nor atomics decides anything.
    • LLC0104 is kept. On WASI a file's identity is the device and inode WASI's stat reports, read through rustix (already a dependency, no unsafe code). The proposal assumes no hard-link-free host: CL-25 hard-links a module and requires LLC0104 from both builds.
    • The lock is not dropped. WASI has no file lock, so acquire_lock refuses with LLV7010 before it touches the project. lock, fmt, build, verify and migrate are refused there, and no private file system or single writer is assumed. check takes no lock.
    • Depth keeps its typed failure. The executable is linked with an 80 MiB stack, config::WASI_STACK_BYTES, one constant that build.rs links with and compile_stack_plan plans with. On WASI the hosted depth is therefore 1,024, and deeper input is LLS8002, not a trap. CL-25 checks nesting 1,000 (same result as native) and 1,040 (LLS8002) with max_scope_depth = 100000000. The stated host requirement is a call stack at least Node 22's default. An embedder links its module with at least WASI_STACK_BYTES.
    • Check-only. §8.3 claims check only. Verification and production stay native capabilities.

    Evidence on release/v0.4 at 465b8ab: conformance_cl_25 passes. 277 projects (every single-step check fixture and every example) give the same exit code and byte-identical JSON as the native executable under Node's node:wasi. A planted defect (the stack link removed) is caught at the nesting vector as a trap. Details and what was not tested are in #503.

  3. afflom commented on Nov 13, 2026

    @afflom
    Member

    Thanks for documenting the intended WASI boundary. Current #503 f77c457 retains that design, and the narrow check-only direction is endorsed. Three concrete items from review #503 (review) remain distinct from the stated design:

    • init creates the destination and writes its skeleton before Engine::lock reaches LLV7010. An early acquire_lock refusal inside Engine does not cover those earlier CLI writes. Guard init before creation and cover it using the same built WASI binary.
    • CL25 is already reserved for snapshot in Execute native Host commands with modeled effects and mirrored validation #439; coordinate a unique ID and its existing bindings with that owner before forward integration.
    • The WASI target install currently runs on every vv matrix leg while the case runs only in rest. Condition that existing install on matrix.part == 'rest'; no extra partition or benchmark is needed.

    Current draft CI43325796203 passed3 jobs and skipped15 groups, with repro passed. That is useful draft evidence, not full qualification. Please carry these focused repairs in the existing owner lane; no duplicate build, producer or patch is requested.

  4. added a commit that references this issue on Nov 15, 2026
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