Skip to main content

BodyMut

Struct BodyMut 

Source
pub struct BodyMut<'a, 'str> {
    pub fun: &'a mut FunctionBody<'str>,
    pub shared: &'a Shared<'str>,
    pub interfaces: &'a Registry<FunctionId, FunctionInterface<'str>>,
}
Expand description

A single function borrowed &mut in place from Context.bodies[id] for exclusive mutation (its interface stays in Context.interfaces[id], reachable read-only through interfaces).

Out of scope (and asserted against on construction): a function with reattributed blocks — a roster block stored in, or parented to, a different function. Those functions go through the sequential (module) path.

Fields§

§fun: &'a mut FunctionBody<'str>§shared: &'a Shared<'str>

The module’s shared IR state, read-only. A checked-out function pass reaches shared data (types, literals, spaces, registers) immutably; it mints types/literals through the interners’ &self paths, and mints no varnodes/temp-spaces (only the V1 argpromote pass does, and it runs on the module path). Holds no &Context — bodies are out of reach by construction (context-split stage 5b-ii Pin B).

§interfaces: &'a Registry<FunctionId, FunctionInterface<'str>>

Every function’s published interface (never checked out): the caller-reasoning surface a pass may consult about its callees.

Implementations§

Source§

impl<'a, 'str> BodyMut<'a, 'str>

Source

pub fn new( fun: &'a mut FunctionBody<'str>, shared: &'a Shared<'str>, interfaces: &'a Registry<FunctionId, FunctionInterface<'str>>, ) -> Self

Wrap fun over the module’s shared state and interface registry. Block ownership is now derived from the storing arena (a rostered block lives in fun’s own arena by construction), so there is no reattribution state left to scan for here.

Source

pub fn from_ctx(fun: &'a mut FunctionBody<'str>, ctx: &'a Context<'str>) -> Self

Wrap fun (checked out under id) over a whole module &Context — the module/test-scope convenience constructor (narrows to the shared state + interface registry).

Source

pub fn reborrow(&mut self) -> BodyMut<'_, 'str>

A shorter-lived BodyMut reborrowing this one’s exclusive references, so the host can be handed to a mutation ref (which owns its host by value) without consuming the original.

Source

pub fn builder(&mut self, block: BlockId) -> Builder<'str, '_>

Narrows this pass backing to the concrete body-local builder.

Source§

impl<'a, 'str> BodyMut<'a, 'str>

The verb + read surface of a checked-out function pass, delegating to the owned FunctionBody’s inherent verbs and self.shared. The module-scope twin of each verb is an inherent method on Context; the primitives below (function{,_mut}/shared/view, and the no-op call-site cache) are the checked-out specializations.

Source

pub fn function_mut(&mut self, f: FunctionId) -> &mut FunctionBody<'str>

The owned function’s storage (write). Panics if f is not this function.

Source

pub fn function(&self, f: FunctionId) -> &FunctionBody<'str>

The owned function’s storage (read).

Source

pub fn shr(&self) -> &Shared<'str>

The module’s shared IR state (Shared) (read).

Source

pub fn view(&self) -> BodyView<'_, 'str>

The static immutable provider for shared reads over this pass body.

Source

pub fn block_ref(&self, id: BlockId) -> BlockRef<'str, '_, BodyView<'_, 'str>>

A read BlockRef over id, body-routed.

Source

pub fn insn_ref( &self, id: InstructionId, ) -> InstructionRef<'str, '_, BodyView<'_, 'str>>

A read InstructionRef over id.

Source

pub fn param_ref( &self, id: BlockParamId, ) -> BlockParamRef<'str, '_, BodyView<'_, 'str>>

A read BlockParamRef over id.

Source

pub fn function_ref( &self, id: FunctionId, ) -> FunctionRef<'str, '_, BodyView<'_, 'str>>

A read FunctionRef over id.

Source

pub fn push_edge(&mut self, edge: EdgeData) -> EdgeId

Source

