aboutsummaryrefslogtreecommitdiff
path: root/crates/libanalysis
diff options
context:
space:
mode:
Diffstat (limited to 'crates/libanalysis')
-rw-r--r--crates/libanalysis/src/db.rs26
-rw-r--r--crates/libanalysis/src/module_map_db.rs23
2 files changed, 18 insertions, 31 deletions
diff --git a/crates/libanalysis/src/db.rs b/crates/libanalysis/src/db.rs
index bfff5357f..2f344f788 100644
--- a/crates/libanalysis/src/db.rs
+++ b/crates/libanalysis/src/db.rs
@@ -113,7 +113,7 @@ impl Cache {
113 113
114pub(crate) struct QueryCtx { 114pub(crate) struct QueryCtx {
115 db: Arc<Db>, 115 db: Arc<Db>,
116 stack: RefCell<Vec<QueryInvocationId>>, 116 stack: RefCell<Vec<(QueryInvocationId, Vec<(QueryInvocationId, OutputHash)>)>>,
117 pub(crate) trace: RefCell<Vec<TraceEvent>>, 117 pub(crate) trace: RefCell<Vec<TraceEvent>>,
118} 118}
119 119
@@ -131,22 +131,16 @@ pub(crate) enum TraceEventKind {
131impl QueryCtx { 131impl QueryCtx {
132 pub(crate) fn get<Q: Get>(&self, params: &Q::Params) -> Q::Output { 132 pub(crate) fn get<Q: Get>(&self, params: &Q::Params) -> Q::Output {
133 let me = id::<Q>(params); 133 let me = id::<Q>(params);
134 eprintln!("eval: {:?}", me);
135 let parent = self.stack.borrow().last().map(|&id| id);
136 self.stack.borrow_mut().push(me);
137 self.trace(TraceEvent { query_id: Q::ID, kind: TraceEventKind::Start }); 134 self.trace(TraceEvent { query_id: Q::ID, kind: TraceEventKind::Start });
138 let res = Q::get(self, params); 135 let res = Q::get(self, params);
139 self.trace(TraceEvent { query_id: Q::ID, kind: TraceEventKind::Finish }); 136 self.trace(TraceEvent { query_id: Q::ID, kind: TraceEventKind::Finish });
140 if let Some(parent) = parent { 137 {
141 let h = output_hash::<Q>(&res); 138 let mut stack = self.stack.borrow_mut();
142 let mut cache = self.db.cache.lock(); 139 if let Some((_, ref mut deps)) = stack.last_mut() {
143 cache.deps 140 deps.push((me, output_hash::<Q>(&res)));
144 .entry(parent) 141 }
145 .or_insert(Vec::new())
146 .push((me, h))
147 } 142 }
148 let also_me = self.stack.borrow_mut().pop(); 143
149 assert_eq!(also_me, Some(me));
150 res 144 res
151 } 145 }
152 fn trace(&self, event: TraceEvent) { 146 fn trace(&self, event: TraceEvent) {
@@ -179,10 +173,14 @@ where
179 return res; 173 return res;
180 } 174 }
181 175
176 let me = id::<Q>(params);
182 ctx.trace(TraceEvent { query_id: Q::ID, kind: TraceEventKind::Evaluating }); 177 ctx.trace(TraceEvent { query_id: Q::ID, kind: TraceEventKind::Evaluating });
178 ctx.stack.borrow_mut().push((me, Vec::new()));
183 let res = Self::eval(ctx, params); 179 let res = Self::eval(ctx, params);
184 180 let (also_me, deps) = ctx.stack.borrow_mut().pop().unwrap();
181 assert_eq!(also_me, me);
185 let mut cache = ctx.db.cache.lock(); 182 let mut cache = ctx.db.cache.lock();
183 cache.deps.insert(me, deps);
186 let gen = cache.gen; 184 let gen = cache.gen;
187 let output_hash = output_hash::<Q>(&res); 185 let output_hash = output_hash::<Q>(&res);
188 let id = id::<Q>(params); 186 let id = id::<Q>(params);
diff --git a/crates/libanalysis/src/module_map_db.rs b/crates/libanalysis/src/module_map_db.rs
index 27f19f96e..72173c7bc 100644
--- a/crates/libanalysis/src/module_map_db.rs
+++ b/crates/libanalysis/src/module_map_db.rs
@@ -169,7 +169,6 @@ mod tests {
169 expected: &[FileId], 169 expected: &[FileId],
170 queries: &[(u32, u64)] 170 queries: &[(u32, u64)]
171 ) { 171 ) {
172 eprintln!();
173 let ctx = self.db.query_ctx(); 172 let ctx = self.db.query_ctx();
174 let actual = ctx.get::<ParentModule>(&file_id); 173 let actual = ctx.get::<ParentModule>(&file_id);
175 assert_eq!(actual.as_slice(), expected); 174 assert_eq!(actual.as_slice(), expected);
@@ -194,23 +193,14 @@ mod tests {
194 fn test_parent_module() { 193 fn test_parent_module() {
195 let mut f = Fixture::new(); 194 let mut f = Fixture::new();
196 let foo = f.add_file("/foo.rs", ""); 195 let foo = f.add_file("/foo.rs", "");
197 f.check_parent_modules(foo, &[], &[ 196 // f.check_parent_modules(foo, &[], &[(ModuleDescr::ID, 1)]);
198 (ModuleDescr::ID, 1),
199 (FileSyntax::ID, 1),
200 ]);
201 197
202 let lib = f.add_file("/lib.rs", "mod foo;"); 198 let lib = f.add_file("/lib.rs", "mod foo;");
203 f.check_parent_modules(foo, &[lib], &[ 199 f.check_parent_modules(foo, &[lib], &[(ModuleDescr::ID, 2)]);
204 (ModuleDescr::ID, 1), 200 f.check_parent_modules(foo, &[lib], &[(ModuleDescr::ID, 0)]);
205 (FileSyntax::ID, 2), 201
206 ]); 202 f.change_file(lib, "");
207 // f.check_parent_modules(foo, &[lib], &[ 203 f.check_parent_modules(foo, &[], &[(ModuleDescr::ID, 2)]);
208 // (ModuleDescr::ID, 0),
209 // (FileSyntax::ID, 2),
210 // ]);
211
212 // f.change_file(lib, "");
213 // f.check_parent_modules(foo, &[], &[(ModuleDescr::ID, 2)]);
214 204
215 // f.change_file(lib, "mod foo;"); 205 // f.change_file(lib, "mod foo;");
216 // f.check_parent_modules(foo, &[lib], &[(ModuleDescr::ID, 2)]); 206 // f.check_parent_modules(foo, &[lib], &[(ModuleDescr::ID, 2)]);
@@ -224,5 +214,4 @@ mod tests {
224 // f.remove_file(lib); 214 // f.remove_file(lib);
225 // f.check_parent_modules(foo, &[], &[(ModuleDescr::ID, 1)]); 215 // f.check_parent_modules(foo, &[], &[(ModuleDescr::ID, 1)]);
226 } 216 }
227
228} 217}