Skip to content

tsp: make transaction conversion reusable by WASI hosts - #5436

Open
yeonwooson wants to merge 2 commits into
meta:mainfrom
yeonwooson:wasi/shared-tsp-conversion
Open

yeonwooson wants to merge 2 commits into
meta:mainfrom
yeonwooson:wasi/shared-tsp-conversion

Conversation

@yeonwooson

Copy link
Copy Markdown
Contributor

Summary

Contributor motivation:

I'm currently integrating Pyrefly into a WASI Worker and I need this to return the same TSP type information as native Pyrefly. This PR moves the conversion out of native-only LSP server so the WASI guest can reuse the existing implementation instead of creating a duplicate

AI-assisted technical summary and validation:

Extract the existing transaction-backed converter into a shared module and
compile it for WebAssembly, without the native LSP server. Native declared,
computed, and expected-type requests call the same helper. Declaration ranges,
re-export resolution, and the query's warm stdlib and Python environment are
preserved.

This is the first enabling piece for the WASI Worker integration, not the
complete guest. It adds no transport, Worker host, filesystem policy, protocol
change, or type-checking behavior. No existing issue or prior maintainer
coordination is claimed; feedback on this shared boundary is welcome.

No issue closure is claimed.

  • I am a human, and I fully understand the code I am submitting.

Test Plan

  • cargo test -p pyrefly --lib tsp:: --locked --offline — passed, 195 tests.
    Includes native declared/computed/expected-type request coverage and a new
    transaction-level regression for re-exported class/function declarations,
    exact source ranges, and two non-default Python platform contexts.
  • cargo test -p pyrefly --lib test::state:: --locked --offline -- --test-threads=4
    — passed, 21 tests, including the existing warm-stdlib/import-context
    regression after moving its resolver to the shared module.
  • cargo check -p pyrefly --lib --target wasm32-wasip1 --locked --offline
    — passed with the shared conversion enabled and native RPC/server modules
    excluded. This is target-compilation evidence, not a complete WASI Worker
    runtime or end-to-end TSP qualification.
  • python .\test.py --no-test --no-tensor-shapes --no-conformance --no-jsonschema --no-extension
    — passed in an isolated exact-base checkout. Formatting left the five
    candidate files unchanged and produced no unrelated changes.

The extracted conversion and export-resolution bodies are mechanically identical
to the native implementation apart from comments and whitespace. The new
regression exercises their use without a Server instance. No protocol schema,
dependency, manifest, or lockfile change is included.

Validation ran on Windows ARM64 using public Rust 1.99.1; the WASI target check
used the official WASI SDK 34 for C dependencies. Existing warnings in unchanged
platform-specific code remain. Host-specific bundled-source URI mapping, a
portable document session, and the guest command/Worker transport are follow-up
integration work rather than claims of this PR.

A WASI type-server guest needs the native transaction-backed conversion without depending on the native LSP server or duplicating the algorithm. Extract the existing converter and source resolvers into a shared module, preserve native request delegation and import context, and cover re-exported declarations across Python platform contexts.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@meta-cla

meta-cla Bot commented Oct 28, 2026

Copy link
Copy Markdown

Hi @yeonwooson!

Thank you for your pull request and welcome to our community.

Action Required

In order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you.

Process

In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks!

@meta-cla

meta-cla Bot commented Oct 28, 2026

Copy link
Copy Markdown

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks!

@kinto0 kinto0 self-assigned this Oct 28, 2026

@kinto0 kinto0 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks great! just a few changes.

I wonder at what point we should put a cargo check --target wasm32-wasip1 step in CI. I don't think we have any wasm tests running in CI right now.

Comment thread pyrefly/lib/lsp/non_wasm/server.rs Outdated
// does for cross-module lookups) so the function's module is found under
// the same `SysInfo` the transaction computed it with; re-deriving a
// config-default `SysInfo` would miss the module in a multi-`SysInfo`
// transaction and silently collapse the range to zero.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we keep this comment?

use crate::test::util::TestEnv;

#[test]
fn converted_reexports_keep_declarations_and_source_sysinfo() {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this test seems very similar to test_resolve_export_location_inherits_source_sysinfo

can we put it next to that test? or just make sure that test covers everything you want tested?

Comment thread pyrefly/lib/lsp/non_wasm/server.rs Outdated
/// `source_handle`'s `SysInfo` — the one whose `Stdlib` this transaction already
/// computed. That keeps the export lookup on the warm `get_stdlib` path:
/// re-deriving the handle from the module path would pick a config-derived
/// `SysInfo` that was never computed, panicking in `get_stdlib` whenever the

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe we keep this part of the comment in the body of the new function?

* LICENSE file in the root directory of this source tree.
*/

//! Convert analyzed types without depending on the native LSP server.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

any reason we didn't put this function in tsp/type_conversion.rs?

@yeonwooson yeonwooson Oct 28, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've moved it under tsp/type_conversion.rs

@github-actions

This comment has been minimized.

Keep transaction-backed conversion with the existing converter and place its regression beside the related state test. Preserve the analysis-context invariants in comments and check WASI compilation in CI to catch portability regressions.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@github-actions github-actions Bot added size/l and removed size/l labels Oct 28, 2026
@yeonwooson

Copy link
Copy Markdown
Contributor Author

looks great! just a few changes.

I wonder at what point we should put a cargo check --target wasm32-wasip1 step in CI. I don't think we have any wasm tests running in CI right now.

Added a dedicated Linux CI job running cargo check -p pyrefly --lib --target wasm32-wasip1 --locked

@meta-codesync

meta-codesync Bot commented Oct 28, 2026

Copy link
Copy Markdown
Contributor

This pull request has been imported. If you are a Meta employee, you can view this in D128197670. (Because this pull request was imported automatically, there will not be any future comments.)

@kinto0 kinto0 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks great! just waiting on the workflow to complete on github before merging

@github-actions

This comment has been minimized.

@meta-codesync meta-codesync Bot closed this in e852c70 Oct 29, 2026
@meta-codesync meta-codesync Bot added the Merged label Oct 29, 2026
@meta-codesync

meta-codesync Bot commented Oct 29, 2026

Copy link
Copy Markdown
Contributor

This pull request has been merged in e852c70.

@kinto0

kinto0 commented Oct 29, 2026

Copy link
Copy Markdown
Contributor

@yeonwooson I'm actually reverting this unfortunately. It broke our wasm32-unknown-unknown builds, which are not checked in your new CI check (they only check your new wasm32-wasip1). I think we might need to change all of our unknown builds to the new wasm32-wasip1 if it is necessary.

@github-actions

Copy link
Copy Markdown

According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅

@facebook-github-tools

Copy link
Copy Markdown

This pull request has been reverted by 4b1547c.

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.

2 participants