use std::collections::BTreeMap;
use rustc_hash::{FxHashMap as HashMap, FxHashSet as HashSet};
use std::rc::Rc;
use std::sync::{Arc, RwLock, Weak};
use indexmap::IndexMap;
use std::path::{Path, PathBuf};
use crate::capabilities::EvalCapabilities;
use crate::error::{Error, Result};
use crate::lexer;
use crate::parser::{
self, BinOp, Body, Entry, Expr, LocalBindings, Modifier, Module, Property, StringInterpPart,
UnOp,
};
use crate::value::{
CapturedScope, ListKind, ListValue, NameSet, ObjectKind, ObjectMap, ObjectSource,
PoisonedMember, ScopeMap, TypeAliasMap, Value,
};
mod amend;
mod analysis;
mod calls;
mod classes;
mod converters;
mod entries;
mod expr;
mod glob;
mod lambda_guard;
mod listing;
mod loading;
mod mapping;
mod members;
mod module;
mod output;
mod package;
mod parsers;
mod prefetch;
mod remote;
pub(crate) mod render;
mod resource;
mod scope;
mod setup;
pub(crate) mod stdlib;
mod trace;
mod typecheck;
mod types;
use amend::*;
use analysis::*;
use calls::*;
use classes::*;
use entries::*;
use expr::*;
pub use glob::expand_glob;
use glob::*;
use lambda_guard::*;
use listing::*;
use loading::*;
use mapping::*;
use members::*;
use module::*;
pub(crate) use package::write_atomic;
use package::*;
use remote::*;
pub(crate) use remote::{parse_triple_dot_path, resolve_triple_dot};
pub(crate) use resource::file_uri_path;
use resource::{DEFAULT_ALLOWED_RESOURCES, file_uri};
pub(crate) use scope::SourceScope;
use scope::*;
use typecheck::*;
use types::*;
fn cancelled() -> Error {
Error::Eval("evaluation cancelled".to_string())
}
const DYNAMIC_SIBLING_REF: &str = "\0pklr:dynamic-sibling";
const MODULE_OUTPUT_TEXT_CONTEXT: &str = "\0pklr:module-output-text-context";
const QUIET_PASS_MARGIN: usize = 2;
pub struct Evaluator {
base_path: PathBuf,
max_depth: usize,
http_cache: HashMap<String, String>,
import_cache: HashMap<PathBuf, Value>,
imports_in_flight: HashSet<PathBuf>,
placeholder_reads: u64,
narrowed_import_cache: HashMap<(PathBuf, Vec<Name>), Value>,
parse_cache: HashMap<PathBuf, Arc<Module>>,
body_roots_cache: HashMap<usize, (crate::parser::Body, Arc<HashSet<Name>>)>,
plan_cache: HashMap<usize, (crate::parser::Body, Arc<EvaluationPlan>)>,
lambda_guards: HashMap<usize, LambdaGuardEntry>,
lambda_guard_prune_at: usize,
#[cfg(test)]
lambda_guard_prune_scans: usize,
#[cfg(test)]
late_passes_run: usize,
resource_cache: HashMap<String, Value>,
allowed_resources: Vec<String>,
environment: Option<BTreeMap<String, String>>,
external_properties: BTreeMap<String, String>,
module_scopes: HashMap<PathBuf, ModuleScopeSnapshot>,
rendered_member_failed: bool,
env_reads: BTreeMap<String, Option<String>>,
scoped_imports_in_flight: HashSet<PathBuf>,
capabilities: Box<dyn EvalCapabilities>,
cancel: Option<Arc<std::sync::atomic::AtomicBool>>,
#[cfg(feature = "package-zip")]
package_dirs: HashMap<String, PathBuf>,
package_checksums: HashMap<String, String>,
#[cfg(feature = "package-zip")]
verified_packages: HashMap<String, (PathBuf, String)>,
package_cache_dir: Option<PathBuf>,
package_http_roots: HashSet<String>,
prefetch: prefetch::PrefetchState,
offline: bool,
http_rewrites: Vec<(String, String)>,
converters: Vec<(String, Value)>,
builtin_classes: HashMap<&'static str, Value>,
output_props: Vec<Arc<Property>>,
module_output: Option<Value>,
output_sets_value: bool,
output_sets_omit_nulls: bool,
output_format: render::RendererKind,
warned_deprecated: std::collections::HashSet<(String, Option<String>)>,
active_typed_defaults: HashSet<Name>,
mapping_key_values: HashMap<Arc<str>, Value>,
module_names: HashMap<String, String>,
}
#[derive(Clone, Default)]
struct MappingInheritedDefault {
value: Option<Value>,
entries: Option<crate::parser::Body>,
}
#[derive(Clone, Default)]
struct ModuleScopeSnapshot {
values: ScopeMap,
type_aliases: TypeAliasMap,
module_identities: IndexMap<String, String>,
late_properties: Vec<Arc<Property>>,
}
#[cfg(feature = "native-io")]
impl Default for Evaluator {
fn default() -> Self {
Self::new()
}
}
#[cfg(test)]
mod auto_trait_tests {
use super::Evaluator;
#[test]
fn evaluator_is_sync() {
fn assert_sync<T: Sync>() {}
assert_sync::<Evaluator>();
}
}