From 5c5dfc11f0beadb00f1c576dc056f1022284841c Mon Sep 17 00:00:00 2001 From: Micha Reiser Date: Wed, 21 Aug 2024 08:58:53 +0200 Subject: [PATCH] Upgrade to Salsa with tables (#13016) --- Cargo.lock | 6 ++-- Cargo.toml | 2 +- crates/red_knot_workspace/src/workspace.rs | 8 ++---- crates/ruff_db/src/files.rs | 32 ++++++---------------- crates/ruff_db/src/testing.rs | 14 ++++++++-- 5 files changed, 26 insertions(+), 36 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index ad259aabcb..0f4e139adc 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2742,7 +2742,7 @@ checksum = "e86697c916019a8588c99b5fac3cead74ec0b4b819707a682fd4d23fa0ce1ba1" [[package]] name = "salsa" version = "0.18.0" -source = "git+https://github.com/MichaReiser/salsa.git?tag=red-knot-0.0.1#ece083e15b79f155f9e4368ec1318cec9a08d88b" +source = "git+https://github.com/salsa-rs/salsa.git?rev=f608ff8b24f07706492027199f51132244034f29#f608ff8b24f07706492027199f51132244034f29" dependencies = [ "append-only-vec", "arc-swap", @@ -2762,12 +2762,12 @@ dependencies = [ [[package]] name = "salsa-macro-rules" version = "0.1.0" -source = "git+https://github.com/MichaReiser/salsa.git?tag=red-knot-0.0.1#ece083e15b79f155f9e4368ec1318cec9a08d88b" +source = "git+https://github.com/salsa-rs/salsa.git?rev=f608ff8b24f07706492027199f51132244034f29#f608ff8b24f07706492027199f51132244034f29" [[package]] name = "salsa-macros" version = "0.18.0" -source = "git+https://github.com/MichaReiser/salsa.git?tag=red-knot-0.0.1#ece083e15b79f155f9e4368ec1318cec9a08d88b" +source = "git+https://github.com/salsa-rs/salsa.git?rev=f608ff8b24f07706492027199f51132244034f29#f608ff8b24f07706492027199f51132244034f29" dependencies = [ "heck", "proc-macro2", diff --git a/Cargo.toml b/Cargo.toml index 699f7d6420..f7e93da531 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -108,7 +108,7 @@ rand = { version = "0.8.5" } rayon = { version = "1.10.0" } regex = { version = "1.10.2" } rustc-hash = { version = "2.0.0" } -salsa = { git = "https://github.com/MichaReiser/salsa.git", tag = "red-knot-0.0.1" } +salsa = { git = "https://github.com/salsa-rs/salsa.git", rev = "f608ff8b24f07706492027199f51132244034f29" } schemars = { version = "0.8.16" } seahash = { version = "4.1.0" } serde = { version = "1.0.197", features = ["derive"] } diff --git a/crates/red_knot_workspace/src/workspace.rs b/crates/red_knot_workspace/src/workspace.rs index 69238db9fe..2d96efbc56 100644 --- a/crates/red_knot_workspace/src/workspace.rs +++ b/crates/red_knot_workspace/src/workspace.rs @@ -143,9 +143,7 @@ impl Workspace { new_packages.insert(path, package); } - self.set_package_tree(db) - .with_durability(Durability::MEDIUM) - .to(new_packages); + self.set_package_tree(db).to(new_packages); } pub fn update_package(self, db: &mut dyn Db, metadata: PackageMetadata) -> anyhow::Result<()> { @@ -358,9 +356,7 @@ impl Package { assert_eq!(root, metadata.root()); if self.name(db) != metadata.name() { - self.set_name(db) - .with_durability(Durability::MEDIUM) - .to(metadata.name); + self.set_name(db).to(metadata.name); } } diff --git a/crates/ruff_db/src/files.rs b/crates/ruff_db/src/files.rs index 0396a32aac..66d29c3bf8 100644 --- a/crates/ruff_db/src/files.rs +++ b/crates/ruff_db/src/files.rs @@ -224,9 +224,7 @@ impl Files { for root in roots.all() { if root.path(db).starts_with(&path) { - root.set_revision(db) - .with_durability(Durability::HIGH) - .to(FileRevision::now()); + root.set_revision(db).to(FileRevision::now()); } } } @@ -249,9 +247,7 @@ impl Files { let roots = inner.roots.read().unwrap(); for root in roots.all() { - root.set_revision(db) - .with_durability(Durability::HIGH) - .to(FileRevision::now()); + root.set_revision(db).to(FileRevision::now()); } } @@ -381,23 +377,17 @@ impl File { return; }; let metadata = db.system().path_metadata(path); - let durability = db.files().root(db, path).map(|root| root.durability(db)); - Self::sync_impl(db, metadata, file, durability); + Self::sync_impl(db, metadata, file); } fn sync_system_virtual_path(db: &mut dyn Db, path: &SystemVirtualPath, file: File) { let metadata = db.system().virtual_path_metadata(path); - Self::sync_impl(db, metadata, file, None); + Self::sync_impl(db, metadata, file); } /// Private method providing the implementation for [`Self::sync_system_path`] and /// [`Self::sync_system_virtual_path`]. - fn sync_impl( - db: &mut dyn Db, - metadata: crate::system::Result, - file: File, - durability: Option, - ) { + fn sync_impl(db: &mut dyn Db, metadata: crate::system::Result, file: File) { let (status, revision, permission) = match metadata { Ok(metadata) if metadata.file_type().is_file() => ( FileStatus::Exists, @@ -410,25 +400,19 @@ impl File { _ => (FileStatus::NotFound, FileRevision::zero(), None), }; - let durability = durability.unwrap_or_default(); - if file.status(db) != status { tracing::debug!("Updating the status of '{}'", file.path(db),); - file.set_status(db).with_durability(durability).to(status); + file.set_status(db).to(status); } if file.revision(db) != revision { tracing::debug!("Updating the revision of '{}'", file.path(db)); - file.set_revision(db) - .with_durability(durability) - .to(revision); + file.set_revision(db).to(revision); } if file.permissions(db) != permission { tracing::debug!("Updating the permissions of '{}'", file.path(db),); - file.set_permissions(db) - .with_durability(durability) - .to(permission); + file.set_permissions(db).to(permission); } } diff --git a/crates/ruff_db/src/testing.rs b/crates/ruff_db/src/testing.rs index 02a6f38f68..c32c57d37c 100644 --- a/crates/ruff_db/src/testing.rs +++ b/crates/ruff_db/src/testing.rs @@ -31,10 +31,20 @@ pub fn assert_const_function_query_was_not_run( Db: salsa::Database, Q: Fn(QDb) -> R, { - let (query_name, will_execute_event) = find_will_execute_event(db, query, (), events); + // Salsa now interns singleton ingredients. But we know that it is a singleton, so we can just search for + // any event of that ingredient. + let query_name = query_name(&query); + + let event = events.iter().find(|event| { + if let salsa::EventKind::WillExecute { database_key } = event.kind { + db.ingredient_debug_name(database_key.ingredient_index()) == query_name + } else { + false + } + }); db.attach(|_| { - if let Some(will_execute_event) = will_execute_event { + if let Some(will_execute_event) = event { panic!( "Expected query {query_name}() not to have run but it did: {will_execute_event:?}" );