Skip to content

Give the WASI module a host-written filesystem - #5565

Open
kinto0 wants to merge 1 commit into
meta:mainfrom
kinto0:export-D130311987
Open

kinto0 wants to merge 1 commit into
meta:mainfrom
kinto0:export-D130311987

Conversation

@kinto0

@kinto0 kinto0 commented Nov 6, 2026

Copy link
Copy Markdown
Contributor

Summary:
Mockup for review discussion of #5493. Not for landing.

  • What: pyrefly_wasm.js gives the module one preopened directory, /, whose files live in JavaScript memory (files.write, files.remove). The module can only read it. A new Workspace (Rust in lib.rs, JavaScript class in pyrefly_wasm.js) checks a project under a root in that filesystem with ordinary ModulePath::filesystem handles. The host edits a file by writing it with files and reporting the change with Workspace.filesChanged, which calls Transaction::invalidate_events, as a file watcher does.
  • Why: a WASI host that resolves imports through a filesystem can show unsaved buffers to importers without any change to State. The host owns the filesystem, so it writes the buffer there and keeps the saved contents itself. This avoids the source overrides of state: load exact module-source overrides before normal sources #5493 (override on every ModulePath variant, a stale Stdlib cache for bundled typeshed overrides, keys that silently miss). It also handles a new unsaved file, which an override cannot, because invalidate_events with created invalidates import resolution.
  • Cost: each edit counts as a disk change, so State::generation increases on each edit.
  • The Playground path does not change: it still uses memory paths and does not touch the filesystem.

Differential Revision: D130311987

Summary:
Mockup for review discussion of meta#5493. Not for landing.

- What: `pyrefly_wasm.js` gives the module one preopened directory, `/`, whose files live in JavaScript memory (`files.write`, `files.remove`). The module can only read it. A new `Workspace` (Rust in `lib.rs`, JavaScript class in `pyrefly_wasm.js`) checks a project under a root in that filesystem with ordinary `ModulePath::filesystem` handles. The host edits a file by writing it with `files` and reporting the change with `Workspace.filesChanged`, which calls `Transaction::invalidate_events`, as a file watcher does.
- Why: a WASI host that resolves imports through a filesystem can show unsaved buffers to importers without any change to `State`. The host owns the filesystem, so it writes the buffer there and keeps the saved contents itself. This avoids the source overrides of meta#5493 (override on every `ModulePath` variant, a stale `Stdlib` cache for bundled typeshed overrides, keys that silently miss). It also handles a new unsaved file, which an override cannot, because `invalidate_events` with `created` invalidates import resolution.
- Cost: each edit counts as a disk change, so `State::generation` increases on each edit.
- The `Playground` path does not change: it still uses memory paths and does not touch the filesystem.

Differential Revision: D130311987
@meta-cla meta-cla Bot added the cla signed label Nov 6, 2026
@meta-codesync

meta-codesync Bot commented Nov 6, 2026

Copy link
Copy Markdown
Contributor

@kinto0 has exported this pull request. If you are a Meta employee, you can view the originating Diff in D130311987.

This branch has not been deployed

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant