Skip to content

Commit 0f73f0f

Browse files
committed
Auto merge of rust-lang#140651 - lnicola:sync-from-ra, r=lnicola
Subtree update of `rust-analyzer` r? `@ghost`
2 parents 243c5a3 + 8f3bb8b commit 0f73f0f

File tree

194 files changed

+2427
-1704
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

194 files changed

+2427
-1704
lines changed

src/tools/rust-analyzer/Cargo.lock

+12-6
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ dependencies = [
8585
"query-group-macro",
8686
"rustc-hash 2.1.1",
8787
"salsa",
88+
"salsa-macros",
8889
"semver",
8990
"span",
9091
"syntax",
@@ -630,6 +631,7 @@ dependencies = [
630631
"rustc-hash 2.1.1",
631632
"rustc_apfloat",
632633
"salsa",
634+
"salsa-macros",
633635
"smallvec",
634636
"span",
635637
"stdx",
@@ -660,6 +662,7 @@ dependencies = [
660662
"query-group-macro",
661663
"rustc-hash 2.1.1",
662664
"salsa",
665+
"salsa-macros",
663666
"smallvec",
664667
"span",
665668
"stdx",
@@ -700,6 +703,7 @@ dependencies = [
700703
"rustc-hash 2.1.1",
701704
"rustc_apfloat",
702705
"salsa",
706+
"salsa-macros",
703707
"scoped-tls",
704708
"smallvec",
705709
"span",
@@ -936,6 +940,7 @@ dependencies = [
936940
"rayon",
937941
"rustc-hash 2.1.1",
938942
"salsa",
943+
"salsa-macros",
939944
"span",
940945
"stdx",
941946
"syntax",
@@ -1729,6 +1734,7 @@ dependencies = [
17291734
"proc-macro2",
17301735
"quote",
17311736
"salsa",
1737+
"salsa-macros",
17321738
"syn",
17331739
]
17341740

@@ -2033,9 +2039,9 @@ checksum = "28d3b2b1366ec20994f1fd18c3c594f05c5dd4bc44d8bb0c1c632c8d6829481f"
20332039

20342040
[[package]]
20352041
name = "salsa"
2036-
version = "0.20.0"
2042+
version = "0.21.1"
20372043
source = "registry+https://github.com/rust-lang/crates.io-index"
2038-
checksum = "1be22155f8d9732518b2db2bf379fe6f0b2375e76b08b7c8fe6c1b887d548c24"
2044+
checksum = "6f80d5cf3c3fcab2cef898012f242a670477a1baa609267376af9cb4409026c5"
20392045
dependencies = [
20402046
"boxcar",
20412047
"crossbeam-queue",
@@ -2056,15 +2062,15 @@ dependencies = [
20562062

20572063
[[package]]
20582064
name = "salsa-macro-rules"
2059-
version = "0.20.0"
2065+
version = "0.21.1"
20602066
source = "registry+https://github.com/rust-lang/crates.io-index"
2061-
checksum = "f55a7ef0a84e336f7c5f0332d81727f5629fe042d2aa556c75307afebc9f78a5"
2067+
checksum = "05303d72606fbf2b9c9523cda2039bb8ecb00304027a3cd7e52b02a65c7d9185"
20622068

20632069
[[package]]
20642070
name = "salsa-macros"
2065-
version = "0.20.0"
2071+
version = "0.21.1"
20662072
source = "registry+https://github.com/rust-lang/crates.io-index"
2067-
checksum = "8d0e88a9c0c0d231a63f83dcd1a2c5e5d11044fac4b65bc9ad3b68ab48b0a0ab"
2073+
checksum = "eb2f0e2a30c65cb3cd63440c491dde68d9af7e1be2b77832ac7057141107db50"
20682074
dependencies = [
20692075
"heck",
20702076
"proc-macro2",

src/tools/rust-analyzer/Cargo.toml

+3-1
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,9 @@ 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+
rowan = "=0.15.15"
135+
salsa = { version = "0.21.1", default-features = false, features = ["rayon","salsa_unstable"] }
136+
salsa-macros = "0.21.1"
135137
semver = "1.0.26"
136138
serde = { version = "1.0.219" }
137139
serde_derive = { version = "1.0.219" }

src/tools/rust-analyzer/crates/base-db/Cargo.toml

+1
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

src/tools/rust-analyzer/crates/base-db/src/input.rs

+1-1
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]

src/tools/rust-analyzer/crates/base-db/src/lib.rs

+76-18
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
}
@@ -57,7 +60,12 @@ pub struct Files {
5760

5861
impl Files {
5962
pub fn file_text(&self, file_id: vfs::FileId) -> FileText {
60-
*self.files.get(&file_id).expect("Unable to fetch file; this is a bug")
63+
match self.files.get(&file_id) {
64+
Some(text) => *text,
65+
None => {
66+
panic!("Unable to fetch file text for `vfs::FileId`: {file_id:?}; this is a bug")
67+
}
68+
}
6169
}
6270

6371
pub fn set_file_text(&self, db: &mut dyn SourceDatabase, file_id: vfs::FileId, text: &str) {
@@ -93,10 +101,12 @@ impl Files {
93101

94102
/// Source root of the file.
95103
pub fn source_root(&self, source_root_id: SourceRootId) -> SourceRootInput {
96-
let source_root = self
97-
.source_roots
98-
.get(&source_root_id)
99-
.expect("Unable to fetch source root id; this is a bug");
104+
let source_root = match self.source_roots.get(&source_root_id) {
105+
Some(source_root) => source_root,
106+
None => panic!(
107+
"Unable to fetch `SourceRootInput` with `SourceRootId` ({source_root_id:?}); this is a bug"
108+
),
109+
};
100110

101111
*source_root
102112
}
@@ -121,10 +131,12 @@ impl Files {
121131
}
122132

123133
pub fn file_source_root(&self, id: vfs::FileId) -> FileSourceRootInput {
124-
let file_source_root = self
125-
.file_source_roots
126-
.get(&id)
127-
.expect("Unable to fetch FileSourceRootInput; this is a bug");
134+
let file_source_root = match self.file_source_roots.get(&id) {
135+
Some(file_source_root) => file_source_root,
136+
None => panic!(
137+
"Unable to get `FileSourceRootInput` with `vfs::FileId` ({id:?}); this is a bug",
138+
),
139+
};
128140
*file_source_root
129141
}
130142

@@ -152,7 +164,7 @@ impl Files {
152164
}
153165
}
154166

155-
#[salsa::interned(no_lifetime, debug, constructor=from_span)]
167+
#[salsa_macros::interned(no_lifetime, debug, constructor=from_span)]
156168
pub struct EditionedFileId {
157169
pub editioned_file_id: span::EditionedFileId,
158170
}
@@ -187,18 +199,18 @@ impl EditionedFileId {
187199
}
188200
}
189201

190-
#[salsa::input(debug)]
202+
#[salsa_macros::input(debug)]
191203
pub struct FileText {
192204
pub text: Arc<str>,
193205
pub file_id: vfs::FileId,
194206
}
195207

196-
#[salsa::input(debug)]
208+
#[salsa_macros::input(debug)]
197209
pub struct FileSourceRootInput {
198210
pub source_root_id: SourceRootId,
199211
}
200212

201-
#[salsa::input(debug)]
213+
#[salsa_macros::input(debug)]
202214
pub struct SourceRootInput {
203215
pub source_root: Arc<SourceRoot>,
204216
}
@@ -265,7 +277,7 @@ pub fn transitive_deps(db: &dyn SourceDatabase, crate_id: Crate) -> FxHashSet<Cr
265277
deps
266278
}
267279

268-
#[salsa::db]
280+
#[salsa_macros::db]
269281
pub trait SourceDatabase: salsa::Database {
270282
/// Text of the file.
271283
fn file_text(&self, file_id: vfs::FileId) -> FileText;
@@ -344,7 +356,7 @@ fn parse(db: &dyn RootQueryDb, file_id: EditionedFileId) -> Parse<ast::SourceFil
344356
}
345357

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

src/tools/rust-analyzer/crates/hir-def/Cargo.toml

+1
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

0 commit comments

Comments
 (0)