use rustc_hash::{FxHashMap, FxHashSet};
use std::cell::{Cell, RefCell};
use std::collections::VecDeque;
use std::rc::Rc;
use std::sync::Arc;
use crate::context::{CheckerContext, TypeCache};
use crate::control_flow::FlowGraph;
use tsz_binder::BinderState;
use tsz_common::checker_options::CheckerOptions;
use tsz_parser::parser::node::NodeArena;
use tsz_solver::def::DefinitionStore;
use tsz_solver::{QueryDatabase, TypeEnvironment};
impl<'a> CheckerContext<'a> {
fn normalize_options(
types: &dyn QueryDatabase,
compiler_options: CheckerOptions,
configure_no_unchecked_indexed_access: bool,
) -> CheckerOptions {
if configure_no_unchecked_indexed_access {
types.set_no_unchecked_indexed_access(compiler_options.no_unchecked_indexed_access);
}
compiler_options
}
pub fn new(
arena: &'a NodeArena,
binder: &'a BinderState,
types: &'a dyn QueryDatabase,
file_name: String,
compiler_options: CheckerOptions,
) -> Self {
let compiler_options = Self::normalize_options(types, compiler_options, true);
let flow_graph = Some(FlowGraph::new(&binder.flow_nodes));
CheckerContext {
arena,
binder,
types,
file_name,
compiler_options,
report_unresolved_imports: false,
spelling_suggestions_emitted: 0,
no_implicit_override: false,
symbol_types: FxHashMap::default(),
symbol_instance_types: FxHashMap::default(),
var_decl_types: FxHashMap::default(),
lib_type_resolution_cache: FxHashMap::default(),
node_types: FxHashMap::default(),
type_environment: Rc::new(RefCell::new(TypeEnvironment::new())),
application_eval_set: FxHashSet::default(),
mapped_eval_set: FxHashSet::default(),
flow_analysis_cache: RefCell::new(FxHashMap::default()),
flow_switch_reference_cache: RefCell::new(FxHashMap::default()),
flow_numeric_atom_cache: RefCell::new(FxHashMap::default()),
flow_worklist: RefCell::new(VecDeque::new()),
flow_in_worklist: RefCell::new(FxHashSet::default()),
flow_visited: RefCell::new(FxHashSet::default()),
flow_results: RefCell::new(FxHashMap::default()),
flow_reference_match_cache: RefCell::new(FxHashMap::default()),
narrowing_cache: tsz_solver::NarrowingCache::new(),
call_type_predicates: FxHashMap::default(),
application_symbols_resolved: FxHashSet::default(),
application_symbols_resolution_set: FxHashSet::default(),
class_instance_type_to_decl: FxHashMap::default(),
class_instance_type_cache: FxHashMap::default(),
class_constructor_type_cache: FxHashMap::default(),
class_symbol_to_decl_cache: RefCell::new(FxHashMap::default()),
heritage_symbol_cache: RefCell::new(FxHashMap::default()),
base_constructor_expr_cache: RefCell::new(FxHashMap::default()),
base_instance_expr_cache: RefCell::new(FxHashMap::default()),
class_decl_miss_cache: RefCell::new(FxHashSet::default()),
jsx_intrinsic_props_cache: FxHashMap::default(),
symbol_dependencies: FxHashMap::default(),
symbol_dependency_stack: Vec::new(),
referenced_symbols: std::cell::RefCell::new(FxHashSet::default()),
written_symbols: std::cell::RefCell::new(FxHashSet::default()),
destructured_bindings: FxHashMap::default(),
next_binding_group_id: 0,
has_parse_errors: false,
has_syntax_parse_errors: false,
syntax_parse_error_positions: Vec::new(),
has_real_syntax_errors: false,
diagnostics: Vec::new(),
emitted_diagnostics: FxHashSet::default(),
modules_with_ts2307_emitted: FxHashSet::default(),
symbol_resolution_stack: Vec::new(),
symbol_resolution_set: FxHashSet::default(),
symbol_resolution_depth: Cell::new(0),
max_symbol_resolution_depth: 50,
class_instance_resolution_set: FxHashSet::default(),
class_constructor_resolution_set: FxHashSet::default(),
pending_implicit_any_vars: FxHashMap::default(),
reported_implicit_any_vars: FxHashSet::default(),
inheritance_graph: tsz_solver::classes::inheritance::InheritanceGraph::new(),
node_resolution_stack: Vec::new(),
node_resolution_set: FxHashSet::default(),
checking_classes: FxHashSet::default(),
checked_classes: FxHashSet::default(),
checking_computed_property_name: None,
type_parameter_scope: FxHashMap::default(),
typeof_param_scope: FxHashMap::default(),
contextual_type: None,
is_checking_statements: false,
is_in_ambient_declaration_file: false,
in_destructuring_target: false,
skip_flow_narrowing: false,
instantiation_depth: RefCell::new(0),
depth_exceeded: RefCell::new(false),
recursion_depth: RefCell::new(tsz_solver::recursion::DepthCounter::with_profile(
tsz_solver::recursion::RecursionProfile::CheckerRecursion,
)),
call_depth: RefCell::new(tsz_solver::recursion::DepthCounter::with_profile(
tsz_solver::recursion::RecursionProfile::CallResolution,
)),
return_type_stack: Vec::new(),
yield_type_stack: Vec::new(),
this_type_stack: Vec::new(),
enclosing_class: None,
type_env: RefCell::new(TypeEnvironment::new()),
definition_store: Arc::new(DefinitionStore::new()),
symbol_to_def: RefCell::new(FxHashMap::default()),
def_to_symbol: RefCell::new(FxHashMap::default()),
def_type_params: RefCell::new(FxHashMap::default()),
def_no_type_params: RefCell::new(FxHashSet::default()),
abstract_constructor_types: FxHashSet::default(),
protected_constructor_types: FxHashSet::default(),
private_constructor_types: FxHashSet::default(),
cross_file_symbol_targets: RefCell::new(FxHashMap::default()),
all_arenas: None,
all_binders: None,
resolved_module_paths: None,
current_file_idx: 0,
resolved_modules: None,
module_augmentation_value_decls: FxHashMap::default(),
is_external_module_by_file: None,
resolved_module_errors: None,
import_resolution_stack: Vec::new(),
type_only_nodes: FxHashSet::default(),
lib_contexts: Vec::new(),
actual_lib_file_count: 0,
flow_graph,
async_depth: 0,
inside_closure_depth: 0,
in_const_assertion: false,
preserve_literal_types: false,
iteration_depth: 0,
switch_depth: 0,
function_depth: 0,
is_unreachable: false,
has_reported_unreachable: false,
label_stack: Vec::new(),
had_outer_loop: false,
suppress_definite_assignment_errors: false,
js_body_uses_arguments: false,
emitted_ts2454_errors: FxHashSet::default(),
type_resolution_fuel: RefCell::new(crate::state::MAX_TYPE_RESOLUTION_OPS),
fuel_exhausted: RefCell::new(false),
typeof_resolution_stack: RefCell::new(FxHashSet::default()),
}
}
pub fn new_with_shared_def_store(
arena: &'a NodeArena,
binder: &'a BinderState,
types: &'a dyn QueryDatabase,
file_name: String,
compiler_options: CheckerOptions,
definition_store: Arc<DefinitionStore>,
) -> Self {
let compiler_options = Self::normalize_options(types, compiler_options, true);
let flow_graph = Some(FlowGraph::new(&binder.flow_nodes));
CheckerContext {
arena,
binder,
types,
file_name,
compiler_options,
report_unresolved_imports: false,
spelling_suggestions_emitted: 0,
no_implicit_override: false,
symbol_types: FxHashMap::default(),
symbol_instance_types: FxHashMap::default(),
var_decl_types: FxHashMap::default(),
lib_type_resolution_cache: FxHashMap::default(),
node_types: FxHashMap::default(),
type_environment: Rc::new(RefCell::new(TypeEnvironment::new())),
application_eval_set: FxHashSet::default(),
mapped_eval_set: FxHashSet::default(),
flow_analysis_cache: RefCell::new(FxHashMap::default()),
flow_switch_reference_cache: RefCell::new(FxHashMap::default()),
flow_numeric_atom_cache: RefCell::new(FxHashMap::default()),
flow_worklist: RefCell::new(VecDeque::new()),
flow_in_worklist: RefCell::new(FxHashSet::default()),
flow_visited: RefCell::new(FxHashSet::default()),
flow_results: RefCell::new(FxHashMap::default()),
flow_reference_match_cache: RefCell::new(FxHashMap::default()),
narrowing_cache: tsz_solver::NarrowingCache::new(),
call_type_predicates: FxHashMap::default(),
application_symbols_resolved: FxHashSet::default(),
application_symbols_resolution_set: FxHashSet::default(),
class_instance_type_to_decl: FxHashMap::default(),
class_instance_type_cache: FxHashMap::default(),
class_constructor_type_cache: FxHashMap::default(),
class_symbol_to_decl_cache: RefCell::new(FxHashMap::default()),
heritage_symbol_cache: RefCell::new(FxHashMap::default()),
base_constructor_expr_cache: RefCell::new(FxHashMap::default()),
base_instance_expr_cache: RefCell::new(FxHashMap::default()),
class_decl_miss_cache: RefCell::new(FxHashSet::default()),
jsx_intrinsic_props_cache: FxHashMap::default(),
symbol_dependencies: FxHashMap::default(),
symbol_dependency_stack: Vec::new(),
referenced_symbols: std::cell::RefCell::new(FxHashSet::default()),
written_symbols: std::cell::RefCell::new(FxHashSet::default()),
destructured_bindings: FxHashMap::default(),
next_binding_group_id: 0,
has_parse_errors: false,
has_syntax_parse_errors: false,
syntax_parse_error_positions: Vec::new(),
has_real_syntax_errors: false,
diagnostics: Vec::new(),
emitted_diagnostics: FxHashSet::default(),
modules_with_ts2307_emitted: FxHashSet::default(),
symbol_resolution_stack: Vec::new(),
symbol_resolution_set: FxHashSet::default(),
symbol_resolution_depth: Cell::new(0),
max_symbol_resolution_depth: 50,
class_instance_resolution_set: FxHashSet::default(),
class_constructor_resolution_set: FxHashSet::default(),
pending_implicit_any_vars: FxHashMap::default(),
reported_implicit_any_vars: FxHashSet::default(),
inheritance_graph: tsz_solver::classes::inheritance::InheritanceGraph::new(),
node_resolution_stack: Vec::new(),
node_resolution_set: FxHashSet::default(),
checking_classes: FxHashSet::default(),
checked_classes: FxHashSet::default(),
checking_computed_property_name: None,
type_parameter_scope: FxHashMap::default(),
typeof_param_scope: FxHashMap::default(),
contextual_type: None,
is_checking_statements: false,
is_in_ambient_declaration_file: false,
in_destructuring_target: false,
skip_flow_narrowing: false,
instantiation_depth: RefCell::new(0),
depth_exceeded: RefCell::new(false),
recursion_depth: RefCell::new(tsz_solver::recursion::DepthCounter::with_profile(
tsz_solver::recursion::RecursionProfile::CheckerRecursion,
)),
call_depth: RefCell::new(tsz_solver::recursion::DepthCounter::with_profile(
tsz_solver::recursion::RecursionProfile::CallResolution,
)),
return_type_stack: Vec::new(),
yield_type_stack: Vec::new(),
this_type_stack: Vec::new(),
enclosing_class: None,
type_env: RefCell::new(TypeEnvironment::new()),
definition_store, symbol_to_def: RefCell::new(FxHashMap::default()),
def_to_symbol: RefCell::new(FxHashMap::default()),
def_type_params: RefCell::new(FxHashMap::default()),
def_no_type_params: RefCell::new(FxHashSet::default()),
abstract_constructor_types: FxHashSet::default(),
protected_constructor_types: FxHashSet::default(),
private_constructor_types: FxHashSet::default(),
cross_file_symbol_targets: RefCell::new(FxHashMap::default()),
all_arenas: None,
all_binders: None,
resolved_module_paths: None,
current_file_idx: 0,
resolved_modules: None,
module_augmentation_value_decls: FxHashMap::default(),
is_external_module_by_file: None,
resolved_module_errors: None,
import_resolution_stack: Vec::new(),
type_only_nodes: FxHashSet::default(),
lib_contexts: Vec::new(),
actual_lib_file_count: 0,
flow_graph,
async_depth: 0,
inside_closure_depth: 0,
in_const_assertion: false,
preserve_literal_types: false,
iteration_depth: 0,
switch_depth: 0,
function_depth: 0,
is_unreachable: false,
has_reported_unreachable: false,
label_stack: Vec::new(),
had_outer_loop: false,
suppress_definite_assignment_errors: false,
js_body_uses_arguments: false,
emitted_ts2454_errors: FxHashSet::default(),
type_resolution_fuel: RefCell::new(crate::state::MAX_TYPE_RESOLUTION_OPS),
fuel_exhausted: RefCell::new(false),
typeof_resolution_stack: RefCell::new(FxHashSet::default()),
}
}
pub fn with_options(
arena: &'a NodeArena,
binder: &'a BinderState,
types: &'a dyn QueryDatabase,
file_name: String,
compiler_options: &CheckerOptions,
) -> Self {
let compiler_options = Self::normalize_options(types, compiler_options.clone(), false);
let flow_graph = Some(FlowGraph::new(&binder.flow_nodes));
CheckerContext {
arena,
binder,
types,
file_name,
compiler_options,
report_unresolved_imports: false,
spelling_suggestions_emitted: 0,
no_implicit_override: false,
symbol_types: FxHashMap::default(),
symbol_instance_types: FxHashMap::default(),
var_decl_types: FxHashMap::default(),
lib_type_resolution_cache: FxHashMap::default(),
node_types: FxHashMap::default(),
type_environment: Rc::new(RefCell::new(TypeEnvironment::new())),
application_eval_set: FxHashSet::default(),
mapped_eval_set: FxHashSet::default(),
flow_analysis_cache: RefCell::new(FxHashMap::default()),
flow_switch_reference_cache: RefCell::new(FxHashMap::default()),
flow_numeric_atom_cache: RefCell::new(FxHashMap::default()),
flow_worklist: RefCell::new(VecDeque::new()),
flow_in_worklist: RefCell::new(FxHashSet::default()),
flow_visited: RefCell::new(FxHashSet::default()),
flow_results: RefCell::new(FxHashMap::default()),
flow_reference_match_cache: RefCell::new(FxHashMap::default()),
narrowing_cache: tsz_solver::NarrowingCache::new(),
call_type_predicates: FxHashMap::default(),
application_symbols_resolved: FxHashSet::default(),
application_symbols_resolution_set: FxHashSet::default(),
class_instance_type_to_decl: FxHashMap::default(),
class_instance_type_cache: FxHashMap::default(),
class_constructor_type_cache: FxHashMap::default(),
class_symbol_to_decl_cache: RefCell::new(FxHashMap::default()),
heritage_symbol_cache: RefCell::new(FxHashMap::default()),
base_constructor_expr_cache: RefCell::new(FxHashMap::default()),
base_instance_expr_cache: RefCell::new(FxHashMap::default()),
class_decl_miss_cache: RefCell::new(FxHashSet::default()),
jsx_intrinsic_props_cache: FxHashMap::default(),
symbol_dependencies: FxHashMap::default(),
symbol_dependency_stack: Vec::new(),
referenced_symbols: std::cell::RefCell::new(FxHashSet::default()),
written_symbols: std::cell::RefCell::new(FxHashSet::default()),
destructured_bindings: FxHashMap::default(),
next_binding_group_id: 0,
has_parse_errors: false,
has_syntax_parse_errors: false,
syntax_parse_error_positions: Vec::new(),
has_real_syntax_errors: false,
diagnostics: Vec::new(),
emitted_diagnostics: FxHashSet::default(),
modules_with_ts2307_emitted: FxHashSet::default(),
symbol_resolution_stack: Vec::new(),
symbol_resolution_set: FxHashSet::default(),
symbol_resolution_depth: Cell::new(0),
max_symbol_resolution_depth: 50,
class_instance_resolution_set: FxHashSet::default(),
class_constructor_resolution_set: FxHashSet::default(),
pending_implicit_any_vars: FxHashMap::default(),
reported_implicit_any_vars: FxHashSet::default(),
inheritance_graph: tsz_solver::classes::inheritance::InheritanceGraph::new(),
node_resolution_stack: Vec::new(),
node_resolution_set: FxHashSet::default(),
checking_classes: FxHashSet::default(),
checked_classes: FxHashSet::default(),
checking_computed_property_name: None,
type_parameter_scope: FxHashMap::default(),
typeof_param_scope: FxHashMap::default(),
contextual_type: None,
is_checking_statements: false,
is_in_ambient_declaration_file: false,
in_destructuring_target: false,
skip_flow_narrowing: false,
instantiation_depth: RefCell::new(0),
depth_exceeded: RefCell::new(false),
recursion_depth: RefCell::new(tsz_solver::recursion::DepthCounter::with_profile(
tsz_solver::recursion::RecursionProfile::CheckerRecursion,
)),
call_depth: RefCell::new(tsz_solver::recursion::DepthCounter::with_profile(
tsz_solver::recursion::RecursionProfile::CallResolution,
)),
return_type_stack: Vec::new(),
yield_type_stack: Vec::new(),
this_type_stack: Vec::new(),
enclosing_class: None,
type_env: RefCell::new(TypeEnvironment::new()),
definition_store: Arc::new(DefinitionStore::new()),
symbol_to_def: RefCell::new(FxHashMap::default()),
def_to_symbol: RefCell::new(FxHashMap::default()),
def_type_params: RefCell::new(FxHashMap::default()),
def_no_type_params: RefCell::new(FxHashSet::default()),
abstract_constructor_types: FxHashSet::default(),
protected_constructor_types: FxHashSet::default(),
private_constructor_types: FxHashSet::default(),
cross_file_symbol_targets: RefCell::new(FxHashMap::default()),
all_arenas: None,
all_binders: None,
resolved_module_paths: None,
current_file_idx: 0,
resolved_modules: None,
module_augmentation_value_decls: FxHashMap::default(),
is_external_module_by_file: None,
resolved_module_errors: None,
import_resolution_stack: Vec::new(),
type_only_nodes: FxHashSet::default(),
lib_contexts: Vec::new(),
actual_lib_file_count: 0,
flow_graph,
async_depth: 0,
inside_closure_depth: 0,
in_const_assertion: false,
preserve_literal_types: false,
iteration_depth: 0,
switch_depth: 0,
function_depth: 0,
is_unreachable: false,
has_reported_unreachable: false,
label_stack: Vec::new(),
had_outer_loop: false,
suppress_definite_assignment_errors: false,
js_body_uses_arguments: false,
emitted_ts2454_errors: FxHashSet::default(),
type_resolution_fuel: RefCell::new(crate::state::MAX_TYPE_RESOLUTION_OPS),
fuel_exhausted: RefCell::new(false),
typeof_resolution_stack: RefCell::new(FxHashSet::default()),
}
}
pub fn with_cache(
arena: &'a NodeArena,
binder: &'a BinderState,
types: &'a dyn QueryDatabase,
file_name: String,
cache: TypeCache,
compiler_options: CheckerOptions,
) -> Self {
let compiler_options = compiler_options.apply_strict_defaults();
let flow_graph = Some(FlowGraph::new(&binder.flow_nodes));
CheckerContext {
arena,
binder,
types,
file_name,
compiler_options,
report_unresolved_imports: false,
spelling_suggestions_emitted: 0,
no_implicit_override: false,
symbol_types: cache.symbol_types,
symbol_instance_types: cache.symbol_instance_types,
var_decl_types: FxHashMap::default(),
lib_type_resolution_cache: FxHashMap::default(),
node_types: cache.node_types,
type_environment: Rc::new(RefCell::new(TypeEnvironment::new())),
application_eval_set: FxHashSet::default(),
mapped_eval_set: FxHashSet::default(),
flow_analysis_cache: RefCell::new(cache.flow_analysis_cache),
flow_switch_reference_cache: RefCell::new(FxHashMap::default()),
flow_numeric_atom_cache: RefCell::new(FxHashMap::default()),
flow_worklist: RefCell::new(VecDeque::new()),
flow_in_worklist: RefCell::new(FxHashSet::default()),
flow_visited: RefCell::new(FxHashSet::default()),
flow_results: RefCell::new(FxHashMap::default()),
flow_reference_match_cache: RefCell::new(FxHashMap::default()),
narrowing_cache: tsz_solver::NarrowingCache::new(),
call_type_predicates: FxHashMap::default(),
application_symbols_resolved: FxHashSet::default(),
application_symbols_resolution_set: FxHashSet::default(),
class_instance_type_to_decl: cache.class_instance_type_to_decl,
class_instance_type_cache: cache.class_instance_type_cache,
class_constructor_type_cache: cache.class_constructor_type_cache,
class_symbol_to_decl_cache: RefCell::new(FxHashMap::default()),
heritage_symbol_cache: RefCell::new(FxHashMap::default()),
base_constructor_expr_cache: RefCell::new(FxHashMap::default()),
base_instance_expr_cache: RefCell::new(FxHashMap::default()),
class_decl_miss_cache: RefCell::new(FxHashSet::default()),
jsx_intrinsic_props_cache: FxHashMap::default(),
symbol_dependencies: cache.symbol_dependencies,
symbol_dependency_stack: Vec::new(),
referenced_symbols: std::cell::RefCell::new(FxHashSet::default()),
written_symbols: std::cell::RefCell::new(FxHashSet::default()),
destructured_bindings: FxHashMap::default(),
next_binding_group_id: 0,
has_parse_errors: false,
has_syntax_parse_errors: false,
syntax_parse_error_positions: Vec::new(),
has_real_syntax_errors: false,
diagnostics: Vec::new(),
emitted_diagnostics: FxHashSet::default(),
modules_with_ts2307_emitted: FxHashSet::default(),
symbol_resolution_stack: Vec::new(),
symbol_resolution_set: FxHashSet::default(),
symbol_resolution_depth: Cell::new(0),
max_symbol_resolution_depth: 50,
class_instance_resolution_set: FxHashSet::default(),
class_constructor_resolution_set: FxHashSet::default(),
pending_implicit_any_vars: FxHashMap::default(),
reported_implicit_any_vars: FxHashSet::default(),
inheritance_graph: tsz_solver::classes::inheritance::InheritanceGraph::new(),
node_resolution_stack: Vec::new(),
node_resolution_set: FxHashSet::default(),
checking_classes: FxHashSet::default(),
checked_classes: FxHashSet::default(),
checking_computed_property_name: None,
type_parameter_scope: FxHashMap::default(),
typeof_param_scope: FxHashMap::default(),
contextual_type: None,
is_checking_statements: false,
is_in_ambient_declaration_file: false,
in_destructuring_target: false,
skip_flow_narrowing: false,
instantiation_depth: RefCell::new(0),
depth_exceeded: RefCell::new(false),
recursion_depth: RefCell::new(tsz_solver::recursion::DepthCounter::with_profile(
tsz_solver::recursion::RecursionProfile::CheckerRecursion,
)),
call_depth: RefCell::new(tsz_solver::recursion::DepthCounter::with_profile(
tsz_solver::recursion::RecursionProfile::CallResolution,
)),
return_type_stack: Vec::new(),
yield_type_stack: Vec::new(),
this_type_stack: Vec::new(),
enclosing_class: None,
type_env: RefCell::new(TypeEnvironment::new()),
definition_store: Arc::new(DefinitionStore::new()),
symbol_to_def: RefCell::new(FxHashMap::default()),
def_type_params: RefCell::new(FxHashMap::default()),
def_no_type_params: RefCell::new(FxHashSet::default()),
abstract_constructor_types: FxHashSet::default(),
protected_constructor_types: FxHashSet::default(),
private_constructor_types: FxHashSet::default(),
def_to_symbol: RefCell::new(cache.def_to_symbol),
cross_file_symbol_targets: RefCell::new(FxHashMap::default()),
all_arenas: None,
all_binders: None,
resolved_module_paths: None,
current_file_idx: 0,
resolved_modules: None,
module_augmentation_value_decls: FxHashMap::default(),
is_external_module_by_file: None,
resolved_module_errors: None,
import_resolution_stack: Vec::new(),
type_only_nodes: FxHashSet::default(),
lib_contexts: Vec::new(),
actual_lib_file_count: 0,
flow_graph,
async_depth: 0,
inside_closure_depth: 0,
in_const_assertion: false,
preserve_literal_types: false,
iteration_depth: 0,
switch_depth: 0,
function_depth: 0,
is_unreachable: false,
has_reported_unreachable: false,
label_stack: Vec::new(),
had_outer_loop: false,
suppress_definite_assignment_errors: false,
js_body_uses_arguments: false,
emitted_ts2454_errors: FxHashSet::default(),
type_resolution_fuel: RefCell::new(crate::state::MAX_TYPE_RESOLUTION_OPS),
fuel_exhausted: RefCell::new(false),
typeof_resolution_stack: RefCell::new(FxHashSet::default()),
}
}
pub fn with_cache_and_options(
arena: &'a NodeArena,
binder: &'a BinderState,
types: &'a dyn QueryDatabase,
file_name: String,
cache: TypeCache,
compiler_options: &CheckerOptions,
) -> Self {
let compiler_options = compiler_options.clone().apply_strict_defaults();
let flow_graph = Some(FlowGraph::new(&binder.flow_nodes));
CheckerContext {
arena,
binder,
types,
file_name,
compiler_options,
report_unresolved_imports: false,
spelling_suggestions_emitted: 0,
no_implicit_override: false,
symbol_types: cache.symbol_types,
symbol_instance_types: cache.symbol_instance_types,
var_decl_types: FxHashMap::default(),
lib_type_resolution_cache: FxHashMap::default(),
node_types: cache.node_types,
type_environment: Rc::new(RefCell::new(TypeEnvironment::new())),
application_eval_set: FxHashSet::default(),
mapped_eval_set: FxHashSet::default(),
flow_analysis_cache: RefCell::new(cache.flow_analysis_cache),
flow_switch_reference_cache: RefCell::new(FxHashMap::default()),
flow_numeric_atom_cache: RefCell::new(FxHashMap::default()),
flow_worklist: RefCell::new(VecDeque::new()),
flow_in_worklist: RefCell::new(FxHashSet::default()),
flow_visited: RefCell::new(FxHashSet::default()),
flow_results: RefCell::new(FxHashMap::default()),
flow_reference_match_cache: RefCell::new(FxHashMap::default()),
narrowing_cache: tsz_solver::NarrowingCache::new(),
call_type_predicates: FxHashMap::default(),
application_symbols_resolved: FxHashSet::default(),
application_symbols_resolution_set: FxHashSet::default(),
class_instance_type_to_decl: cache.class_instance_type_to_decl,
class_instance_type_cache: cache.class_instance_type_cache,
class_constructor_type_cache: cache.class_constructor_type_cache,
class_symbol_to_decl_cache: RefCell::new(FxHashMap::default()),
heritage_symbol_cache: RefCell::new(FxHashMap::default()),
base_constructor_expr_cache: RefCell::new(FxHashMap::default()),
base_instance_expr_cache: RefCell::new(FxHashMap::default()),
class_decl_miss_cache: RefCell::new(FxHashSet::default()),
jsx_intrinsic_props_cache: FxHashMap::default(),
symbol_dependencies: cache.symbol_dependencies,
symbol_dependency_stack: Vec::new(),
referenced_symbols: std::cell::RefCell::new(FxHashSet::default()),
written_symbols: std::cell::RefCell::new(FxHashSet::default()),
destructured_bindings: FxHashMap::default(),
next_binding_group_id: 0,
has_parse_errors: false,
has_syntax_parse_errors: false,
syntax_parse_error_positions: Vec::new(),
has_real_syntax_errors: false,
diagnostics: Vec::new(),
emitted_diagnostics: FxHashSet::default(),
modules_with_ts2307_emitted: FxHashSet::default(),
symbol_resolution_stack: Vec::new(),
symbol_resolution_set: FxHashSet::default(),
symbol_resolution_depth: Cell::new(0),
max_symbol_resolution_depth: 50,
class_instance_resolution_set: FxHashSet::default(),
class_constructor_resolution_set: FxHashSet::default(),
pending_implicit_any_vars: FxHashMap::default(),
reported_implicit_any_vars: FxHashSet::default(),
inheritance_graph: tsz_solver::classes::inheritance::InheritanceGraph::new(),
node_resolution_stack: Vec::new(),
node_resolution_set: FxHashSet::default(),
checking_classes: FxHashSet::default(),
checked_classes: FxHashSet::default(),
checking_computed_property_name: None,
type_parameter_scope: FxHashMap::default(),
typeof_param_scope: FxHashMap::default(),
contextual_type: None,
is_checking_statements: false,
is_in_ambient_declaration_file: false,
in_destructuring_target: false,
skip_flow_narrowing: false,
instantiation_depth: RefCell::new(0),
depth_exceeded: RefCell::new(false),
recursion_depth: RefCell::new(tsz_solver::recursion::DepthCounter::with_profile(
tsz_solver::recursion::RecursionProfile::CheckerRecursion,
)),
call_depth: RefCell::new(tsz_solver::recursion::DepthCounter::with_profile(
tsz_solver::recursion::RecursionProfile::CallResolution,
)),
return_type_stack: Vec::new(),
yield_type_stack: Vec::new(),
this_type_stack: Vec::new(),
enclosing_class: None,
type_env: RefCell::new(TypeEnvironment::new()),
definition_store: Arc::new(DefinitionStore::new()),
symbol_to_def: RefCell::new(FxHashMap::default()),
def_type_params: RefCell::new(FxHashMap::default()),
def_no_type_params: RefCell::new(FxHashSet::default()),
abstract_constructor_types: FxHashSet::default(),
protected_constructor_types: FxHashSet::default(),
private_constructor_types: FxHashSet::default(),
def_to_symbol: RefCell::new(cache.def_to_symbol),
cross_file_symbol_targets: RefCell::new(FxHashMap::default()),
all_arenas: None,
all_binders: None,
resolved_module_paths: None,
current_file_idx: 0,
resolved_modules: None,
module_augmentation_value_decls: FxHashMap::default(),
is_external_module_by_file: None,
resolved_module_errors: None,
import_resolution_stack: Vec::new(),
type_only_nodes: FxHashSet::default(),
lib_contexts: Vec::new(),
actual_lib_file_count: 0,
flow_graph,
async_depth: 0,
inside_closure_depth: 0,
in_const_assertion: false,
preserve_literal_types: false,
iteration_depth: 0,
switch_depth: 0,
function_depth: 0,
is_unreachable: false,
has_reported_unreachable: false,
label_stack: Vec::new(),
had_outer_loop: false,
suppress_definite_assignment_errors: false,
js_body_uses_arguments: false,
emitted_ts2454_errors: FxHashSet::default(),
type_resolution_fuel: RefCell::new(crate::state::MAX_TYPE_RESOLUTION_OPS),
fuel_exhausted: RefCell::new(false),
typeof_resolution_stack: RefCell::new(FxHashSet::default()),
}
}
pub fn with_parent_cache(
arena: &'a NodeArena,
binder: &'a BinderState,
types: &'a dyn QueryDatabase,
file_name: String,
compiler_options: CheckerOptions,
parent: &Self,
) -> Self {
let compiler_options = compiler_options.apply_strict_defaults();
let flow_graph = Some(FlowGraph::new(&binder.flow_nodes));
use std::cell::RefCell;
use std::rc::Rc;
CheckerContext {
arena,
binder,
types,
file_name,
compiler_options,
report_unresolved_imports: false,
spelling_suggestions_emitted: 0,
no_implicit_override: parent.no_implicit_override,
symbol_types: parent.symbol_types.clone(),
symbol_instance_types: parent.symbol_instance_types.clone(),
var_decl_types: FxHashMap::default(),
lib_type_resolution_cache: FxHashMap::default(),
node_types: FxHashMap::default(),
type_environment: Rc::new(RefCell::new(TypeEnvironment::new())),
application_eval_set: FxHashSet::default(),
mapped_eval_set: FxHashSet::default(),
flow_analysis_cache: RefCell::new(FxHashMap::default()),
flow_switch_reference_cache: RefCell::new(FxHashMap::default()),
flow_numeric_atom_cache: RefCell::new(FxHashMap::default()),
flow_worklist: RefCell::new(VecDeque::new()),
flow_in_worklist: RefCell::new(FxHashSet::default()),
flow_visited: RefCell::new(FxHashSet::default()),
flow_results: RefCell::new(FxHashMap::default()),
flow_reference_match_cache: RefCell::new(FxHashMap::default()),
narrowing_cache: tsz_solver::NarrowingCache::new(),
call_type_predicates: FxHashMap::default(),
application_symbols_resolved: FxHashSet::default(),
application_symbols_resolution_set: FxHashSet::default(),
class_instance_type_to_decl: FxHashMap::default(),
class_instance_type_cache: FxHashMap::default(),
class_constructor_type_cache: FxHashMap::default(),
class_symbol_to_decl_cache: RefCell::new(FxHashMap::default()),
heritage_symbol_cache: RefCell::new(FxHashMap::default()),
base_constructor_expr_cache: RefCell::new(FxHashMap::default()),
base_instance_expr_cache: RefCell::new(FxHashMap::default()),
class_decl_miss_cache: RefCell::new(FxHashSet::default()),
jsx_intrinsic_props_cache: FxHashMap::default(),
symbol_dependencies: FxHashMap::default(),
symbol_dependency_stack: Vec::new(),
referenced_symbols: std::cell::RefCell::new(FxHashSet::default()),
written_symbols: std::cell::RefCell::new(FxHashSet::default()),
destructured_bindings: FxHashMap::default(),
next_binding_group_id: 0,
has_parse_errors: false,
has_syntax_parse_errors: false,
syntax_parse_error_positions: Vec::new(),
has_real_syntax_errors: false,
diagnostics: Vec::new(),
emitted_diagnostics: FxHashSet::default(),
modules_with_ts2307_emitted: FxHashSet::default(),
symbol_resolution_stack: Vec::new(),
symbol_resolution_set: FxHashSet::default(),
symbol_resolution_depth: Cell::new(parent.symbol_resolution_depth.get()),
max_symbol_resolution_depth: 50,
class_instance_resolution_set: FxHashSet::default(),
class_constructor_resolution_set: FxHashSet::default(),
pending_implicit_any_vars: FxHashMap::default(),
reported_implicit_any_vars: FxHashSet::default(),
inheritance_graph: tsz_solver::classes::inheritance::InheritanceGraph::new(),
node_resolution_stack: Vec::new(),
node_resolution_set: FxHashSet::default(),
checking_classes: FxHashSet::default(),
checked_classes: FxHashSet::default(),
checking_computed_property_name: None,
type_parameter_scope: FxHashMap::default(),
typeof_param_scope: FxHashMap::default(),
contextual_type: None,
is_checking_statements: false,
is_in_ambient_declaration_file: false,
in_destructuring_target: false,
skip_flow_narrowing: false,
instantiation_depth: RefCell::new(0),
depth_exceeded: RefCell::new(false),
recursion_depth: RefCell::new(tsz_solver::recursion::DepthCounter::with_initial_depth(
tsz_solver::recursion::RecursionProfile::CheckerRecursion.max_depth(),
parent.recursion_depth.borrow().depth(),
)),
call_depth: RefCell::new(tsz_solver::recursion::DepthCounter::with_profile(
tsz_solver::recursion::RecursionProfile::CallResolution,
)),
return_type_stack: Vec::new(),
yield_type_stack: Vec::new(),
this_type_stack: Vec::new(),
enclosing_class: None,
type_env: RefCell::new(TypeEnvironment::new()),
definition_store: std::sync::Arc::clone(&parent.definition_store),
symbol_to_def: RefCell::new(FxHashMap::default()),
def_type_params: RefCell::new(FxHashMap::default()),
def_no_type_params: RefCell::new(FxHashSet::default()),
abstract_constructor_types: FxHashSet::default(),
protected_constructor_types: FxHashSet::default(),
private_constructor_types: FxHashSet::default(),
def_to_symbol: RefCell::new(FxHashMap::default()),
cross_file_symbol_targets: RefCell::new(FxHashMap::default()),
all_arenas: None,
all_binders: None,
resolved_module_paths: None,
current_file_idx: 0,
resolved_modules: None,
module_augmentation_value_decls: FxHashMap::default(),
is_external_module_by_file: None,
resolved_module_errors: None,
import_resolution_stack: Vec::new(),
type_only_nodes: FxHashSet::default(),
lib_contexts: Vec::new(),
actual_lib_file_count: 0,
flow_graph,
async_depth: 0,
inside_closure_depth: 0,
in_const_assertion: false,
preserve_literal_types: false,
iteration_depth: 0,
switch_depth: 0,
function_depth: 0,
is_unreachable: false,
has_reported_unreachable: false,
label_stack: Vec::new(),
had_outer_loop: false,
suppress_definite_assignment_errors: false,
js_body_uses_arguments: false,
emitted_ts2454_errors: FxHashSet::default(),
type_resolution_fuel: RefCell::new(crate::state::MAX_TYPE_RESOLUTION_OPS),
fuel_exhausted: RefCell::new(false),
typeof_resolution_stack: RefCell::new(FxHashSet::default()),
}
}
}