Skip to content

Commit 5951f9f

Browse files
committed
Backport rust-lang/rust-analyzer#18760: internal: Workaround salsa cycles leaking
1 parent fe9b975 commit 5951f9f

File tree

4 files changed

+11
-6
lines changed

4 files changed

+11
-6
lines changed

Diff for: src/tools/rust-analyzer/crates/proc-macro-srv/src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ fn expand_id(
175175
});
176176
let res = match thread {
177177
Ok(handle) => handle.join(),
178-
Err(e) => std::panic::resume_unwind(Box::new(e)),
178+
Err(e) => return Err(e.to_string()),
179179
};
180180

181181
match res {
@@ -223,7 +223,7 @@ fn expand_ra_span(
223223
});
224224
let res = match thread {
225225
Ok(handle) => handle.join(),
226-
Err(e) => std::panic::resume_unwind(Box::new(e)),
226+
Err(e) => return Err(e.to_string()),
227227
};
228228

229229
match res {

Diff for: src/tools/rust-analyzer/crates/ra-salsa/src/lib.rs

-2
Original file line numberDiff line numberDiff line change
@@ -610,11 +610,9 @@ where
610610
#[non_exhaustive]
611611
pub enum Cancelled {
612612
/// The query was operating on revision R, but there is a pending write to move to revision R+1.
613-
#[non_exhaustive]
614613
PendingWrite,
615614

616615
/// The query was blocked on another thread, and that thread panicked.
617-
#[non_exhaustive]
618616
PropagatedPanic,
619617
}
620618

Diff for: src/tools/rust-analyzer/crates/rust-analyzer/src/handlers/dispatch.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use std::{
55
};
66

77
use ide::Cancelled;
8+
use ide_db::base_db::ra_salsa::Cycle;
89
use lsp_server::{ExtractError, Response, ResponseError};
910
use serde::{de::DeserializeOwned, Serialize};
1011
use stdx::thread::ThreadIntent;
@@ -328,7 +329,13 @@ where
328329
if let Some(panic_message) = panic_message {
329330
message.push_str(": ");
330331
message.push_str(panic_message)
331-
};
332+
} else if let Some(cycle) = panic.downcast_ref::<Cycle>() {
333+
tracing::error!("Cycle propagated out of salsa! This is a bug: {cycle:?}");
334+
return Err(Cancelled::PropagatedPanic);
335+
} else if let Ok(cancelled) = panic.downcast::<Cancelled>() {
336+
tracing::error!("Cancellation propagated out of salsa! This is a bug");
337+
return Err(*cancelled);
338+
}
332339

333340
Ok(lsp_server::Response::new_err(
334341
id,

Diff for: src/tools/rust-analyzer/crates/rust-analyzer/tests/slow-tests/main.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1085,7 +1085,7 @@ fn resolve_proc_macro() {
10851085
let sysroot = project_model::Sysroot::discover(
10861086
&AbsPathBuf::assert_utf8(std::env::current_dir().unwrap()),
10871087
&Default::default(),
1088-
project_model::SysrootQueryMetadata::CargoMetadata,
1088+
&project_model::SysrootQueryMetadata::default(),
10891089
);
10901090

10911091
let proc_macro_server_path = sysroot.discover_proc_macro_srv().unwrap();

0 commit comments

Comments
 (0)