Skip to content
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

feat!: implement collections using a BumpAllocator parameter #38

Merged
merged 49 commits into from
Nov 15, 2024

Conversation

bluurryy
Copy link
Owner

@bluurryy bluurryy commented Nov 14, 2024

We reimplement the collections so instead of

struct BumpVec<'b, 'a, T, A, const MIN_ALIGN: usize, const UP: bool, const GUARANTEED_ALLOCATED: bool>
where
    MinimumAlignment<MIN_ALIGN>: SupportedMinimumAlignment,
    A: BaseAllocator<GUARANTEED_ALLOCATED>,
{ /* ... */ }

we now have

struct BumpVec<T, A: BumpAllocator> { /* ... */ }

This should clean up the api and implementation nicely but also add complexity in that we now have to account for A being anything and not just &BumpScope.

BumpAllocator will gain new methods for more optimized versions of allocate and friends so the generated code does not degrade.

With the new trait BumpAllocatorScope<'a> we can dish out objects for the 'a lifetime from functions like into_slice. Most functions don't need to know about the bump scope lifetime so BumpAllocator suffices. Some valid BumpAllocators can't implement BumpAllocatorScope<'a> like Bump (but &'a Bump can).

With this trait based design we should be able to replace Mut* collections by implementing the mut optimizations on their non-mut container equivalents whenever the BumpAllocator supports this.

We still need separate Mut* collections because in Mut* collections we need to protect the allocator and make sure no one can access it.

Todo:

  • implement Bump{Vec,String} using BumpAllocator(Scope)
  • implement MutBump{Vec,String} using BumpAllocator(Scope)
  • replace (GuaranteedAllocated)Stats<'a, UP> with a new (GuaranteedAllocated)Stats<'a>
  • add migration guide no, there are no straightforward migration steps from what i can tell
  • rename to use Mut* prefix instead to match the collections (the collections themselves match the Fixed* prefix)
  • review all docs and update where necessary

@bluurryy bluurryy added enhancement New feature or request breaking This is a breaking change labels Nov 14, 2024
@bluurryy bluurryy added this to the v0.11 milestone Nov 14, 2024
@bluurryy bluurryy merged commit 810c8ef into main Nov 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking This is a breaking change enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant