Skip to main content

Crate tsz_solver

Crate tsz_solver 

Source
Expand description

Query-Based Structural Solver

This module implements a declarative, query-based type solver architecture. It uses:

  • Ena: For unification (Union-Find) in generic type inference
  • Custom TypeData: Structural type representation with interning
  • Cycle Detection: Coinductive semantics for recursive types

Key benefits:

  • O(1) type equality via interning (TypeId comparison)
  • Automatic cycle handling via coinductive semantics
  • Lazy evaluation - only compute types that are queried

Re-exports§

pub use operations::infer_generic_function;
pub use visitor::ConstAssertionVisitor;
pub use visitor::ObjectTypeKind;
pub use visitor::RecursiveTypeCollector;
pub use visitor::TypeCollectorVisitor;
pub use visitor::TypeKind;
pub use visitor::TypeKindVisitor;
pub use visitor::TypePredicateVisitor;
pub use visitor::TypeVisitor;
pub use visitor::application_id;
pub use visitor::array_element_type;
pub use visitor::bound_parameter_index;
pub use visitor::callable_shape_id;
pub use visitor::classify_object_type;
pub use visitor::collect_all_types;
pub use visitor::collect_enum_def_ids;
pub use visitor::collect_lazy_def_ids;
pub use visitor::collect_referenced_types;
pub use visitor::collect_type_queries;
pub use visitor::conditional_type_id;
pub use visitor::contains_error_type;
pub use visitor::contains_infer_types;
pub use visitor::contains_this_type;
pub use visitor::contains_type_matching;
pub use visitor::contains_type_parameters;
pub use visitor::enum_components;
pub use visitor::for_each_child;
pub use visitor::function_shape_id;
pub use visitor::index_access_parts;
pub use visitor::intersection_list_id;
pub use visitor::intrinsic_kind;
pub use visitor::is_array_type;
pub use visitor::is_conditional_type;
pub use visitor::is_empty_object_type;
pub use visitor::is_empty_object_type_db;
pub use visitor::is_enum_type;
pub use visitor::is_error_type;
pub use visitor::is_function_type;
pub use visitor::is_function_type_db;
pub use visitor::is_generic_application;
pub use visitor::is_index_access_type;
pub use visitor::is_intersection_type;
pub use visitor::is_literal_type;
pub use visitor::is_literal_type_db;
pub use visitor::is_mapped_type;
pub use visitor::is_module_namespace_type;
pub use visitor::is_module_namespace_type_db;
pub use visitor::is_object_like_type;
pub use visitor::is_object_like_type_db;
pub use visitor::is_primitive_type;
pub use visitor::is_template_literal_type;
pub use visitor::is_this_type;
pub use visitor::is_tuple_type;
pub use visitor::is_type_kind;
pub use visitor::is_type_parameter;
pub use visitor::is_type_reference;
pub use visitor::is_union_type;
pub use visitor::is_unit_type;
pub use visitor::keyof_inner_type;
pub use visitor::lazy_def_id;
pub use visitor::literal_number;
pub use visitor::literal_string;
pub use visitor::literal_value;
pub use visitor::mapped_type_id;
pub use visitor::module_namespace_symbol_ref;
pub use visitor::no_infer_inner_type;
pub use visitor::object_shape_id;
pub use visitor::object_with_index_shape_id;
pub use visitor::readonly_inner_type;
pub use visitor::recursive_index;
pub use visitor::ref_symbol;
pub use visitor::string_intrinsic_components;
pub use visitor::template_literal_id;
pub use visitor::test_type;
pub use visitor::tuple_list_id;
pub use visitor::type_param_info;
pub use visitor::type_query_symbol;
pub use visitor::union_list_id;
pub use visitor::unique_symbol_ref;
pub use visitor::walk_referenced_types;
pub use operations::AssignabilityChecker;
pub use operations::CallEvaluator;
pub use operations::CallResult;
pub use operations::MAX_CONSTRAINT_RECURSION_DEPTH;
pub use operations::get_contextual_signature_with_compat_checker;
pub use subtype::TypeEnvironment;
pub use subtype::TypeResolver;
pub use types::CallSignature;
pub use types::CallableShapeId;
pub use types::IntrinsicKind;
pub use types::LiteralValue;
pub use types::MappedModifier;
pub use types::ObjectShapeId;
pub use types::PropertyInfo;
pub use types::PropertyLookup;
pub use types::SymbolRef;
pub use types::TypeApplication;
pub use types::TypeApplicationId;
pub use types::TypeData;
pub use types::TypeId;
pub use types::TypeListId;
pub use types::Visibility;
pub use types::is_compiler_managed_type;
pub use types::CallableShape;
pub use types::ConditionalType;
pub use types::FunctionShape;
pub use types::FunctionShapeId;
pub use types::IndexSignature;
pub use types::MappedType;
pub use types::MappedTypeId;
pub use types::ObjectFlags;
pub use types::ObjectShape;
pub use types::OrderedFloat;
pub use types::ParamInfo;
pub use types::RelationCacheKey;
pub use types::TemplateSpan;
pub use types::TupleElement;
pub use types::TupleListId;
pub use types::TypeParamInfo;
pub use types::TypePredicate;
pub use types::TypePredicateTarget;
pub use binary_ops::*;
pub use canonicalize::*;
pub use compat::*;
pub use compound_assignment::*;
pub use def::*;
pub use element_access::*;
pub use freshness::*;
pub use inheritance::*;
pub use judge::*;
pub use objects::*;
pub use relation_queries::*;
pub use sound::*;
pub use unsoundness_audit::*;
pub use variance::*;
pub use widening::*;

