about summary refs log tree commit diff
diff options
context:
space:
mode:
authorLukas Wirth <lukastw97@gmail.com>2024-12-26 14:09:49 +0000
committerGitHub <noreply@github.com>2024-12-26 14:09:49 +0000
commitec5e4855cc43cf4a7d240312ae1827b1e63ad09d (patch)
treeace8c200b815a5cd05fcf62d7a05d8972aef1208
parent022bece913ef6dfd1010b127ac5fda9db7cd0ece (diff)
parent27dd75d93cf14daaf233cb536bfe8e1f61738bf8 (diff)
downloadrust-ec5e4855cc43cf4a7d240312ae1827b1e63ad09d.tar.gz
rust-ec5e4855cc43cf4a7d240312ae1827b1e63ad09d.zip
Merge pull request #18760 from Veykril/push-tkvlvvqyszrs
internal: Workaround salsa cycles leaking
-rw-r--r--src/tools/rust-analyzer/crates/proc-macro-srv/src/lib.rs4
-rw-r--r--src/tools/rust-analyzer/crates/ra-salsa/src/lib.rs2
-rw-r--r--src/tools/rust-analyzer/crates/rust-analyzer/src/handlers/dispatch.rs9
-rw-r--r--src/tools/rust-analyzer/crates/rust-analyzer/tests/slow-tests/main.rs2
4 files changed, 11 insertions, 6 deletions
diff --git a/src/tools/rust-analyzer/crates/proc-macro-srv/src/lib.rs b/src/tools/rust-analyzer/crates/proc-macro-srv/src/lib.rs
index 85833dab1b0..c8d9e6cc299 100644
--- a/src/tools/rust-analyzer/crates/proc-macro-srv/src/lib.rs
+++ b/src/tools/rust-analyzer/crates/proc-macro-srv/src/lib.rs
@@ -175,7 +175,7 @@ fn expand_id(
             });
         let res = match thread {
             Ok(handle) => handle.join(),
-            Err(e) => std::panic::resume_unwind(Box::new(e)),
+            Err(e) => return Err(e.to_string()),
         };
 
         match res {
@@ -223,7 +223,7 @@ fn expand_ra_span(
             });
         let res = match thread {
             Ok(handle) => handle.join(),
-            Err(e) => std::panic::resume_unwind(Box::new(e)),
+            Err(e) => return Err(e.to_string()),
         };
 
         match res {
diff --git a/src/tools/rust-analyzer/crates/ra-salsa/src/lib.rs b/src/tools/rust-analyzer/crates/ra-salsa/src/lib.rs
index 8530521d915..6e43676354c 100644
--- a/src/tools/rust-analyzer/crates/ra-salsa/src/lib.rs
+++ b/src/tools/rust-analyzer/crates/ra-salsa/src/lib.rs
@@ -610,11 +610,9 @@ where
 #[non_exhaustive]
 pub enum Cancelled {
     /// The query was operating on revision R, but there is a pending write to move to revision R+1.
-    #[non_exhaustive]
     PendingWrite,
 
     /// The query was blocked on another thread, and that thread panicked.
-    #[non_exhaustive]
     PropagatedPanic,
 }
 
diff --git a/src/tools/rust-analyzer/crates/rust-analyzer/src/handlers/dispatch.rs b/src/tools/rust-analyzer/crates/rust-analyzer/src/handlers/dispatch.rs
index 2aa4ffbe1dc..148a8194cda 100644
--- a/src/tools/rust-analyzer/crates/rust-analyzer/src/handlers/dispatch.rs
+++ b/src/tools/rust-analyzer/crates/rust-analyzer/src/handlers/dispatch.rs
@@ -5,6 +5,7 @@ use std::{
 };
 
 use ide::Cancelled;
+use ide_db::base_db::ra_salsa::Cycle;
 use lsp_server::{ExtractError, Response, ResponseError};
 use serde::{de::DeserializeOwned, Serialize};
 use stdx::thread::ThreadIntent;
@@ -328,7 +329,13 @@ where
             if let Some(panic_message) = panic_message {
                 message.push_str(": ");
                 message.push_str(panic_message)
-            };
+            } else if let Some(cycle) = panic.downcast_ref::<Cycle>() {
+                tracing::error!("Cycle propagated out of salsa! This is a bug: {cycle:?}");
+                return Err(Cancelled::PropagatedPanic);
+            } else if let Ok(cancelled) = panic.downcast::<Cancelled>() {
+                tracing::error!("Cancellation propagated out of salsa! This is a bug");
+                return Err(*cancelled);
+            }
 
             Ok(lsp_server::Response::new_err(
                 id,
diff --git a/src/tools/rust-analyzer/crates/rust-analyzer/tests/slow-tests/main.rs b/src/tools/rust-analyzer/crates/rust-analyzer/tests/slow-tests/main.rs
index c1ca5960637..ccd2ecdb130 100644
--- a/src/tools/rust-analyzer/crates/rust-analyzer/tests/slow-tests/main.rs
+++ b/src/tools/rust-analyzer/crates/rust-analyzer/tests/slow-tests/main.rs
@@ -1085,7 +1085,7 @@ fn resolve_proc_macro() {
     let sysroot = project_model::Sysroot::discover(
         &AbsPathBuf::assert_utf8(std::env::current_dir().unwrap()),
         &Default::default(),
-        project_model::SysrootQueryMetadata::CargoMetadata,
+        &project_model::SysrootQueryMetadata::default(),
     );
 
     let proc_macro_server_path = sysroot.discover_proc_macro_srv().unwrap();