Skip to main content

EvalPolicy

Trait EvalPolicy 

Source
pub trait EvalPolicy: Send + Sync {
    // Required methods
    fn name(&self) -> &'static str;
    fn prepare_call_args(
        &self,
        cx: &mut Cx,
        raw: RawArgs,
        demands: &[Demand],
    ) -> Result<PreparedArgs>;
    fn force(&self, cx: &mut Cx, value: Value, demand: Demand) -> Result<Value>;
    fn eval_expr(&self, cx: &mut Cx, expr: Expr) -> Result<Value>;

    // Provided methods
    fn allow_macro_expansion(&self, _phase: Phase) -> bool { ... }
    fn resolve_unbound_symbol(
        &self,
        cx: &mut Cx,
        symbol: Symbol,
    ) -> Result<Value> { ... }
    fn resolve_unbound_call(
        &self,
        cx: &mut Cx,
        operator: Symbol,
        args: Vec<Expr>,
    ) -> Result<Value> { ... }
}
Expand description

The eval-policy contract: how a call site evaluates its arguments and body.

An eval policy decides argument strategy (eager, lazy, by-need, or strict by Demand), whether macro expansion is permitted in a given Phase, how a value is forced to satisfy a demand, and how a bare Expr is evaluated. The kernel ships several reference policies (EagerPolicy, LazyPolicy, NeedPolicy, StrictByShapePolicy, HybridPolicy, NoopEvalPolicy); libraries may supply their own. Concrete language semantics stay out of the kernel.

Required Methods§

Source

fn name(&self) -> &'static str

A stable, human-readable name for this policy.

Source

fn prepare_call_args( &self, cx: &mut Cx, raw: RawArgs, demands: &[Demand], ) -> Result<PreparedArgs>

Prepares raw call arguments into PreparedArgs per the demands.

The per-position demands slice states how strongly each argument must be forced; positions beyond its length take a policy default.

Source

fn force(&self, cx: &mut Cx, value: Value, demand: Demand) -> Result<Value>

Forces value far enough to satisfy demand.

Source

fn eval_expr(&self, cx: &mut Cx, expr: Expr) -> Result<Value>

Evaluates a bare expression to a value under this policy.

Provided Methods§

Source

fn allow_macro_expansion(&self, _phase: Phase) -> bool

Whether macro expansion is permitted in the given Phase.

Defaults to false (no expansion in any phase).

Source

fn resolve_unbound_symbol(&self, cx: &mut Cx, symbol: Symbol) -> Result<Value>

Resolve a symbol that bound to nothing in value position.

The default keeps it as data, which makes eval total and fits the symbolic substrate. A strict language policy can override this to fail.

Source

fn resolve_unbound_call( &self, cx: &mut Cx, operator: Symbol, args: Vec<Expr>, ) -> Result<Value>

Resolve a call whose operator bound to nothing.

The default keeps the unevaluated application as data, matching the symbolic substrate. A strict language policy can override this to fail.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§