The Mojo programming language leverages MLIR?s attribute system to represent compile-time expressions as attribute trees, enabling parametric IR where operations are ?staged? with expression attributes that evaluate to constants during the compilation pipeline. Our expression language is built on a typed lambda calculus using de Bruijn indices for bound variables, with dialects contributing their own types and operators to create a rich, extensible system. To evaluate these expressions, we developed a custom AttrTypeReplacer with depth-aware caching (handling de Bruijn index-based references) and context-aware replacement (providing access to outer symbol tables). This talk presents our representation and our evaluator design as a case study for programming language developers using MLIR for high-level IR, demonstrating how MLIR?s attribute system can be so much more than just for ?constants?.
Speaker: Billy Zhu (Modular)