Skip to main content

luaur_analysis/methods/
constraint_solver_constraint_solver_constraint_solver.rs

1use crate::functions::borrow_constraints::borrow_constraints;
2use crate::records::constraint_graph::ConstraintGraph;
3use crate::records::constraint_set::ConstraintSet;
4use crate::records::constraint_solver::ConstraintSolver;
5use crate::records::data_flow_graph::DataFlowGraph;
6use crate::records::dcr_logger::DcrLogger;
7use crate::records::module_resolver::ModuleResolver;
8use crate::records::normalizer::Normalizer;
9use crate::records::require_cycle::RequireCycle;
10use crate::records::subtyping::Subtyping;
11use crate::records::to_string_options::ToStringOptions;
12use crate::records::type_check_limits::TypeCheckLimits;
13use crate::records::type_function_runtime::TypeFunctionRuntime;
14use crate::type_aliases::module_ptr_module::ModulePtr;
15use luaur_common::FInt;
16
17impl ConstraintSolver {
18    pub fn constraint_solver_not_null_normalizer_not_null_type_function_runtime_module_ptr_not_null_module_resolver_vector_require_cycle_dcr_logger_not_null_data_flow_graph_type_check_limits_constraint_graph_not_null_subtyping(
19        normalizer: *const Normalizer,
20        type_function_runtime: *const TypeFunctionRuntime,
21        module: ModulePtr,
22        module_resolver: *const ModuleResolver,
23        require_cycles: alloc::vec::Vec<RequireCycle>,
24        logger: *mut DcrLogger,
25        dfg: *const DataFlowGraph,
26        limits: TypeCheckLimits,
27        mut constraint_set: ConstraintSet,
28        cgraph: *mut ConstraintGraph,
29        subtyping: *const Subtyping,
30    ) -> Self {
31        let empty_instantiation_signature =
32            crate::records::instantiation_signature::InstantiationSignature {
33                fn_sig: crate::records::type_fun::TypeFun {
34                    type_params: alloc::vec::Vec::new(),
35                    type_pack_params: alloc::vec::Vec::new(),
36                    r#type: core::ptr::null(),
37                    definition_location: None,
38                },
39                arguments: alloc::vec::Vec::new(),
40                pack_arguments: alloc::vec::Vec::new(),
41            };
42        let empty_subtype_constraint =
43            crate::records::subtype_constraint_record::SubtypeConstraintRecord {
44                subTy: core::ptr::null(),
45                superTy: core::ptr::null(),
46                variance: crate::enums::subtyping_variance::SubtypingVariance::Invalid,
47            };
48
49        let mut result =
50            ConstraintSolver {
51                arena: unsafe { (*normalizer).arena },
52                builtin_types: unsafe { (*normalizer).builtin_types },
53                ice_reporter: unsafe { (*type_function_runtime).ice.clone() },
54                normalizer: normalizer as *mut Normalizer,
55                type_function_runtime: type_function_runtime as *mut TypeFunctionRuntime,
56                constraint_set,
57                constraints: alloc::vec::Vec::new(),
58                scope_to_function: core::ptr::null_mut(),
59                root_scope: core::ptr::null_mut(),
60                module: Some(module),
61                dfg,
62                solver_constraints: alloc::vec::Vec::new(),
63                solver_constraint_limit: FInt::LuauSolverConstraintLimit.get() as usize,
64                unsolved_constraints: alloc::vec::Vec::new(),
65                deprecated_blocked_constraints: std::collections::HashMap::new(),
66                deprecated_blocked: std::collections::HashMap::new(),
67                instantiated_aliases: luaur_common::records::dense_hash_map::DenseHashMap::new(
68                    empty_instantiation_signature,
69                ),
70                upper_bound_contributors: luaur_common::records::dense_hash_map::DenseHashMap::new(
71                    core::ptr::null(),
72                ),
73                deprecated_type_to_constraint_set: std::collections::HashMap::new(),
74                deprecated_constraint_to_mutated_types:
75                    luaur_common::records::dense_hash_map::DenseHashMap::new(core::ptr::null()),
76                uninhabited_type_functions:
77                    luaur_common::records::dense_hash_set::DenseHashSet::new(core::ptr::null()),
78                seen_constraints: luaur_common::records::dense_hash_map::DenseHashMap::new(
79                    empty_subtype_constraint,
80                ),
81                generalized_types_: luaur_common::records::dense_hash_set::DenseHashSet::new(
82                    core::ptr::null(),
83                ),
84                generalized_types: core::ptr::null(),
85                errors: alloc::vec::Vec::new(),
86                module_resolver: module_resolver as *mut ModuleResolver,
87                require_cycles,
88                logger,
89                limits: limits.clone(),
90                type_functions_to_finalize:
91                    luaur_common::records::dense_hash_map::DenseHashMap::new(core::ptr::null()),
92                opts: ToStringOptions {
93                    exhaustive: true,
94                    ..ToStringOptions::default()
95                },
96                cgraph,
97                subtyping: subtyping as *mut Subtyping,
98            };
99
100        result.constraints = borrow_constraints(&result.constraint_set.constraints);
101        result.scope_to_function = &mut result.constraint_set.scope_to_function as *mut _;
102        result.root_scope = result.constraint_set.root_scope;
103        result.generalized_types = &result.generalized_types_ as *const _;
104
105        result.init_free_type_tracking();
106
107        result
108    }
109}