pub struct HashConsArena { /* private fields */ }Expand description
A hash-consing wrapper around Arena<Expr>.
Every mk_* method checks a HashMap<ExprKey, Idx<Expr>> before
allocating. If an equal node already exists in the arena the existing
Idx is returned (a hit). Otherwise the node is allocated and
indexed (a miss).
§Structural sharing guarantee
For any two calls mk_foo(…args…) with structurally identical arguments,
the returned Idx<Expr> values are equal. This means:
O(1)equality of deduplicated nodes via index comparison- Significantly reduced arena memory for expression-heavy workloads (e.g. type checking with many repeated sub-expressions)
Implementations§
Source§impl HashConsArena
impl HashConsArena
Sourcepub fn with_capacity(cap: usize) -> Self
pub fn with_capacity(cap: usize) -> Self
Creates a HashConsArena with pre-allocated capacity for cap nodes.
Sourcepub fn stats(&self) -> HashConsStats
pub fn stats(&self) -> HashConsStats
Returns a statistics snapshot.
Sourcepub fn mk_sort(&mut self, level: Level) -> Idx<Expr>
pub fn mk_sort(&mut self, level: Level) -> Idx<Expr>
Allocate (or deduplicate) Expr::Sort(level).
Sourcepub fn mk_const(&mut self, name: Name, levels: Vec<Level>) -> Idx<Expr>
pub fn mk_const(&mut self, name: Name, levels: Vec<Level>) -> Idx<Expr>
Allocate (or deduplicate) Expr::Const(name, levels).
Sourcepub fn mk_app(&mut self, f_expr: Expr, a_expr: Expr) -> Idx<Expr>
pub fn mk_app(&mut self, f_expr: Expr, a_expr: Expr) -> Idx<Expr>
Allocate (or deduplicate) Expr::App(f_expr, a_expr).
f_expr and a_expr are cloned once to build the ExprKey; no
extra clones occur on a cache hit.
Sourcepub fn mk_lam(
&mut self,
bi: BinderInfo,
name: Name,
dom: Expr,
body: Expr,
) -> Idx<Expr>
pub fn mk_lam( &mut self, bi: BinderInfo, name: Name, dom: Expr, body: Expr, ) -> Idx<Expr>
Allocate (or deduplicate) Expr::Lam(bi, name, dom, body).
Sourcepub fn mk_pi(
&mut self,
bi: BinderInfo,
name: Name,
dom: Expr,
cod: Expr,
) -> Idx<Expr>
pub fn mk_pi( &mut self, bi: BinderInfo, name: Name, dom: Expr, cod: Expr, ) -> Idx<Expr>
Allocate (or deduplicate) Expr::Pi(bi, name, dom, cod).