pub fn push_insn(&mut self, insn: Instruction<'str>) -> InstructionId

Source

pub fn push_block(&mut self, block: BasicBlock<'str>) -> BlockId

Source

pub fn make_block(&mut self) -> BlockId

Source

pub fn push_block_param(&mut self, param: BlockParam<'str>) -> BlockParamId

Source

pub fn push_mnemonic( &mut self, mnemonic: Mnemonic, size: usize, ) -> InstructionId

Source

pub fn push_mnemonic_with_type( &mut self, mnemonic: Mnemonic, type_id: TypeId, ) -> InstructionId

Source

pub fn remove_cfg_edge(&mut self, edge_id: EdgeId)

Remove CFG edge edge_id (unqualified; EdgeId is body-local). The module-path twin is the function-qualified Context::remove_cfg_edge.

Source

pub fn register_local_name( &mut self, id: ValueId, name: Cow<'str, str>, old_name: Option<&str>, ) -> Result<()>

Trait Implementations§

Source§

impl<'a, 'str> QCodeMut<'str> for BodyMut<'a, 'str>

Source§

type View<'v> = BodyView<'v, 'str> where Self: 'v, 'str: 'v

The host’s Copy read provider (ModuleView or BodyView).
Source§

fn function_mut(&mut self, id: FunctionId) -> &mut FunctionBody<'str>

The storage of the function id (write). The checked-out host panics if id is not its own function.
Source§

fn body(&self, id: FunctionId) -> &FunctionBody<'str>

The storage of the function id (read), tied to &self. The borrow-friendly read primitive for host-generic ref code: a fully generic H cannot prove 'str outlives a view GAT borrow, but a plain &self-tied borrow needs no such proof.
Source§

fn shr(&self) -> &Shared<'str>

The module’s shared IR state (read-only through this trait).
Source§

fn interfaces(&self) -> &Registry<FunctionId, FunctionInterface<'str>>

Every function’s published interface (the caller-reasoning surface).
Source§

fn view(&self) -> BodyView<'_, 'str>

The static immutable provider for reads over this host.
Source§

fn instruction_mut(&mut self, id: InstructionId) -> &mut Instruction<'str>

Mutably borrows the instruction id from its owning function’s arena.
Source§

fn block_mut(&mut self, id: BlockId) -> &mut BasicBlock<'str>

Mutably borrows the block id from its owning function’s arena.
Source§

fn block_param_mut(&mut self, id: BlockParamId) -> &mut BlockParam<'str>

Mutably borrows the block parameter id from its owning function’s arena.
Source§

fn register_body_name( &mut self, id: ValueId, name: Cow<'str, str>, old_name: Option<&str>, ) -> Result<()>

Register name for the function-scoped id (block/instruction/param/ Temp) in its owning function’s local name table. Panics on a global-scoped id — shared-name registration is a module-only operation outside this trait’s body-local contract. Errors only on a duplicate name.
Source§

fn remove_block_param(&mut self, id: BlockParamId)

Physically removes a block parameter and its local bookkeeping. Positional block and edge-argument rewrites belong to the caller and may complete later in the same transformation.
Source§

fn insert_insn_before( &mut self, block: BlockId, before: InstructionId, insn: InstructionId, )

Insert insn immediately before before in block, setting its parent.
Source§

fn move_insn_before(&mut self, insn: InstructionId, before: InstructionId)

Move insn immediately before the arbitrary live instruction before, preserving the moved instruction’s stable ID. Both instructions must belong to the same function; the destination block is inferred from the anchor.
Source§

fn add_cfg_edge(&mut self, from: BlockId, to: BlockId) -> EdgeId

Adds a directed edge in the CFG from from to to, returning its id. Read more
Source§

fn replace_all_uses_with( &mut self, old: impl Into<ValueId>, new: impl Into<ValueId>, )

Replace every use of old with new across old’s owning function and update the reverse use-map (SSA defs only; all uses are intra-function).
Source§

fn remove_instruction(&mut self, id: InstructionId)

Remove instruction id from its block, unlink its outgoing CFG edges if a terminator, clear its name, prune its operand use-lists, and physically drop its payload.
Source§

fn replace_instruction(&mut self, id: InstructionId, new: impl Into<ValueId>)

Replace every use of instruction id with new, then remove id — the standard “rewrite to a cheaper value” epilogue (replace_all_uses_with + remove_instruction).
Source§

fn remove_instructions(&mut self, dead: &FxHashSet<InstructionId>)

Physically removes a set of instructions after pruning their operands from the reverse-use maps, grouped per owning function. Call after removing them from their parent blocks and unlinking any CFG edges owned by terminators.
Source§

fn rehome_outgoing_edges(&mut self, keep: BlockId, remove: BlockId)

Rehome remove’s outgoing CFG edges onto keep. The direct edge and keep’s forwarding terminator have already been removed by the caller.
Source§

fn replace_instruction_mnemonic( &mut self, id: InstructionId, mnemonic: Mnemonic, )

Replace an instruction’s mnemonic in place, keeping the reverse use-map in sync. For transforms that change an instruction without changing its identity, parent block, address, or result type.
Source§

fn unroster_block(&mut self, block: BlockId)

Drop block from its function’s ownership roster. Ownership is derived from the storing arena (block.func); the arena slot is untouched.
Source§

fn delete_block(&mut self, block: BlockId)

Remove block from its function: unlink every incident CFG edge, remove its instructions and params, clear ownership metadata, then drop its payload.
Source§

fn absorb_block(&mut self, keep: BlockId, other: BlockId, edge_ab: EdgeId)

Absorb other into keep: drop keep’s terminal branch, append other’s instructions, rehome its outgoing edges, and remove it. edge_ab is the direct edge keep -> other.

Auto Trait Implementations§

§

impl<'a, 'str> !UnwindSafe for BodyMut<'a, 'str>

§

impl<'a, 'str> Freeze for BodyMut<'a, 'str>

§

impl<'a, 'str> RefUnwindSafe for BodyMut<'a, 'str>

§

impl<'a, 'str> Send for BodyMut<'a, 'str>

§

impl<'a, 'str> Sync for BodyMut<'a, 'str>

§

impl<'a, 'str> Unpin for BodyMut<'a, 'str>

§

impl<'a, 'str> UnsafeUnpin for BodyMut<'a, 'str>

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> 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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.