From 98da200d45b040401bc5c1ff04fd678d37d3dd3e Mon Sep 17 00:00:00 2001 From: Micha Reiser Date: Thu, 22 May 2025 16:10:07 +0200 Subject: [PATCH] [ty] Fix server panic when calling `system_mut` (#18252) --- crates/ty_project/src/db.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/crates/ty_project/src/db.rs b/crates/ty_project/src/db.rs index ecbd3f65a8..14fb3ae244 100644 --- a/crates/ty_project/src/db.rs +++ b/crates/ty_project/src/db.rs @@ -25,9 +25,17 @@ pub trait Db: SemanticDb + Upcast { #[derive(Clone)] pub struct ProjectDatabase { project: Option, - storage: salsa::Storage, files: Files, + + // IMPORTANT: Never return clones of `system` outside `ProjectDatabase` (only return references) + // or the "trick" to get a mutable `Arc` in `Self::system_mut` is no longer guaranteed to work. system: Arc, + + // IMPORTANT: This field must be the last because we use `zalsa_mut` (drops all other storage references) + // to drop all other references to the database, which gives us exclusive access to other `Arc`s stored on this db. + // However, for this to work it's important that the `storage` is dropped AFTER any `Arc` that + // we try to mutably borrow using `Arc::get_mut` (like `system`). + storage: salsa::Storage, } impl ProjectDatabase {