Skip to main content

luaur_analysis/records/
module.rs

1//! Generated skeleton item.
2//! Node: `cxx:Record:Luau.Analysis:Analysis/include/Luau/Module.h:76:module`
3//! Source: `Analysis/include/Luau/Module.h`
4//! Graph edges:
5//! - declared_by: source_file Analysis/include/Luau/Module.h
6//! - source_includes:
7//!   - includes -> source_file Analysis/include/Luau/Error.h
8//!   - includes -> source_file Analysis/include/Luau/Linter.h
9//!   - includes -> source_file Analysis/include/Luau/FileResolver.h
10//!   - includes -> source_file Ast/include/Luau/ParseOptions.h
11//!   - includes -> source_file Ast/include/Luau/ParseResult.h
12//!   - includes -> source_file Analysis/include/Luau/Scope.h
13//!   - includes -> source_file Analysis/include/Luau/TypeArena.h
14//!   - includes -> source_file Analysis/include/Luau/DataFlowGraph.h
15//! - incoming:
16//!   - declares <- source_file Analysis/include/Luau/Module.h
17//!   - type_ref <- record FrontendOptions (Analysis/include/Luau/Frontend.h)
18//!   - type_ref <- type_alias ModulePtr (Analysis/include/Luau/Module.h)
19//!   - type_ref <- type_alias ModulePtr (Analysis/include/Luau/ModuleResolver.h)
20//!   - type_ref <- type_alias ModulePtr (Analysis/include/Luau/Normalize.h)
21//!   - type_ref <- record UserDefinedFunctionData (Analysis/include/Luau/Type.h)
22//!   - type_ref <- record TypeArena (Analysis/include/Luau/TypeArena.h)
23//!   - type_ref <- record TypeChecker2 (Analysis/include/Luau/TypeChecker2.h)
24//!   - type_ref <- function findScopeAtPosition (Analysis/src/AstQuery.cpp)
25//!   - type_ref <- function findTypeAtPosition (Analysis/src/AstQuery.cpp)
26//!   - type_ref <- function findExpectedTypeAtPosition (Analysis/src/AstQuery.cpp)
27//!   - type_ref <- function findBindingAtPosition (Analysis/src/AstQuery.cpp)
28//!   - type_ref <- function checkOverloadedDocumentationSymbol (Analysis/src/AstQuery.cpp)
29//!   - type_ref <- function getMetatableDocumentation (Analysis/src/AstQuery.cpp)
30//!   - type_ref <- function getDocumentationSymbolAtPosition (Analysis/src/AstQuery.cpp)
31//!   - type_ref <- function findExpectedTypeAt (Analysis/src/AutocompleteCore.cpp)
32//!   - type_ref <- function checkTypeMatch (Analysis/src/AutocompleteCore.cpp)
33//!   - type_ref <- function checkTypeCorrectKind (Analysis/src/AutocompleteCore.cpp)
34//!   - type_ref <- function autocompleteProps (Analysis/src/AutocompleteCore.cpp)
35//!   - type_ref <- function autocompleteProps (Analysis/src/AutocompleteCore.cpp)
36//!   - type_ref <- function autocompleteProps (Analysis/src/AutocompleteCore.cpp)
37//!   - type_ref <- function autocompleteModuleTypes (Analysis/src/AutocompleteCore.cpp)
38//!   - type_ref <- function getLocalTypeInScopeAt (Analysis/src/AutocompleteCore.cpp)
39//!   - type_ref <- function functionIsExpectedAt (Analysis/src/AutocompleteCore.cpp)
40//!   - type_ref <- function autocompleteTypeNames (Analysis/src/AutocompleteCore.cpp)
41//!   - type_ref <- function autocompleteStatement (Analysis/src/AutocompleteCore.cpp)
42//!   - type_ref <- function autocompleteExpression (Analysis/src/AutocompleteCore.cpp)
43//!   - type_ref <- function autocompleteExpression (Analysis/src/AutocompleteCore.cpp)
44//!   - type_ref <- method ConstraintSolver::resolveModule (Analysis/src/ConstraintSolver.cpp)
45//!   - type_ref <- function typecheckFragment_ (Analysis/src/FragmentAutocomplete.cpp)
46//!   - type_ref <- function accumulateErrors (Analysis/src/Frontend.cpp)
47//!   - type_ref <- function check (Analysis/src/Frontend.cpp)
48//!   - type_ref <- method Frontend::parseType (Analysis/src/Frontend.cpp)
49//!   - type_ref <- record LintContext (Analysis/src/Linter.cpp)
50//!   - type_ref <- function lint (Analysis/src/Linter.cpp)
51//!   - type_ref <- record ClonePublicInterface (Analysis/src/Module.cpp)
52//!   - type_ref <- method ClonePublicInterface::ClonePublicInterface (Analysis/src/Module.cpp)
53//!   - type_ref <- method Module::~Module (Analysis/src/Module.cpp)
54//!   - type_ref <- function synthesizeExportReturn (Analysis/src/Module.cpp)
55//!   - type_ref <- record NonStrictTypeChecker (Analysis/src/NonStrictTypeChecker.cpp)
56//!   - type_ref <- method NonStrictTypeChecker::NonStrictTypeChecker (Analysis/src/NonStrictTypeChecker.cpp)
57//!   - type_ref <- function checkNonStrict (Analysis/src/NonStrictTypeChecker.cpp)
58//!   - type_ref <- method TypeAttacher::TypeAttacher (Analysis/src/TypeAttach.cpp)
59//!   - type_ref <- record TypeAttacher (Analysis/src/TypeAttach.cpp)
60//!   - type_ref <- function attachTypeData (Analysis/src/TypeAttach.cpp)
61//!   - type_ref <- function check (Analysis/src/TypeChecker2.cpp)
62//!   - type_ref <- method TypeChecker2::TypeChecker2 (Analysis/src/TypeChecker2.cpp)
63//!   - type_ref <- method TypeChecker::checkWithoutRecursionCheck (Analysis/src/TypeInfer.cpp)
64//!   - type_ref <- method TypeChecker::checkRequire (Analysis/src/TypeInfer.cpp)
65//!   - type_ref <- method CliFileResolver::readSource (CLI/src/Analyze.cpp)
66//!   - type_ref <- method TestFileResolver::readSource (tests/Fixture.cpp)
67//!   - type_ref <- method Fixture::dumpErrors (tests/Fixture.cpp)
68//!   - type_ref <- record Fixture (tests/Fixture.h)
69//!   - type_ref <- method DemoFileResolver::readSource (CLI/src/Web.cpp)
70//!   - type_ref <- method Module::clonePublicInterface (Analysis/src/Module.cpp)
71//!   - type_ref <- method Module::hasModuleScope (Analysis/src/Module.cpp)
72//!   - type_ref <- method Module::getModuleScope (Analysis/src/Module.cpp)
73//! - outgoing:
74//!   - type_ref -> record TypeArena (Analysis/include/Luau/TypeArena.h)
75//!   - type_ref -> record Allocator (Ast/include/Luau/Allocator.h)
76//!   - type_ref -> record AstNameTable (Ast/include/Luau/Lexer.h)
77//!   - type_ref -> record AstStatBlock (Ast/include/Luau/Ast.h)
78//!   - type_ref -> record Location (Ast/include/Luau/Location.h)
79//!   - type_ref -> type_alias ScopePtr (Analysis/include/Luau/Module.h)
80//!   - type_ref -> record DenseHashMap (Common/include/Luau/DenseHash.h)
81//!   - type_ref -> record AstExpr (Ast/include/Luau/Ast.h)
82//!   - type_ref -> type_alias TypeId (Analysis/include/Luau/TypeFwd.h)
83//!   - type_ref -> type_alias TypePackId (Analysis/include/Luau/TypeFwd.h)
84//!   - type_ref -> record AstNode (Ast/include/Luau/Ast.h)
85//!   - type_ref -> record AstType (Ast/include/Luau/Ast.h)
86//!   - type_ref -> record AstTypePack (Ast/include/Luau/Ast.h)
87//!   - type_ref -> record AstStat (Ast/include/Luau/Ast.h)
88//!   - type_ref -> record Scope (Analysis/include/Luau/Scope.h)
89//!   - type_ref -> record TypeFun (Analysis/include/Luau/Type.h)
90//!   - type_ref -> type_alias ErrorVec (Analysis/include/Luau/Error.h)
91//!   - type_ref -> record LintResult (Analysis/include/Luau/Linter.h)
92//!   - type_ref -> enum Mode (Ast/include/Luau/ParseOptions.h)
93//!   - type_ref -> record DefArena (Analysis/include/Luau/Def.h)
94//!   - type_ref -> record RefinementKeyArena (Analysis/include/Luau/DataFlowGraph.h)
95//!   - type_ref -> record BuiltinTypes (Analysis/include/Luau/Type.h)
96//!   - type_ref -> record InternalErrorReporter (Analysis/include/Luau/Error.h)
97//!   - type_ref -> enum SolverMode (Analysis/include/Luau/Type.h)
98//!   - translates_to -> rust_item Module
99
100use crate::records::def_arena::DefArena;
101use crate::records::lint_result::LintResult;
102use crate::records::refinement_key_arena::RefinementKeyArena;
103use crate::records::scope::Scope;
104use crate::records::type_arena::TypeArena;
105use crate::records::type_fun::TypeFun;
106use crate::type_aliases::error_vec::ErrorVec;
107use crate::type_aliases::module_name_file_resolver::ModuleName;
108use crate::type_aliases::name_type::Name;
109use crate::type_aliases::scope_ptr_module::ScopePtr;
110use crate::type_aliases::type_id::TypeId;
111use crate::type_aliases::type_pack_id::TypePackId;
112use alloc::boxed::Box;
113use alloc::string::String;
114use alloc::sync::Arc;
115use alloc::vec::Vec;
116use luaur_ast::enums::mode::Mode;
117use luaur_ast::records::allocator::Allocator;
118use luaur_ast::records::ast_expr::AstExpr;
119use luaur_ast::records::ast_name_table::AstNameTable;
120use luaur_ast::records::ast_node::AstNode;
121use luaur_ast::records::ast_stat::AstStat;
122use luaur_ast::records::ast_stat_block::AstStatBlock;
123use luaur_ast::records::ast_type::AstType;
124use luaur_ast::records::ast_type_pack::AstTypePack;
125use luaur_ast::records::location::Location;
126use luaur_common::records::dense_hash_map::DenseHashMap;
127use std::collections::HashMap;
128
129#[derive(Debug)]
130pub struct Module {
131    pub checked_in_new_solver: bool,
132
133    pub name: ModuleName,
134    pub human_readable_name: String,
135
136    pub interface_types: TypeArena,
137    pub internal_types: TypeArena,
138
139    pub allocator: Option<Arc<Allocator>>,
140    pub names: Option<Arc<AstNameTable>>,
141    pub root: *mut AstStatBlock,
142
143    pub scopes: Vec<(Location, ScopePtr)>,
144
145    pub ast_types: DenseHashMap<*const AstExpr, TypeId>,
146    pub ast_type_packs: DenseHashMap<*const AstExpr, TypePackId>,
147    pub ast_expected_types: DenseHashMap<*const AstExpr, TypeId>,
148
149    pub ast_original_call_types: DenseHashMap<*const AstNode, TypeId>,
150    pub ast_overload_resolved_types: DenseHashMap<*const AstNode, TypeId>,
151    pub ast_for_in_next_types: DenseHashMap<*const AstNode, TypeId>,
152
153    pub ast_resolved_types: DenseHashMap<*const AstType, TypeId>,
154    pub ast_resolved_type_packs: DenseHashMap<*const AstTypePack, TypePackId>,
155
156    pub ast_compound_assign_result_types: DenseHashMap<*const AstStat, TypeId>,
157
158    pub upper_bound_contributors: DenseHashMap<TypeId, Vec<(Location, TypeId)>>,
159
160    pub ast_scopes: DenseHashMap<*const AstNode, *mut Scope>,
161
162    pub type_function_aliases: Vec<Box<TypeFun>>,
163
164    pub declared_globals: HashMap<Name, TypeId>,
165    pub errors: ErrorVec,
166    pub lint_result: LintResult,
167    pub mode: Mode,
168    pub r#type: crate::enums::type_file_resolver::Type,
169    pub check_duration_sec: f64,
170    pub timeout: bool,
171    pub cancelled: bool,
172
173    pub return_type: TypePackId,
174    pub exported_type_bindings: HashMap<Name, TypeFun>,
175
176    pub def_arena: DefArena,
177    pub key_arena: RefinementKeyArena,
178
179    pub constraint_generation_did_not_complete: bool,
180}
181
182impl Default for Module {
183    fn default() -> Self {
184        // Faithful port of the C++ `Module` default ctor (`Module.h:76`), which
185        // default-initializes every member via its in-class initializer.
186        Self {
187            checked_in_new_solver: false,
188
189            name: ModuleName::new(),
190            human_readable_name: String::new(),
191
192            interface_types: TypeArena::default(),
193            internal_types: TypeArena::default(),
194
195            allocator: None,
196            names: None,
197            root: core::ptr::null_mut(),
198
199            scopes: Vec::new(),
200
201            // `DenseHashMap<...>{nullptr}` — pointer-keyed maps use the null
202            // sentinel as their empty key.
203            ast_types: DenseHashMap::new(core::ptr::null::<AstExpr>()),
204            ast_type_packs: DenseHashMap::new(core::ptr::null::<AstExpr>()),
205            ast_expected_types: DenseHashMap::new(core::ptr::null::<AstExpr>()),
206
207            ast_original_call_types: DenseHashMap::new(core::ptr::null::<AstNode>()),
208            ast_overload_resolved_types: DenseHashMap::new(core::ptr::null::<AstNode>()),
209            ast_for_in_next_types: DenseHashMap::new(core::ptr::null::<AstNode>()),
210
211            ast_resolved_types: DenseHashMap::new(core::ptr::null::<AstType>()),
212            ast_resolved_type_packs: DenseHashMap::new(core::ptr::null::<AstTypePack>()),
213
214            ast_compound_assign_result_types: DenseHashMap::new(core::ptr::null::<AstStat>()),
215
216            upper_bound_contributors: DenseHashMap::new(core::ptr::null::<
217                crate::records::r#type::Type,
218            >()),
219
220            ast_scopes: DenseHashMap::new(core::ptr::null::<AstNode>()),
221
222            type_function_aliases: Vec::new(),
223
224            declared_globals: HashMap::new(),
225            errors: ErrorVec::new(),
226            lint_result: LintResult::default(),
227            // C++ `Mode mode;` has no in-class initializer; the first enumerator
228            // (`NoCheck`) is the deterministic zero-init value.
229            mode: Mode::NoCheck,
230            // C++ `SourceCode::Type type;` — first enumerator is `None`.
231            r#type: crate::enums::type_file_resolver::Type::None,
232            check_duration_sec: 0.0,
233            timeout: false,
234            cancelled: false,
235
236            // `TypePackId returnType = nullptr;` — TypePackId is `*const TypePackVar`.
237            return_type: core::ptr::null(),
238            exported_type_bindings: HashMap::new(),
239
240            def_arena: DefArena::default(),
241            key_arena: RefinementKeyArena::default(),
242
243            constraint_generation_did_not_complete: true,
244        }
245    }
246}