Expand description
Arena allocation for Mago.
Three bump arenas, all implementing the Arena trait:
LocalArena: single-threaded, fastest,Sendbut!Sync.SharedArena:Send + Sync, safe to share across threads (for example behind a&SharedArenahanded to every worker in arayonpass).ScopedArena: a thread-local view into aSharedArena(viaSharedArena::scoped) for contention-free, non-escaping scratch.
Because all three implement Arena (and the underlying Allocator trait),
allocation code is written generically over A: Arena and never needs to know
which arena it was given:
fn lower<'arena, A: Arena + ?Sized>(arena: &'arena A, ast: &Ast) -> &'arena Ir<'arena> {
arena.alloc(Ir::from(ast))
}Allocations live as long as the borrow of the arena they came from, and are
reclaimed wholesale when the arena is dropped or reset. For growable
collections, use the aliases in vec, boxed, and
collections, each built with its *_in(arena) constructor; to collect an
iterator straight into the arena, use CollectIn (and ParallelCollectIn
under the rayon feature); for an immutable string copied into the arena, use
Arena::alloc_str; to deep-copy an arena-resident value into a different
arena, implement CopyInto.
Each module also re-exports the items of its underlying crate (allocator_api2
for alloc, boxed, vec; hashbrown for
collections), so anything not surfaced by the aliases above is still
reachable.
Re-exports§
pub use arena::Arena;pub use arena::LocalArena;pub use arena::ScopedArena;pub use copy::CopyInto;pub use iter::CollectIn;pub use iter::FromIteratorIn;
Modules§
- alloc
- arena
- The bump arenas and the
Arenaallocation trait. - boxed
- collections
- copy
- iter
- Collecting iterators directly into an arena.
- prelude
- Common imports for working with arenas.
- vec