Skip to main content

luaur_analysis/records/
data_flow_graph.rs

1//! @interface-stub
2use 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    /// C++ `DataFlowGraph(DataFlowGraph&&) = default;` move-ctor; the Rust port
29    /// moves by value, so this special member has no call site.
30    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    /// C++ `DataFlowGraph(const DataFlowGraph&) = delete;` — the deleted copy
34    /// ctor (DataFlowGraph is non-copyable); never callable in C++ either.
35    pub fn data_flow_graph_data_flow_graph(&self) {
36        unreachable!("C++ DataFlowGraph copy-ctor is `= delete` — non-copyable, no call site")
37    }
38    /// Skeleton artifact of the private arena ctor with a malformed `&self`/no-arg
39    /// signature; the real ctor is `DataFlowGraph::data_flow_graph(def_arena, key_arena)`
40    /// (`methods/data_flow_graph_data_flow_graph_data_flow_graph_alt_c.rs`).
41    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    /// `DefId DataFlowGraph::getDef(const AstExpr* expr) const`.
47    /// Reference: `DataFlowGraph.cpp` — `getDefOptional` plus an assert.
48    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    /// `DefId DataFlowGraph::getDef(const AstLocal* local) const`. Reference: `DataFlowGraph.cpp:79-84`.
55    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    /// `DefId DataFlowGraph::getDef(const AstStatDeclareGlobal* global) const`. Reference: `DataFlowGraph.cpp:86-91`.
62    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    /// `DefId DataFlowGraph::getDef(const AstStatDeclareFunction* func) const`. Reference: `DataFlowGraph.cpp:93-98`.
69    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    /// Skeleton artifact duplicating the private arena ctor; the real
75    /// constructor (`DataFlowGraph::data_flow_graph(def_arena, key_arena)`,
76    /// `methods/data_flow_graph_data_flow_graph_data_flow_graph_alt_c.rs`) returns
77    /// `Self`, whereas this generated variant takes `&self` and returns `()`.
78    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}