2020-10-02 15:45:09 +02:00
|
|
|
//! Applies changes to the IDE state transactionally.
|
2019-09-30 11:58:53 +03:00
|
|
|
|
2021-08-05 12:02:52 +01:00
|
|
|
use std::sync::Arc;
|
2019-02-08 11:52:18 +03:00
|
|
|
|
2020-08-13 16:25:38 +02:00
|
|
|
use base_db::{
|
2021-10-06 22:42:54 +02:00
|
|
|
salsa::{Database, Durability},
|
2021-08-05 12:02:52 +01:00
|
|
|
Change, SourceRootId,
|
2019-02-08 11:52:18 +03:00
|
|
|
};
|
2020-08-13 16:25:38 +02:00
|
|
|
use profile::{memory_usage, Bytes};
|
2020-06-11 11:04:09 +02:00
|
|
|
use rustc_hash::FxHashSet;
|
2019-02-08 11:52:18 +03:00
|
|
|
|
2020-06-18 08:29:34 +02:00
|
|
|
use crate::{symbol_index::SymbolsDatabase, RootDatabase};
|
2019-02-08 11:52:18 +03:00
|
|
|
|
|
|
|
impl RootDatabase {
|
2020-02-06 12:43:56 +01:00
|
|
|
pub fn request_cancellation(&mut self) {
|
2020-08-12 16:32:36 +02:00
|
|
|
let _p = profile::span("RootDatabase::request_cancellation");
|
2020-01-24 16:35:37 +01:00
|
|
|
self.salsa_runtime_mut().synthetic_write(Durability::LOW);
|
|
|
|
}
|
|
|
|
|
2020-10-02 15:45:09 +02:00
|
|
|
pub fn apply_change(&mut self, change: Change) {
|
2020-08-12 16:32:36 +02:00
|
|
|
let _p = profile::span("RootDatabase::apply_change");
|
2020-01-24 16:35:37 +01:00
|
|
|
self.request_cancellation();
|
2021-08-15 20:46:13 +08:00
|
|
|
tracing::info!("apply_change {:?}", change);
|
2020-10-02 15:45:09 +02:00
|
|
|
if let Some(roots) = &change.roots {
|
2020-06-11 11:04:09 +02:00
|
|
|
let mut local_roots = FxHashSet::default();
|
|
|
|
let mut library_roots = FxHashSet::default();
|
2020-10-02 15:45:09 +02:00
|
|
|
for (idx, root) in roots.iter().enumerate() {
|
2020-06-11 11:04:09 +02:00
|
|
|
let root_id = SourceRootId(idx as u32);
|
|
|
|
if root.is_library {
|
|
|
|
library_roots.insert(root_id);
|
2020-06-18 08:29:34 +02:00
|
|
|
} else {
|
2020-06-11 11:04:09 +02:00
|
|
|
local_roots.insert(root_id);
|
|
|
|
}
|
2019-02-08 11:52:18 +03:00
|
|
|
}
|
2019-06-26 09:12:46 +03:00
|
|
|
self.set_local_roots_with_durability(Arc::new(local_roots), Durability::HIGH);
|
2020-06-11 11:04:09 +02:00
|
|
|
self.set_library_roots_with_durability(Arc::new(library_roots), Durability::HIGH);
|
2019-02-08 11:52:18 +03:00
|
|
|
}
|
2020-10-02 15:45:09 +02:00
|
|
|
change.apply(self);
|
2019-02-08 11:52:18 +03:00
|
|
|
}
|
|
|
|
|
2020-07-07 12:10:14 +02:00
|
|
|
// Feature: Memory Usage
|
|
|
|
//
|
|
|
|
// Clears rust-analyzer's internal database and prints memory usage statistics.
|
|
|
|
//
|
|
|
|
// |===
|
|
|
|
// | Editor | Action Name
|
|
|
|
//
|
|
|
|
// | VS Code | **Rust Analyzer: Memory Usage (Clears Database)**
|
|
|
|
// |===
|
2021-03-31 00:08:10 +01:00
|
|
|
// image::https://user-images.githubusercontent.com/48062697/113065592-08559f00-91b1-11eb-8c96-64b88068ec02.gif[]
|
2020-02-06 12:43:56 +01:00
|
|
|
pub fn per_query_memory_usage(&mut self) -> Vec<(String, Bytes)> {
|
2019-06-30 14:40:01 +03:00
|
|
|
let mut acc: Vec<(String, Bytes)> = vec![];
|
2021-10-06 22:42:54 +02:00
|
|
|
macro_rules! purge_each_query {
|
2019-06-30 14:40:01 +03:00
|
|
|
($($q:path)*) => {$(
|
2020-07-22 18:44:40 +02:00
|
|
|
let before = memory_usage().allocated;
|
|
|
|
$q.in_db(self).purge();
|
|
|
|
let after = memory_usage().allocated;
|
|
|
|
let q: $q = Default::default();
|
2021-10-06 22:42:54 +02:00
|
|
|
let name = format!("{:?}", q);
|
2020-07-22 18:44:40 +02:00
|
|
|
acc.push((name, before - after));
|
2019-06-30 14:40:01 +03:00
|
|
|
)*}
|
|
|
|
}
|
2021-10-06 22:42:54 +02:00
|
|
|
purge_each_query![
|
2020-01-29 16:10:46 +01:00
|
|
|
// SourceDatabase
|
2020-08-13 16:25:38 +02:00
|
|
|
base_db::ParseQuery
|
|
|
|
base_db::CrateGraphQuery
|
2020-07-22 18:44:40 +02:00
|
|
|
|
|
|
|
// SourceDatabaseExt
|
2020-08-13 16:25:38 +02:00
|
|
|
base_db::FileTextQuery
|
|
|
|
base_db::FileSourceRootQuery
|
|
|
|
base_db::SourceRootQuery
|
|
|
|
base_db::SourceRootCratesQuery
|
2020-01-29 16:10:46 +01:00
|
|
|
|
|
|
|
// AstDatabase
|
2019-06-30 14:40:01 +03:00
|
|
|
hir::db::AstIdMapQuery
|
2020-07-22 21:50:37 +03:00
|
|
|
hir::db::MacroArgTextQuery
|
2020-01-29 16:10:46 +01:00
|
|
|
hir::db::MacroDefQuery
|
2020-11-24 21:57:51 +01:00
|
|
|
hir::db::ParseMacroExpansionQuery
|
2019-06-30 14:40:01 +03:00
|
|
|
hir::db::MacroExpandQuery
|
2021-01-04 10:53:31 +08:00
|
|
|
hir::db::HygieneFrameQuery
|
2021-11-14 16:25:40 +01:00
|
|
|
hir::db::InternMacroCallQuery
|
2020-01-29 16:10:46 +01:00
|
|
|
|
|
|
|
// DefDatabase
|
2021-03-13 02:24:26 +01:00
|
|
|
hir::db::FileItemTreeQuery
|
2021-01-21 15:22:17 +01:00
|
|
|
hir::db::BlockDefMapQuery
|
2020-03-07 00:11:52 +01:00
|
|
|
hir::db::CrateDefMapQueryQuery
|
2021-04-06 22:25:44 +02:00
|
|
|
hir::db::FieldsAttrsQuery
|
|
|
|
hir::db::VariantsAttrsQuery
|
|
|
|
hir::db::FieldsAttrsSourceMapQuery
|
|
|
|
hir::db::VariantsAttrsSourceMapQuery
|
2019-06-30 14:40:01 +03:00
|
|
|
hir::db::StructDataQuery
|
2020-01-29 16:10:46 +01:00
|
|
|
hir::db::UnionDataQuery
|
2019-06-30 14:40:01 +03:00
|
|
|
hir::db::EnumDataQuery
|
2020-01-29 16:10:46 +01:00
|
|
|
hir::db::ImplDataQuery
|
2019-06-30 14:40:01 +03:00
|
|
|
hir::db::TraitDataQuery
|
|
|
|
hir::db::TypeAliasDataQuery
|
2020-01-29 16:10:46 +01:00
|
|
|
hir::db::FunctionDataQuery
|
2019-06-30 14:40:01 +03:00
|
|
|
hir::db::ConstDataQuery
|
|
|
|
hir::db::StaticDataQuery
|
2020-01-29 16:10:46 +01:00
|
|
|
hir::db::BodyWithSourceMapQuery
|
|
|
|
hir::db::BodyQuery
|
|
|
|
hir::db::ExprScopesQuery
|
|
|
|
hir::db::GenericParamsQuery
|
|
|
|
hir::db::AttrsQuery
|
2019-09-25 20:01:02 +02:00
|
|
|
hir::db::CrateLangItemsQuery
|
2019-06-30 14:40:01 +03:00
|
|
|
hir::db::LangItemQuery
|
2020-06-05 13:10:43 +02:00
|
|
|
hir::db::ImportMapQuery
|
2020-01-29 16:10:46 +01:00
|
|
|
|
|
|
|
// HirDatabase
|
2020-03-07 00:11:52 +01:00
|
|
|
hir::db::InferQueryQuery
|
2019-11-26 21:04:24 +03:00
|
|
|
hir::db::TyQuery
|
|
|
|
hir::db::ValueTyQuery
|
2020-01-29 16:10:46 +01:00
|
|
|
hir::db::ImplSelfTyQuery
|
|
|
|
hir::db::ImplTraitQuery
|
2019-11-24 23:48:39 +03:00
|
|
|
hir::db::FieldTypesQuery
|
2019-06-30 14:40:01 +03:00
|
|
|
hir::db::CallableItemSignatureQuery
|
2020-01-29 16:10:46 +01:00
|
|
|
hir::db::GenericPredicatesForParamQuery
|
2019-06-30 14:40:01 +03:00
|
|
|
hir::db::GenericPredicatesQuery
|
|
|
|
hir::db::GenericDefaultsQuery
|
2020-07-01 17:15:20 +02:00
|
|
|
hir::db::InherentImplsInCrateQuery
|
2021-03-24 18:59:35 +01:00
|
|
|
hir::db::TraitEnvironmentQuery
|
2020-07-01 17:15:20 +02:00
|
|
|
hir::db::TraitImplsInCrateQuery
|
|
|
|
hir::db::TraitImplsInDepsQuery
|
2019-06-30 14:40:01 +03:00
|
|
|
hir::db::AssociatedTyDataQuery
|
2020-07-22 18:44:40 +02:00
|
|
|
hir::db::AssociatedTyDataQuery
|
2019-06-30 14:40:01 +03:00
|
|
|
hir::db::TraitDatumQuery
|
|
|
|
hir::db::StructDatumQuery
|
|
|
|
hir::db::ImplDatumQuery
|
2020-07-22 18:44:40 +02:00
|
|
|
hir::db::FnDefDatumQuery
|
|
|
|
hir::db::ReturnTypeImplTraitsQuery
|
|
|
|
hir::db::InternCallableDefQuery
|
|
|
|
hir::db::InternTypeParamIdQuery
|
|
|
|
hir::db::InternImplTraitIdQuery
|
|
|
|
hir::db::InternClosureQuery
|
2020-03-25 18:41:46 +01:00
|
|
|
hir::db::AssociatedTyValueQuery
|
2021-04-14 19:11:17 +03:00
|
|
|
hir::db::TraitSolveQueryQuery
|
2021-10-06 22:42:54 +02:00
|
|
|
hir::db::InternTypeParamIdQuery
|
2020-03-25 18:41:46 +01:00
|
|
|
|
|
|
|
// SymbolsDatabase
|
2021-11-27 13:00:02 +00:00
|
|
|
crate::symbol_index::ModuleSymbolsQuery
|
2020-07-22 18:44:40 +02:00
|
|
|
crate::symbol_index::LibrarySymbolsQuery
|
|
|
|
crate::symbol_index::LocalRootsQuery
|
|
|
|
crate::symbol_index::LibraryRootsQuery
|
2020-03-25 18:41:46 +01:00
|
|
|
|
|
|
|
// LineIndexDatabase
|
|
|
|
crate::LineIndexQuery
|
2020-07-03 17:12:29 +02:00
|
|
|
|
|
|
|
// InternDatabase
|
|
|
|
hir::db::InternFunctionQuery
|
|
|
|
hir::db::InternStructQuery
|
|
|
|
hir::db::InternUnionQuery
|
|
|
|
hir::db::InternEnumQuery
|
|
|
|
hir::db::InternConstQuery
|
|
|
|
hir::db::InternStaticQuery
|
|
|
|
hir::db::InternTraitQuery
|
|
|
|
hir::db::InternTypeAliasQuery
|
|
|
|
hir::db::InternImplQuery
|
|
|
|
];
|
|
|
|
|
2019-06-30 14:40:01 +03:00
|
|
|
acc.sort_by_key(|it| std::cmp::Reverse(it.1));
|
|
|
|
acc
|
|
|
|
}
|
2019-02-08 11:52:18 +03:00
|
|
|
}
|