Skip to main content

luaur_analysis/methods/
def_arena_phi_def_alt_b.rs

1//! Node: `cxx:Function:Luau.Analysis:Analysis/src/Def.cpp:49:DefArena::phi`
2//! Source: `Analysis/src/Def.cpp` (Def.cpp:49-60, hand-ported)
3
4use crate::functions::collect_operands::collect_operands;
5use crate::records::def::Def;
6use crate::records::def_arena::DefArena;
7use crate::records::phi::Phi;
8use crate::records::symbol::Symbol;
9use crate::type_aliases::def_id_def::DefId;
10use crate::type_aliases::variant::Variant as DefVariant;
11use alloc::vec::Vec;
12use luaur_ast::records::location::Location;
13
14impl DefArena {
15    pub fn phi_vector_def_id(&mut self, defs: &Vec<DefId>) -> DefId {
16        let mut operands: Vec<DefId> = Vec::new();
17        for &operand in defs.iter() {
18            collect_operands(operand, &mut operands);
19        }
20
21        // There's no need to allocate a Phi node for a singleton set.
22        if operands.len() == 1 {
23            operands[0]
24        } else {
25            self.allocator.allocate(Def {
26                v: DefVariant::V1(Phi { operands }),
27                name: Symbol::default(),
28                location: Location::default(),
29            }) as DefId
30        }
31    }
32}