Skip to main content

TypeEvaluator

Struct TypeEvaluator 

Source
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>

Source

pub fn new(interner: &'a dyn TypeDatabase) -> Self

Create a new evaluator without a resolver.

Source§

impl<'a, R: TypeResolver> TypeEvaluator<'a, R>

Source

pub fn with_resolver(interner: &'a dyn TypeDatabase, resolver: &'a R) -> Self

Create a new evaluator with a custom resolver.

Source

pub fn with_query_db(self, db: &'a dyn QueryDatabase) -> Self

Set the query database for Salsa-backed memoization.

Source

pub fn set_no_unchecked_indexed_access(&mut self, enabled: bool)

Source

pub fn reset(&mut self)

Reset per-evaluation state so this evaluator can be reused.

Clears the cache, cycle detection sets, and counters while preserving configuration and borrowed references. Uses .clear() to reuse memory.

Source

pub const fn is_depth_exceeded(&self) -> bool

Check if depth limit was exceeded.

Source

pub fn evaluate(&mut self, type_id: TypeId) -> TypeId

Evaluate a type, resolving any meta-types if possible. Returns the evaluated type (may be the same if no evaluation needed).

Source§

impl<'a, R: TypeResolver> TypeEvaluator<'a, R>

Source

pub fn evaluate_conditional(&mut self, initial_cond: &ConditionalType) -> TypeId

Evaluate a conditional type: T extends U ? X : Y

Algorithm:

  1. If check_type is a union and the conditional is distributive, distribute
  2. Otherwise, check if check_type <: extends_type
  3. If true -> return true_type
  4. If false (disjoint) -> return false_type
  5. 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>

Source

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>

Source

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>

Source

pub fn evaluate_mapped(&mut self, mapped: &MappedType) -> TypeId

Evaluate a mapped type: { [K in Keys]: Template }

Algorithm:

  1. Extract the constraint (Keys) - this defines what keys to iterate over
  2. For each key K in the constraint:
    • Substitute K into the template type
    • Apply readonly/optional modifiers
  3. Construct a new object type with the resulting properties
Source§

impl<'a, R: TypeResolver> TypeEvaluator<'a, R>

Source

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”

Source

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.

Source

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.

Auto Trait Implementations§

§

impl<'a, R> Freeze for TypeEvaluator<'a, R>

§

impl<'a, R = NoopResolver> !RefUnwindSafe for TypeEvaluator<'a, R>

§

impl<'a, R = NoopResolver> !Send for TypeEvaluator<'a, R>

§

impl<'a, R = NoopResolver> !Sync for TypeEvaluator<'a, R>

§

impl<'a, R> Unpin for TypeEvaluator<'a, R>

§

impl<'a, R> UnsafeUnpin for TypeEvaluator<'a, R>

§

impl<'a, R = NoopResolver> !UnwindSafe for TypeEvaluator<'a, R>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<S, T> Upcast<T> for S
where T: UpcastFrom<S> + ?Sized, S: ?Sized,

Source§

fn upcast(&self) -> &T
where Self: ErasableGeneric, T: ErasableGeneric<Repr = Self::Repr>,

Perform a zero-cost type-safe upcast to a wider ref type within the Wasm bindgen generics type system. Read more
Source§

fn upcast_into(self) -> T
where Self: Sized + ErasableGeneric, T: ErasableGeneric<Repr = Self::Repr>,

Perform a zero-cost type-safe upcast to a wider type within the Wasm bindgen generics type system. Read more
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more