Tracker
Roadmap search
Versions, deliverables, workstreams, tasks, and pages
Design model
articleStandard
src/content/docs/platform-spec/compiler/codegen-and-ir/lowering-contract/design-model.mdx
import SpecArticleChrome from '@beskid/beskid-ui/platform-spec/SpecArticleChrome.astro';
<SpecArticleChrome />Lowering boundary
Lowering is the last semantic gate before any backend runs. Inputs are a post-merge program snapshot (HIR + ModuleIndex + resolved types); output is an immutable CodegenArtifact containing Cranelift modules, data descriptors, extern imports, and debug metadata.
Backends must not re-run parse, mod host, or semantic rules on the artifact.
flowchart TB
subgraph analysis [beskid_analysis]
hir[HIR + ModuleIndex]
end
subgraph codegen [beskid_codegen]
lower[lower_program / lower_source]
art[CodegenArtifact]
end
subgraph backends [beskid_engine]
jit[JitModule]
aot[AOT object emit]
end
hir --> lower --> art
art --> jit
art --> aot
Artifact contents
| Slice | Role |
|---|---|
| CLIF modules | Per-compilation-unit functions and globals |
| Builtin imports | declare_builtin_imports from BUILTIN_SPECS |
ExternImport rows | User contract symbols for link step |
| Type descriptors | GC layout + array/string shapes for alloc |
Invariants
- Lowering runs only when
syntax_generation_idmatches the merged tree used by semantic rules (stage ordering). - Panic/abort paths use
AbiReturnKind::Neverimports so unreachable blocks are correct. - JIT and AOT consume the same artifact type; divergence happens only after
CodegenArtifactis sealed.
Code anchors
beskid_codegen::lower_sourceincompiler/crates/beskid_codegenCodegenArtifactconstruction incompiler/crates/beskid_codegenJitModuleincompiler/crates/beskid_engine/src/jit_module.rs- Runtime smoke:
compiler/crates/beskid_tests/src/runtime/jit.rs