Representation Optimization & ARC Intelligence
12 sections
Overview
Complete the representation optimization system as one cohesive machine: from abstract types through range analysis and escape analysis to optimally-narrowed LLVM IR, with ARC header compression and thread-local fast paths — making Ori's generated code competitive with hand-written C while the programmer never sees a bit width.
Planned
5 sections
Escape Analysis & Stack Promotion
Determine which heap allocations never escape their defining function and promote them to stack allocations, eliminating ARC overhead entirely
ARC Header Compression
Specialize RC count storage and operations from the V5 header based on proven sharing bounds, using a genuinely smaller-than-32-byte header for bounded-count variants
Thread-Local Non-Atomic ARC
Use non-atomic (plain load/store) reference counting for values that are provably never shared across threads, eliminating atomic operation overhead
Collection Specialization
Optimize collection representations: small string optimization (SSO), small vector optimization (SVO), packed bool arrays, and narrow-element backing stores
Verification & Benchmarks
Prove correctness and measure performance of all representation optimizations through exhaustive testing, dual-execution verification, memory safety validation, and performance benchmarks
Completed
6 sections
Representation IR & Decision Framework
Create the ReprPlan data structure that records all narrowing decisions, integrated into the compilation pipeline between type checking and LLVM codegen
Transitive Triviality & ARC Elision
Classify compound types as trivial when all transitive children are scalar, eliding all ARC operations for these types
Value Range Analysis Framework
Build an abstract interpretation engine over integer intervals that computes provable value ranges for every int-typed expression in a function
Integer Narrowing Pipeline
Lower int (semantic i64) to the smallest machine integer (i8/i16/i32) that preserves correctness, saving memory in struct fields, collections, and stack slots
Float Narrowing Pipeline
Lower float (semantic f64) to f32 when the compiler can prove zero precision loss for the specific values used
Struct & Tuple Layout Optimization
Reorder struct fields for optimal alignment and minimal padding, then record the layout in ReprPlan for codegen