rust-analyzer icon indicating copy to clipboard operation
rust-analyzer copied to clipboard

internal: start porting VFS to Salsa

Open davidbarsky opened this issue 6 months ago • 8 comments

This is a small PR that starts porting the VFS over to Salsa (For context, https://github.com/rust-lang/rust-analyzer/issues/18948). In this PR, I'm starting by converting FileId to a salsa::input. The harder part—which is not done in this PR—is removing the vfs field on GlobalState and refactoring the read/write lock that is currently separate from the Salsa database.

davidbarsky avatar Jun 25 '25 17:06 davidbarsky

I think that if we want to simplify the VFS, it will need to take a dependency on Salsa. This means that the proc-macro-server-api will also need a Salsa dependency.

davidbarsky avatar Jun 25 '25 17:06 davidbarsky

Why does the proc macro server need the VFS?

ChayimFriedman2 avatar Jun 25 '25 17:06 ChayimFriedman2

The dependency graph is proc-macro-srv-cli -> proc-macro-api -> span -> vfs. Span declares EditionedFileId, which can be constructed from a vfs::FileId.

davidbarsky avatar Jun 25 '25 17:06 davidbarsky

Then we can continue as we did (do now? I don't remember), with span using a cfg and defining FileId as either a salsa::input or a wrapper around u32.

ChayimFriedman2 avatar Jun 25 '25 17:06 ChayimFriedman2

Then we can continue as we did (do now? I don't remember), with span using a cfg and defining FileId as either a salsa::input or a wrapper around u32.

Yeah, we do a #[cfg(feature = "salsa")]/#[cfg(not(feature = "salsa"))] dance with SyntaxContext in crates/span/src/hygiene.rs. I think that we should probably do something similar to vfs::FileId, but I'll hold off on implementing that until I move the vfs over use a Ruff-style Files, as that might design implications.

(The implementation for a ruff-style Vfs will be in a separate PR.)

davidbarsky avatar Jun 26 '25 16:06 davidbarsky

We should probably reconsider exposing span to proc-macro-srv in general, once we have bidirectional messages there, the server knowing the format is merely a performance thing (as we could skip going back and forth for some semantic requests).

Veykril avatar Jun 27 '25 05:06 Veykril

Is the span thing the main blocker here?

ShoyuVanilla avatar Oct 10 '25 09:10 ShoyuVanilla

It's not a blocker really, it's mainly about dependency cruft. Salsa is a big dependency and the proc-macro server should never need to use or depend on it.

Veykril avatar Oct 11 '25 19:10 Veykril