pub struct MirEmitCtx<'a> {
pub symbol_table: &'a SymbolTable,
pub module_prefixes: &'a HashSet<String>,
pub codegen: Option<&'a CodegenContext>,
pub local_types: &'a HashMap<String, Type>,
pub rc_wrapped: &'a HashSet<String>,
pub borrowed_params: &'a HashSet<String>,
pub owned_params: &'a HashSet<String>,
pub current_module_scope: Option<&'a str>,
pub mir_builtins: &'a [String],
pub bare: &'a FnBareFacts,
}Expand description
Walker-side emit context. Holds the slice of the
CodegenContext the MIR-to-Rust walker reads — kept explicit
so future CodegenContext refactors don’t ripple through the
walker, and so other backends (wasm-gc, wasip2) can introduce
their own emit-ctx structs without inheriting Rust-specific
fields.
Two distinct shapes share this struct:
- coverage / test (
for_test): onlysymbol_table+module_prefixesare populated;codegenisNoneand the borrow fields are empty. The coverage walk only asks “does this fn emitSome”, so it never needs the borrow machinery or the fullCodegenContext. - production parity gate (
for_fn): carries the full&CodegenContextplus the per-fn borrow policy (local_types/rc_wrapped/borrowed_params/current_module_scope), recomputed from theResolvedFnDefthe HIR walker uses. This is the slice ofsuper::emit_ctx::EmitCtxthe covered arms need so their clone / borrow /Arc::newdecisions match HIR byte-for-byte.
Fields§
§symbol_table: &'a SymbolTable§module_prefixes: &'a HashSet<String>§codegen: Option<&'a CodegenContext>Full codegen context — Some only on the production parity
gate path. constructor_boxed_positions /
callee_borrow_mask need it; the coverage walk leaves it
None (no borrow decisions, just structural reach).
local_types: &'a HashMap<String, Type>Local variable types (fn params + let bindings) for copy-type elision. Empty on the coverage path.
rc_wrapped: &'a HashSet<String>Params passed as Rc<T> (self-TCO) / &T (mutual-TCO).
borrowed_params: &'a HashSet<String>Params emitted as &T (borrow-by-default for non-Copy,
non-Str params).
owned_params: &'a HashSet<String>Collection (Vector/Map) params that the own_param MIR pass
PROVED uniquely owned (cleared their aliased_slots bit). These
are emitted owned-by-value (mut p: T, NOT &T) and, at a
last-use read, skip the .clone() so an in-place Rc::make_mut
runs on a refcount-1 backing (native O(n) mutate instead of the
O(n²) borrow+clone COW). SOUNDNESS: a name is in this set only
when own_param cleared its bit — never broadened past what the
pass proved. Disjoint from borrowed_params by construction.
current_module_scope: Option<&'a str>Owning module prefix for the fn whose body this ctx emits.
mir_builtins: &'a [String]Interned built-in fn names, indexed by BuiltinId
(MirProgram.builtins). The Call(Builtin(id)) arm resolves
id → dotted name through this slice, mirroring wasm-gc’s
ctx.mir_builtins. Empty on the coverage / test path — a
BuiltinId then resolves to nothing (None → HIR fallback),
which is fine because that path only inspects Some vs None.
bare: &'a FnBareFactsPer-LocalId bare-i64 representation facts for the fn whose body
this ctx emits — the Int “unboxing” analysis output. A slot proven
Bare emits native i64 (raw literal / raw arithmetic / i64
param-return signature); every other slot keeps aver_rt::AverInt.
Empty (all-Boxed) on the coverage / test / free-standing paths.
SOUNDNESS: a slot is read here as Bare only when the analysis
proved raw_i64_eligible && !escapes; a missing fact is Boxed.
Implementations§
Source§impl<'a> MirEmitCtx<'a>
impl<'a> MirEmitCtx<'a>
Sourcepub fn for_test(
symbol_table: &'a SymbolTable,
module_prefixes: &'a HashSet<String>,
) -> Self
pub fn for_test( symbol_table: &'a SymbolTable, module_prefixes: &'a HashSet<String>, ) -> Self
Construct a minimal walker ctx for the coverage walk /
tests. Caller supplies a hand-built symbol table;
module_prefixes defaults to the caller’s owned empty set
(or a populated one when the test needs to exercise
module-scoped name resolution). No CodegenContext, no
borrow policy — the covered arms emit conservative output
(no clone / borrow / Arc::new), which is fine because the
coverage walk only inspects Some vs None.
Trait Implementations§
Source§impl<'a> Clone for MirEmitCtx<'a>
impl<'a> Clone for MirEmitCtx<'a>
Source§fn clone(&self) -> MirEmitCtx<'a>
fn clone(&self) -> MirEmitCtx<'a>
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more