Context
NASA Kamodo represents datasets as mathematical functions that can be composed, with automatic unit conversion. The core insight: transformations are first-class, composable objects with declared input/output types.
Problem
Loom's 12-phase pipeline is a fixed sequence. Each pass has implicit requirements about what IR shape it expects and what it guarantees. These requirements aren't declared in the type system — they're implicit in the code and documentation.
Proposal
Make each optimization pass a typed, composable transformation:
trait OptimizationPass {
/// What IR properties this pass requires (e.g., "SSA form", "no dead code")
type Input: IrConstraint;
/// What IR properties this pass guarantees after running
type Output: IrConstraint;
/// Run the pass
fn apply(&self, ir: Ir<Self::Input>) -> Ir<Self::Output>;
}
Benefits
- Compile-time safety: The type system prevents invalid pass orderings (can't run LICM before SSA construction)
- Self-documenting: Each pass declares its requirements and guarantees
- Automated search: The island-model optimization (see related issue) can automatically explore valid pass orderings by matching Output types to Input types
- Verification integration: Each pass's Output type carries verification evidence
Implementation
Use Rust's type system with marker traits for IR properties:
trait SsaForm {}
trait NoDeadCode {}
trait ConstantsFolded {}
// DCE requires SSA, guarantees NoDeadCode
impl OptimizationPass for DeadCodeElimination {
type Input = dyn SsaForm;
type Output = dyn SsaForm + NoDeadCode;
}
Effort
Low-Medium — can be introduced incrementally as a wrapper around existing passes.
References
Context
NASA Kamodo represents datasets as mathematical functions that can be composed, with automatic unit conversion. The core insight: transformations are first-class, composable objects with declared input/output types.
Problem
Loom's 12-phase pipeline is a fixed sequence. Each pass has implicit requirements about what IR shape it expects and what it guarantees. These requirements aren't declared in the type system — they're implicit in the code and documentation.
Proposal
Make each optimization pass a typed, composable transformation:
Benefits
Implementation
Use Rust's type system with marker traits for IR properties:
Effort
Low-Medium — can be introduced incrementally as a wrapper around existing passes.
References