-
Notifications
You must be signed in to change notification settings - Fork 0
Add reset! function and safe rewind! behavior
#8
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
Conversation
Add reset!(pool) that clears all n_active counters and checkpoint stacks to sentinel state while preserving allocated vectors for reuse. Unlike empty! which releases all memory, reset! allows continued use of pre-allocated storage - useful when functions acquire without proper checkpoint/rewind management.
Cover 10 test cases including: - Basic n_active reset to zero - Vector preservation after reset - Checkpoint stack restoration to sentinel - Fallback types (others dict) handling - nothing compatibility - Pool usability after reset - A/B scenario (unmanaged acquires then reset) - reset! vs empty! comparison - TypedPool direct reset
When rewind! is called at depth=1 (no pending checkpoints), it now safely delegates to reset! instead of breaking. This enables: - Safe rewind! without matching checkpoint - Safe rewind! after reset! - Multiple consecutive rewind! calls - A/B scenario cleanup with just rewind!
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #8 +/- ##
==========================================
+ Coverage 96.52% 96.68% +0.16%
==========================================
Files 7 7
Lines 575 603 +28
==========================================
+ Hits 555 583 +28
Misses 20 20 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR adds a new reset! function for state-only cleanup that preserves allocated storage, and improves safety of rewind! when called without a matching checkpoint. The changes enable cleanup of unmanaged acquires while avoiding memory reallocation costs.
Key Changes:
- New
reset!function that clears state (n_active, checkpoint stacks) while preserving all allocated storage (vectors, views, caches) - Safety guard in
rewind!(pool::AdaptiveArrayPool)that delegates toreset!when called at depth=1 (no checkpoint) - Comprehensive test coverage with 14 new tests for
reset!and 4 tests for saferewind!behavior
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| src/AdaptiveArrayPools.jl | Exports the new reset! function |
| src/state.jl | Implements reset! for TypedPool and AdaptiveArrayPool; adds depth=1 safety guard to rewind! |
| test/test_state.jl | Adds comprehensive tests for reset! behavior and safe rewind! at depth=1 |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Add reset!(pool, Type) and reset!(pool, Type...) for API consistency - Add depth=1 safety guard to rewind!(pool, Type) and rewind!(pool, Type...) - Add tests for type-specific reset! and safe typed rewind! behavior
This reverts commit abc1a73.
- Remove redundant TypedPool public overloads (checkpoint!/rewind!) - All rewind variants now use _rewind_typed_pool! with orphan cleanup - Reorganize state.jl into sections: checkpoint!, rewind!, empty!, reset! - Update tests to use internal helpers (_checkpoint_typed_pool!, _rewind_typed_pool!)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- checkpoint!(pool, Type): explicitly return nothing - rewind!(pool, Type): explicitly return nothing - reset!(pool, Type): return pool (not TypedPool) - reset!(pool, Type...): return pool (not nothing)
Summary
reset!(pool)for state-only reset (preserves allocated vectors)rewind!(pool)safe when called without matchingcheckpoint!state.jlNew
reset!(pool): State-only reset (n_active=0, stacks to sentinel, vectors preserved)reset!(pool, Type): Type-specific resetreset!(pool, Type...): Multi-type resetModified
rewind!(pool): At depth=1 (no checkpoint), delegates toreset!instead of error/undefined behaviorrewind!(pool, Type): At depth=1, delegates toreset!(TypedPool)rewind!(pool, Type...): At depth=1, delegates toreset!for each typed poolAPI Comparison
rewind!reset!empty!Use Case: Unmanaged acquire cleanup
Safety Improvements
rewind!variants at depth=1 (no checkpoint) now delegate toreset!rewind!(pool),rewind!(pool, Type),rewind!(pool, Type...)rewind!calls without checkpoint are safereset!followed byrewind!is safecheckpoint!/rewind!cycle works afterreset!_rewind_typed_pool!with depth trackingInternal Cleanup
TypedPoolpublic overloads (checkpoint!(tp),rewind!(tp))_checkpoint_typed_pool!,_rewind_typed_pool!state.jlinto clear sections: checkpoint!, rewind!, empty!, reset!Changes
src/state.jl: Addreset!, add depth=1 guard torewind!, reorganize structuretest/test_state.jl: Add 20+ tests forreset!and safe rewind behavior