mirror of
https://github.com/rust-lang/rust-analyzer
synced 2025-01-12 21:28:51 +00:00
Merge #10069
10069: internal: Use `ManuallyDrop` in `RootDatabase` to improve build times r=matklad a=jonas-schievink Co-authored-by: Jonas Schievink <jonasschievink@gmail.com>
This commit is contained in:
commit
7e31c5ec0d
1 changed files with 16 additions and 4 deletions
|
@ -19,7 +19,7 @@ pub mod path_transform;
|
||||||
pub mod search;
|
pub mod search;
|
||||||
pub mod rename;
|
pub mod rename;
|
||||||
|
|
||||||
use std::{fmt, sync::Arc};
|
use std::{fmt, mem::ManuallyDrop, sync::Arc};
|
||||||
|
|
||||||
use base_db::{
|
use base_db::{
|
||||||
salsa::{self, Durability},
|
salsa::{self, Durability},
|
||||||
|
@ -44,7 +44,19 @@ pub use base_db;
|
||||||
hir::db::HirDatabaseStorage
|
hir::db::HirDatabaseStorage
|
||||||
)]
|
)]
|
||||||
pub struct RootDatabase {
|
pub struct RootDatabase {
|
||||||
storage: salsa::Storage<RootDatabase>,
|
// We use `ManuallyDrop` here because every codegen unit that contains a
|
||||||
|
// `&RootDatabase -> &dyn OtherDatabase` cast will instantiate its drop glue in the vtable,
|
||||||
|
// which duplicates `Weak::drop` and `Arc::drop` tens of thousands of times, which makes
|
||||||
|
// compile times of all `ide_*` and downstream crates suffer greatly.
|
||||||
|
storage: ManuallyDrop<salsa::Storage<RootDatabase>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Drop for RootDatabase {
|
||||||
|
fn drop(&mut self) {
|
||||||
|
unsafe {
|
||||||
|
ManuallyDrop::drop(&mut self.storage);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Debug for RootDatabase {
|
impl fmt::Debug for RootDatabase {
|
||||||
|
@ -93,7 +105,7 @@ impl Default for RootDatabase {
|
||||||
|
|
||||||
impl RootDatabase {
|
impl RootDatabase {
|
||||||
pub fn new(lru_capacity: Option<usize>) -> RootDatabase {
|
pub fn new(lru_capacity: Option<usize>) -> RootDatabase {
|
||||||
let mut db = RootDatabase { storage: salsa::Storage::default() };
|
let mut db = RootDatabase { storage: ManuallyDrop::new(salsa::Storage::default()) };
|
||||||
db.set_crate_graph_with_durability(Default::default(), Durability::HIGH);
|
db.set_crate_graph_with_durability(Default::default(), Durability::HIGH);
|
||||||
db.set_local_roots_with_durability(Default::default(), Durability::HIGH);
|
db.set_local_roots_with_durability(Default::default(), Durability::HIGH);
|
||||||
db.set_library_roots_with_durability(Default::default(), Durability::HIGH);
|
db.set_library_roots_with_durability(Default::default(), Durability::HIGH);
|
||||||
|
@ -112,7 +124,7 @@ impl RootDatabase {
|
||||||
|
|
||||||
impl salsa::ParallelDatabase for RootDatabase {
|
impl salsa::ParallelDatabase for RootDatabase {
|
||||||
fn snapshot(&self) -> salsa::Snapshot<RootDatabase> {
|
fn snapshot(&self) -> salsa::Snapshot<RootDatabase> {
|
||||||
salsa::Snapshot::new(RootDatabase { storage: self.storage.snapshot() })
|
salsa::Snapshot::new(RootDatabase { storage: ManuallyDrop::new(self.storage.snapshot()) })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue