Skip to content

Commit a552fd9

Browse files
committed
Pass query revisions into add_read directly
1 parent b9e38e1 commit a552fd9

File tree

4 files changed

+27
-57
lines changed

4 files changed

+27
-57
lines changed

src/accumulator/accumulated_map.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,14 @@ impl InputAccumulatedValues {
7676
pub const fn is_empty(self) -> bool {
7777
matches!(self, Self::Empty)
7878
}
79+
80+
pub fn or_shortcircuiting(self, other: impl FnOnce() -> Self) -> Self {
81+
if self.is_any() {
82+
Self::Any
83+
} else {
84+
other()
85+
}
86+
}
7987
}
8088

8189
impl ops::BitOr for InputAccumulatedValues {

src/active_query.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,15 +70,18 @@ impl ActiveQuery {
7070
pub(super) fn add_read(
7171
&mut self,
7272
input: DatabaseKeyIndex,
73-
durability: Durability,
74-
revision: Revision,
75-
accumulated: InputAccumulatedValues,
73+
revisions: &QueryRevisions,
7674
cycle_heads: &CycleHeads,
7775
) {
78-
self.durability = self.durability.min(durability);
79-
self.changed_at = self.changed_at.max(revision);
76+
self.durability = self.durability.min(revisions.durability);
77+
self.changed_at = self.changed_at.max(revisions.changed_at);
8078
self.input_outputs.insert(QueryEdge::Input(input));
81-
self.accumulated_inputs |= accumulated;
79+
self.accumulated_inputs =
80+
self.accumulated_inputs
81+
.or_shortcircuiting(|| match &revisions.accumulated {
82+
Some(_) => InputAccumulatedValues::Any,
83+
None => revisions.accumulated_inputs.load(),
84+
});
8285
self.cycle_heads.extend(cycle_heads);
8386
}
8487

src/function/fetch.rs

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
use super::{memo::Memo, Configuration, IngredientImpl, VerifyResult};
22
use crate::zalsa::MemoIngredientIndex;
33
use crate::{
4-
accumulator::accumulated_map::InputAccumulatedValues,
5-
runtime::StampedValue,
64
table::sync::ClaimResult,
75
zalsa::{Zalsa, ZalsaDatabase},
86
zalsa_local::QueryRevisions,
@@ -20,26 +18,16 @@ where
2018
let memo = self.refresh_memo(db, id);
2119
// SAFETY: We just refreshed the memo so it is guaranteed to contain a value now.
2220
let memo_value = unsafe { memo.value.as_ref().unwrap_unchecked() };
23-
let StampedValue {
24-
value,
25-
durability,
26-
changed_at,
27-
} = memo.revisions.stamped_value(memo_value);
2821

2922
self.lru.record_use(id);
3023

3124
zalsa_local.report_tracked_read(
3225
self.database_key_index(id),
33-
durability,
34-
changed_at,
35-
match &memo.revisions.accumulated {
36-
Some(_) => InputAccumulatedValues::Any,
37-
None => memo.revisions.accumulated_inputs.load(),
38-
},
26+
&memo.revisions,
3927
memo.cycle_heads(),
4028
);
4129

42-
value
30+
memo_value
4331
}
4432

4533
#[inline]

src/zalsa_local.rs

Lines changed: 8 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
use rustc_hash::FxHashMap;
22
use tracing::debug;
33

4-
use crate::accumulator::accumulated_map::{
5-
AccumulatedMap, AtomicInputAccumulatedValues, InputAccumulatedValues,
6-
};
4+
use crate::accumulator::accumulated_map::{AccumulatedMap, AtomicInputAccumulatedValues};
75
use crate::active_query::QueryStack;
86
use crate::cycle::CycleHeads;
97
use crate::durability::Durability;
108
use crate::key::DatabaseKeyIndex;
11-
use crate::runtime::{Stamp, StampedValue};
9+
use crate::runtime::Stamp;
1210
use crate::table::PageIndex;
1311
use crate::table::Slot;
1412
use crate::table::Table;
@@ -19,7 +17,7 @@ use crate::Cancelled;
1917
use crate::Id;
2018
use crate::Revision;
2119
use std::cell::RefCell;
22-
use std::panic::UnwindSafe;
20+
use std::panic::{AssertUnwindSafe, UnwindSafe};
2321
use std::sync::atomic::AtomicBool;
2422

2523
/// State that is specific to a single execution thread.
@@ -162,18 +160,18 @@ impl ZalsaLocal {
162160
pub(crate) fn report_tracked_read(
163161
&self,
164162
input: DatabaseKeyIndex,
165-
durability: Durability,
166-
changed_at: Revision,
167-
accumulated: InputAccumulatedValues,
163+
revisions: &QueryRevisions,
168164
cycle_heads: &CycleHeads,
169165
) {
170166
debug!(
171167
"report_tracked_read(input={:?}, durability={:?}, changed_at={:?})",
172-
input, durability, changed_at
168+
input, revisions.durability, revisions.changed_at
173169
);
170+
// We don't access the accumulator anyways
171+
let revisions = AssertUnwindSafe(revisions);
174172
self.with_query_stack(|stack| {
175173
if let Some(top_query) = stack.last_mut() {
176-
top_query.add_read(input, durability, changed_at, accumulated, cycle_heads);
174+
top_query.add_read(input, { revisions }.0, cycle_heads);
177175
}
178176
})
179177
}
@@ -345,33 +343,6 @@ impl QueryRevisions {
345343
cycle_heads: CycleHeads::from(query),
346344
}
347345
}
348-
349-
pub(crate) fn stamped_value<V>(&self, value: V) -> StampedValue<V> {
350-
self.stamp_template().stamp(value)
351-
}
352-
353-
pub(crate) fn stamp_template(&self) -> StampTemplate {
354-
StampTemplate {
355-
durability: self.durability,
356-
changed_at: self.changed_at,
357-
}
358-
}
359-
}
360-
361-
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
362-
pub(crate) struct StampTemplate {
363-
durability: Durability,
364-
changed_at: Revision,
365-
}
366-
367-
impl StampTemplate {
368-
pub(crate) fn stamp<V>(self, value: V) -> StampedValue<V> {
369-
StampedValue {
370-
value,
371-
durability: self.durability,
372-
changed_at: self.changed_at,
373-
}
374-
}
375346
}
376347

377348
/// Tracks the way that a memoized value for a query was created.

0 commit comments

Comments
 (0)