HIR to CLIF lowering rules
- CLIF is the only executable IR.
- One lowering path for JIT and AOT.
- Lowering input is
Spanned<HIRProgram>produced by the phase-indexed shared-core AST/HIR model.
Boundary requirements
Section titled “Boundary requirements”- Lowering must remain backend-neutral for language semantics.
- Runtime/system operations must lower through runtime ABI entrypoints only.
- Lowering must not encode platform syscall policy.
Function lowering
Section titled “Function lowering”- Each
HIRFunctionDefinitionbecomes one CraneliftFunctionwith a signature from the HIR type. - Parameters become CLIF block params in the entry block.
Control flow
Section titled “Control flow”if: entry -> then/else blocks -> merge block.while: loop header -> body -> backedge to header.match: chain of test blocks; later jump-table for enums.for range(...): lowers through numeric fast-path.for iterator_expr: lowers throughNext()loop untilOption::None.
Locals and variables
Section titled “Locals and variables”- Locals map to
VariableinFunctionBuilder. def_varused at first assignment;use_varat reads.
Aggregates
Section titled “Aggregates”- Struct allocation:
allocbuiltin returns pointer;field_setvia stores. - Arrays/strings use runtime builtins (
array_new,str_new).
- Calls use
callwith signature registered viaModule::declare_function. - Runtime builtins are imported via
declare_func_in_func. - Lowering dispatches calls by typed call classification metadata (
MethodDispatch,ItemCall,CallableValueCall). - Method dispatch uses one canonical lowering path independent of source syntax shape.
Returns
Section titled “Returns”- Use
returnterminator with explicit values.
Source locations
Section titled “Source locations”- Use
set_srclocfor diagnostics mapping.
Non-goals
Section titled “Non-goals”- Selecting linker strategy or artifact packaging format.
- Defining runtime ABI versioning policy.