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>
impl<'a> FlowTypeEvaluator<'a>
Sourcepub fn new(db: &'a dyn QueryDatabase) -> Self
pub fn new(db: &'a dyn QueryDatabase) -> Self
Create a new flow type evaluator
Sourcepub fn compute_narrowed_type(
&self,
original_type: TypeId,
flow_facts: &FlowFacts,
variable_name: &str,
) -> TypeId
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 variableflow_facts: Flow facts gathered from control flow analysisvariable_name: The name of the variable being checked
§Returns
The narrowed type, or the original type if no narrowing applies
Sourcepub fn narrow_by_typeof(
&self,
source_type: TypeId,
typeof_result: &str,
) -> TypeId
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
}Sourcepub fn narrow_by_discriminant(
&self,
union_type: TypeId,
property_path: &[Atom],
literal_value: TypeId,
) -> TypeId
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
}Sourcepub fn narrow_excluding_type(
&self,
source_type: TypeId,
excluded_type: TypeId,
) -> TypeId
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
}Sourcepub fn is_definitely_assigned(
&self,
variable: &str,
flow_facts: &FlowFacts,
) -> bool
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 checkflow_facts: Flow facts gathered from control flow analysis
§Returns
true if the variable is definitely assigned, false otherwise
Sourcepub fn has_tdz_violation(&self, variable: &str, flow_facts: &FlowFacts) -> bool
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 checkflow_facts: Flow facts gathered from control flow analysis
§Returns
true if the variable has a TDZ violation, false otherwise
Sourcepub fn facts_from_assignments(
&self,
assignments: FxHashSet<String>,
) -> FlowFacts
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.