mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-04 18:58:04 +00:00
[internal]: Upgrade salsa (#16794)
## Summary Another salsa upgrade. The main motivation is to stay on a recent salsa version because there are still a lot of breaking changes happening. The most significant changes in this update: * Salsa no longer derives `Debug` by default. It now requires `interned(debug)` (or similar) * This version ships the foundation for garbage collecting interned values. However, this comes at the cost that queries now track which interned values they created (or read). The micro benchmarks in the salsa repo showed a significant perf regression. Will see if this also visible in our benchmarks. ## Test Plan `cargo test`
This commit is contained in:
parent
dbdb46dcd2
commit
c100d519e9
21 changed files with 70 additions and 56 deletions
|
@ -1,14 +1,14 @@
|
|||
use std::fmt::Formatter;
|
||||
use std::fmt;
|
||||
use std::sync::Arc;
|
||||
|
||||
use countme::Count;
|
||||
use dashmap::mapref::entry::Entry;
|
||||
use salsa::{Durability, Setter};
|
||||
|
||||
pub use file_root::{FileRoot, FileRootKind};
|
||||
pub use path::FilePath;
|
||||
use ruff_notebook::{Notebook, NotebookError};
|
||||
use ruff_python_ast::PySourceType;
|
||||
use salsa::plumbing::AsId;
|
||||
use salsa::{Durability, Setter};
|
||||
|
||||
use crate::file_revision::FileRevision;
|
||||
use crate::files::file_root::FileRoots;
|
||||
|
@ -255,7 +255,7 @@ impl Files {
|
|||
}
|
||||
}
|
||||
|
||||
impl std::fmt::Debug for Files {
|
||||
impl fmt::Debug for Files {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
let mut map = f.debug_map();
|
||||
|
||||
|
@ -429,6 +429,24 @@ impl File {
|
|||
}
|
||||
}
|
||||
|
||||
impl fmt::Debug for File {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
salsa::with_attached_database(|db| {
|
||||
if f.alternate() {
|
||||
f.debug_struct("File")
|
||||
.field("path", &self.path(db))
|
||||
.field("status", &self.status(db))
|
||||
.field("permissions", &self.permissions(db))
|
||||
.field("revision", &self.revision(db))
|
||||
.finish()
|
||||
} else {
|
||||
f.debug_tuple("File").field(&self.path(db)).finish()
|
||||
}
|
||||
})
|
||||
.unwrap_or_else(|| f.debug_tuple("file").field(&self.as_id()).finish())
|
||||
}
|
||||
}
|
||||
|
||||
/// A virtual file that doesn't exist on the file system.
|
||||
///
|
||||
/// This is a wrapper around a [`File`] that provides additional methods to interact with a virtual
|
||||
|
@ -481,8 +499,8 @@ pub enum FileError {
|
|||
NotFound,
|
||||
}
|
||||
|
||||
impl std::fmt::Display for FileError {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||
impl fmt::Display for FileError {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
match self {
|
||||
FileError::IsADirectory => f.write_str("Is a directory"),
|
||||
FileError::NotFound => f.write_str("Not found"),
|
||||
|
|
|
@ -16,7 +16,7 @@ use crate::Db;
|
|||
/// The main usage of file roots is to determine a file's durability. But it can also be used
|
||||
/// to make a salsa query dependent on whether a file in a root has changed without writing any
|
||||
/// manual invalidation logic.
|
||||
#[salsa::input]
|
||||
#[salsa::input(debug)]
|
||||
pub struct FileRoot {
|
||||
/// The path of a root is guaranteed to never change.
|
||||
#[return_ref]
|
||||
|
|
|
@ -22,7 +22,7 @@ use crate::Db;
|
|||
/// for determining if a query result is unchanged.
|
||||
#[salsa::tracked(return_ref, no_eq)]
|
||||
pub fn parsed_module(db: &dyn Db, file: File) -> ParsedModule {
|
||||
let _span = tracing::trace_span!("parsed_module", file = %file.path(db)).entered();
|
||||
let _span = tracing::trace_span!("parsed_module", ?file).entered();
|
||||
|
||||
let source = source_text(db, file);
|
||||
let path = file.path(db);
|
||||
|
|
|
@ -159,7 +159,7 @@ pub enum SourceTextError {
|
|||
/// Computes the [`LineIndex`] for `file`.
|
||||
#[salsa::tracked]
|
||||
pub fn line_index(db: &dyn Db, file: File) -> LineIndex {
|
||||
let _span = tracing::trace_span!("line_index", file = ?file.path(db)).entered();
|
||||
let _span = tracing::trace_span!("line_index", ?file).entered();
|
||||
|
||||
let source = source_text(db, file);
|
||||
|
||||
|
|
|
@ -223,7 +223,7 @@ fn query_was_not_run() {
|
|||
use crate::tests::TestDb;
|
||||
use salsa::prelude::*;
|
||||
|
||||
#[salsa::input]
|
||||
#[salsa::input(debug)]
|
||||
struct Input {
|
||||
text: String,
|
||||
}
|
||||
|
@ -258,7 +258,7 @@ fn query_was_not_run_fails_if_query_was_run() {
|
|||
use crate::tests::TestDb;
|
||||
use salsa::prelude::*;
|
||||
|
||||
#[salsa::input]
|
||||
#[salsa::input(debug)]
|
||||
struct Input {
|
||||
text: String,
|
||||
}
|
||||
|
@ -321,7 +321,7 @@ fn query_was_run_fails_if_query_was_not_run() {
|
|||
use crate::tests::TestDb;
|
||||
use salsa::prelude::*;
|
||||
|
||||
#[salsa::input]
|
||||
#[salsa::input(debug)]
|
||||
struct Input {
|
||||
text: String,
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue