diff options
author | Aspen Smith <root@gws.fyi> | 2024-08-11T15·15-0400 |
---|---|---|
committer | clbot <clbot@tvl.fyi> | 2024-10-12T12·27+0000 |
commit | b7a6fc2812f3ed281ba1a0b985a2ae150095f7b1 (patch) | |
tree | 8a7703be32a79fc8a6faa03385469efa24fe8be4 /tvix/eval/src/vm/mod.rs | |
parent | 934e03c0deb88b3a0cff2e407e28f134c29657af (diff) |
refactor(tvix/eval): Make `strict` an EvalMode enum r/8796
Refactor the `strict` boolean passed into evaluation at the top-level to be a (two-variant, so far) EvalMode enum of Lazy and Strict. This is more explicit than a boolean, and if we ever add more EvalModes it's a simple extension of the enum. Change-Id: I3de50e74ec971011664f6cd0999d08b792118410 Reviewed-on: https://cl.tvl.fyi/c/depot/+/12186 Tested-by: BuildkiteCI Reviewed-by: flokli <flokli@flokli.de> Autosubmit: aspen <root@gws.fyi>
Diffstat (limited to 'tvix/eval/src/vm/mod.rs')
-rw-r--r-- | tvix/eval/src/vm/mod.rs | 19 |
1 files changed, 16 insertions, 3 deletions
diff --git a/tvix/eval/src/vm/mod.rs b/tvix/eval/src/vm/mod.rs index 49e9fc5864be..0630ed4174e8 100644 --- a/tvix/eval/src/vm/mod.rs +++ b/tvix/eval/src/vm/mod.rs @@ -1378,6 +1378,18 @@ async fn final_deep_force(co: GenCo) -> Result<Value, ErrorKind> { Ok(generators::request_deep_force(&co, value).await) } +/// Specification for how to handle top-level values returned by evaluation +#[derive(Debug, Clone, Copy, Default)] +pub enum EvalMode { + /// The default. Values are returned from evaluations as-is, without any extra forcing or + /// special handling. + #[default] + Lazy, + + /// Strictly and deeply evaluate top-level values returned by evaluation. + Strict, +} + pub fn run_lambda<IO>( nix_search_path: NixSearchPath, io_handle: IO, @@ -1385,7 +1397,7 @@ pub fn run_lambda<IO>( source: SourceCode, globals: Rc<GlobalsMap>, lambda: Rc<Lambda>, - strict: bool, + mode: EvalMode, ) -> EvalResult<RuntimeResult> where IO: AsRef<dyn EvalIO> + 'static, @@ -1409,8 +1421,9 @@ where // When evaluating strictly, synthesise a frame that will instruct // the VM to deep-force the final value before returning it. - if strict { - vm.enqueue_generator("final_deep_force", root_span, final_deep_force); + match mode { + EvalMode::Lazy => {} + EvalMode::Strict => vm.enqueue_generator("final_deep_force", root_span, final_deep_force), } vm.frames.push(Frame::CallFrame { |