Skip to main content

MirEmitCtx

Struct MirEmitCtx 

Source
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): only symbol_table + module_prefixes are populated; codegen is None and the borrow fields are empty. The coverage walk only asks “does this fn emit Some”, so it never needs the borrow machinery or the full CodegenContext.
  • production parity gate (for_fn): carries the full &CodegenContext plus the per-fn borrow policy (local_types / rc_wrapped / borrowed_params / current_module_scope), recomputed from the ResolvedFnDef the HIR walker uses. This is the slice of super::emit_ctx::EmitCtx the covered arms need so their clone / borrow / Arc::new decisions 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 FnBareFacts

Per-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>

Source

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>

Source§

fn clone(&self) -> MirEmitCtx<'a>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'a> Copy for MirEmitCtx<'a>

Auto Trait Implementations§

§

impl<'a> !RefUnwindSafe for MirEmitCtx<'a>

§

impl<'a> !Send for MirEmitCtx<'a>

§

impl<'a> !Sync for MirEmitCtx<'a>

§

impl<'a> !UnwindSafe for MirEmitCtx<'a>

§

impl<'a> Freeze for MirEmitCtx<'a>

§

impl<'a> Unpin for MirEmitCtx<'a>

§

impl<'a> UnsafeUnpin for MirEmitCtx<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V