From dbdf72e2e2fb3ebc1a5cdeac4e70108371bb91fb Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 11 Sep 2018 11:31:07 +0300 Subject: fix dep tracking --- crates/libanalysis/src/db.rs | 26 ++++++++++++-------------- crates/libanalysis/src/module_map_db.rs | 23 ++++++----------------- 2 files changed, 18 insertions(+), 31 deletions(-) (limited to 'crates') 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 { pub(crate) struct QueryCtx { db: Arc, - stack: RefCell>, + stack: RefCell)>>, pub(crate) trace: RefCell>, } @@ -131,22 +131,16 @@ pub(crate) enum TraceEventKind { impl QueryCtx { pub(crate) fn get(&self, params: &Q::Params) -> Q::Output { let me = id::(params); - eprintln!("eval: {:?}", me); - let parent = self.stack.borrow().last().map(|&id| id); - self.stack.borrow_mut().push(me); self.trace(TraceEvent { query_id: Q::ID, kind: TraceEventKind::Start }); let res = Q::get(self, params); self.trace(TraceEvent { query_id: Q::ID, kind: TraceEventKind::Finish }); - if let Some(parent) = parent { - let h = output_hash::(&res); - let mut cache = self.db.cache.lock(); - cache.deps - .entry(parent) - .or_insert(Vec::new()) - .push((me, h)) + { + let mut stack = self.stack.borrow_mut(); + if let Some((_, ref mut deps)) = stack.last_mut() { + deps.push((me, output_hash::(&res))); + } } - let also_me = self.stack.borrow_mut().pop(); - assert_eq!(also_me, Some(me)); + res } fn trace(&self, event: TraceEvent) { @@ -179,10 +173,14 @@ where return res; } + let me = id::(params); ctx.trace(TraceEvent { query_id: Q::ID, kind: TraceEventKind::Evaluating }); + ctx.stack.borrow_mut().push((me, Vec::new())); let res = Self::eval(ctx, params); - + let (also_me, deps) = ctx.stack.borrow_mut().pop().unwrap(); + assert_eq!(also_me, me); let mut cache = ctx.db.cache.lock(); + cache.deps.insert(me, deps); let gen = cache.gen; let output_hash = output_hash::(&res); let id = id::(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 { expected: &[FileId], queries: &[(u32, u64)] ) { - eprintln!(); let ctx = self.db.query_ctx(); let actual = ctx.get::(&file_id); assert_eq!(actual.as_slice(), expected); @@ -194,23 +193,14 @@ mod tests { fn test_parent_module() { let mut f = Fixture::new(); let foo = f.add_file("/foo.rs", ""); - f.check_parent_modules(foo, &[], &[ - (ModuleDescr::ID, 1), - (FileSyntax::ID, 1), - ]); + // f.check_parent_modules(foo, &[], &[(ModuleDescr::ID, 1)]); let lib = f.add_file("/lib.rs", "mod foo;"); - f.check_parent_modules(foo, &[lib], &[ - (ModuleDescr::ID, 1), - (FileSyntax::ID, 2), - ]); - // f.check_parent_modules(foo, &[lib], &[ - // (ModuleDescr::ID, 0), - // (FileSyntax::ID, 2), - // ]); - - // f.change_file(lib, ""); - // f.check_parent_modules(foo, &[], &[(ModuleDescr::ID, 2)]); + f.check_parent_modules(foo, &[lib], &[(ModuleDescr::ID, 2)]); + f.check_parent_modules(foo, &[lib], &[(ModuleDescr::ID, 0)]); + + f.change_file(lib, ""); + f.check_parent_modules(foo, &[], &[(ModuleDescr::ID, 2)]); // f.change_file(lib, "mod foo;"); // f.check_parent_modules(foo, &[lib], &[(ModuleDescr::ID, 2)]); @@ -224,5 +214,4 @@ mod tests { // f.remove_file(lib); // f.check_parent_modules(foo, &[], &[(ModuleDescr::ID, 1)]); } - } -- cgit v1.2.3