luaur_analysis/methods/
constraint_generator_constraint_generator.rs1use crate::records::builtin_types::BuiltinTypes;
2use crate::records::constraint_generator::ConstraintGenerator;
3use crate::records::constraint_graph::ConstraintGraph;
4use crate::records::data_flow_graph::DataFlowGraph;
5use crate::records::dcr_logger::DcrLogger;
6use crate::records::internal_error_reporter::InternalErrorReporter;
7use crate::records::module_resolver::ModuleResolver;
8use crate::records::normalizer::Normalizer;
9use crate::records::require_cycle::RequireCycle;
10use crate::records::type_function_runtime::TypeFunctionRuntime;
11use crate::type_aliases::module_name_type_fwd::ModuleName;
12use crate::type_aliases::module_ptr_module::ModulePtr;
13use crate::type_aliases::scope_ptr_constraint_generator::ScopePtr;
14use alloc::rc::Rc;
15use alloc::vec::Vec;
16use core::ptr::NonNull;
17use luaur_common::macros::luau_assert::LUAU_ASSERT;
18
19impl ConstraintGenerator {
20 pub fn constraint_generator(
21 module: ModulePtr,
22 normalizer: NonNull<Normalizer>,
23 type_function_runtime: NonNull<TypeFunctionRuntime>,
24 module_resolver: NonNull<ModuleResolver>,
25 builtin_types: NonNull<BuiltinTypes>,
26 ice: NonNull<InternalErrorReporter>,
27 global_scope: ScopePtr,
28 type_function_scope: ScopePtr,
29 prepare_module_scope: Rc<dyn Fn(&ModuleName, &ScopePtr)>,
30 logger: *mut DcrLogger,
31 dfg: NonNull<DataFlowGraph>,
32 require_cycles: Vec<RequireCycle>,
33 cgraph: *mut ConstraintGraph,
34 ) -> Self {
35 let normalizer_ref = unsafe { normalizer.as_ref() };
36 let arena = unsafe { (*normalizer_ref).arena };
37
38 let result = ConstraintGenerator {
39 scopes: Vec::new(),
40 module: Some(module),
41 builtin_types: builtin_types.as_ptr(),
42 arena,
43 root_scope: core::ptr::null_mut(),
44 type_context: crate::enums::type_context::TypeContext::default(),
45 inferred_bindings: luaur_common::records::dense_hash_map::DenseHashMap::new(
46 crate::records::symbol::Symbol::default(),
47 ),
48 constraints: Vec::new(),
49 free_types: crate::records::type_ids::TypeIds::type_ids(),
50 scope_to_function: luaur_common::records::dense_hash_map::DenseHashMap::new(
51 core::ptr::null_mut(),
52 ),
53 ast_type_alias_defining_scopes:
54 luaur_common::records::dense_hash_map::DenseHashMap::new(core::ptr::null()),
55 dfg: dfg.as_ptr(),
56 refinement_arena: crate::records::refinement_arena_refinement::RefinementArena {
57 allocator: crate::records::typed_allocator::TypedAllocator::default(),
58 },
59 recursion_count: 0,
60 errors: Vec::new(),
61 normalizer: normalizer.as_ptr(),
62 type_function_runtime: type_function_runtime.as_ptr(),
63 ast_type_function_environment_scopes:
64 luaur_common::records::dense_hash_map::DenseHashMap::new(core::ptr::null()),
65 module_resolver: module_resolver.as_ptr(),
66 ice: ice.as_ptr(),
67 global_scope: Some(global_scope),
68 type_function_scope: Some(type_function_scope),
69 prepare_module_scope,
70 require_cycles,
71 local_types: luaur_common::records::dense_hash_map::DenseHashMap::new(core::ptr::null()),
72 inferred_expr_cache: luaur_common::records::dense_hash_map::DenseHashMap::new(
73 core::ptr::null_mut(),
74 ),
75 class_decl_records: luaur_common::records::dense_hash_map::DenseHashMap::new(
76 core::ptr::null_mut(),
77 ),
78 logger,
79 recursion_limit_met: false,
80 cgraph,
81 interior_free_types: Vec::new(),
82 unions_to_simplify: Vec::new(),
83 uninitialized_globals: crate::records::set::Set::new(
84 luaur_ast::records::ast_name::AstName::default(),
85 ),
86 polarity: crate::enums::polarity::Polarity::default(),
87 prop_index_pairs_seen: luaur_common::records::dense_hash_map::DenseHashMap::new((
88 core::ptr::null(),
89 alloc::string::String::new(),
90 )),
91 large_table_depth: 0,
92 };
93
94 LUAU_ASSERT!(result.module.is_some());
95
96 result
97 }
98}