Skip to main content

EvalContext

Struct EvalContext 

Source
pub struct EvalContext {
Show 20 fields pub module_cache: RefCell<BTreeMap<PathBuf, BTreeMap<String, Value>>>, pub embedded_files: RefCell<BTreeMap<PathBuf, Vec<u8>>>, pub current_file: RefCell<Vec<PathBuf>>, pub module_exports: RefCell<Vec<Option<Vec<String>>>>, pub module_load_stack: RefCell<Vec<PathBuf>>, pub call_stack: RefCell<Vec<CallFrame>>, pub span_table: RefCell<HashMap<usize, Span>>, pub eval_depth: Cell<usize>, pub max_eval_depth: Cell<usize>, pub eval_step_limit: Cell<usize>, pub eval_steps: Cell<usize>, pub eval_deadline: Cell<Option<Instant>>, pub sandbox: Sandbox, pub user_context: RefCell<Vec<BTreeMap<Value, Value>>>, pub hidden_context: RefCell<Vec<BTreeMap<Value, Value>>>, pub context_stacks: ContextStacks, pub eval_fn: Cell<Option<EvalCallbackFn>>, pub call_fn: Cell<Option<CallCallbackFn>>, pub call_owned_fn: Cell<Option<CallOwnedCallbackFn>>, pub interactive: Cell<bool>, /* private fields */
}

Fields§

§module_cache: RefCell<BTreeMap<PathBuf, BTreeMap<String, Value>>>§embedded_files: RefCell<BTreeMap<PathBuf, Vec<u8>>>§current_file: RefCell<Vec<PathBuf>>§module_exports: RefCell<Vec<Option<Vec<String>>>>§module_load_stack: RefCell<Vec<PathBuf>>§call_stack: RefCell<Vec<CallFrame>>§span_table: RefCell<HashMap<usize, Span>>§eval_depth: Cell<usize>§max_eval_depth: Cell<usize>§eval_step_limit: Cell<usize>§eval_steps: Cell<usize>§eval_deadline: Cell<Option<Instant>>

Optional wall-clock deadline for evaluation. When set, the bytecode VM periodically checks whether the current time has passed this instant and, if so, abort with an error. Used by the notebook engine to bound how long a single cell evaluation can run.

§sandbox: Sandbox§user_context: RefCell<Vec<BTreeMap<Value, Value>>>§hidden_context: RefCell<Vec<BTreeMap<Value, Value>>>§context_stacks: ContextStacks§eval_fn: Cell<Option<EvalCallbackFn>>§call_fn: Cell<Option<CallCallbackFn>>§call_owned_fn: Cell<Option<CallOwnedCallbackFn>>§interactive: Cell<bool>

Implementations§

Source§

impl EvalContext

Source

pub fn new() -> Self

Source

pub fn new_with_sandbox(sandbox: Sandbox) -> Self

Source

pub fn task_context(&self) -> Option<TaskContextHandle>

Source

pub fn task_context_installed_is(&self, handle: &TaskContextHandle) -> bool

Whether handle is the task context already installed on this thread. A pointer compare, so callers can skip a scoped reinstall (and its extension-map refresh) when the context they would install is the one currently live — the common case for natives invoked inside the task’s own runtime quantum.

Source

pub fn install_task_context( &self, handle: TaskContextHandle, ) -> Option<TaskContextHandle>

Source

pub fn scope_task_context( &self, handle: TaskContextHandle, ) -> TaskContextGuard<'_>

Source

pub fn enter_runtime_quantum( &self, ) -> Result<RuntimeQuantumGuard<'_>, SemaError>

Source

pub fn runtime_quantum_active(&self) -> bool

Source

pub fn take_task_context(&self) -> Option<TaskContextHandle>

Source

pub fn push_file_path(&self, path: PathBuf)

Source

pub fn pop_file_path(&self)

Source

pub fn current_file_dir(&self) -> Option<PathBuf>

Source

pub fn current_file_path(&self) -> Option<PathBuf>

Source

