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 operations::widening;
pub use operations::compound_assignment;
pub use operations::expression_ops;
pub use operations::AssignabilityChecker;
pub use operations::BinaryOpEvaluator;
pub use operations::BinaryOpResult;
pub use operations::CallEvaluator;
pub use operations::CallResult;
pub use operations::MAX_CONSTRAINT_RECURSION_DEPTH;
pub use operations::PrimitiveClass;
pub use operations::get_contextual_signature_with_compat_checker;
pub use relations::subtype::TypeEnvironment;
pub use relations::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 canonicalize::*;
pub use classes::class_hierarchy::*;
pub use classes::inheritance::*;
pub use def::*;
pub use objects::*;
pub use operations::compound_assignment::*;
pub use operations::expression_ops::*;
pub use unsoundness_audit::*;
pub use widening::*;

Modules§

canonicalize
Canonicalization for structural type identity (Task #32: Graph Isomorphism)
classes
Class hierarchy and inheritance graph.
def
Definition identifiers and storage for the solver.
evaluation
judge
objects
Object property query ecosystem.
operations
Type operations and expression evaluation.
recursion
Unified recursion guard for cycle detection, depth limiting, and iteration bounding in recursive type computations.
relations
type_queries
Type Query Functions
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.
visitor

Structs§

AnyPropagationRules
Rules for any propagation in type checking.
ApplicationEvaluator
Evaluator for generic type applications.
AssignabilityFailureAnalysis
Structured failure details for assignability diagnostics.
CompatChecker
Compatibility checker that applies TypeScript’s unsound rules before delegating to the structural subtype engine.
ConstAssertionVisitor
Visitor that applies as const transformation to a type.
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.
DefaultJudge
Default implementation of the Judge trait.
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.
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.
JudgeConfig
Configuration options for the Judge.
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.
NoopOverrideProvider
A no-op implementation of AssignabilityOverrideProvider for when no checker context is available.
PendingDiagnostic
A pending diagnostic that hasn’t been rendered yet.
PendingDiagnosticBuilder
Builder for creating lazy pending diagnostics.
PrimitiveFlags
Flags indicating primitive-like behavior.
QueryCache
Query database wrapper with basic caching.
RecursiveTypeCollector
A visitor that recursively collects all types referenced by a root type. Unlike TypeCollectorVisitor, this properly traverses into nested structures.
RelationCacheStats
RelationContext
Optional shared context needed by relation engines.
RelationPolicy
Policy knobs for relation checks.
RelationQueryInputs
Bundled inputs for relation queries.
RelationResult
Result of a relation check.
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.
TypeCollectorVisitor
Visitor that collects all TypeIds referenced by a type.
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.
TypeKindVisitor
Visitor that checks if a type is a specific TypeKind.
TypePredicateVisitor
Visitor that checks if a type matches a specific predicate.
TypeSubstitution
A substitution map from type parameter names to concrete types.

Enums§

AnyPropagationMode
Controls how any is treated during subtype checks.
ApplicationResult
Result of application type evaluation.
CallableKind
Classification of how a type can be called.
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.
InferenceError
Inference error
IterableKind
Classification of how a type can be iterated.
ObjectTypeKind
Classification of object types for freshness tracking.
PropertyResult
Property access result from the Judge.
RelationCacheProbe
RelationKind
Relation categories supported by the unified query API.
SubtypeFailureReason
Detailed reason for a subtype check failure.
SubtypeResult
Result of a subtype check
TruthinessKind
Classification of a type’s truthiness behavior.
TypeGuard
AST-agnostic representation of a type narrowing condition.
TypeKind
Classification of types into broad categories.
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§

AssignabilityOverrideProvider
Trait for providing checker-specific assignability overrides.
Judge
The Judge trait: pure type algebra queries.
QueryDatabase
Query layer for higher-level solver operations.
TypeDatabase
Query interface for the solver.
TypeVisitor
Visitor pattern for TypeData traversal and transformation.

Functions§

analyze_assignability_failure_with_resolver
Analyze assignability failure details using a configured compat checker.
application_id
Extract the application id if this is a generic application type.
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.
array_element_type
Extract the array element type if this is an array type.
bound_parameter_index
Extract the De Bruijn index if this is a bound type parameter.
callable_shape_id
Extract the callable shape id if this is a callable type.
classify_object_type
Classify a type as an object type kind.
collect_all_types
Collect all types recursively reachable from a root type.
collect_enum_def_ids
Collect all unique enum DefIds reachable from root.
collect_infer_bindings
Recursively walk the type graph and collect all Infer type bindings.
collect_lazy_def_ids
Collect all unique lazy DefIds reachable from root.
collect_referenced_types
Collect all types referenced by a type.
collect_type_queries
Collect all unique type-query symbol references reachable from root.
conditional_type_id
Extract the conditional type id if this is a conditional type.
contains_error_type
Check if a type contains the error type.
contains_infer_types
Check if a type contains any infer types.
contains_this_type
Check if a type contains the this type anywhere.
contains_type_matching
Check if a type contains any type matching a predicate.
contains_type_parameters
Check if a type contains any type parameters.
enum_components
Extract the enum components (DefId and member type) if this is an Enum type.
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.
for_each_child
Invoke a function on each immediate child TypeId of a TypeData.
for_each_child_by_id
Walk all transitively referenced type IDs from root.
function_shape_id
Extract the function shape id if this is a function type.
index_access_parts
Extract index access components if this is an index access type.
instantiate_type
Convenience function for instantiating a type with a substitution.
intersection_list_id
Extract the intersection list id if this is an intersection type.
intrinsic_kind
Extract the intrinsic kind if this is an intrinsic type.
is_array_type
Check if a type is an array type.
is_conditional_type
Check if a type is a conditional type.
is_definitely_nullish
Check if a type is definitely nullish (only null/undefined/void).
is_empty_object_type
Check if a type is an empty object type (no properties, no index signatures).
is_empty_object_type_db
Check if a type is an empty object type (TypeDatabase version).
is_enum_type
Check if this is an Enum type.
is_error_type
Check whether this is an explicit error type.
is_function_type
Check if a type is a function type (Function or Callable).
is_function_type_db
Check if a type is a function type (TypeDatabase version).
is_generic_application
Check if a type is a generic type application.
is_identity_comparable_type
Check if a type can be compared by TypeId identity alone (O(1) equality).
is_index_access_type
Check if a type is an index access type.
is_intersection_type
Check if a type is an intersection type.
is_literal_type
Check if a type is a literal type.
is_literal_type_db
Check if a type is a literal type (TypeDatabase version).
is_mapped_type
Check if a type is a mapped type.
is_module_namespace_type
Check if a type is a module namespace type (import * as ns).
is_nullish_type
Check if a type is nullish (null/undefined/void or union containing them).
is_object_like_type
Check if a type is an object-like type (suitable for typeof “object”).
is_object_like_type_db
Check if a type is object-like (TypeDatabase version).
is_primitive_type
Check if a type is a primitive type (intrinsic or literal).
is_subtype_of
Convenience function for one-off subtype checks (without resolver)
is_template_literal_type
Check if a type is a template literal type.
is_this_type
Check if a type is the special this type.
is_tuple_type
Check if a type is a tuple type.
is_type_kind
Check if a type is a specific kind using the TypeKindVisitor.
is_type_parameter
Check if a type is a type parameter.
is_type_reference
Check if a type is a type reference (Lazy/DefId).
is_union_type
Check if a type is a union type.
keyof_inner_type
Extract the inner type if this is a keyof type.
lazy_def_id
Extract the lazy DefId if this is a Lazy type.
literal_number
Extract the numeric literal if this is a number literal type.
literal_string
Extract the string literal atom if this is a string literal type.
literal_value
Extract the literal value if this is a literal type.
mapped_type_id
Extract the mapped type id if this is a mapped type.
module_namespace_symbol_ref
Extract the module namespace symbol ref if this is a module namespace type.
narrow_by_discriminant
Convenience function for narrowing by discriminant.
narrow_by_typeof
Convenience function for typeof narrowing.
no_infer_inner_type
Extract the inner type if this is a NoInfer type.
object_shape_id
Extract the object shape id if this is an object type.
object_with_index_shape_id
Extract the object-with-index shape id if this is an indexed object type.
query_relation
Query a relation using a no-op resolver and no overrides.
query_relation_with_overrides
Query a relation using a custom resolver and checker-provided overrides.
query_relation_with_resolver
Query a relation using a custom resolver and no checker overrides.
readonly_inner_type
Extract the inner type if this is a readonly type.
recursive_index
Extract the De Bruijn index if this is a recursive type reference.
ref_symbol
Extract the type reference symbol if this is a Ref type.
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.
string_intrinsic_components
Extract string intrinsic components if this is a string intrinsic type.
substitute_this_type
Substitute ThisType with a concrete type throughout a type.
template_literal_id
Extract the template literal list id if this is a template literal type.
test_type
Test a type against a predicate function.
tuple_list_id
Extract the tuple list id if this is a tuple type.
type_contains_undefined
Check if a type contains undefined (or void).
type_param_info
Extract the type parameter info if this is a type parameter or infer type.
type_query_symbol
Extract the type query symbol if this is a TypeQuery.
union_list_id
Extract the union list id if this is a union type.
unique_symbol_ref
Extract the unique symbol ref if this is a unique symbol type.
walk_referenced_types
The callback is invoked once per unique reachable type (including root).