diff options
Diffstat (limited to 'crates/libanalysis/src/db.rs')
-rw-r--r-- | crates/libanalysis/src/db.rs | 26 |
1 files changed, 12 insertions, 14 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 | ||
114 | pub(crate) struct QueryCtx { | 114 | pub(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 { | |||
131 | impl QueryCtx { | 131 | impl 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); |