Skip to content

Conversation

@ClementWalter
Copy link
Contributor

Summary

  • Replace Box<T> recursive variants with arena allocation using u32 indices
  • Makes BaseExpr and ExtExpr Copy types, eliminating the need to manually .clone() every expression reuse in constraint definitions
  • String interning for Param variants (StringId instead of String)

Motivation

When building AIR constraints, every reuse of an expression required manual .clone() calls:

// Before (tedious and error-prone)
let enabler = cols.opcode_add_flag.clone()
    + cols.opcode_sub_flag.clone()
    + cols.opcode_xor_flag.clone();
// After (expressions are Copy)
let enabler = cols.opcode_add_flag
    + cols.opcode_sub_flag
    + cols.opcode_xor_flag;

Implementation

  • New arena.rs module with ExprArena, thread-local storage, and node types
  • BaseExpr(u32) and ExtExpr(u32) are now just indices into the arena
  • All operator impls use thread-local arena for allocation
  • Pattern matching via .node() method instead of direct enum access

Benefits

  • No more manual .clone() calls on expression reuse
  • Better cache locality from contiguous arena storage
  • Potential performance improvement from reduced allocations

Test plan

  • All existing tests pass with --features prover
  • Benchmark constraint evaluation performance

Replace Box<T> recursive variants with arena allocation using u32 indices,
making BaseExpr and ExtExpr Copy types. This eliminates the need to
manually .clone() every expression reuse in constraint definitions.

Key changes:
- New arena.rs module with ExprArena, thread-local storage, and node types
- BaseExpr and ExtExpr are now Copy (just u32 indices into the arena)
- String interning for Param variants (StringId instead of String)
- All operator impls use thread-local arena for allocation
- Pattern matching via .node() method instead of direct enum access

Benefits:
- No more manual .clone() calls on expression reuse
- Better cache locality from contiguous arena storage
- Potential performance improvement from reduced allocations
@reviewable-StarkWare
Copy link

This change is Reviewable

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants