aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ide_db
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_ide_db')
-rw-r--r--crates/ra_ide_db/src/change.rs20
-rw-r--r--crates/ra_ide_db/src/lib.rs35
-rw-r--r--crates/ra_ide_db/src/symbol_index.rs8
3 files changed, 30 insertions, 33 deletions
diff --git a/crates/ra_ide_db/src/change.rs b/crates/ra_ide_db/src/change.rs
index 2504d7a33..d8da3f949 100644
--- a/crates/ra_ide_db/src/change.rs
+++ b/crates/ra_ide_db/src/change.rs
@@ -147,21 +147,21 @@ impl RootDatabase {
147 147
148 let sweep = SweepStrategy::default().discard_values().sweep_all_revisions(); 148 let sweep = SweepStrategy::default().discard_values().sweep_all_revisions();
149 149
150 self.query(ra_db::ParseQuery).sweep(sweep); 150 ra_db::ParseQuery.in_db(self).sweep(sweep);
151 self.query(hir::db::ParseMacroQuery).sweep(sweep); 151 hir::db::ParseMacroQuery.in_db(self).sweep(sweep);
152 152
153 // Macros do take significant space, but less then the syntax trees 153 // Macros do take significant space, but less then the syntax trees
154 // self.query(hir::db::MacroDefQuery).sweep(sweep); 154 // self.query(hir::db::MacroDefQuery).sweep(sweep);
155 // self.query(hir::db::MacroArgQuery).sweep(sweep); 155 // self.query(hir::db::MacroArgQuery).sweep(sweep);
156 // self.query(hir::db::MacroExpandQuery).sweep(sweep); 156 // self.query(hir::db::MacroExpandQuery).sweep(sweep);
157 157
158 self.query(hir::db::AstIdMapQuery).sweep(sweep); 158 hir::db::AstIdMapQuery.in_db(self).sweep(sweep);
159 159
160 self.query(hir::db::BodyWithSourceMapQuery).sweep(sweep); 160 hir::db::BodyWithSourceMapQuery.in_db(self).sweep(sweep);
161 161
162 self.query(hir::db::ExprScopesQuery).sweep(sweep); 162 hir::db::ExprScopesQuery.in_db(self).sweep(sweep);
163 self.query(hir::db::InferQueryQuery).sweep(sweep); 163 hir::db::InferQueryQuery.in_db(self).sweep(sweep);
164 self.query(hir::db::BodyQuery).sweep(sweep); 164 hir::db::BodyQuery.in_db(self).sweep(sweep);
165 } 165 }
166 166
167 pub fn per_query_memory_usage(&mut self) -> Vec<(String, Bytes)> { 167 pub fn per_query_memory_usage(&mut self) -> Vec<(String, Bytes)> {
@@ -170,14 +170,14 @@ impl RootDatabase {
170 macro_rules! sweep_each_query { 170 macro_rules! sweep_each_query {
171 ($($q:path)*) => {$( 171 ($($q:path)*) => {$(
172 let before = memory_usage().allocated; 172 let before = memory_usage().allocated;
173 self.query($q).sweep(sweep); 173 $q.in_db(self).sweep(sweep);
174 let after = memory_usage().allocated; 174 let after = memory_usage().allocated;
175 let q: $q = Default::default(); 175 let q: $q = Default::default();
176 let name = format!("{:?}", q); 176 let name = format!("{:?}", q);
177 acc.push((name, before - after)); 177 acc.push((name, before - after));
178 178
179 let before = memory_usage().allocated; 179 let before = memory_usage().allocated;
180 self.query($q).sweep(sweep.discard_everything()); 180 $q.in_db(self).sweep(sweep.discard_everything());
181 let after = memory_usage().allocated; 181 let after = memory_usage().allocated;
182 let q: $q = Default::default(); 182 let q: $q = Default::default();
183 let name = format!("{:?} (deps)", q); 183 let name = format!("{:?} (deps)", q);
@@ -252,7 +252,7 @@ impl RootDatabase {
252 // write. 252 // write.
253 // We do this after collecting the non-interned queries to correctly attribute memory used 253 // We do this after collecting the non-interned queries to correctly attribute memory used
254 // by interned data. 254 // by interned data.
255 self.runtime.synthetic_write(Durability::HIGH); 255 self.salsa_runtime_mut().synthetic_write(Durability::HIGH);
256 256
257 sweep_each_query![ 257 sweep_each_query![
258 // AstDatabase 258 // AstDatabase
diff --git a/crates/ra_ide_db/src/lib.rs b/crates/ra_ide_db/src/lib.rs
index c78071ad6..6900cac73 100644
--- a/crates/ra_ide_db/src/lib.rs
+++ b/crates/ra_ide_db/src/lib.rs
@@ -11,11 +11,11 @@ pub mod imports_locator;
11pub mod source_change; 11pub mod source_change;
12mod wasm_shims; 12mod wasm_shims;
13 13
14use std::sync::Arc; 14use std::{fmt, sync::Arc};
15 15
16use hir::db::{AstDatabase, DefDatabase, HirDatabase}; 16use hir::db::{AstDatabase, DefDatabase, HirDatabase};
17use ra_db::{ 17use ra_db::{
18 salsa::{self, Database, Durability}, 18 salsa::{self, Durability},
19 Canceled, CheckCanceled, CrateId, FileId, FileLoader, FileLoaderDelegate, SourceDatabase, 19 Canceled, CheckCanceled, CrateId, FileId, FileLoader, FileLoaderDelegate, SourceDatabase,
20 Upcast, 20 Upcast,
21}; 21};
@@ -33,13 +33,18 @@ use crate::{line_index::LineIndex, symbol_index::SymbolsDatabase};
33 hir::db::DefDatabaseStorage, 33 hir::db::DefDatabaseStorage,
34 hir::db::HirDatabaseStorage 34 hir::db::HirDatabaseStorage
35)] 35)]
36#[derive(Debug)]
37pub struct RootDatabase { 36pub struct RootDatabase {
38 runtime: salsa::Runtime<RootDatabase>, 37 storage: salsa::Storage<RootDatabase>,
39 pub last_gc: crate::wasm_shims::Instant, 38 pub last_gc: crate::wasm_shims::Instant,
40 pub last_gc_check: crate::wasm_shims::Instant, 39 pub last_gc_check: crate::wasm_shims::Instant,
41} 40}
42 41
42impl fmt::Debug for RootDatabase {
43 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
44 f.debug_struct("RootDatabase").finish()
45 }
46}
47
43impl Upcast<dyn AstDatabase> for RootDatabase { 48impl Upcast<dyn AstDatabase> for RootDatabase {
44 fn upcast(&self) -> &(dyn AstDatabase + 'static) { 49 fn upcast(&self) -> &(dyn AstDatabase + 'static) {
45 &*self 50 &*self
@@ -71,17 +76,11 @@ impl FileLoader for RootDatabase {
71} 76}
72 77
73impl salsa::Database for RootDatabase { 78impl salsa::Database for RootDatabase {
74 fn salsa_runtime(&self) -> &salsa::Runtime<RootDatabase> {
75 &self.runtime
76 }
77 fn salsa_runtime_mut(&mut self) -> &mut salsa::Runtime<Self> {
78 &mut self.runtime
79 }
80 fn on_propagated_panic(&self) -> ! { 79 fn on_propagated_panic(&self) -> ! {
81 Canceled::throw() 80 Canceled::throw()
82 } 81 }
83 fn salsa_event(&self, event: impl Fn() -> salsa::Event<RootDatabase>) { 82 fn salsa_event(&self, event: salsa::Event) {
84 match event().kind { 83 match event.kind {
85 salsa::EventKind::DidValidateMemoizedValue { .. } 84 salsa::EventKind::DidValidateMemoizedValue { .. }
86 | salsa::EventKind::WillExecute { .. } => { 85 | salsa::EventKind::WillExecute { .. } => {
87 self.check_canceled(); 86 self.check_canceled();
@@ -100,7 +99,7 @@ impl Default for RootDatabase {
100impl RootDatabase { 99impl RootDatabase {
101 pub fn new(lru_capacity: Option<usize>) -> RootDatabase { 100 pub fn new(lru_capacity: Option<usize>) -> RootDatabase {
102 let mut db = RootDatabase { 101 let mut db = RootDatabase {
103 runtime: salsa::Runtime::default(), 102 storage: salsa::Storage::default(),
104 last_gc: crate::wasm_shims::Instant::now(), 103 last_gc: crate::wasm_shims::Instant::now(),
105 last_gc_check: crate::wasm_shims::Instant::now(), 104 last_gc_check: crate::wasm_shims::Instant::now(),
106 }; 105 };
@@ -113,16 +112,16 @@ impl RootDatabase {
113 112
114 pub fn update_lru_capacity(&mut self, lru_capacity: Option<usize>) { 113 pub fn update_lru_capacity(&mut self, lru_capacity: Option<usize>) {
115 let lru_capacity = lru_capacity.unwrap_or(ra_db::DEFAULT_LRU_CAP); 114 let lru_capacity = lru_capacity.unwrap_or(ra_db::DEFAULT_LRU_CAP);
116 self.query_mut(ra_db::ParseQuery).set_lru_capacity(lru_capacity); 115 ra_db::ParseQuery.in_db_mut(self).set_lru_capacity(lru_capacity);
117 self.query_mut(hir::db::ParseMacroQuery).set_lru_capacity(lru_capacity); 116 hir::db::ParseMacroQuery.in_db_mut(self).set_lru_capacity(lru_capacity);
118 self.query_mut(hir::db::MacroExpandQuery).set_lru_capacity(lru_capacity); 117 hir::db::MacroExpandQuery.in_db_mut(self).set_lru_capacity(lru_capacity);
119 } 118 }
120} 119}
121 120
122impl salsa::ParallelDatabase for RootDatabase { 121impl salsa::ParallelDatabase for RootDatabase {
123 fn snapshot(&self) -> salsa::Snapshot<RootDatabase> { 122 fn snapshot(&self) -> salsa::Snapshot<RootDatabase> {
124 salsa::Snapshot::new(RootDatabase { 123 salsa::Snapshot::new(RootDatabase {
125 runtime: self.runtime.snapshot(self), 124 storage: self.storage.snapshot(),
126 last_gc: self.last_gc, 125 last_gc: self.last_gc,
127 last_gc_check: self.last_gc_check, 126 last_gc_check: self.last_gc_check,
128 }) 127 })
@@ -134,7 +133,7 @@ pub trait LineIndexDatabase: ra_db::SourceDatabase + CheckCanceled {
134 fn line_index(&self, file_id: FileId) -> Arc<LineIndex>; 133 fn line_index(&self, file_id: FileId) -> Arc<LineIndex>;
135} 134}
136 135
137fn line_index(db: &impl LineIndexDatabase, file_id: FileId) -> Arc<LineIndex> { 136fn line_index(db: &dyn LineIndexDatabase, file_id: FileId) -> Arc<LineIndex> {
138 let text = db.file_text(file_id); 137 let text = db.file_text(file_id);
139 Arc::new(LineIndex::new(&*text)) 138 Arc::new(LineIndex::new(&*text))
140} 139}
diff --git a/crates/ra_ide_db/src/symbol_index.rs b/crates/ra_ide_db/src/symbol_index.rs
index 5a09e7d1d..131e2a128 100644
--- a/crates/ra_ide_db/src/symbol_index.rs
+++ b/crates/ra_ide_db/src/symbol_index.rs
@@ -87,7 +87,7 @@ impl Query {
87} 87}
88 88
89#[salsa::query_group(SymbolsDatabaseStorage)] 89#[salsa::query_group(SymbolsDatabaseStorage)]
90pub trait SymbolsDatabase: hir::db::HirDatabase + SourceDatabaseExt + ParallelDatabase { 90pub trait SymbolsDatabase: hir::db::HirDatabase + SourceDatabaseExt {
91 fn file_symbols(&self, file_id: FileId) -> Arc<SymbolIndex>; 91 fn file_symbols(&self, file_id: FileId) -> Arc<SymbolIndex>;
92 fn library_symbols(&self) -> Arc<FxHashMap<SourceRootId, SymbolIndex>>; 92 fn library_symbols(&self) -> Arc<FxHashMap<SourceRootId, SymbolIndex>>;
93 /// The set of "local" (that is, from the current workspace) roots. 93 /// The set of "local" (that is, from the current workspace) roots.
@@ -100,9 +100,7 @@ pub trait SymbolsDatabase: hir::db::HirDatabase + SourceDatabaseExt + ParallelDa
100 fn library_roots(&self) -> Arc<FxHashSet<SourceRootId>>; 100 fn library_roots(&self) -> Arc<FxHashSet<SourceRootId>>;
101} 101}
102 102
103fn library_symbols( 103fn library_symbols(db: &dyn SymbolsDatabase) -> Arc<FxHashMap<SourceRootId, SymbolIndex>> {
104 db: &(impl SymbolsDatabase + ParallelDatabase),
105) -> Arc<FxHashMap<SourceRootId, SymbolIndex>> {
106 let _p = profile("library_symbols"); 104 let _p = profile("library_symbols");
107 105
108 let roots = db.library_roots(); 106 let roots = db.library_roots();
@@ -123,7 +121,7 @@ fn library_symbols(
123 Arc::new(res) 121 Arc::new(res)
124} 122}
125 123
126fn file_symbols(db: &impl SymbolsDatabase, file_id: FileId) -> Arc<SymbolIndex> { 124fn file_symbols(db: &dyn SymbolsDatabase, file_id: FileId) -> Arc<SymbolIndex> {
127 db.check_canceled(); 125 db.check_canceled();
128 let parse = db.parse(file_id); 126 let parse = db.parse(file_id);
129 127