Skip to main content

luaur_analysis/methods/
cfg_allocator_new_instruction.rs

1//! Source: `Analysis/include/Luau/ControlFlowGraph.h:237-243` (hand-ported)
2//! C++ `template<typename T, typename... Args> InstrId CFGAllocator::newInstruction(Args&&... args)`.
3use crate::records::cfg_allocator::CfgAllocator;
4use crate::type_aliases::instr_id::InstrId;
5use crate::type_aliases::instruction::Instruction;
6use luaur_common::macros::luau_assert::LUAU_ASSERT;
7
8impl CfgAllocator {
9    /// C++ builds `Instruction* inst = instructions.allocate(T{args...})` and
10    /// returns `NotNull{inst}`. The variant `T{args...}` is constructed by the
11    /// caller (`CFGBuilder::emit`) and threaded through as the `Instruction`.
12    pub fn new_instruction(&mut self, inst: Instruction) -> InstrId {
13        // C++: LUAU_ASSERT(!frozen);
14        LUAU_ASSERT!(!self.frozen);
15        // C++: Instruction* inst = instructions.allocate(...); return NotNull{inst};
16        self.instructions.allocate(inst)
17    }
18}