From 63c367b4877c345c05892b288b4cb4e5d5c5c9cf Mon Sep 17 00:00:00 2001 From: Lukas Wirth Date: Sat, 4 Jan 2025 10:37:36 +0100 Subject: [PATCH] Improve safety comments on function/fetch --- src/function/fetch.rs | 14 ++++++-------- src/function/input_outputs.rs | 21 --------------------- src/table.rs | 2 +- 3 files changed, 7 insertions(+), 30 deletions(-) delete mode 100644 src/function/input_outputs.rs diff --git a/src/function/fetch.rs b/src/function/fetch.rs index f6d495df..65aeaea6 100644 --- a/src/function/fetch.rs +++ b/src/function/fetch.rs @@ -52,10 +52,9 @@ where if memo.value.is_some() && self.shallow_verify_memo(db, zalsa, self.database_key_index(id), memo) { - // Unsafety invariant: memo is present in memo_map - unsafe { - return Some(self.extend_memo_lifetime(memo)); - } + // Unsafety invariant: memo is present in memo_map and we have verified that it is + // still valid for the current revision. + return unsafe { Some(self.extend_memo_lifetime(memo)) }; } } None @@ -81,10 +80,9 @@ where let opt_old_memo = self.get_memo_from_table_for(zalsa, id); if let Some(old_memo) = &opt_old_memo { if old_memo.value.is_some() && self.deep_verify_memo(db, old_memo, &active_query) { - // Unsafety invariant: memo is present in memo_map. - unsafe { - return Some(self.extend_memo_lifetime(old_memo)); - } + // Unsafety invariant: memo is present in memo_map and we have verified that it is + // still valid for the current revision. + return unsafe { Some(self.extend_memo_lifetime(old_memo)) }; } } diff --git a/src/function/input_outputs.rs b/src/function/input_outputs.rs deleted file mode 100644 index dab66fdf..00000000 --- a/src/function/input_outputs.rs +++ /dev/null @@ -1,21 +0,0 @@ -use crate::{ - accumulator::accumulated_map::AccumulatedMap, zalsa::Zalsa, zalsa_local::QueryOrigin, Id, -}; - -use super::{Configuration, IngredientImpl}; - -impl IngredientImpl -where - C: Configuration, -{ - pub(super) fn origin(&self, zalsa: &Zalsa, key: Id) -> Option { - self.get_memo_from_table_for(zalsa, key) - .map(|m| m.revisions.origin.clone()) - } - - pub(super) fn accumulated(&self, zalsa: &Zalsa, key: Id) -> Option<&AccumulatedMap> { - // NEXT STEP: stash and refactor `fetch` to return an `&Memo` so we can make this work - self.get_memo_from_table_for(zalsa, key) - .map(|m| &m.revisions.accumulated) - } -} diff --git a/src/table.rs b/src/table.rs index af6ace70..47296c7b 100644 --- a/src/table.rs +++ b/src/table.rs @@ -293,7 +293,7 @@ impl dyn TablePage { fn make_id(page: PageIndex, slot: SlotIndex) -> Id { let page = page.0 as u32; let slot = slot.0 as u32; - Id::from_u32(page << PAGE_LEN_BITS | slot) + Id::from_u32((page << PAGE_LEN_BITS) | slot) } fn split_id(id: Id) -> (PageIndex, SlotIndex) {