Skip to main content

luaur_analysis/methods/
frontend_check_frontend_alt_b.rs

1use crate::enums::solver_mode::SolverMode;
2use crate::functions::check_frontend::check as check_new_solver;
3use crate::records::frontend::{Frontend, FrontendStats};
4use crate::records::require_cycle::RequireCycle;
5use crate::records::source_module::SourceModule;
6use crate::records::stats::Stats;
7use crate::records::type_check_limits::TypeCheckLimits;
8use crate::records::type_checker::TypeChecker;
9use crate::type_aliases::module_ptr_module::ModulePtr;
10use crate::type_aliases::scope_ptr_type::ScopePtr;
11use alloc::rc::Rc;
12use alloc::vec::Vec;
13use luaur_ast::enums::mode::Mode;
14
15impl Frontend {
16    pub fn check_source_module_mode_vector_require_cycle_optional_scope_ptr_bool_bool_frontend_stats_type_check_limits(
17        &mut self,
18        source_module: &SourceModule,
19        mode: Mode,
20        require_cycles: Vec<RequireCycle>,
21        environment_scope: Option<ScopePtr>,
22        for_autocomplete: bool,
23        record_json_log: bool,
24        stats: &mut FrontendStats,
25        type_check_limits: TypeCheckLimits,
26    ) -> ModulePtr {
27        if self.get_luau_solver_mode() == SolverMode::New {
28            let prepare_module_scope_wrap = {
29                let prepare_module_scope = self.prepare_module_scope.clone();
30                Rc::new(
31                    move |name: &crate::type_aliases::module_name_type::ModuleName,
32                          scope: &ScopePtr| {
33                        if let Some(prepare_module_scope) = &prepare_module_scope {
34                            prepare_module_scope(name, scope, for_autocomplete);
35                        }
36                    },
37                )
38            };
39
40            let mut function_stats = Stats {
41                files: stats.files,
42                lines: stats.lines,
43                files_strict: stats.files_strict,
44                files_nonstrict: stats.files_nonstrict,
45                types_allocated: stats.types_allocated,
46                type_packs_allocated: stats.type_packs_allocated,
47                bool_singletons_minted: stats.bool_singletons_minted,
48                str_singletons_minted: stats.str_singletons_minted,
49                unique_str_singletons_minted: stats.unique_str_singletons_minted,
50                time_read: stats.time_read,
51                time_parse: stats.time_parse,
52                time_check: stats.time_check,
53                time_lint: stats.time_lint,
54                dynamic_constraints_created: stats.dynamic_constraints_created,
55            };
56
57            let write_json_log = self.write_json_log.clone().unwrap_or_else(|| {
58                Rc::new(
59                    |_: &crate::type_aliases::module_name_type::ModuleName,
60                     _: alloc::string::String| {},
61                )
62            });
63
64            let module = check_new_solver(
65                source_module,
66                mode,
67                &require_cycles,
68                self.builtin_types,
69                &mut self.ice_handler,
70                if for_autocomplete {
71                    &mut self.module_resolver_for_autocomplete as *mut _
72                        as *mut crate::records::module_resolver::ModuleResolver
73                } else {
74                    &mut self.module_resolver as *mut _
75                        as *mut crate::records::module_resolver::ModuleResolver
76                },
77                self.file_resolver,
78                environment_scope
79                    .as_ref()
80                    .unwrap_or(&self.globals.global_scope),
81                &self.globals.global_type_function_scope,
82                prepare_module_scope_wrap,
83                self.options.clone(),
84                type_check_limits,
85                record_json_log,
86                &mut function_stats,
87                write_json_log,
88            );
89
90            stats.files = function_stats.files;
91            stats.lines = function_stats.lines;
92            stats.files_strict = function_stats.files_strict;
93            stats.files_nonstrict = function_stats.files_nonstrict;
94            stats.types_allocated = function_stats.types_allocated;
95            stats.type_packs_allocated = function_stats.type_packs_allocated;
96            stats.bool_singletons_minted = function_stats.bool_singletons_minted;
97            stats.str_singletons_minted = function_stats.str_singletons_minted;
98            stats.unique_str_singletons_minted = function_stats.unique_str_singletons_minted;
99            stats.time_read = function_stats.time_read;
100            stats.time_parse = function_stats.time_parse;
101            stats.time_check = function_stats.time_check;
102            stats.time_lint = function_stats.time_lint;
103            stats.dynamic_constraints_created = function_stats.dynamic_constraints_created;
104
105            module
106        } else {
107            let global_scope = if for_autocomplete {
108                &self.globals_for_autocomplete.global_scope
109            } else {
110                &self.globals.global_scope
111            };
112            let resolver = if for_autocomplete {
113                &mut self.module_resolver_for_autocomplete as *mut _
114                    as *mut crate::records::module_resolver::ModuleResolver
115            } else {
116                &mut self.module_resolver as *mut _
117                    as *mut crate::records::module_resolver::ModuleResolver
118            };
119            let mut type_checker = TypeChecker::new(
120                global_scope,
121                resolver,
122                self.builtin_types,
123                &mut self.ice_handler,
124            );
125            if self.prepare_module_scope.is_some() {
126                let prepare_module_scope = self.prepare_module_scope.clone();
127                type_checker.prepare_module_scope = Some(Rc::new(move |name, scope| {
128                    if let Some(prepare_module_scope) = &prepare_module_scope {
129                        prepare_module_scope(name, scope, for_autocomplete);
130                    }
131                }));
132            }
133            type_checker.require_cycles = require_cycles;
134            type_checker.finish_time = type_check_limits.finishTime();
135            type_checker.instantiation_child_limit = type_check_limits.instantiationChildLimit();
136            type_checker.unifier_iteration_limit = type_check_limits.unifierIterationLimit();
137            type_checker.cancellation_token = type_check_limits.cancellationToken();
138
139            type_checker.check_source_module_mode_optional_scope_ptr(
140                source_module,
141                mode,
142                environment_scope,
143            )
144        }
145    }
146}