From e6e029a8b7bbb1f1fc156980d1f3368cd264a3a8 Mon Sep 17 00:00:00 2001 From: Ibraheem Ahmed Date: Fri, 18 Jul 2025 12:14:28 -0400 Subject: [PATCH] Update salsa (#19258) ## Summary Pulls in https://github.com/salsa-rs/salsa/pull/934. --- Cargo.lock | 37 ++++++++++++----------------------- Cargo.toml | 2 +- crates/ruff_wasm/src/lib.rs | 21 ++++++++++++++++++++ crates/ruff_wasm/tests/api.rs | 10 ++++++++++ crates/ty_wasm/src/lib.rs | 21 ++++++++++++++++++++ crates/ty_wasm/tests/api.rs | 2 ++ fuzz/Cargo.toml | 2 +- 7 files changed, 69 insertions(+), 26 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 45fa25d305..4a97100b25 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1557,6 +1557,15 @@ dependencies = [ "memoffset", ] +[[package]] +name = "inventory" +version = "0.3.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ab08d7cd2c5897f2c949e5383ea7c7db03fb19130ffcfbf7eda795137ae3cb83" +dependencies = [ + "rustversion", +] + [[package]] name = "is-docker" version = "0.2.0" @@ -2123,16 +2132,6 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b15813163c1d831bf4a13c3610c05c0d03b39feb07f7e09fa234dac9b15aaf39" -[[package]] -name = "papaya" -version = "0.2.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f92dd0b07c53a0a0c764db2ace8c541dc47320dad97c2200c2a637ab9dd2328f" -dependencies = [ - "equivalent", - "seize", -] - [[package]] name = "parking_lot" version = "0.12.3" @@ -3409,7 +3408,7 @@ checksum = "28d3b2b1366ec20994f1fd18c3c594f05c5dd4bc44d8bb0c1c632c8d6829481f" [[package]] name = "salsa" version = "0.23.0" -source = "git+https://github.com/salsa-rs/salsa?rev=fc00eba89e5dcaa5edba51c41aa5f309b5cb126b#fc00eba89e5dcaa5edba51c41aa5f309b5cb126b" +source = "git+https://github.com/salsa-rs/salsa?rev=dba66f1a37acca014c2402f231ed5b361bd7d8fe#dba66f1a37acca014c2402f231ed5b361bd7d8fe" dependencies = [ "boxcar", "compact_str", @@ -3419,7 +3418,7 @@ dependencies = [ "hashlink", "indexmap", "intrusive-collections", - "papaya", + "inventory", "parking_lot", "portable-atomic", "rayon", @@ -3434,12 +3433,12 @@ dependencies = [ [[package]] name = "salsa-macro-rules" version = "0.23.0" -source = "git+https://github.com/salsa-rs/salsa?rev=fc00eba89e5dcaa5edba51c41aa5f309b5cb126b#fc00eba89e5dcaa5edba51c41aa5f309b5cb126b" +source = "git+https://github.com/salsa-rs/salsa?rev=dba66f1a37acca014c2402f231ed5b361bd7d8fe#dba66f1a37acca014c2402f231ed5b361bd7d8fe" [[package]] name = "salsa-macros" version = "0.23.0" -source = "git+https://github.com/salsa-rs/salsa?rev=fc00eba89e5dcaa5edba51c41aa5f309b5cb126b#fc00eba89e5dcaa5edba51c41aa5f309b5cb126b" +source = "git+https://github.com/salsa-rs/salsa?rev=dba66f1a37acca014c2402f231ed5b361bd7d8fe#dba66f1a37acca014c2402f231ed5b361bd7d8fe" dependencies = [ "proc-macro2", "quote", @@ -3492,16 +3491,6 @@ version = "4.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1c107b6f4780854c8b126e228ea8869f4d7b71260f962fefb57b996b8959ba6b" -[[package]] -name = "seize" -version = "0.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e4b8d813387d566f627f3ea1b914c068aac94c40ae27ec43f5f33bde65abefe7" -dependencies = [ - "libc", - "windows-sys 0.52.0", -] - [[package]] name = "serde" version = "1.0.219" diff --git a/Cargo.toml b/Cargo.toml index 8ca8a0d2d2..4bf239e882 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -138,7 +138,7 @@ regex-automata = { version = "0.4.9" } rustc-hash = { version = "2.0.0" } rustc-stable-hash = { version = "0.1.2" } # When updating salsa, make sure to also update the revision in `fuzz/Cargo.toml` -salsa = { git = "https://github.com/salsa-rs/salsa", rev = "fc00eba89e5dcaa5edba51c41aa5f309b5cb126b" } +salsa = { git = "https://github.com/salsa-rs/salsa", rev = "dba66f1a37acca014c2402f231ed5b361bd7d8fe" } schemars = { version = "0.8.16" } seahash = { version = "4.1.0" } serde = { version = "1.0.197", features = ["derive"] } diff --git a/crates/ruff_wasm/src/lib.rs b/crates/ruff_wasm/src/lib.rs index 9066d17df8..bf378e0eb4 100644 --- a/crates/ruff_wasm/src/lib.rs +++ b/crates/ruff_wasm/src/lib.rs @@ -77,10 +77,31 @@ struct ExpandedEdit { content: Option, } +/// Perform global constructor initialization. +#[cfg(target_family = "wasm")] +#[expect(unsafe_code)] +pub fn before_main() { + unsafe extern "C" { + fn __wasm_call_ctors(); + } + + // Salsa uses the `inventory` crate, which registers global constructors that may need to be + // called explicitly on WASM. See + // for details. + unsafe { + __wasm_call_ctors(); + } +} + +#[cfg(not(target_family = "wasm"))] +pub fn before_main() {} + #[wasm_bindgen(start)] pub fn run() { use log::Level; + before_main(); + // When the `console_error_panic_hook` feature is enabled, we can call the // `set_panic_hook` function at least once during initialization, and then // we will get better error messages if our code ever panics. diff --git a/crates/ruff_wasm/tests/api.rs b/crates/ruff_wasm/tests/api.rs index 036a435de0..fb7478d3b2 100644 --- a/crates/ruff_wasm/tests/api.rs +++ b/crates/ruff_wasm/tests/api.rs @@ -21,6 +21,8 @@ macro_rules! check { #[wasm_bindgen_test] fn empty_config() { + ruff_wasm::before_main(); + check!( "if (1, 2):\n pass", r#"{}"#, @@ -42,6 +44,8 @@ fn empty_config() { #[wasm_bindgen_test] fn syntax_error() { + ruff_wasm::before_main(); + check!( "x =\ny = 1\n", r#"{}"#, @@ -63,6 +67,8 @@ fn syntax_error() { #[wasm_bindgen_test] fn unsupported_syntax_error() { + ruff_wasm::before_main(); + check!( "match 2:\n case 1: ...", r#"{"target-version": "py39"}"#, @@ -84,11 +90,15 @@ fn unsupported_syntax_error() { #[wasm_bindgen_test] fn partial_config() { + ruff_wasm::before_main(); + check!("if (1, 2):\n pass", r#"{"ignore": ["F"]}"#, []); } #[wasm_bindgen_test] fn partial_nested_config() { + ruff_wasm::before_main(); + let config = r#"{ "select": ["Q"], "flake8-quotes": { diff --git a/crates/ty_wasm/src/lib.rs b/crates/ty_wasm/src/lib.rs index cc3d6ab29e..f21d2ddaa4 100644 --- a/crates/ty_wasm/src/lib.rs +++ b/crates/ty_wasm/src/lib.rs @@ -32,10 +32,31 @@ pub fn version() -> String { .to_string() } +/// Perform global constructor initialization. +#[cfg(target_family = "wasm")] +#[expect(unsafe_code)] +pub fn before_main() { + unsafe extern "C" { + fn __wasm_call_ctors(); + } + + // Salsa uses the `inventory` crate, which registers global constructors that may need to be + // called explicitly on WASM. See + // for details. + unsafe { + __wasm_call_ctors(); + } +} + +#[cfg(not(target_family = "wasm"))] +pub fn before_main() {} + #[wasm_bindgen(start)] pub fn run() { use log::Level; + before_main(); + ruff_db::set_program_version(version()).unwrap(); // When the `console_error_panic_hook` feature is enabled, we can call the diff --git a/crates/ty_wasm/tests/api.rs b/crates/ty_wasm/tests/api.rs index f98381f43b..dca70bdc66 100644 --- a/crates/ty_wasm/tests/api.rs +++ b/crates/ty_wasm/tests/api.rs @@ -5,6 +5,8 @@ use wasm_bindgen_test::wasm_bindgen_test; #[wasm_bindgen_test] fn check() { + ty_wasm::before_main(); + let mut workspace = Workspace::new( "/", PositionEncoding::Utf32, diff --git a/fuzz/Cargo.toml b/fuzz/Cargo.toml index e3d0cb63f8..55e6403dcf 100644 --- a/fuzz/Cargo.toml +++ b/fuzz/Cargo.toml @@ -30,7 +30,7 @@ ty_python_semantic = { path = "../crates/ty_python_semantic" } ty_vendored = { path = "../crates/ty_vendored" } libfuzzer-sys = { git = "https://github.com/rust-fuzz/libfuzzer", default-features = false } -salsa = { git = "https://github.com/salsa-rs/salsa", rev = "fc00eba89e5dcaa5edba51c41aa5f309b5cb126b" } +salsa = { git = "https://github.com/salsa-rs/salsa", rev = "dba66f1a37acca014c2402f231ed5b361bd7d8fe" } similar = { version = "2.5.0" } tracing = { version = "0.1.40" }