Skip to main content

luaur_analysis/records/
cfg_allocator.rs

1//! Source: `Analysis/include/Luau/ControlFlowGraph.h:233` (hand-ported)
2//! C++ `struct CFGAllocator`.
3use crate::records::block::Block;
4use crate::records::refinement_arena_control_flow_graph::RefinementArena;
5use crate::records::typed_allocator::TypedAllocator;
6use crate::type_aliases::definition::Definition;
7use crate::type_aliases::instruction::Instruction;
8
9#[allow(non_snake_case)]
10#[derive(Debug)]
11pub struct CfgAllocator {
12    // public:
13    pub refinement_arena: RefinementArena,
14    // private:
15    pub(crate) block: TypedAllocator<Block>,
16    pub(crate) instructions: TypedAllocator<Instruction>,
17    pub(crate) defs: TypedAllocator<Definition>,
18    pub(crate) frozen: bool,
19}
20
21impl Default for CfgAllocator {
22    fn default() -> Self {
23        Self {
24            // `RefinementArena` holds a single `TypedAllocator<Refinement>`
25            // (default-constructed). Built via struct literal (field is
26            // `pub(crate)`, same crate) to avoid a Default impl on the arena.
27            refinement_arena: RefinementArena {
28                allocator: TypedAllocator::default(),
29            },
30            block: TypedAllocator::default(),
31            instructions: TypedAllocator::default(),
32            defs: TypedAllocator::default(),
33            // C++ `bool frozen = false;`
34            frozen: false,
35        }
36    }
37}
38
39unsafe impl Send for CfgAllocator {}
40unsafe impl Sync for CfgAllocator {}