pub fn get_cached_module( &self, path: &PathBuf, ) -> Option<BTreeMap<String, Value>>

Source

pub fn cache_module(&self, path: PathBuf, exports: BTreeMap<String, Value>)

Source

pub fn clear_module_cache(&self)

Source

pub fn embedded_file_exists(&self, path: &PathBuf) -> bool

Source

pub fn get_embedded_file(&self, path: &PathBuf) -> Option<Vec<u8>>

Source

pub fn set_embedded_file(&self, path: PathBuf, bytes: Vec<u8>)

Source

pub fn clear_embedded_files(&self)

Source

pub fn set_embedded_files_only(&self, enabled: bool)

When enabled, import and load may only resolve host-provided embedded files.

Source

pub fn embedded_files_only(&self) -> bool

Source

pub fn set_module_exports(&self, names: Vec<String>)

Source

pub fn clear_module_exports(&self)

Source

pub fn take_module_exports(&self) -> Option<Vec<String>>

Source

pub fn enter_module_load( &self, path: PathBuf, ) -> Result<ModuleLoadGuard<'_>, SemaError>

Enter a module-load scope, guarding against import/load cycles. The returned ModuleLoadGuard pops the load stack when dropped, keeping it balanced on any exit path. Errors if path is already being loaded.

Source

pub fn push_call_frame(&self, frame: CallFrame)

Source

pub fn call_stack_depth(&self) -> usize

Source

pub fn truncate_call_stack(&self, depth: usize)

Source

pub fn capture_stack_trace(&self) -> StackTrace

Source

pub fn merge_span_table(&self, spans: SpanMap)

Source

pub fn lookup_span(&self, ptr: usize) -> Option<Span>

Source

pub fn set_eval_step_limit(&self, limit: usize)

Source

pub fn set_eval_deadline(&self, deadline: Option<Instant>)

Set a wall-clock deadline after which evaluation should abort. Passing None clears any existing deadline.

Source

pub fn deadline_exceeded(&self) -> bool

Returns true if a deadline is set and has been exceeded.

Source

pub fn check_deadline(&self) -> Result<(), SemaError>

Returns an eval error if a deadline is set and exceeded; otherwise Ok(()).

Source

pub fn check_loop_interrupt(&self) -> Result<(), SemaError>

Per-iteration loop/recursion guard, called by the VM at loop back-edges and frame transitions. Counts a step and aborts when:

  • the step limit is exceeded (wasm-safe runaway-loop guard — the wall clock is unavailable in wasm, so the step counter is the guard there);
  • the wall-clock deadline is exceeded (native);
  • a cancellation has been requested (e.g. the playground Stop button).

The step compare runs every call (cheap); the clock read and the cancellation thread-local read run only periodically to keep tight loops fast. eval_steps is reset per top-level eval by the evaluator.

Source

pub fn context_get(&self, key: &Value) -> Option<Value>

Source

pub fn context_set(&self, key: Value, value: Value)

Source

pub fn context_has(&self, key: &Value) -> bool

Source

pub fn context_remove(&self, key: &Value) -> Option<Value>

Source

pub fn context_all(&self) -> BTreeMap<Value, Value>

Source

pub fn context_push_frame(&self)

Source

pub fn context_push_frame_with(&self, bindings: BTreeMap<Value, Value>)

Source

pub fn context_pop_frame(&self)

Source

pub fn context_clear(&self)

Source

pub fn hidden_get(&self, key: &Value) -> Option<Value>

Source

pub fn hidden_set(&self, key: Value, value: Value)

Source

pub fn hidden_has(&self, key: &Value) -> bool

Source

pub fn hidden_push_frame(&self)

Source

pub fn hidden_pop_frame(&self)

Source

pub fn context_stack_push(&self, key: Value, value: Value)

Source

pub fn context_stack_get(&self, key: &Value) -> Vec<Value>

Source

pub fn context_stack_pop(&self, key: &Value) -> Option<Value>

Trait Implementations§

Source§

impl Default for EvalContext

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

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

Source§

type Error = !

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.