Add Collector supertrait over Allocator#18
Open
Ironankit525 wants to merge 1 commit intoboa-dev:mainfrom
Open
Conversation
Introduces a Collector trait that extends allocator_api2::Allocator, plus a GcAllocator wrapper around MarkSweepGarbageCollector using RefCell for interior mutability. This lets the GC be plugged into any collection that accepts a custom allocator. Wired behind the mark_sweep feature flag. Five tests cover basic allocation, ZSTs, drop, string payloads, and trait-bound checks.
Contributor
Proposed follow-up (design-first, non-overlapping with #18/#15/#21)I want to take a narrow, reviewable slice that does not duplicate the Collector:Allocator wiring currently in flight. Scope (proposal)Focus area: GC-aware allocation accounting + safety invariants for allocations made through GC-facing allocators. Goal:
Non-goals (explicitly out of scope):
Design note (draft)Problem statementAs allocator integration evolves, there are two classes of memory that matter:
If GC threshold logic only considers (1), it can under-estimate pressure and delay collection incorrectly. Proposed modelIntroduce a clear accounting split:
Threshold checks and OOM/collection triggers should be based on Why this slice is safe to do now
Invariants (must hold)
Test plan (first pass)Unit tests
Integration-ish tests (minimal)
Regression test framing
Deliverable formatIf maintainers agree, I can submit this as:
|
Contributor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #11
What this does
Adds a
Collectorsupertrait overallocator_api2::Allocatoralong with aGcAllocatorwrapper that usesRefCellfor interior mutability, letting third-party collections allocate through the GC.Changes
oscars/Cargo.toml- addedallocator-api2dependencyoscars/src/collector.rs- new module withCollectortrait,GcAllocatorstruct, and testsoscars/src/lib.rs- wiredcollectorbehindmark_sweepfeatureoscars/src/collectors/mark_sweep/mod.rs- madeallocatorfieldpub(crate)Tests
Five new tests covering basic alloc, ZST, drop, trait bounds, and string payloads. All 37 tests pass.