o3 0.61.0

shared-nothing primitives
Documentation
use crate::depot::queue::{
    indexed::{lanes, lanes::runtime},
    links, tagged,
};

impl<C: crate::depot::raw::Count, const N: usize> tagged::Domain<[links::Chain; N], C> {
    /// Allocates detached hooks at their final addresses; payloads remain uninitialized.
    pub fn allocate<T>(
        self,
    ) -> Result<
        crate::alloc::array::Block<lanes::Value<T>, Self, [links::Chain; N]>,
        crate::alloc::Error,
    > {
        let mut block =
            crate::alloc::array::Block::<std::mem::MaybeUninit<lanes::Value<T>>, _, _>::try_new(
                self,
                [const { links::Chain::new() }; N],
            )?;
        for (offset, node) in block.iter_mut().enumerate() {
            // SAFETY: the admitted u32 extent excludes Index::END at every allocated offset.
            let index = unsafe { links::Index::new_usize(offset) };
            // SAFETY: this unpublished final row owns its hook; its payload is MaybeUninit<T>.
            unsafe { (&raw mut (*node.as_mut_ptr()).hook).write(tagged::Hook::new(index)) };
        }
        // SAFETY: every hook is initialized; UnsafeCell<MaybeUninit<T>> needs no payload writes.
        Ok(unsafe { block.assume_init() })
    }
}

// SAFETY: the retained Domain fixes disjoint node/endpoint ranges and the inline heads.
// These projections expose only metadata; callers of raw mutation retain membership authority.
unsafe impl<T, C: crate::depot::raw::Count, const N: usize> crate::depot::raw::TagStore
    for crate::alloc::array::Block<
        lanes::Value<T>,
        tagged::Domain<[links::Chain; N], C>,
        [links::Chain; N],
    >
{
    type Head = links::Chain;
    type Heads = [links::Chain; N];

    fn heads(&self) -> &Self::Heads {
        self.state()
    }

    unsafe fn hook(&self, index: links::Index) -> &tagged::Hook {
        // SAFETY: this input names an initialized hook in the same fixed backing.
        &unsafe { self.get_unchecked(index.get()) }.hook
    }
}

// SAFETY: construction retains the allocation's validated immutable shape and initializes every hook.
unsafe impl<T, C: crate::depot::raw::Count, L: crate::depot::raw::Count, H: tagged::raw::Head>
    crate::depot::raw::TagStore for runtime::Fifo<T, C, L, H>
{
    type Head = H;
    type Heads = [H];
    fn heads(&self) -> &Self::Heads {
        self.block.tail()
    }
    fn is_node(&self, word: u32) -> bool {
        (word as usize) < self.block.extent().shape().capacity().count().get()
    }
    unsafe fn hook(&self, index: links::Index) -> &tagged::Hook {
        &unsafe { self.nodes().get_unchecked(index.get()) }.hook
    }
}

// SAFETY: this owner initializes every hook and publishes values before membership.
unsafe impl<T, C: crate::depot::raw::Count, L: crate::depot::raw::Count, H: tagged::raw::Head>
    crate::depot::raw::LaneStore for runtime::Fifo<T, C, L, H>
{
    type Item = T;
    fn nodes(&self) -> &[lanes::Value<T>] {
        self.block.as_ref()
    }
}

// SAFETY: the initialized lane proof retains this exact owner's live payload.
unsafe impl<'a, T, C: crate::depot::raw::Count, L: crate::depot::raw::Count, H: tagged::raw::Head>
    crate::depot::raw::Project<links::Index, links::Chain> for &'a runtime::Fifo<T, C, L, H>
{
    type Output = &'a T;

    unsafe fn project(self, index: links::Index) -> Self::Output {
        unsafe { (*self.nodes().get_unchecked(index.get()).value.get()).assume_init_ref() }
    }
}

mod store;
pub(in crate::depot) use store::LaneStore;