pub trait ToMasmComponent {
// Required method
fn to_masm_component(
&self,
analysis_manager: AnalysisManager,
) -> Result<MasmComponent, Report>;
}Expand description
This trait represents a conversion pass from some HIR entity to a Miden Assembly component.
Required Methods§
fn to_masm_component( &self, analysis_manager: AnalysisManager, ) -> Result<MasmComponent, Report>
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".
Implementations on Foreign Types§
Source§impl ToMasmComponent for Component
1:1 conversion from HIR component to MASM component
impl ToMasmComponent for Component
1:1 conversion from HIR component to MASM component
fn to_masm_component( &self, analysis_manager: AnalysisManager, ) -> Result<MasmComponent, Report>
Source§impl ToMasmComponent for World
Derivation of a MASM component from an HIR world
impl ToMasmComponent for World
Derivation of a MASM component from an HIR world
A world is not a component, and the difference is what this impl exists to handle: a
component’s body holds modules, interfaces and functions, while a world’s body holds
components as well. Handing a world’s own operation to MasmComponentBuilder, which walks a
component body, therefore panics the moment it meets the first builtin.component.
So the shape of the world decides how it is lowered:
- A world holding no component is treated as one logical component whose body is the
world’s, which is what it has always meant here. This is the shape
frontend/masm’s disassembler produces — it defines modules directly on the world — so it is a live path. - A world holding one component is lowered by lowering that component, because a
component is what a Miden package is rooted at and carries the identity it is rooted at.
Delegating rather than reimplementing is deliberate: the result is then the same
MasmComponentthe equivalent standalonebuiltin.componentproduces, by construction rather than by two implementations agreeing. - A world holding more than one component is reported, and that limitation is external to
this crate — see
too_many_components.
§Top-level items beside the component are normal, and are not an error
A world is not “a component, optionally”. It may hold a component — the current codegen unit — plus any number of sibling interfaces and modules, which are either
- external dependencies represented in the IR, which hold declarations only and contribute nothing to the generated Miden Assembly, or
- supporting modules, which are translated 1:1 to Miden Assembly modules and linked into the final assembly as ad-hoc modules.
A world holding a single component is only the happy path, and only for the Rust frontend, which compiles to one Wasm component and translates it to one HIR component. Other frontends, the MASM one included, legitimately produce several top-level items. Neither kind of sibling may fail a build.
The first kind is recognized by is_declaration_only and ignored, silently, because that is
exactly what it is worth. The second is translated beside the component, by handing it to the
same MasmComponentBuilder the component is lowered by — which is what makes it share the
component’s LinkInfo rather than lay a layout of its own over it.
The one shape left out is a top-level module that owns memory, i.e. declares a global
variable or a data segment; see report_siblings_that_own_memory for the rule and why it is
where the line falls.
Every producer hands this impl a top-level world: the world a whole-builtin.world .hir
file parses to, the world midenc_hir::parse anchors any other top-level operation at, the
world the Wasm frontend builds, and the one frontend/masm’s disassembler builds.