1use crate::enums::polarity::Polarity;
5use crate::enums::type_context::TypeContext;
6use crate::records::builtin_types::BuiltinTypes;
7use crate::records::constraint_graph::ConstraintGraph;
8use crate::records::data_flow_graph::DataFlowGraph;
9use crate::records::dcr_logger::DcrLogger;
10use crate::records::inference::Inference;
11use crate::records::interior_free_types::InteriorFreeTypes;
12use crate::records::internal_error_reporter::InternalErrorReporter;
13use crate::records::module_resolver::ModuleResolver;
14use crate::records::normalizer::Normalizer;
15use crate::records::refinement_arena_refinement::RefinementArena;
16use crate::records::require_cycle::RequireCycle;
17use crate::records::scope::Scope;
18use crate::records::set::Set;
19use crate::records::symbol::Symbol;
20use crate::records::type_arena::TypeArena;
21use crate::records::type_error::TypeError;
22use crate::records::type_function_runtime::TypeFunctionRuntime;
23use crate::records::type_ids::TypeIds;
24use crate::type_aliases::constraint_ptr::ConstraintPtr;
25use crate::type_aliases::module_name_type_fwd::ModuleName;
26use crate::type_aliases::module_ptr_module::ModulePtr;
27use crate::type_aliases::scope_ptr_type::ScopePtr;
28use crate::type_aliases::type_id::TypeId;
29use alloc::rc::Rc;
30use alloc::string::String;
31use alloc::vec::Vec;
32use luaur_ast::records::ast_expr::AstExpr;
33use luaur_ast::records::ast_local::AstLocal;
34use luaur_ast::records::ast_name::AstName;
35use luaur_ast::records::ast_stat_type_alias::AstStatTypeAlias;
36use luaur_ast::records::ast_stat_type_function::AstStatTypeFunction;
37use luaur_ast::records::location::Location;
38use luaur_common::records::dense_hash_map::DenseHashMap;
39
40#[derive(Debug)]
41pub struct InferredBinding {
42 pub scope: *mut Scope,
43 pub location: Location,
44 pub types: TypeIds,
45}
46
47pub struct ConstraintGenerator {
48 pub scopes: Vec<(Location, ScopePtr)>,
49 pub module: Option<ModulePtr>,
50 pub builtin_types: *mut BuiltinTypes,
51 pub arena: *mut TypeArena,
52 pub root_scope: *mut Scope,
53 pub type_context: TypeContext,
54 pub inferred_bindings: DenseHashMap<Symbol, InferredBinding>,
55 pub constraints: Vec<ConstraintPtr>,
56 pub free_types: TypeIds,
57 pub scope_to_function: DenseHashMap<*mut Scope, TypeId>,
58 pub ast_type_alias_defining_scopes: DenseHashMap<*const AstStatTypeAlias, Option<ScopePtr>>,
59 pub dfg: *const DataFlowGraph,
60 pub refinement_arena: RefinementArena,
61 pub recursion_count: i32,
62 pub errors: Vec<TypeError>,
63 pub normalizer: *mut Normalizer,
64 pub type_function_runtime: *mut TypeFunctionRuntime,
65 pub ast_type_function_environment_scopes:
66 DenseHashMap<*const AstStatTypeFunction, Option<ScopePtr>>,
67 pub module_resolver: *mut ModuleResolver,
68 pub ice: *mut InternalErrorReporter,
69 pub global_scope: Option<ScopePtr>,
70 pub type_function_scope: Option<ScopePtr>,
71 pub prepare_module_scope: Rc<dyn Fn(&ModuleName, &ScopePtr)>,
72 pub require_cycles: Vec<RequireCycle>,
73 pub local_types: DenseHashMap<TypeId, TypeIds>,
74 pub inferred_expr_cache: DenseHashMap<*mut AstExpr, Inference>,
75 pub class_decl_records: DenseHashMap<*mut AstLocal, ClassDeclRecord>,
76 pub logger: *mut DcrLogger,
77 pub recursion_limit_met: bool,
78 pub cgraph: *mut ConstraintGraph,
79 pub interior_free_types: Vec<InteriorFreeTypes>,
80 pub unions_to_simplify: Vec<TypeId>,
81 pub uninitialized_globals: Set<AstName>,
82 pub polarity: Polarity,
83 pub prop_index_pairs_seen: DenseHashMap<(TypeId, String), TypeId>,
84 pub large_table_depth: usize,
85}
86
87use crate::records::class_decl_record::ClassDeclRecord;
88
89impl core::fmt::Debug for ConstraintGenerator {
90 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
91 f.debug_struct("ConstraintGenerator")
92 .field("scopes", &self.scopes)
93 .field("module", &self.module)
94 .field("builtin_types", &self.builtin_types)
95 .field("arena", &self.arena)
96 .field("root_scope", &self.root_scope)
97 .field("type_context", &self.type_context)
98 .field("inferred_bindings", &self.inferred_bindings)
99 .field("constraints", &self.constraints)
100 .field("free_types", &self.free_types)
101 .field("scope_to_function", &self.scope_to_function)
102 .field(
103 "ast_type_alias_defining_scopes",
104 &self.ast_type_alias_defining_scopes,
105 )
106 .field("dfg", &self.dfg)
107 .field("refinement_arena", &self.refinement_arena)
108 .field("recursion_count", &self.recursion_count)
109 .field("errors", &self.errors)
110 .field("normalizer", &self.normalizer)
111 .field("type_function_runtime", &self.type_function_runtime)
112 .field(
113 "ast_type_function_environment_scopes",
114 &self.ast_type_function_environment_scopes,
115 )
116 .field("module_resolver", &self.module_resolver)
117 .field("ice", &self.ice)
118 .field("global_scope", &self.global_scope)
119 .field("type_function_scope", &self.type_function_scope)
120 .field("prepare_module_scope", &"...")
121 .field("require_cycles", &self.require_cycles)
122 .field("local_types", &self.local_types)
123 .field("inferred_expr_cache", &self.inferred_expr_cache)
124 .field("class_decl_records", &self.class_decl_records)
125 .field("logger", &self.logger)
126 .field("recursion_limit_met", &self.recursion_limit_met)
127 .field("cgraph", &self.cgraph)
128 .field("interior_free_types", &self.interior_free_types)
129 .field("unions_to_simplify", &self.unions_to_simplify)
130 .field("uninitialized_globals", &self.uninitialized_globals)
131 .field("polarity", &self.polarity)
132 .field("prop_index_pairs_seen", &self.prop_index_pairs_seen)
133 .field("large_table_depth", &self.large_table_depth)
134 .finish()
135 }
136}