Skip to content

Commit f39e194

Browse files
committed
Pass references
1 parent 545b0e3 commit f39e194

File tree

2 files changed

+25
-16
lines changed

2 files changed

+25
-16
lines changed

src/function/fetch.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
use rustc_hash::FxHashMap;
2+
13
use crate::cycle::{CycleHeads, CycleRecoveryStrategy, IterationCount};
24
use crate::function::maybe_changed_after::VerifyCycleHeads;
35
use crate::function::memo::Memo;
@@ -181,17 +183,19 @@ where
181183
return unsafe { Some(self.extend_memo_lifetime(old_memo)) };
182184
}
183185

184-
let mut cycle_heads = VerifyCycleHeads::default();
186+
let mut cycle_heads = Vec::new();
187+
let mut participating_queries = FxHashMap::default();
188+
185189
let verify_result = self.deep_verify_memo(
186190
db,
187191
zalsa,
188192
old_memo,
189193
database_key_index,
190-
&mut cycle_heads,
194+
&mut VerifyCycleHeads::new(&mut cycle_heads, &mut participating_queries),
191195
can_shallow_update,
192196
);
193197

194-
if verify_result.is_unchanged() && !cycle_heads.has_any() {
198+
if verify_result.is_unchanged() && cycle_heads.is_empty() {
195199
// SAFETY: memo is present in memo_map and we have verified that it is
196200
// still valid for the current revision.
197201
return unsafe { Some(self.extend_memo_lifetime(old_memo)) };

src/function/maybe_changed_after.rs

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -588,11 +588,9 @@ where
588588
// The `MaybeChangeAfterCycleHeads` is used as an out parameter and it's
589589
// the caller's responsibility to pass an empty `heads`, which is what we do here.
590590
let mut inner_cycle_heads = VerifyCycleHeads {
591-
heads: std::mem::take(&mut child_cycle_heads),
592-
participating_queries: std::mem::take(
593-
&mut cycle_heads.participating_queries,
594-
),
595591
has_outer_cycles: cycle_heads.has_any(),
592+
heads: &mut child_cycle_heads,
593+
participating_queries: cycle_heads.participating_queries,
596594
};
597595

598596
let input_result = dependency_index.maybe_changed_after(
@@ -602,10 +600,6 @@ where
602600
&mut inner_cycle_heads,
603601
);
604602

605-
// Reuse the cycle head allocation.
606-
child_cycle_heads = inner_cycle_heads.heads;
607-
cycle_heads.participating_queries =
608-
inner_cycle_heads.participating_queries;
609603
// Aggregate the cycle heads into the parent cycle heads
610604
cycle_heads.append_heads(&mut child_cycle_heads);
611605

@@ -756,23 +750,34 @@ impl ShallowUpdate {
756750
/// aren't included.
757751
///
758752
/// [`maybe_changed_after`]: crate::ingredient::Ingredient::maybe_changed_after
759-
#[derive(Debug, Default)]
760-
pub struct VerifyCycleHeads {
753+
#[derive(Debug)]
754+
pub struct VerifyCycleHeads<'a> {
761755
/// The cycle heads encountered while verifying this ingredient and its subtree.
762-
heads: Vec<DatabaseKeyIndex>,
756+
heads: &'a mut Vec<DatabaseKeyIndex>,
763757

764758
/// The cached `maybe_changed_after` results for queries that participate in cycles but aren't a cycle head
765759
/// themselves. We need to cache the results here to avoid calling `deep_verify_memo` repeatedly
766760
/// for queries that have cyclic dependencies (b depends on a (iteration 0) and a depends on b(iteration 1))
767761
/// as well as to avoid a run-away situation if a query is dependet on a lot inside a single cycle.
768-
participating_queries: FxHashMap<DatabaseKeyIndex, VerifyResult>,
762+
participating_queries: &'a mut FxHashMap<DatabaseKeyIndex, VerifyResult>,
769763

770764
/// Whether the outer query (e.g. the parent query running `maybe_changed_after`) has encountered
771765
/// any cycles to this point.
772766
has_outer_cycles: bool,
773767
}
774768

775-
impl VerifyCycleHeads {
769+
impl<'a> VerifyCycleHeads<'a> {
770+
pub(crate) fn new(
771+
heads: &'a mut Vec<DatabaseKeyIndex>,
772+
participating_queries: &'a mut FxHashMap<DatabaseKeyIndex, VerifyResult>,
773+
) -> Self {
774+
Self {
775+
heads,
776+
participating_queries,
777+
has_outer_cycles: false,
778+
}
779+
}
780+
776781
/// Returns `true` if this query or any of its dependencies depend on this cycle.
777782
#[inline]
778783
fn contains_head(&self, key: DatabaseKeyIndex) -> bool {

0 commit comments

Comments
 (0)