pub struct TypeEvaluator<'a, R: TypeResolver = NoopResolver> { /* private fields */ }Expand description
Type evaluator for meta-types.
§Salsa Preparation
This struct uses &mut self methods instead of RefCell + &self.
This makes the evaluator thread-safe (Send) and prepares for future
Salsa integration where state is managed by the database runtime.
Implementations§
Source§impl<'a> TypeEvaluator<'a, NoopResolver>
impl<'a> TypeEvaluator<'a, NoopResolver>
Sourcepub fn new(interner: &'a dyn TypeDatabase) -> Self
pub fn new(interner: &'a dyn TypeDatabase) -> Self
Create a new evaluator without a resolver.
Source§impl<'a, R: TypeResolver> TypeEvaluator<'a, R>
impl<'a, R: TypeResolver> TypeEvaluator<'a, R>
Sourcepub fn with_resolver(interner: &'a dyn TypeDatabase, resolver: &'a R) -> Self
pub fn with_resolver(interner: &'a dyn TypeDatabase, resolver: &'a R) -> Self
Create a new evaluator with a custom resolver.
Sourcepub fn with_query_db(self, db: &'a dyn QueryDatabase) -> Self
pub fn with_query_db(self, db: &'a dyn QueryDatabase) -> Self
Set the query database for Salsa-backed memoization.
pub fn set_no_unchecked_indexed_access(&mut self, enabled: bool)
Source§impl<'a, R: TypeResolver> TypeEvaluator<'a, R>
impl<'a, R: TypeResolver> TypeEvaluator<'a, R>
Sourcepub fn evaluate_conditional(&mut self, initial_cond: &ConditionalType) -> TypeId
pub fn evaluate_conditional(&mut self, initial_cond: &ConditionalType) -> TypeId
Evaluate a conditional type: T extends U ? X : Y
Algorithm:
- If
check_typeis a union and the conditional is distributive, distribute - Otherwise, check if
check_type<:extends_type - If true -> return
true_type - If false (disjoint) -> return
false_type - If ambiguous (unresolved type param) -> return deferred conditional
§Tail-Recursion Elimination
If the chosen branch (true/false) evaluates to another ConditionalType,
we immediately evaluate it in the current stack frame instead of recursing.
This allows tail-recursive patterns to work with up to MAX_TAIL_RECURSION_DEPTH
iterations instead of being limited by MAX_EVALUATE_DEPTH.
Source§impl<'a, R: TypeResolver> TypeEvaluator<'a, R>
impl<'a, R: TypeResolver> TypeEvaluator<'a, R>
Sourcepub fn evaluate_index_access(
&mut self,
object_type: TypeId,
index_type: TypeId,
) -> TypeId
pub fn evaluate_index_access( &mut self, object_type: TypeId, index_type: TypeId, ) -> TypeId
Evaluate an index access type: T[K]
This resolves property access on object types.
Source§impl<'a, R: TypeResolver> TypeEvaluator<'a, R>
impl<'a, R: TypeResolver> TypeEvaluator<'a, R>
Sourcepub fn evaluate_keyof(&mut self, operand: TypeId) -> TypeId
pub fn evaluate_keyof(&mut self, operand: TypeId) -> TypeId
Evaluate keyof T - extract the keys of an object type
Source§impl<'a, R: TypeResolver> TypeEvaluator<'a, R>
impl<'a, R: TypeResolver> TypeEvaluator<'a, R>
Sourcepub fn evaluate_mapped(&mut self, mapped: &MappedType) -> TypeId
pub fn evaluate_mapped(&mut self, mapped: &MappedType) -> TypeId
Evaluate a mapped type: { [K in Keys]: Template }
Algorithm:
- Extract the constraint (Keys) - this defines what keys to iterate over
- For each key K in the constraint:
- Substitute K into the template type
- Apply readonly/optional modifiers
- Construct a new object type with the resulting properties
Source§impl<'a, R: TypeResolver> TypeEvaluator<'a, R>
impl<'a, R: TypeResolver> TypeEvaluator<'a, R>
Sourcepub fn evaluate_template_literal(&mut self, spans: TemplateLiteralId) -> TypeId
pub fn evaluate_template_literal(&mut self, spans: TemplateLiteralId) -> TypeId
Evaluate a template literal type: hello${T}world
Template literals evaluate to a union of all possible literal string combinations.
For example: get${K} where K = “a” | “b” evaluates to “geta” | “getb”
Multiple unions compute a Cartesian product: ${"a"|"b"}-${"x"|"y"} => “a-x”|“a-y”|“b-x”|“b-y”
Sourcepub fn count_literal_members(&self, type_id: TypeId) -> usize
pub fn count_literal_members(&self, type_id: TypeId) -> usize
Count the number of literal members that can be converted to strings. Returns 0 if the type contains non-literal types that cannot be stringified.
Sourcepub fn extract_literal_strings(&self, type_id: TypeId) -> Vec<String>
pub fn extract_literal_strings(&self, type_id: TypeId) -> Vec<String>
Extract string representations from a type. Handles string, number, boolean, and bigint literals, converting them to their string form. For unions, extracts all members recursively.