Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/active_query.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use std::ops::Not;
use std::sync::atomic::AtomicBool;
use std::{mem, ops};

use super::zalsa_local::{QueryEdges, QueryOrigin, QueryRevisions};
Expand Down Expand Up @@ -74,9 +75,9 @@ impl ActiveQuery {
accumulated: InputAccumulatedValues,
cycle_heads: &CycleHeads,
) {
self.input_outputs.insert(QueryEdge::Input(input));
self.durability = self.durability.min(durability);
self.changed_at = self.changed_at.max(revision);
self.input_outputs.insert(QueryEdge::Input(input));
self.accumulated_inputs |= accumulated;
self.cycle_heads.extend(cycle_heads);
}
Expand All @@ -87,9 +88,9 @@ impl ActiveQuery {
durability: Durability,
revision: Revision,
) {
self.input_outputs.insert(QueryEdge::Input(input));
self.durability = self.durability.min(durability);
self.changed_at = self.changed_at.max(revision);
self.input_outputs.insert(QueryEdge::Input(input));
}

pub(super) fn add_untracked_read(&mut self, changed_at: Revision) {
Expand Down Expand Up @@ -182,6 +183,7 @@ impl ActiveQuery {
tracked_struct_ids,
accumulated_inputs,
accumulated,
verified_final: AtomicBool::new(cycle_heads.is_empty()),
cycle_heads,
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/function/maybe_changed_after.rs
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ where
}
// Relaxed is sufficient here because there are no other writes we need to ensure have
// happened before marking this memo as verified-final.
memo.verified_final.store(true, Ordering::Relaxed);
memo.revisions.verified_final.store(true, Ordering::Relaxed);
true
}

Expand Down
11 changes: 3 additions & 8 deletions src/function/memo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::any::Any;
use std::fmt::Debug;
use std::fmt::Formatter;
use std::ptr::NonNull;
use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::atomic::Ordering;

use crate::accumulator::accumulated_map::InputAccumulatedValues;
use crate::revision::AtomicRevision;
Expand Down Expand Up @@ -133,24 +133,20 @@ pub(super) struct Memo<V> {
/// as the current revision.
pub(super) verified_at: AtomicRevision,

/// Is this memo verified to not be a provisional cycle result?
pub(super) verified_final: AtomicBool,

/// Revision information
pub(super) revisions: QueryRevisions,
}

// Memo's are stored a lot, make sure their size is doesn't randomly increase.
// #[cfg(test)]
const _: [(); std::mem::size_of::<Memo<std::num::NonZeroUsize>>()] =
[(); std::mem::size_of::<[usize; 14]>()];
[(); std::mem::size_of::<[usize; 13]>()];

impl<V> Memo<V> {
pub(super) fn new(value: Option<V>, revision_now: Revision, revisions: QueryRevisions) -> Self {
Memo {
value,
verified_at: AtomicRevision::from(revision_now),
verified_final: AtomicBool::new(revisions.cycle_heads.is_empty()),
revisions,
}
}
Expand All @@ -162,7 +158,7 @@ impl<V> Memo<V> {
// `false` to `true`), and changing it to `true` on memos with cycle heads where it was
// ever `false` is purely an optimization; if we read an out-of-date `false`, it just means
// we might go validate it again unnecessarily.
!self.verified_final.load(Ordering::Relaxed)
!self.revisions.verified_final.load(Ordering::Relaxed)
}

/// Invoked when `refresh_memo` is about to return a memo to the caller; if that memo is
Expand Down Expand Up @@ -270,7 +266,6 @@ impl<V> Memo<V> {
},
)
.field("verified_at", &self.memo.verified_at)
.field("verified_final", &self.memo.verified_final)
.field("revisions", &self.memo.revisions)
.finish()
}
Expand Down
2 changes: 1 addition & 1 deletion src/function/specify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ where
tracked_struct_ids: Default::default(),
accumulated: Default::default(),
accumulated_inputs: Default::default(),
verified_final: AtomicBool::new(true),
cycle_heads: Default::default(),
};

Expand All @@ -91,7 +92,6 @@ where
let memo = Memo {
value: Some(value),
verified_at: AtomicRevision::from(revision),
verified_final: AtomicBool::new(true),
revisions,
};

Expand Down
5 changes: 5 additions & 0 deletions src/zalsa_local.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ use crate::Id;
use crate::Revision;
use std::cell::RefCell;
use std::panic::UnwindSafe;
use std::sync::atomic::AtomicBool;

/// State that is specific to a single execution thread.
///
Expand Down Expand Up @@ -317,6 +318,9 @@ pub(crate) struct QueryRevisions {
/// has any direct or indirect accumulated values.
pub(super) accumulated_inputs: AtomicInputAccumulatedValues,

/// Are the `cycle_heads` verified to not be provisional anymore?
pub(super) verified_final: AtomicBool,

/// This result was computed based on provisional values from
/// these cycle heads. The "cycle head" is the query responsible
/// for managing a fixpoint iteration. In a cycle like
Expand All @@ -337,6 +341,7 @@ impl QueryRevisions {
tracked_struct_ids: Default::default(),
accumulated: Default::default(),
accumulated_inputs: Default::default(),
verified_final: AtomicBool::new(false),
cycle_heads: CycleHeads::from(query),
}
}
Expand Down