mirror of
https://github.com/rust-lang/rust-analyzer
synced 2025-01-26 20:05:03 +00:00
fix dep tracking
This commit is contained in:
parent
c81d0d51bf
commit
dbdf72e2e2
2 changed files with 17 additions and 30 deletions
|
@ -113,7 +113,7 @@ impl Cache {
|
||||||
|
|
||||||
pub(crate) struct QueryCtx {
|
pub(crate) struct QueryCtx {
|
||||||
db: Arc<Db>,
|
db: Arc<Db>,
|
||||||
stack: RefCell<Vec<QueryInvocationId>>,
|
stack: RefCell<Vec<(QueryInvocationId, Vec<(QueryInvocationId, OutputHash)>)>>,
|
||||||
pub(crate) trace: RefCell<Vec<TraceEvent>>,
|
pub(crate) trace: RefCell<Vec<TraceEvent>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -131,22 +131,16 @@ pub(crate) enum TraceEventKind {
|
||||||
impl QueryCtx {
|
impl QueryCtx {
|
||||||
pub(crate) fn get<Q: Get>(&self, params: &Q::Params) -> Q::Output {
|
pub(crate) fn get<Q: Get>(&self, params: &Q::Params) -> Q::Output {
|
||||||
let me = id::<Q>(params);
|
let me = id::<Q>(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 });
|
self.trace(TraceEvent { query_id: Q::ID, kind: TraceEventKind::Start });
|
||||||
let res = Q::get(self, params);
|
let res = Q::get(self, params);
|
||||||
self.trace(TraceEvent { query_id: Q::ID, kind: TraceEventKind::Finish });
|
self.trace(TraceEvent { query_id: Q::ID, kind: TraceEventKind::Finish });
|
||||||
if let Some(parent) = parent {
|
{
|
||||||
let h = output_hash::<Q>(&res);
|
let mut stack = self.stack.borrow_mut();
|
||||||
let mut cache = self.db.cache.lock();
|
if let Some((_, ref mut deps)) = stack.last_mut() {
|
||||||
cache.deps
|
deps.push((me, output_hash::<Q>(&res)));
|
||||||
.entry(parent)
|
}
|
||||||
.or_insert(Vec::new())
|
|
||||||
.push((me, h))
|
|
||||||
}
|
}
|
||||||
let also_me = self.stack.borrow_mut().pop();
|
|
||||||
assert_eq!(also_me, Some(me));
|
|
||||||
res
|
res
|
||||||
}
|
}
|
||||||
fn trace(&self, event: TraceEvent) {
|
fn trace(&self, event: TraceEvent) {
|
||||||
|
@ -179,10 +173,14 @@ where
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let me = id::<Q>(params);
|
||||||
ctx.trace(TraceEvent { query_id: Q::ID, kind: TraceEventKind::Evaluating });
|
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 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();
|
let mut cache = ctx.db.cache.lock();
|
||||||
|
cache.deps.insert(me, deps);
|
||||||
let gen = cache.gen;
|
let gen = cache.gen;
|
||||||
let output_hash = output_hash::<Q>(&res);
|
let output_hash = output_hash::<Q>(&res);
|
||||||
let id = id::<Q>(params);
|
let id = id::<Q>(params);
|
||||||
|
|
|
@ -169,7 +169,6 @@ mod tests {
|
||||||
expected: &[FileId],
|
expected: &[FileId],
|
||||||
queries: &[(u32, u64)]
|
queries: &[(u32, u64)]
|
||||||
) {
|
) {
|
||||||
eprintln!();
|
|
||||||
let ctx = self.db.query_ctx();
|
let ctx = self.db.query_ctx();
|
||||||
let actual = ctx.get::<ParentModule>(&file_id);
|
let actual = ctx.get::<ParentModule>(&file_id);
|
||||||
assert_eq!(actual.as_slice(), expected);
|
assert_eq!(actual.as_slice(), expected);
|
||||||
|
@ -194,23 +193,14 @@ mod tests {
|
||||||
fn test_parent_module() {
|
fn test_parent_module() {
|
||||||
let mut f = Fixture::new();
|
let mut f = Fixture::new();
|
||||||
let foo = f.add_file("/foo.rs", "");
|
let foo = f.add_file("/foo.rs", "");
|
||||||
f.check_parent_modules(foo, &[], &[
|
// f.check_parent_modules(foo, &[], &[(ModuleDescr::ID, 1)]);
|
||||||
(ModuleDescr::ID, 1),
|
|
||||||
(FileSyntax::ID, 1),
|
|
||||||
]);
|
|
||||||
|
|
||||||
let lib = f.add_file("/lib.rs", "mod foo;");
|
let lib = f.add_file("/lib.rs", "mod foo;");
|
||||||
f.check_parent_modules(foo, &[lib], &[
|
f.check_parent_modules(foo, &[lib], &[(ModuleDescr::ID, 2)]);
|
||||||
(ModuleDescr::ID, 1),
|
f.check_parent_modules(foo, &[lib], &[(ModuleDescr::ID, 0)]);
|
||||||
(FileSyntax::ID, 2),
|
|
||||||
]);
|
|
||||||
// f.check_parent_modules(foo, &[lib], &[
|
|
||||||
// (ModuleDescr::ID, 0),
|
|
||||||
// (FileSyntax::ID, 2),
|
|
||||||
// ]);
|
|
||||||
|
|
||||||
// f.change_file(lib, "");
|
f.change_file(lib, "");
|
||||||
// f.check_parent_modules(foo, &[], &[(ModuleDescr::ID, 2)]);
|
f.check_parent_modules(foo, &[], &[(ModuleDescr::ID, 2)]);
|
||||||
|
|
||||||
// f.change_file(lib, "mod foo;");
|
// f.change_file(lib, "mod foo;");
|
||||||
// f.check_parent_modules(foo, &[lib], &[(ModuleDescr::ID, 2)]);
|
// f.check_parent_modules(foo, &[lib], &[(ModuleDescr::ID, 2)]);
|
||||||
|
@ -224,5 +214,4 @@ mod tests {
|
||||||
// f.remove_file(lib);
|
// f.remove_file(lib);
|
||||||
// f.check_parent_modules(foo, &[], &[(ModuleDescr::ID, 1)]);
|
// f.check_parent_modules(foo, &[], &[(ModuleDescr::ID, 1)]);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue