High-level intermediate representation: analyzed form still close to source structure, ready for MIR lowering.
| Status | Active — analysis product component (ADR 0012) |
| Owners | echo_hir (built inside echo_pipeline::analyze) |
| Related | docs/sota-gaps.md, docs/semantics.md, docs/mir.md |
HIR is source-shaped IR with import classification, method tables, and expression/statement spans. It is not a VM and does not embed LLVM types.
- Entry:
lower_file(&File, &HashSet import_module_names) -> HirModule. - Function values:
- Design: nameless closed values; binds name them like any other value.
HirModule.bodies= closed code objects (HirBody.symbol= linkage).- Bind →
FnRef { symbol }→ MIRFnValue(runtime: code pointer asi64). - Call known bind →
Call { symbol }(direct). Call through value (param/local) →CallValue→ MIRCallTarget::Indirect. Nested bodies use__n_{id}. - Function values carry ret shape (plain/result/option) for indirect calls.
- Methods remain call-form only (not freestanding values).
- Top-level executable stmts →
entry(includes function-value binds asFnRef). - Import names (analysis fact) classify
ModuleCall/ModuleFieldvsMethodCall/Field— MIR must not re-decide import vs value. - Methods:
%/@fn members →__m_{struct}_{method}body symbol +HirModule.methods(graph-wide union at MIR lower). - Struct lits: tagged
name { … }→StructLitwith type name; structural{ k: v }→StructLitwith empty name (not a%type / methods). - Match arms: value multi-expr,
% Type(HirMatchArm::Type), default, Option/Result$/!binds. - Every
HirExprhasspan; stmts carryspanfor provenance. - Built only as part of
AnalysisProduct; hosts useecho_pipeline, not raw lower.
When HIR node shapes change in a way that would invalidate stored lower
artifacts, bump HIR_SCHEMA_VERSION / HIR_LOWERER_VERSION in
echo_fingerprint (incremental.md).
- How much desugaring stays in HIR vs MIR as surface grows