[ty] Update salsa (#17937)

## Summary

* Update salsa to pull in https://github.com/salsa-rs/salsa/pull/850.
* Some refactoring of salsa event callbacks in various `Db`'s due to
https://github.com/salsa-rs/salsa/pull/849

closes https://github.com/astral-sh/ty/issues/108

## Test Plan

Ran `cargo run --bin ty -- -vvv` on a test file to make sure that salsa
Events are still logged.
This commit is contained in:
David Peter 2025-05-08 12:02:53 +02:00 committed by GitHub
parent d566636ca5
commit 4f890b2867
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
10 changed files with 96 additions and 113 deletions

View file

@ -16,7 +16,7 @@ pub trait Db: SourceDb + Upcast<dyn SourceDb> {
#[cfg(test)]
pub(crate) mod tests {
use std::sync::Arc;
use std::sync::{Arc, Mutex};
use crate::program::{Program, SearchPathSettings};
use crate::{default_lint_registry, ProgramSettings, PythonPlatform};
@ -32,6 +32,8 @@ pub(crate) mod tests {
use ruff_db::{Db as SourceDb, Upcast};
use ruff_python_ast::PythonVersion;
type Events = Arc<Mutex<Vec<salsa::Event>>>;
#[salsa::db]
#[derive(Clone)]
pub(crate) struct TestDb {
@ -39,30 +41,34 @@ pub(crate) mod tests {
files: Files,
system: TestSystem,
vendored: VendoredFileSystem,
events: Arc<std::sync::Mutex<Vec<salsa::Event>>>,
events: Events,
rule_selection: Arc<RuleSelection>,
}
impl TestDb {
pub(crate) fn new() -> Self {
let events = Events::default();
Self {
storage: salsa::Storage::default(),
storage: salsa::Storage::new(Some(Box::new({
let events = events.clone();
move |event| {
tracing::trace!("event: {event:?}");
let mut events = events.lock().unwrap();
events.push(event);
}
}))),
system: TestSystem::default(),
vendored: ty_vendored::file_system().clone(),
events: Arc::default(),
events,
files: Files::default(),
rule_selection: Arc::new(RuleSelection::from_registry(default_lint_registry())),
}
}
/// Takes the salsa events.
///
/// ## Panics
/// If there are any pending salsa snapshots.
pub(crate) fn take_salsa_events(&mut self) -> Vec<salsa::Event> {
let inner = Arc::get_mut(&mut self.events).expect("no pending salsa snapshots");
let mut events = self.events.lock().unwrap();
let events = inner.get_mut().unwrap();
std::mem::take(&mut *events)
}
@ -129,14 +135,7 @@ pub(crate) mod tests {
}
#[salsa::db]
impl salsa::Database for TestDb {
fn salsa_event(&self, event: &dyn Fn() -> salsa::Event) {
let event = event();
tracing::trace!("event: {event:?}");
let mut events = self.events.lock().unwrap();
events.push(event);
}
}
impl salsa::Database for TestDb {}
pub(crate) struct TestDbBuilder<'a> {
/// Target Python version