Add generic logical guards and atomic storage publication

This commit is contained in:
2026-10-22 22:24:28 +01:00
parent f7d7c16753
commit d9b9eeb171
17 changed files with 749 additions and 4 deletions
+40
View File
@@ -428,6 +428,34 @@ impl Heap {
self.allocation_count.load(Ordering::Relaxed)
}
/// Host-side observations only, outside guest execution and atomic commits.
#[cfg(feature = "resource-diagnostics")]
pub fn diagnostic_typed_storage(&self) -> Vec<crate::resource_diagnostics::StorageObject> {
use crate::resource_diagnostics::{StorageObject, StorageValue};
self.objects
.iter()
.enumerate()
.filter_map(|(index, object)| {
let storage = object.as_ref()?.typed.as_ref()?;
let groups = (0..storage.len())
.map(|i| {
storage
.read(i)
.expect("initialized typed storage")
.as_slice()
.iter()
.map(StorageValue::observe)
.collect()
})
.collect();
Some(StorageObject {
reference: HeapRef { index: index as u32, generation: self.generations[index] },
type_id: storage.type_id(),
groups,
})
})
.collect()
}
#[cfg(feature = "resource-diagnostics")]
pub(crate) fn diagnostic_handles(&self) -> (usize, usize) {
(self.free_list.len(), self.objects.len() - self.free_list.len() - self.len())
@@ -520,6 +548,18 @@ impl Heap {
value_contract::validate(registry, self, storage.slot_type(index)?, values.as_slice())?;
Ok(values)
}
/// Caller has checked all receivers, bounds and groups for the entire attempt.
/// This commit path performs no allocation, provenance lookup or guest callback.
pub(crate) fn commit_typed(&mut self, r: HeapRef, index: usize, values: &[Value]) {
self.objects[r.index as usize]
.as_mut()
.unwrap()
.typed
.as_mut()
.unwrap()
.write_validated(index, values)
.expect("prevalidated storage publication");
}
pub(crate) fn store_typed(
&mut self,
registry: &Registry,