Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

internal: Workaround salsa cycles leaking #18760

Merged
merged 1 commit into from
Dec 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions crates/proc-macro-srv/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 0 additions & 2 deletions crates/ra-salsa/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}

Expand Down
9 changes: 8 additions & 1 deletion crates/rust-analyzer/src/handlers/dispatch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm rebasing my fork against this PR now, and I'm debating whether this the removal of #[non_exhaustive] in Salsa is necessary—could we return a different error here or is salsa::Cancelled load-bearing?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At this point the value of cancelled doesn't really matter anymore I think so we could also return some other unit error type here (the caller merely wants to know whether cancellation occured)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done: #18762

} 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,
Expand Down
2 changes: 1 addition & 1 deletion crates/rust-analyzer/tests/slow-tests/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Loading