Skip to main content

FlowTypeEvaluator

Struct FlowTypeEvaluator 

Source
pub struct FlowTypeEvaluator<'a> { /* private fields */ }
Expand description

Flow type evaluator that integrates flow analysis with the solver.

This evaluator uses the solver’s type operations to compute narrowed types based on flow facts gathered during control flow analysis.

Implementations§

Source§

impl<'a> FlowTypeEvaluator<'a>

Source

pub fn new(db: &'a dyn QueryDatabase) -> Self

Create a new flow type evaluator

Source

pub fn compute_narrowed_type( &self, original_type: TypeId, flow_facts: &FlowFacts, variable_name: &str, ) -> TypeId

Compute the narrowed type for a variable based on flow facts.

This integrates with the solver’s narrowing logic to apply type guards (typeof checks, discriminant checks, null checks) to produce a refined type.

§Arguments
  • original_type: The declared type of the variable
  • flow_facts: Flow facts gathered from control flow analysis
  • variable_name: The name of the variable being checked
§Returns

The narrowed type, or the original type if no narrowing applies

Source

pub fn narrow_by_typeof( &self, source_type: TypeId, typeof_result: &str, ) -> TypeId

Narrow a type based on a typeof guard.

This is used when flow analysis encounters a typeof check:

if (typeof x === "string") {
    // x is narrowed to string
}
Source

pub fn narrow_by_discriminant( &self, union_type: TypeId, property_path: &[Atom], literal_value: TypeId, ) -> TypeId

Narrow a type based on a discriminant check.

This is used for discriminated unions:

if (action.type === "add") {
    // action is narrowed to the "add" variant
}
Source

pub fn narrow_excluding_type( &self, source_type: TypeId, excluded_type: TypeId, ) -> TypeId

Narrow a type by excluding a specific type.

This is used for negative type guards:

if (x !== null) {
    // x is narrowed to non-null
}
Source

pub fn is_definitely_assigned( &self, variable: &str, flow_facts: &FlowFacts, ) -> bool

Check if a variable is definitely assigned at this point.

This integrates with the flow analysis to determine if a variable has been assigned on all control flow paths leading to this point.

§Arguments
  • variable: The name of the variable to check
  • flow_facts: Flow facts gathered from control flow analysis
§Returns

true if the variable is definitely assigned, false otherwise

Source

pub fn has_tdz_violation(&self, variable: &str, flow_facts: &FlowFacts) -> bool

Check if a variable has a TDZ (Temporal Dead Zone) violation.

TDZ violations occur when a variable is used before its declaration:

console.log(x); // TDZ violation!
let x;
§Arguments
  • variable: The name of the variable to check
  • flow_facts: Flow facts gathered from control flow analysis
§Returns

true if the variable has a TDZ violation, false otherwise

Source

pub fn facts_from_assignments( &self, assignments: FxHashSet<String>, ) -> FlowFacts

Create flow facts from a set of definite assignments.

This is a convenience method for creating FlowFacts when you only have definite assignment information.

Source

pub fn facts_from_narrowings( &self, narrowings: FxHashMap<String, TypeId>, ) -> FlowFacts

Create flow facts from a set of type narrowings.

This is a convenience method for creating FlowFacts when you only have type narrowing information.

Auto Trait Implementations§

§

impl<'a> !Freeze for FlowTypeEvaluator<'a>

§

impl<'a> !RefUnwindSafe for FlowTypeEvaluator<'a>

§

impl<'a> !Send for FlowTypeEvaluator<'a>

§

impl<'a> !Sync for FlowTypeEvaluator<'a>

§

impl<'a> Unpin for FlowTypeEvaluator<'a>

§

impl<'a> UnsafeUnpin for FlowTypeEvaluator<'a>

§

impl<'a> !UnwindSafe for FlowTypeEvaluator<'a>

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