Semantic Optimization Pipeline
10 sections
Overview
Make proven facts survive into optimization — including algebraic structure. Ori's compiler already proves rich semantic facts about types, ownership, purity, and structure through the trait system, AIMS lattice, ARC pipeline, and type checker. But too many of these facts are consumed internally and discarded before they can benefit LLVM's optimizer. This plan extends existing infrastructure so that facts the compiler already proves travel one phase farther in the pipeline, and adds algebraic law metadata so that user-defined types (matrix, vector, bignum) receive the same algebraic optimizations that built-in types get today.
Planned
10 sections
Hygiene & Targeted Fixes
Split bloated files so downstream sections have clean, right-sized modules to extend (BUG-04-029 shift overflow already fixed)
LLVM Metadata Infrastructure
Build the metadata emission layer so Sections 03-04 can attach TBAA, range, and alias metadata to LLVM instructions
AIMS State Export to Codegen
Thread AIMS ownership and uniqueness facts to LLVM codegen so standard LLVM passes benefit from Ori's memory analysis
TBAA, Range, and Invariant Metadata
Emit TBAA on struct field accesses, !range on bounded returns, and !invariant.load on immutable borrowed params
Structural Derive Normalization
Mark derived methods as memory(read) and leave a clean handoff for ARC-level peepholes to Section 09
Runtime Identity Fixes
Fix runtime string and list concat to be true algebraic identities so identity elimination in Section 09 is sound
Algebra Law Schema
Add algebraic law declarations, identity-provider traits, and the exported law/provenance index that Section 09 consumes
Algebra Law Adoption
Install algebraic law declarations on stdlib operator traits and impls so the normalization pass has laws to consume
Algebraic Normalization Pass
Build a step-3b ARC IR normalization pass that rewrites expressions using exported algebraic law metadata
Advanced Rewrites & Verification
Add distributivity with cost model, multiplicative inverse, and comprehensive verification of the full optimization pipeline