Skip to content

Add {save,restore}_checkpoint to PartialPaths to rewind the arena allocator pointers #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions stack-graphs/src/arena.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,11 @@ impl<T> Arena<T> {
self.items.truncate(1);
}

// __NOMIC_FOUNDATION_FORK__ (added this function)
pub(crate) fn truncate(&mut self, new_len: usize) {
self.items.truncate(new_len);
}

/// Adds a new instance to this arena, returning a stable handle to it.
///
/// Note that we do not deduplicate instances of `T` in any way. If you add two instances that
Expand Down
26 changes: 26 additions & 0 deletions stack-graphs/src/partial.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2631,4 +2631,30 @@ impl PartialPaths {
self.partial_scope_stacks.clear();
self.partial_path_edges.clear();
}

// __NOMIC_FOUNDATION_FORK__ (added this function)
pub fn save_checkpoint(&self) -> PartialPathsCheckpoint {
PartialPathsCheckpoint {
partial_symbol_stacks_len: self.partial_symbol_stacks.len(),
partial_scope_stacks_len: self.partial_scope_stacks.len(),
partial_path_edges_len: self.partial_path_edges.len(),
}
}

// __NOMIC_FOUNDATION_FORK__ (added this function)
pub fn restore_checkpoint(&mut self, checkpoint: PartialPathsCheckpoint) {
self.partial_symbol_stacks
.truncate(checkpoint.partial_symbol_stacks_len);
self.partial_scope_stacks
.truncate(checkpoint.partial_scope_stacks_len);
self.partial_path_edges
.truncate(checkpoint.partial_path_edges_len);
}
}

// __NOMIC_FOUNDATION_FORK__ (added this struct)
pub struct PartialPathsCheckpoint {
partial_symbol_stacks_len: usize,
partial_scope_stacks_len: usize,
partial_path_edges_len: usize,
}
Loading