Skip to content

Commit

Permalink
Add {save,restore}_checkpoint to PartialPaths to rewind the arena…
Browse files Browse the repository at this point in the history
… allocator pointers (#2)

* Add `{save,restore}_checkpoint` to `PartialPaths` to be able to reclaim memory

* Add comment markers to make merging from upstream easier
  • Loading branch information
ggiraldez authored Dec 24, 2024
1 parent a79c671 commit 9631ed9
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
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,
}

0 comments on commit 9631ed9

Please sign in to comment.