luaur_analysis/records/
data_flow_graph.rs1use crate::records::def::Def;
3use crate::records::def_arena::DefArena;
4use crate::records::refinement_key::RefinementKey;
5use crate::records::refinement_key_arena::RefinementKeyArena;
6use crate::records::symbol::Symbol;
7use crate::type_aliases::def_id_def::DefId;
8use luaur_ast::records::ast_expr::AstExpr;
9use luaur_ast::records::ast_local::AstLocal;
10use luaur_ast::records::ast_stat::AstStat;
11use luaur_ast::records::ast_stat_declare_function::AstStatDeclareFunction;
12use luaur_ast::records::ast_stat_declare_global::AstStatDeclareGlobal;
13use luaur_common::macros::luau_assert::LUAU_ASSERT;
14use luaur_common::records::dense_hash_map::DenseHashMap;
15
16#[derive(Debug, Clone)]
17pub struct DataFlowGraph {
18 pub(crate) def_arena: *mut DefArena,
19 pub(crate) key_arena: *mut RefinementKeyArena,
20 pub(crate) ast_defs: DenseHashMap<*const AstExpr, *const Def>,
21 pub(crate) local_defs: DenseHashMap<*const AstLocal, *const Def>,
22 pub(crate) declared_defs: DenseHashMap<*const AstStat, *const Def>,
23 pub(crate) def_to_symbol: DenseHashMap<*const Def, Symbol>,
24 pub(crate) ast_refinement_keys: DenseHashMap<*const AstExpr, *const RefinementKey>,
25}
26
27impl DataFlowGraph {
28 pub fn data_flow_graph_data_flow_graph_mut(&mut self) {
31 unreachable!("C++ DataFlowGraph move-ctor; Rust moves by value — no call site")
32 }
33 pub fn data_flow_graph_data_flow_graph(&self) {
36 unreachable!("C++ DataFlowGraph copy-ctor is `= delete` — non-copyable, no call site")
37 }
38 pub fn data_flow_graph_data_flow_graph_not_null_def_arena_not_null_refinement_key_arena(&self) {
42 unreachable!(
43 "superseded by DataFlowGraph::data_flow_graph(def_arena, key_arena) — no call site"
44 )
45 }
46 pub fn get_def_ast_expr(&self, expr: *const AstExpr) -> DefId {
49 let def = self.ast_defs.find(&expr);
50 LUAU_ASSERT!(def.is_some());
51 *def.unwrap()
52 }
53
54 pub fn get_def_ast_local(&self, local: *const AstLocal) -> DefId {
56 let def = self.local_defs.find(&local);
57 LUAU_ASSERT!(def.is_some());
58 *def.unwrap()
59 }
60
61 pub fn get_def_ast_stat_declare_global(&self, global: *const AstStatDeclareGlobal) -> DefId {
63 let def = self.declared_defs.find(&(global as *const AstStat));
64 LUAU_ASSERT!(def.is_some());
65 *def.unwrap()
66 }
67
68 pub fn get_def_ast_stat_declare_function(&self, func: *const AstStatDeclareFunction) -> DefId {
70 let def = self.declared_defs.find(&(func as *const AstStat));
71 LUAU_ASSERT!(def.is_some());
72 *def.unwrap()
73 }
74 pub fn data_flow_graph_not_null_def_arena_not_null_refinement_key_arena(
79 &self,
80 _def_arena: *mut DefArena,
81 _key_arena: *mut RefinementKeyArena,
82 ) {
83 unreachable!(
84 "superseded by DataFlowGraph::data_flow_graph(def_arena, key_arena) — no call site"
85 )
86 }
87}