Skip to main content

tsz_solver/
lib.rs

1//! Query-Based Structural Solver
2//!
3//! This module implements a declarative, query-based type solver architecture.
4//! It uses:
5//!
6//! - **Ena**: For unification (Union-Find) in generic type inference
7//! - **Custom `TypeData`**: Structural type representation with interning
8//! - **Cycle Detection**: Coinductive semantics for recursive types
9//!
10//! Key benefits:
11//! - O(1) type equality via interning (`TypeId` comparison)
12//! - Automatic cycle handling via coinductive semantics
13//! - Lazy evaluation - only compute types that are queried
14mod apparent;
15mod application;
16pub mod binary_ops;
17pub mod canonicalize;
18mod class_hierarchy;
19pub mod compat;
20pub mod compound_assignment;
21mod contextual;
22mod db;
23pub mod def;
24mod diagnostics;
25pub mod element_access;
26mod evaluate;
27pub mod evaluate_rules;
28pub mod expression_ops;
29mod flow_analysis;
30mod format;
31pub mod freshness;
32mod index_signatures;
33mod infer;
34mod infer_bct;
35mod infer_resolve;
36pub mod inheritance;
37mod instantiate;
38mod intern;
39mod intern_normalize;
40mod intern_template;
41pub mod judge;
42mod lawyer;
43mod narrowing;
44mod narrowing_compound;
45mod narrowing_discriminants;
46mod narrowing_property;
47mod narrowing_utils;
48mod object_literal;
49pub mod objects;
50pub mod operations;
51mod operations_constraints;
52mod operations_constructors;
53mod operations_generic_call;
54pub mod operations_generics;
55pub mod operations_iterators;
56pub mod operations_property;
57mod operations_property_readonly;
58mod operations_property_visitor;
59mod query_trace;
60pub mod recursion;
61pub mod relation_queries;
62pub mod sound;
63mod subtype;
64mod subtype_explain;
65mod subtype_helpers;
66mod subtype_overlap;
67mod subtype_rules;
68mod subtype_visitor;
69pub mod tracer;
70mod type_factory;
71pub mod type_queries;
72pub mod type_queries_classifiers;
73pub mod type_queries_data;
74pub mod type_queries_extended;
75pub mod type_queries_flow;
76pub mod type_resolver;
77pub mod types;
78pub mod unsoundness_audit;
79pub mod utils;
80pub mod variance;
81pub mod visitor;
82mod visitor_extract;
83pub mod widening;
84pub use intern::TypeInterner;
85pub use operations::infer_generic_function;
86pub use visitor::{
87    ConstAssertionVisitor, ObjectTypeKind, RecursiveTypeCollector, TypeCollectorVisitor, TypeKind,
88    TypeKindVisitor, TypePredicateVisitor, TypeVisitor, application_id, array_element_type,
89    bound_parameter_index, callable_shape_id, classify_object_type, collect_all_types,
90    collect_enum_def_ids, collect_lazy_def_ids, collect_referenced_types, collect_type_queries,
91    conditional_type_id, contains_error_type, contains_infer_types, contains_this_type,
92    contains_type_matching, contains_type_parameters, enum_components, for_each_child,
93    function_shape_id, index_access_parts, intersection_list_id, intrinsic_kind, is_array_type,
94    is_conditional_type, is_empty_object_type, is_empty_object_type_db, is_enum_type,
95    is_error_type, is_function_type, is_function_type_db, is_generic_application,
96    is_index_access_type, is_intersection_type, is_literal_type, is_literal_type_db,
97    is_mapped_type, is_module_namespace_type, is_module_namespace_type_db, is_object_like_type,
98    is_object_like_type_db, is_primitive_type, is_template_literal_type, is_this_type,
99    is_tuple_type, is_type_kind, is_type_parameter, is_type_reference, is_union_type, is_unit_type,
100    keyof_inner_type, lazy_def_id, literal_number, literal_string, literal_value, mapped_type_id,
101    module_namespace_symbol_ref, no_infer_inner_type, object_shape_id, object_with_index_shape_id,
102    readonly_inner_type, recursive_index, ref_symbol, string_intrinsic_components,
103    template_literal_id, test_type, tuple_list_id, type_param_info, type_query_symbol,
104    union_list_id, unique_symbol_ref, walk_referenced_types,
105};
106
107pub use apparent::{
108    ApparentMemberKind, apparent_object_member_kind, apparent_primitive_member_kind,
109    apparent_primitive_members,
110};
111pub use application::*;
112pub use binary_ops::*;
113pub use canonicalize::*;
114pub use class_hierarchy::*;
115pub use compat::*;
116pub use compound_assignment::*;
117pub use contextual::{ContextualTypeContext, apply_contextual_type};
118pub use db::{QueryCache, QueryDatabase, RelationCacheProbe, RelationCacheStats, TypeDatabase};
119pub use def::*;
120pub use diagnostics::SubtypeFailureReason;
121pub use diagnostics::{
122    DiagnosticArg, DiagnosticBuilder, DiagnosticCollector, DiagnosticSeverity, PendingDiagnostic,
123    PendingDiagnosticBuilder, SourceLocation, SourceSpan, SpannedDiagnosticBuilder,
124};
125pub use element_access::*;
126pub use evaluate::*;
127pub use flow_analysis::*;
128pub use format::TypeFormatter;
129pub use freshness::*;
130pub use index_signatures::*;
131pub use infer::*;
132pub use inheritance::*;
133pub use instantiate::{
134    MAX_INSTANTIATION_DEPTH, TypeInstantiator, TypeSubstitution, instantiate_type,
135    substitute_this_type,
136};
137pub use judge::*;
138pub use lawyer::AnyPropagationRules;
139pub use narrowing::*;
140pub use object_literal::ObjectLiteralBuilder;
141pub use objects::*;
142pub use operations::{
143    AssignabilityChecker, CallEvaluator, CallResult, MAX_CONSTRAINT_RECURSION_DEPTH,
144    get_contextual_signature_with_compat_checker,
145};
146pub use relation_queries::*;
147pub use sound::*;
148pub use subtype::{
149    AnyPropagationMode, SubtypeChecker, SubtypeResult, TypeEnvironment, TypeResolver,
150    are_types_structurally_identical, is_subtype_of,
151};
152pub use type_factory::*;
153pub use types::{
154    CallSignature, CallableShapeId, IntrinsicKind, LiteralValue, MappedModifier, ObjectShapeId,
155    PropertyInfo, PropertyLookup, SymbolRef, TypeApplication, TypeApplicationId, TypeData, TypeId,
156    TypeListId, Visibility, is_compiler_managed_type,
157};
158pub use types::{
159    CallableShape, ConditionalType, FunctionShape, FunctionShapeId, IndexSignature, MappedType,
160    MappedTypeId, ObjectFlags, ObjectShape, OrderedFloat, ParamInfo, RelationCacheKey,
161    TemplateSpan, TupleElement, TupleListId, TypeParamInfo, TypePredicate, TypePredicateTarget,
162};
163pub use unsoundness_audit::*;
164pub use variance::*;
165pub use widening::*;
166
167// Test modules: Most are loaded by their source files via #[path = "tests/..."] declarations.
168// Only include modules here that aren't loaded elsewhere to avoid duplicate_mod warnings.
169#[cfg(test)]
170#[path = "../tests/bidirectional_tests.rs"]
171mod bidirectional_tests;
172// callable_tests: loaded from subtype.rs
173// compat_tests: loaded from compat.rs
174// contextual_tests: loaded from contextual.rs
175// db_tests: loaded from db.rs
176// diagnostics_tests: loaded from diagnostics.rs
177// evaluate_tests: loaded from evaluate.rs
178// index_signature_tests: loaded from subtype.rs
179// infer_tests: loaded from infer.rs
180// instantiate_tests: loaded from instantiate.rs
181#[cfg(test)]
182#[path = "../tests/integration_tests.rs"]
183mod integration_tests;
184// intern_tests: loaded from intern.rs
185#[cfg(test)]
186#[path = "../tests/enum_nominality.rs"]
187mod enum_nominality;
188#[cfg(test)]
189#[path = "../tests/intersection_union_tests.rs"]
190mod intersection_union_tests;
191// lawyer_tests: loaded from lawyer.rs
192#[cfg(test)]
193#[path = "../tests/mapped_key_remap_tests.rs"]
194mod mapped_key_remap_tests;
195// narrowing_tests: loaded from narrowing.rs
196// operations_tests: loaded from operations.rs
197// subtype_tests: loaded from subtype.rs
198#[cfg(test)]
199#[path = "../tests/intersection_distributivity_tests.rs"]
200mod intersection_distributivity_tests;
201#[cfg(test)]
202#[path = "../tests/intersection_type_param_tests.rs"]
203mod intersection_type_param_tests;
204#[cfg(test)]
205#[path = "../tests/template_expansion_tests.rs"]
206mod template_expansion_tests;
207#[cfg(test)]
208#[path = "../tests/template_literal_comprehensive_test.rs"]
209mod template_literal_comprehensive_test;
210#[cfg(test)]
211#[path = "../tests/template_literal_subtype_tests.rs"]
212mod template_literal_subtype_tests;
213// tracer_tests: tests are in tracer.rs module
214#[cfg(test)]
215#[path = "../tests/type_law_tests.rs"]
216mod type_law_tests;
217// types_tests: loaded from types.rs
218// union_tests: loaded from subtype.rs
219#[cfg(test)]
220#[path = "../tests/isomorphism_tests.rs"]
221mod isomorphism_tests;
222#[cfg(test)]
223#[path = "../tests/isomorphism_validation.rs"]
224mod isomorphism_validation;
225// solver_refactoring_tests: kept in root crate (depends on checker types)
226#[cfg(test)]
227#[path = "../tests/array_comprehensive_tests.rs"]
228mod array_comprehensive_tests;
229#[cfg(test)]
230#[path = "../tests/async_promise_comprehensive_tests.rs"]
231mod async_promise_comprehensive_tests;
232#[cfg(test)]
233#[path = "../tests/class_comprehensive_tests.rs"]
234mod class_comprehensive_tests;
235#[cfg(test)]
236#[path = "../tests/compound_assignment_tests.rs"]
237mod compound_assignment_tests;
238#[cfg(test)]
239#[path = "../tests/conditional_comprehensive_tests.rs"]
240mod conditional_comprehensive_tests;
241#[cfg(test)]
242#[path = "../tests/function_comprehensive_tests.rs"]
243mod function_comprehensive_tests;
244#[cfg(test)]
245#[path = "../tests/index_access_comprehensive_tests.rs"]
246mod index_access_comprehensive_tests;
247#[cfg(test)]
248#[path = "../tests/interface_comprehensive_tests.rs"]
249mod interface_comprehensive_tests;
250#[cfg(test)]
251#[path = "../tests/keyof_comprehensive_tests.rs"]
252mod keyof_comprehensive_tests;
253#[cfg(test)]
254#[path = "../tests/mapped_comprehensive_tests.rs"]
255mod mapped_comprehensive_tests;
256#[cfg(test)]
257#[path = "../tests/narrowing_comprehensive_tests.rs"]
258mod narrowing_comprehensive_tests;
259#[cfg(test)]
260#[path = "../tests/template_literal_comprehensive_tests.rs"]
261mod template_literal_comprehensive_tests;
262#[cfg(test)]
263#[path = "../tests/tuple_comprehensive_tests.rs"]
264mod tuple_comprehensive_tests;
265#[cfg(test)]
266#[path = "../tests/type_parameter_comprehensive_tests.rs"]
267mod type_parameter_comprehensive_tests;
268#[cfg(test)]
269#[path = "tests/type_queries_contextual_structure_tests.rs"]
270mod type_queries_contextual_structure_tests;
271#[cfg(test)]
272#[path = "tests/type_queries_function_rewrite_tests.rs"]
273mod type_queries_function_rewrite_tests;
274#[cfg(test)]
275#[path = "tests/type_queries_property_names_tests.rs"]
276mod type_queries_property_names_tests;
277#[cfg(test)]
278#[path = "tests/typedata_contract_tests.rs"]
279mod typedata_contract_tests;
280#[cfg(test)]
281#[path = "../tests/union_intersection_comprehensive_tests.rs"]
282mod union_intersection_comprehensive_tests;
283#[cfg(test)]
284#[path = "tests/visitor_tests.rs"]
285mod visitor_tests;