Skip to content

Commit 98da200

Browse files
authored
[ty] Fix server panic when calling system_mut (#18252)
1 parent 029085f commit 98da200

File tree

1 file changed

+9
-1
lines changed
  • crates/ty_project/src

1 file changed

+9
-1
lines changed

crates/ty_project/src/db.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,17 @@ pub trait Db: SemanticDb + Upcast<dyn SemanticDb> {
2525
#[derive(Clone)]
2626
pub struct ProjectDatabase {
2727
project: Option<Project>,
28-
storage: salsa::Storage<ProjectDatabase>,
2928
files: Files,
29+
30+
// IMPORTANT: Never return clones of `system` outside `ProjectDatabase` (only return references)
31+
// or the "trick" to get a mutable `Arc` in `Self::system_mut` is no longer guaranteed to work.
3032
system: Arc<dyn System + Send + Sync + RefUnwindSafe>,
33+
34+
// IMPORTANT: This field must be the last because we use `zalsa_mut` (drops all other storage references)
35+
// to drop all other references to the database, which gives us exclusive access to other `Arc`s stored on this db.
36+
// However, for this to work it's important that the `storage` is dropped AFTER any `Arc` that
37+
// we try to mutably borrow using `Arc::get_mut` (like `system`).
38+
storage: salsa::Storage<ProjectDatabase>,
3139
}
3240

3341
impl ProjectDatabase {

0 commit comments

Comments
 (0)