]> git.lizzy.rs Git - rust.git/blobdiff - crates/ide_db/src/lib.rs
Merge #11157
[rust.git] / crates / ide_db / src / lib.rs
index bde8767dd68fdc3c6997aa57bc7b1249740f2098..bcbb09e31b5a33a0a6d88c1b9bcc90f1d0718e32 100644 (file)
@@ -3,6 +3,7 @@
 //! It is mainly a `HirDatabase` for semantic analysis, plus a `SymbolsDatabase`, for fuzzy search.
 
 mod apply_change;
+
 pub mod assists;
 pub mod label;
 pub mod line_index;
 pub mod source_change;
 pub mod ty_filter;
 pub mod traits;
-pub mod call_info;
 pub mod helpers;
 pub mod path_transform;
 
 pub mod search;
 pub mod rename;
+pub mod active_parameter;
 
-use std::{fmt, sync::Arc};
+use std::{fmt, mem::ManuallyDrop, sync::Arc};
 
 use base_db::{
     salsa::{self, Durability},
 /// `base_db` is normally also needed in places where `ide_db` is used, so this re-export is for convenience.
 pub use base_db;
 
+pub type FxIndexSet<T> = indexmap::IndexSet<T, std::hash::BuildHasherDefault<rustc_hash::FxHasher>>;
+pub type FxIndexMap<K, V> =
+    indexmap::IndexMap<K, V, std::hash::BuildHasherDefault<rustc_hash::FxHasher>>;
+
 #[salsa::database(
     base_db::SourceDatabaseStorage,
     base_db::SourceDatabaseExtStorage,
     hir::db::HirDatabaseStorage
 )]
 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 {
@@ -93,7 +110,7 @@ fn default() -> RootDatabase {
 
 impl 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_local_roots_with_durability(Default::default(), Durability::HIGH);
         db.set_library_roots_with_durability(Default::default(), Durability::HIGH);
@@ -112,7 +129,7 @@ pub fn update_lru_capacity(&mut self, lru_capacity: Option<usize>) {
 
 impl salsa::ParallelDatabase for 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()) })
     }
 }
 
@@ -128,8 +145,11 @@ fn line_index(db: &dyn LineIndexDatabase, file_id: FileId) -> Arc<LineIndex> {
 
 #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)]
 pub enum SymbolKind {
+    Attribute,
+    BuiltinAttr,
     Const,
     ConstParam,
+    Derive,
     Enum,
     Field,
     Function,
@@ -142,6 +162,7 @@ pub enum SymbolKind {
     SelfParam,
     Static,
     Struct,
+    ToolModule,
     Trait,
     TypeAlias,
     TypeParam,
@@ -149,3 +170,20 @@ pub enum SymbolKind {
     ValueParam,
     Variant,
 }
+
+impl From<hir::MacroKind> for SymbolKind {
+    fn from(it: hir::MacroKind) -> Self {
+        match it {
+            hir::MacroKind::Declarative | hir::MacroKind::BuiltIn | hir::MacroKind::ProcMacro => {
+                SymbolKind::Macro
+            }
+            hir::MacroKind::Derive => SymbolKind::Derive,
+            hir::MacroKind::Attr => SymbolKind::Attribute,
+        }
+    }
+}
+
+#[cfg(test)]
+mod tests {
+    mod sourcegen_lints;
+}