1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
//! # arena_lang
//!
//! Typed bump/arena allocation for AST and IR nodes with stable addresses.
//!
//! `arena-lang` is the allocation floor a tree of compiler nodes is built on. It
//! offers one focused, append-only surface: allocate a value into an [`Arena`] and
//! get back an [`Id`] — a four-byte, `Copy`, type-tagged handle that stays valid
//! for the life of the arena and keeps resolving to the same value no matter how
//! many later allocations grow it.
//!
//! The handle, not a raw pointer, is the stable address. A node stores `Id`s
//! pointing at its children, so a tree is wired by handle and never tangles the
//! borrow checker — the pattern an AST or IR is built on. Values are never freed
//! individually; the whole arena is released at once when it is dropped.
//!
//! It owns typed allocation and stable addressing only — no tree shape, no
//! traversal, no parsing.
//!
//! ## Quickstart
//!
//! ```
//! use arena_lang::{Arena, Id};
//!
//! enum Expr {
//! Int(i64),
//! Neg(Id<Expr>),
//! }
//!
//! let mut arena = Arena::new();
//! let five = arena.alloc(Expr::Int(5));
//! let neg = arena.alloc(Expr::Neg(five)); // stores a handle to `five`
//!
//! // The child handle still resolves after the parent was allocated.
//! if let Some(Expr::Neg(inner)) = arena.get(neg) {
//! assert!(matches!(arena.get(*inner), Some(Expr::Int(5))));
//! }
//! ```
extern crate alloc;
pub use Arena;
pub use ArenaError;
pub use Id;