Modules§

binary_ops
Binary operation type evaluation.
canonicalize
Canonicalization for structural type identity (Task #32: Graph Isomorphism)
compat
TypeScript compatibility layer for assignability rules.
compound_assignment
def
Definition identifiers and storage for the solver.
element_access
evaluate_rules
Type evaluation rules organized by type category.
expression_ops
Expression type computation operations.
freshness
Freshness helpers for object literal excess property checking.
inheritance
Inheritance Graph Solver
judge
The Judge: Query-based type algebra engine.
objects
Property collection and merging for intersection types.
operations
Type operations and expression evaluation.
operations_generics
Generic type instantiation validation.
operations_iterators
Iterator and async iterator type extraction.
operations_property
Property access resolution (PropertyAccessEvaluator) for resolving property access on types (obj.prop, obj[“key”], etc.).
recursion
Unified recursion guard for cycle detection, depth limiting, and iteration bounding in recursive type computations.
relation_queries
Unified relation query entrypoints.
sound
Sound Mode: Strict type checking beyond TypeScript’s defaults.
tracer
Tracer-based subtype checking.
type_queries
Type Query Functions
type_queries_classifiers
Additional type query classifiers.
type_queries_data
Type Content Queries and Data Extraction Helpers
type_queries_extended
Extended Type Query Functions
type_queries_flow
Control Flow and Advanced Type Classification Queries
type_resolver
Type resolution trait and environment.
types
Type representation for the structural solver.
unsoundness_audit
TypeScript Unsoundness Catalog Implementation Audit
utils
Shared utility functions for the solver module.
variance
Variance calculation for type parameters.
visitor
Type Visitor Pattern
widening
Type widening operations for literal types.

Structs§

AnyPropagationRules
Rules for any propagation in type checking.
ApplicationEvaluator
Evaluator for generic type applications.
ClassTypeBuilder
Builder for constructing class instance types.
ConstraintSet
Constraint set for an inference variable. Tracks both lower bounds (L <: α) and upper bounds (α <: U).
ContextualTypeContext
Context for contextual typing. Holds the expected type and provides methods to extract type information.
DiagnosticBuilder
Builder for creating type error diagnostics.
DiagnosticCollector
A diagnostic collector that accumulates diagnostics with source tracking.
DiscriminantInfo
Result of finding discriminant properties in a union.
FlowFacts
Flow facts that represent the state of variables at a specific program point.
FlowTypeEvaluator
Flow type evaluator that integrates flow analysis with the solver.
IndexSignatureResolver
Resolver for index signature queries on types.
InferenceCandidate
A candidate type for an inference variable.
InferenceContext
Type inference context for a single function call or expression.
InferenceInfo
Value stored for each inference variable root.
InferenceVar
An inference variable representing an unknown type. These are created when instantiating generic functions.
NarrowingCache
Narrowing context for type guards and control flow analysis. Shared across multiple narrowing contexts to persist resolution results.
NarrowingContext
Narrowing context for type guards and control flow analysis.
NarrowingResult
Result of a narrowing operation.
ObjectLiteralBuilder
Builder for constructing object literal types.
PendingDiagnostic
A pending diagnostic that hasn’t been rendered yet.
PendingDiagnosticBuilder
Builder for creating lazy pending diagnostics.
QueryCache
Query database wrapper with basic caching.
RelationCacheStats
SourceLocation
Tracks source locations for AST nodes during type checking.
SourceSpan
A source location span.
SpannedDiagnosticBuilder
A diagnostic builder that automatically attaches source spans.
SubtypeChecker
Subtype checking context. Maintains the “seen” set for cycle detection.
TypeEvaluator
Type evaluator for meta-types.
TypeFactory
TypeFormatter
Context for generating type strings.
TypeInstantiator
Instantiator for applying type substitutions.
TypeInterner
Type interning table with lock-free concurrent access.
TypeSubstitution
A substitution map from type parameter names to concrete types.

Enums§

AnyPropagationMode
Controls how any is treated during subtype checks.
ApparentMemberKind
ApplicationResult
Result of application type evaluation.
ConditionalResult
Result of conditional type evaluation
ConstraintConflict
Conflict detected between constraints on an inference variable.
DiagnosticArg
Argument for a diagnostic message template.
DiagnosticSeverity
Diagnostic severity level.
IndexKind
Distinguishes between string and numeric index signatures.
InferenceError
Inference error
RelationCacheProbe
SubtypeFailureReason
Detailed reason for a subtype check failure.
SubtypeResult
Result of a subtype check
TypeGuard
AST-agnostic representation of a type narrowing condition.
TypeofKind
The result of a typeof expression, restricted to the 8 standard JavaScript types.

Constants§

ARRAY_METHODS_RETURN_ANY
Array methods that return any (used for apparent type computation).
ARRAY_METHODS_RETURN_BOOLEAN
Array methods that return boolean.
ARRAY_METHODS_RETURN_NUMBER
Array methods that return number.
ARRAY_METHODS_RETURN_STRING
Array methods that return string.
ARRAY_METHODS_RETURN_VOID
Array methods that return void.
MAX_CONSTRAINT_ITERATIONS
Maximum iterations for constraint strengthening loops to prevent infinite loops.
MAX_INSTANTIATION_DEPTH
Maximum depth for recursive type instantiation.
MAX_TYPE_RECURSION_DEPTH
Maximum recursion depth for type containment checks.
MAX_VISITING_SET_SIZE
Maximum number of unique types to track in the visiting set. Prevents unbounded memory growth in pathological cases.

Traits§

QueryDatabase
Query layer for higher-level solver operations.
TypeDatabase
Query interface for the solver.

Functions§

apparent_object_member_kind
apparent_primitive_member_kind
apparent_primitive_members
apply_contextual_type
Apply contextual type to infer a more specific type.
are_types_structurally_identical
Check if two types are structurally identical using De Bruijn indices for cycles.
can_be_nullish
Check if a type can be nullish (contains null/undefined/void).
evaluate_conditional
Convenience function for evaluating conditional types
evaluate_index_access
Convenience function for evaluating index access types
evaluate_index_access_with_options
Convenience function for evaluating index access types with options.
evaluate_keyof
Convenience function for evaluating keyof types
evaluate_mapped
Convenience function for evaluating mapped types
evaluate_type
Convenience function for full type evaluation
find_discriminants
Convenience function for finding discriminants.
instantiate_type
Convenience function for instantiating a type with a substitution.
is_definitely_nullish
Check if a type is definitely nullish (only null/undefined/void).
is_nullish_type
Check if a type is nullish (null/undefined/void or union containing them).
is_subtype_of
Convenience function for one-off subtype checks (without resolver)
narrow_by_discriminant
Convenience function for narrowing by discriminant.
narrow_by_typeof
Convenience function for typeof narrowing.
remove_definitely_falsy_types
Remove types that are definitely falsy from a union, without narrowing non-falsy types. This matches TypeScript’s removeDefinitelyFalsyTypes: removes null, undefined, void, false, 0, "", 0n but keeps boolean, string, number, bigint, and object types unchanged.
remove_nullish
Remove nullish parts of a type (non-null assertion).
split_nullish_type
Split a type into its non-nullish part and its nullish cause.
substitute_this_type
Substitute ThisType with a concrete type throughout a type.
type_contains_nullish
Check if a type (possibly a union) contains null or undefined.
type_contains_undefined
Check if a type contains undefined (or void).
would_create_inheritance_cycle
Detects if adding a parent to a child would create a cycle in the inheritance graph.