Skip to content

Commit 78a488d

Browse files
authored
Merge pull request #19716 from Veykril/push-wmmvswskoktw
Update salsa
2 parents a871773 + 996d6ed commit 78a488d

File tree

30 files changed

+137
-80
lines changed

30 files changed

+137
-80
lines changed

Cargo.lock

Lines changed: 12 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,8 @@ process-wrap = { version = "8.2.0", features = ["std"] }
131131
pulldown-cmark-to-cmark = "10.0.4"
132132
pulldown-cmark = { version = "0.9.6", default-features = false }
133133
rayon = "1.10.0"
134-
salsa = "0.20.0"
134+
salsa = { version = "0.21.0", default-features = false, features = ["rayon","salsa_unstable"] }
135+
salsa-macros = "0.21.0"
135136
semver = "1.0.26"
136137
serde = { version = "1.0.219" }
137138
serde_derive = { version = "1.0.219" }

crates/base-db/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ rust-version.workspace = true
1515
la-arena.workspace = true
1616
dashmap.workspace = true
1717
salsa.workspace = true
18+
salsa-macros.workspace = true
1819
query-group.workspace = true
1920
rustc-hash.workspace = true
2021
triomphe.workspace = true

crates/base-db/src/input.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,7 @@ impl BuiltDependency {
392392

393393
pub type CratesIdMap = FxHashMap<CrateBuilderId, Crate>;
394394

395-
#[salsa::input]
395+
#[salsa_macros::input]
396396
#[derive(Debug)]
397397
pub struct Crate {
398398
#[return_ref]

crates/base-db/src/lib.rs

Lines changed: 63 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
//! base_db defines basic database traits. The concrete DB is defined by ide.
2+
3+
pub use salsa;
4+
pub use salsa_macros;
5+
26
// FIXME: Rename this crate, base db is non descriptive
37
mod change;
48
mod input;
59

6-
use std::hash::BuildHasherDefault;
10+
use std::{cell::RefCell, hash::BuildHasherDefault, panic, sync::Once};
711

812
pub use crate::{
913
change::FileChange,
@@ -17,7 +21,6 @@ pub use crate::{
1721
use dashmap::{DashMap, mapref::entry::Entry};
1822
pub use query_group::{self};
1923
use rustc_hash::{FxHashSet, FxHasher};
20-
pub use salsa::{self};
2124
use salsa::{Durability, Setter};
2225
pub use semver::{BuildMetadata, Prerelease, Version, VersionReq};
2326
use span::Edition;
@@ -28,7 +31,7 @@ pub use vfs::{AnchoredPath, AnchoredPathBuf, FileId, VfsPath, file_set::FileSet}
2831
#[macro_export]
2932
macro_rules! impl_intern_key {
3033
($id:ident, $loc:ident) => {
31-
#[salsa::interned(no_lifetime)]
34+
#[salsa_macros::interned(no_lifetime)]
3235
pub struct $id {
3336
pub loc: $loc,
3437
}
@@ -60,7 +63,7 @@ impl Files {
6063
match self.files.get(&file_id) {
6164
Some(text) => *text,
6265
None => {
63-
panic!("Unable to fetch file text for `vfs::FileId`: {:?}; this is a bug", file_id)
66+
panic!("Unable to fetch file text for `vfs::FileId`: {file_id:?}; this is a bug")
6467
}
6568
}
6669
}
@@ -101,8 +104,7 @@ impl Files {
101104
let source_root = match self.source_roots.get(&source_root_id) {
102105
Some(source_root) => source_root,
103106
None => panic!(
104-
"Unable to fetch `SourceRootInput` with `SourceRootId` ({:?}); this is a bug",
105-
source_root_id
107+
"Unable to fetch `SourceRootInput` with `SourceRootId` ({source_root_id:?}); this is a bug"
106108
),
107109
};
108110

@@ -132,8 +134,7 @@ impl Files {
132134
let file_source_root = match self.file_source_roots.get(&id) {
133135
Some(file_source_root) => file_source_root,
134136
None => panic!(
135-
"Unable to get `FileSourceRootInput` with `vfs::FileId` ({:?}); this is a bug",
136-
id
137+
"Unable to get `FileSourceRootInput` with `vfs::FileId` ({id:?}); this is a bug",
137138
),
138139
};
139140
*file_source_root
@@ -163,7 +164,7 @@ impl Files {
163164
}
164165
}
165166

166-
#[salsa::interned(no_lifetime, debug, constructor=from_span)]
167+
#[salsa_macros::interned(no_lifetime, debug, constructor=from_span)]
167168
pub struct EditionedFileId {
168169
pub editioned_file_id: span::EditionedFileId,
169170
}
@@ -198,18 +199,18 @@ impl EditionedFileId {
198199
}
199200
}
200201

201-
#[salsa::input(debug)]
202+
#[salsa_macros::input(debug)]
202203
pub struct FileText {
203204
pub text: Arc<str>,
204205
pub file_id: vfs::FileId,
205206
}
206207

207-
#[salsa::input(debug)]
208+
#[salsa_macros::input(debug)]
208209
pub struct FileSourceRootInput {
209210
pub source_root_id: SourceRootId,
210211
}
211212

212-
#[salsa::input(debug)]
213+
#[salsa_macros::input(debug)]
213214
pub struct SourceRootInput {
214215
pub source_root: Arc<SourceRoot>,
215216
}
@@ -276,7 +277,7 @@ pub fn transitive_deps(db: &dyn SourceDatabase, crate_id: Crate) -> FxHashSet<Cr
276277
deps
277278
}
278279

279-
#[salsa::db]
280+
#[salsa_macros::db]
280281
pub trait SourceDatabase: salsa::Database {
281282
/// Text of the file.
282283
fn file_text(&self, file_id: vfs::FileId) -> FileText;
@@ -355,7 +356,7 @@ fn parse(db: &dyn RootQueryDb, file_id: EditionedFileId) -> Parse<ast::SourceFil
355356
}
356357

357358
fn parse_errors(db: &dyn RootQueryDb, file_id: EditionedFileId) -> Option<&[SyntaxError]> {
358-
#[salsa::tracked(return_ref)]
359+
#[salsa_macros::tracked(return_ref)]
359360
fn parse_errors(db: &dyn RootQueryDb, file_id: EditionedFileId) -> Option<Box<[SyntaxError]>> {
360361
let errors = db.parse(file_id).errors();
361362
match &*errors {
@@ -384,3 +385,51 @@ fn relevant_crates(db: &dyn RootQueryDb, file_id: FileId) -> Arc<[Crate]> {
384385
let source_root = db.file_source_root(file_id);
385386
db.source_root_crates(source_root.source_root_id(db))
386387
}
388+
389+
#[must_use]
390+
pub struct DbPanicContext {
391+
// prevent arbitrary construction
392+
_priv: (),
393+
}
394+
395+
impl Drop for DbPanicContext {
396+
fn drop(&mut self) {
397+
Self::with_ctx(|ctx| assert!(ctx.pop().is_some()));
398+
}
399+
}
400+
401+
impl DbPanicContext {
402+
pub fn enter(frame: String) -> DbPanicContext {
403+
#[expect(clippy::print_stderr, reason = "already panicking anyway")]
404+
fn set_hook() {
405+
let default_hook = panic::take_hook();
406+
panic::set_hook(Box::new(move |panic_info| {
407+
DbPanicContext::with_ctx(|ctx| {
408+
if !ctx.is_empty() {
409+
eprintln!("Panic context:");
410+
for frame in ctx.iter() {
411+
eprintln!("> {frame}\n");
412+
}
413+
}
414+
});
415+
if let Some(backtrace) = salsa::Backtrace::capture() {
416+
eprintln!("{backtrace}");
417+
}
418+
default_hook(panic_info);
419+
}));
420+
}
421+
422+
static SET_HOOK: Once = Once::new();
423+
SET_HOOK.call_once(set_hook);
424+
425+
Self::with_ctx(|ctx| ctx.push(frame));
426+
DbPanicContext { _priv: () }
427+
}
428+
429+
fn with_ctx(f: impl FnOnce(&mut Vec<String>)) {
430+
thread_local! {
431+
static CTX: RefCell<Vec<String>> = const { RefCell::new(Vec::new()) };
432+
}
433+
CTX.with(|ctx| f(&mut ctx.borrow_mut()));
434+
}
435+
}

crates/hir-def/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ triomphe.workspace = true
2828
rustc_apfloat = "0.2.2"
2929
text-size.workspace = true
3030
salsa.workspace = true
31+
salsa-macros.workspace = true
3132
query-group.workspace = true
3233

3334
ra-ap-rustc_parse_format.workspace = true

crates/hir-def/src/lang_item.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ impl LangItemTarget {
8484
}
8585

8686
/// Salsa query. This will look for lang items in a specific crate.
87-
#[salsa::tracked(return_ref)]
87+
#[salsa_macros::tracked(return_ref)]
8888
pub fn crate_lang_items(db: &dyn DefDatabase, krate: Crate) -> Option<Box<LangItems>> {
8989
let _p = tracing::info_span!("crate_lang_items_query").entered();
9090

@@ -153,7 +153,7 @@ pub fn crate_lang_items(db: &dyn DefDatabase, krate: Crate) -> Option<Box<LangIt
153153

154154
/// Salsa query. Look for a lang item, starting from the specified crate and recursively
155155
/// traversing its dependencies.
156-
#[salsa::tracked]
156+
#[salsa_macros::tracked]
157157
pub fn lang_item(
158158
db: &dyn DefDatabase,
159159
start_crate: Crate,

crates/hir-def/src/lib.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -554,7 +554,7 @@ pub enum ItemContainerId {
554554
impl_from!(ModuleId for ItemContainerId);
555555

556556
/// A Data Type
557-
#[derive(Debug, PartialOrd, Ord, Clone, Copy, PartialEq, Eq, Hash, salsa::Supertype)]
557+
#[derive(Debug, PartialOrd, Ord, Clone, Copy, PartialEq, Eq, Hash, salsa_macros::Supertype)]
558558
pub enum AdtId {
559559
StructId(StructId),
560560
UnionId(UnionId),
@@ -563,7 +563,7 @@ pub enum AdtId {
563563
impl_from!(StructId, UnionId, EnumId for AdtId);
564564

565565
/// A macro
566-
#[derive(Debug, PartialOrd, Ord, Clone, Copy, PartialEq, Eq, Hash, salsa::Supertype)]
566+
#[derive(Debug, PartialOrd, Ord, Clone, Copy, PartialEq, Eq, Hash, salsa_macros::Supertype)]
567567
pub enum MacroId {
568568
Macro2Id(Macro2Id),
569569
MacroRulesId(MacroRulesId),
@@ -619,7 +619,7 @@ impl_from!(
619619

620620
/// A constant, which might appears as a const item, an anonymous const block in expressions
621621
/// or patterns, or as a constant in types with const generics.
622-
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, salsa::Supertype)]
622+
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, salsa_macros::Supertype)]
623623
pub enum GeneralConstId {
624624
ConstId(ConstId),
625625
StaticId(StaticId),
@@ -656,7 +656,7 @@ impl GeneralConstId {
656656
}
657657

658658
/// The defs which have a body (have root expressions for type inference).
659-
#[derive(Debug, PartialOrd, Ord, Clone, Copy, PartialEq, Eq, Hash, salsa::Supertype)]
659+
#[derive(Debug, PartialOrd, Ord, Clone, Copy, PartialEq, Eq, Hash, salsa_macros::Supertype)]
660660
pub enum DefWithBodyId {
661661
FunctionId(FunctionId),
662662
StaticId(StaticId),
@@ -701,7 +701,7 @@ pub enum AssocItemId {
701701
// casting them, and somehow making the constructors private, which would be annoying.
702702
impl_from!(FunctionId, ConstId, TypeAliasId for AssocItemId);
703703

704-
#[derive(Debug, PartialOrd, Ord, Clone, Copy, PartialEq, Eq, Hash, salsa::Supertype)]
704+
#[derive(Debug, PartialOrd, Ord, Clone, Copy, PartialEq, Eq, Hash, salsa_macros::Supertype)]
705705
pub enum GenericDefId {
706706
AdtId(AdtId),
707707
// consts can have type parameters from their parents (i.e. associated consts of traits)
@@ -790,7 +790,7 @@ impl From<AssocItemId> for GenericDefId {
790790
}
791791
}
792792

793-
#[derive(Debug, PartialOrd, Ord, Clone, Copy, PartialEq, Eq, Hash, salsa::Supertype)]
793+
#[derive(Debug, PartialOrd, Ord, Clone, Copy, PartialEq, Eq, Hash, salsa_macros::Supertype)]
794794
pub enum CallableDefId {
795795
FunctionId(FunctionId),
796796
StructId(StructId),
@@ -906,7 +906,7 @@ impl From<VariantId> for AttrDefId {
906906
}
907907
}
908908

909-
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, salsa::Supertype)]
909+
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, salsa_macros::Supertype)]
910910
pub enum VariantId {
911911
EnumVariantId(EnumVariantId),
912912
StructId(StructId),

crates/hir-def/src/test_db.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use crate::{
1919
src::HasSource,
2020
};
2121

22-
#[salsa::db]
22+
#[salsa_macros::db]
2323
#[derive(Clone)]
2424
pub(crate) struct TestDB {
2525
storage: salsa::Storage<Self>,
@@ -44,7 +44,7 @@ impl Default for TestDB {
4444
}
4545
}
4646

47-
#[salsa::db]
47+
#[salsa_macros::db]
4848
impl salsa::Database for TestDB {
4949
fn salsa_event(&self, event: &dyn std::ops::Fn() -> salsa::Event) {
5050
let mut events = self.events.lock().unwrap();
@@ -63,7 +63,7 @@ impl fmt::Debug for TestDB {
6363

6464
impl panic::RefUnwindSafe for TestDB {}
6565

66-
#[salsa::db]
66+
#[salsa_macros::db]
6767
impl SourceDatabase for TestDB {
6868
fn file_text(&self, file_id: base_db::FileId) -> FileText {
6969
self.files.file_text(file_id)

crates/hir-expand/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ smallvec.workspace = true
2121
triomphe.workspace = true
2222
query-group.workspace = true
2323
salsa.workspace = true
24+
salsa-macros.workspace = true
2425

2526
# local deps
2627
stdx.workspace = true

0 commit comments

Comments
 (0)