Skip to main content

Module eval

Module eval 

Source
Expand description

Tree-walking evaluator using rnix’s typed AST. Tree-walking Nix evaluator using rnix’s typed AST.

Implements Tvix-style lazy evaluation with thunks: let-bindings and rec-attrset values are wrapped in Value::Thunk and only evaluated when their value is actually needed (call-by-need with memoization).

Structs§

EvalFileGuard
RAII guard that pops the top of the eval-file stack on drop.
SourceIdGuard
RAII guard that restores the previous CURRENT_SOURCE_ID on drop.

Enums§

NixTraceFrame
A single frame in the Nix-level error trace.

Functions§

apply
apply_and_force
Apply a function to an argument.
attach_trace
Capture the current Nix trace and attach it to an error.
current_eval_dir
Return the directory of the file currently being evaluated, if any. Used by the PathRel AST handler to resolve relative path literals.
current_eval_file
Return the file currently being evaluated, if any. Used by error sites to attach source location context.
dump_force_sites
Dump force-site counters (call from perf reporting).
eval
Evaluate a Nix expression string.
eval_expr
Evaluate an rnix expression in an environment.
eval_file_stack_snapshot
Snapshot the entire eval file stack (debug).
eval_with_file
Evaluate a Nix expression string, optionally tagged with the path of the source file. The file is stored on the root Env so that any closure created during evaluation captures it and can resolve relative path literals (./foo.nix) in function defaults that fire after control has left the file’s scope.
force_concrete
Force a value: if it is a thunk, evaluate and memoize the result. Concrete values are returned unchanged. Force a value: if it is a thunk, evaluate and memoize the result. Concrete values are returned unchanged.
force_value
Force a value (legacy API — returns Value for backward compatibility).
force_value_tracked
Force with call-site tracking (legacy API).
is_pure_mode
Whether the current thread is in hermetic (pure) evaluation mode.
normalize_path
Normalize a path by removing . and resolving .. components without touching the filesystem.
push_eval_file
Push a file onto the eval stack. Returns an RAII guard that pops it on drop. Use when entering an import <file> so subsequent relative path literals resolve against the right directory.
push_eval_frame
Push a frame that may be fileless. None means “this code has no source file” and MUST still occupy a stack slot — pushing nothing would leave the caller’s file visible to current_eval_file, which is exactly the unsafeGetAttrPos divergence documented on EVAL_FILE_STACK.
push_source_id
Set CURRENT_SOURCE_ID to id, returning an RAII guard that restores the previous id on drop. Used at thunk force so a cross-file thunk’s idents key the (source_id, offset) symbol cache against the file where the thunk was DEFINED, not the ambient source at force time — the sibling of the eval-file guard, closing the parse.nix cross-file collision.
set_pure_mode
Enable or disable hermetic (pure) evaluation mode for the current thread.