refactor extend_memo_lifetime to return memo

This is a step towards refactoring `fetch`
to return the memo itself and not the value.
This commit is contained in:
Niko Matsakis 2024-09-21 06:27:49 -04:00
parent 2528045540
commit dcb0eb242e
2 changed files with 5 additions and 6 deletions

View file

@ -155,9 +155,8 @@ where
unsafe fn extend_memo_lifetime<'this, 'memo>(
&'this self,
memo: &'memo memo::Memo<C::Output<'this>>,
) -> Option<&'this C::Output<'this>> {
let memo_value: Option<&'memo C::Output<'this>> = memo.value.as_ref();
std::mem::transmute(memo_value)
) -> &'this memo::Memo<C::Output<'this>> {
std::mem::transmute(memo)
}
fn insert_memo<'db>(
@ -170,7 +169,7 @@ where
let value = unsafe {
// Unsafety conditions: memo must be in the map (it's not yet, but it will be by the time this
// value is returned) and anything removed from map is added to deleted entries (ensured elsewhere).
self.extend_memo_lifetime(&memo)
self.extend_memo_lifetime(&memo).value.as_ref()
};
if let Some(old_value) = self.insert_memo_into_table_for(zalsa, id, memo) {
// In case there is a reference to the old memo out there, we have to store it

View file

@ -52,7 +52,7 @@ where
{
let value = unsafe {
// Unsafety invariant: memo is present in memo_map
self.extend_memo_lifetime(memo).unwrap()
self.extend_memo_lifetime(memo).value.as_ref().unwrap()
};
return Some(memo.revisions.stamped_value(value));
}
@ -86,7 +86,7 @@ where
if old_memo.value.is_some() && self.deep_verify_memo(db, old_memo, &active_query) {
let value = unsafe {
// Unsafety invariant: memo is present in memo_map.
self.extend_memo_lifetime(old_memo).unwrap()
self.extend_memo_lifetime(old_memo).value.as_ref().unwrap()
};
return Some(old_memo.revisions.stamped_value(value));
}