diff --git a/stack-graphs/src/arena.rs b/stack-graphs/src/arena.rs index 7380f4a8d..e6b2ee425 100644 --- a/stack-graphs/src/arena.rs +++ b/stack-graphs/src/arena.rs @@ -173,6 +173,20 @@ impl Drop for Arena { } } +impl Clone for Arena +where + T: Clone, +{ + fn clone(&self) -> Self { + let mut items = Vec::with_capacity(self.items.len()); + items.extend((0..self.items.len()).map(|_| MaybeUninit::uninit())); + unsafe { + std::ptr::copy_nonoverlapping(self.items.as_ptr(), items.as_mut_ptr(), self.items.len()) + }; + Self { items } + } +} + impl Arena { /// Creates a new arena. pub fn new() -> Arena { @@ -271,6 +285,23 @@ impl Drop for SupplementalArena { } } +impl Clone for SupplementalArena +where + T: Clone, +{ + fn clone(&self) -> Self { + let mut items = Vec::with_capacity(self.items.len()); + items.extend((0..self.items.len()).map(|_| MaybeUninit::uninit())); + unsafe { + std::ptr::copy_nonoverlapping(self.items.as_ptr(), items.as_mut_ptr(), self.items.len()) + }; + Self { + items, + _phantom: PhantomData::default(), + } + } +} + impl SupplementalArena { /// Creates a new, empty supplemental arena. pub fn new() -> SupplementalArena { @@ -374,6 +405,15 @@ pub struct HandleSet { _phantom: PhantomData, } +impl Clone for HandleSet { + fn clone(&self) -> Self { + Self { + elements: self.elements.clone(), + _phantom: PhantomData::default(), + } + } +} + impl HandleSet { /// Creates a new, empty handle set. pub fn new() -> HandleSet { @@ -457,6 +497,7 @@ pub struct List { #[doc(hidden)] #[repr(C)] +#[derive(Clone)] pub struct ListCell { head: T, // The value of this handle will be EMPTY_LIST_HANDLE if this is the last element of the list. @@ -610,6 +651,7 @@ pub struct ReversibleList { #[repr(C)] #[doc(hidden)] +#[derive(Clone)] pub struct ReversibleListCell { head: T, tail: Handle>, diff --git a/stack-graphs/src/partial.rs b/stack-graphs/src/partial.rs index 261624dcb..49c889939 100644 --- a/stack-graphs/src/partial.rs +++ b/stack-graphs/src/partial.rs @@ -2610,6 +2610,7 @@ struct Join { /// Manages the state of a collection of partial paths built up as part of the partial-path-finding /// algorithm or path-stitching algorithm. +#[derive(Clone)] pub struct PartialPaths { pub(crate) partial_symbol_stacks: DequeArena, pub(crate) partial_scope_stacks: DequeArena>, diff --git a/stack-graphs/src/stitching.rs b/stack-graphs/src/stitching.rs index 94755453b..c201183b4 100644 --- a/stack-graphs/src/stitching.rs +++ b/stack-graphs/src/stitching.rs @@ -227,6 +227,7 @@ impl Candidates for GraphEdges { /// We've written the path-stitching algorithm so that you have a chance to only load in the /// partial paths that are actually needed, placing them into a `Database` instance as they're /// needed. +#[derive(Clone)] pub struct Database { pub(crate) partial_paths: Arena, pub(crate) local_nodes: HandleSet,