Skip to content
This repository was archived by the owner on Oct 24, 2025. It is now read-only.

Commit 9631ed9

Browse files
authored
Add {save,restore}_checkpoint to PartialPaths to rewind the arena allocator pointers (#2)
* Add `{save,restore}_checkpoint` to `PartialPaths` to be able to reclaim memory * Add comment markers to make merging from upstream easier
1 parent a79c671 commit 9631ed9

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

stack-graphs/src/arena.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,11 @@ impl<T> Arena<T> {
188188
self.items.truncate(1);
189189
}
190190

191+
// __NOMIC_FOUNDATION_FORK__ (added this function)
192+
pub(crate) fn truncate(&mut self, new_len: usize) {
193+
self.items.truncate(new_len);
194+
}
195+
191196
/// Adds a new instance to this arena, returning a stable handle to it.
192197
///
193198
/// Note that we do not deduplicate instances of `T` in any way. If you add two instances that

stack-graphs/src/partial.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2631,4 +2631,30 @@ impl PartialPaths {
26312631
self.partial_scope_stacks.clear();
26322632
self.partial_path_edges.clear();
26332633
}
2634+
2635+
// __NOMIC_FOUNDATION_FORK__ (added this function)
2636+
pub fn save_checkpoint(&self) -> PartialPathsCheckpoint {
2637+
PartialPathsCheckpoint {
2638+
partial_symbol_stacks_len: self.partial_symbol_stacks.len(),
2639+
partial_scope_stacks_len: self.partial_scope_stacks.len(),
2640+
partial_path_edges_len: self.partial_path_edges.len(),
2641+
}
2642+
}
2643+
2644+
// __NOMIC_FOUNDATION_FORK__ (added this function)
2645+
pub fn restore_checkpoint(&mut self, checkpoint: PartialPathsCheckpoint) {
2646+
self.partial_symbol_stacks
2647+
.truncate(checkpoint.partial_symbol_stacks_len);
2648+
self.partial_scope_stacks
2649+
.truncate(checkpoint.partial_scope_stacks_len);
2650+
self.partial_path_edges
2651+
.truncate(checkpoint.partial_path_edges_len);
2652+
}
2653+
}
2654+
2655+
// __NOMIC_FOUNDATION_FORK__ (added this struct)
2656+
pub struct PartialPathsCheckpoint {
2657+
partial_symbol_stacks_len: usize,
2658+
partial_scope_stacks_len: usize,
2659+
partial_path_edges_len: usize,
26342660
}

0 commit comments

Comments
 (0)