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 (
TypeIdcomparison) - 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§
- AnyPropagation
Rules - Rules for
anypropagation in type checking. - Application
Evaluator - Evaluator for generic type applications.
- Assignability
Failure Analysis - Structured failure details for assignability diagnostics.
- Compat
Checker - Compatibility checker that applies TypeScript’s unsound rules before delegating to the structural subtype engine.
- Const
Assertion Visitor - Visitor that applies
as consttransformation to a type. - Constraint
Set - Constraint set for an inference variable. Tracks both lower bounds (L <: α) and upper bounds (α <: U).
- Contextual
Type Context - Context for contextual typing. Holds the expected type and provides methods to extract type information.
- Default
Judge - Default implementation of the Judge trait.
- Diagnostic
Builder - Builder for creating type error diagnostics.
- Diagnostic
Collector - A diagnostic collector that accumulates diagnostics with source tracking.
- Discriminant
Info - Result of finding discriminant properties in a union.
- Inference
Candidate - A candidate type for an inference variable.
- Inference
Context - Type inference context for a single function call or expression.
- Inference
Info - Value stored for each inference variable root.
- Inference
Var - An inference variable representing an unknown type. These are created when instantiating generic functions.
- Judge
Config - Configuration options for the Judge.
- Narrowing
Cache - Narrowing context for type guards and control flow analysis. Shared across multiple narrowing contexts to persist resolution results.
- Narrowing
Context - Narrowing context for type guards and control flow analysis.
- Narrowing
Result - Result of a narrowing operation.
- Noop
Override Provider - A no-op implementation of
AssignabilityOverrideProviderfor when no checker context is available. - Pending
Diagnostic - A pending diagnostic that hasn’t been rendered yet.
- Pending
Diagnostic Builder - Builder for creating lazy pending diagnostics.
- Primitive
Flags - Flags indicating primitive-like behavior.
- Query
Cache - Query database wrapper with basic caching.
- Recursive
Type Collector - A visitor that recursively collects all types referenced by a root type.
Unlike
TypeCollectorVisitor, this properly traverses into nested structures. - Relation
Cache Stats - Relation
Context - Optional shared context needed by relation engines.
- Relation
Policy - Policy knobs for relation checks.
- Relation
Query Inputs - Bundled inputs for relation queries.
- Relation
Result - Result of a relation check.
- Source
Location - Tracks source locations for AST nodes during type checking.
- Source
Span - A source location span.
- Spanned
Diagnostic Builder - A diagnostic builder that automatically attaches source spans.
- Subtype
Checker - Subtype checking context. Maintains the “seen” set for cycle detection.
- Type
Collector Visitor - Visitor that collects all
TypeIdsreferenced by a type. - Type
Evaluator - Type evaluator for meta-types.
- Type
Factory - Type
Formatter - Context for generating type strings.
- Type
Instantiator - Instantiator for applying type substitutions.
- Type
Interner - Type interning table with lock-free concurrent access.
- Type
Kind Visitor - Visitor that checks if a type is a specific
TypeKind. - Type
Predicate Visitor - Visitor that checks if a type matches a specific predicate.
- Type
Substitution - A substitution map from type parameter names to concrete types.
Enums§
- AnyPropagation
Mode - Controls how
anyis treated during subtype checks. - Application
Result - Result of application type evaluation.
- Callable
Kind - Classification of how a type can be called.
- Conditional
Result - Result of conditional type evaluation
- Constraint
Conflict - Conflict detected between constraints on an inference variable.
- Diagnostic
Arg - Argument for a diagnostic message template.
- Diagnostic
Severity - Diagnostic severity level.
- Inference
Error - Inference error
- Iterable
Kind - Classification of how a type can be iterated.
- Object
Type Kind - Classification of object types for freshness tracking.
- Property
Result - Property access result from the Judge.
- Relation
Cache Probe - Relation
Kind - Relation categories supported by the unified query API.
- Subtype
Failure Reason - Detailed reason for a subtype check failure.
- Subtype
Result - Result of a subtype check
- Truthiness
Kind - Classification of a type’s truthiness behavior.
- Type
Guard - AST-agnostic representation of a type narrowing condition.
- Type
Kind - Classification of types into broad categories.
- Typeof
Kind - The result of a
typeofexpression, 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§
- Assignability
Override Provider - Trait for providing checker-specific assignability overrides.
- Judge
- The Judge trait: pure type algebra queries.
- Query
Database - Query layer for higher-level solver operations.
- Type
Database - Query interface for the solver.
- Type
Visitor - Visitor pattern for
TypeDatatraversal 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
DefIdsreachable fromroot. - collect_
infer_ bindings - Recursively walk the type graph and collect all
Infertype bindings. - collect_
lazy_ def_ ids - Collect all unique lazy
DefIdsreachable fromroot. - 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
infertypes. - contains_
this_ type - Check if a type contains the
thistype 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 (
DefIdand 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
TypeIdof aTypeData. - 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 (
TypeDatabaseversion). - 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 (
TypeDatabaseversion). - is_
generic_ application - Check if a type is a generic type application.
- is_
identity_ comparable_ type - Check if a type can be compared by
TypeIdidentity 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 (
TypeDatabaseversion). - 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 (
TypeDatabaseversion). - 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
thistype. - 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
DefIdif 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
NoInfertype. - 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: removesnull,undefined,void,false,0,"",0nbut keepsboolean,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
ThisTypewith 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).