diff options
author | Vincent Ambo <tazjin@tvl.su> | 2024-02-20T08·29+0700 |
---|---|---|
committer | tazjin <tazjin@tvl.su> | 2024-02-20T09·18+0000 |
commit | 3c87687798a3cfb6c3cfcc231e6c60511e3341ab (patch) | |
tree | 90dd1bb7daefbd09cd308240858689c6a405701f /tvix/eval/src/vm/mod.rs | |
parent | b38badf2063b4eba31abffbeba01c1c8c3212be8 (diff) |
refactor(tvix/eval): add SourceCode directly into error types r/7571
With this change it's no longer necessary to track the SourceCode struct separately from the evaluation for error reporting: It's just stored directly in the errors. This also ends up resolving an issue in compiler::bindings, where we cloned the Arc containing file references way too often. In fact those clones probably compensate for all additional SourceCode clones during error construction now. Change-Id: Ice93bf161e61f8ea3d48103435e20c53e6aa8c3a Reviewed-on: https://cl.tvl.fyi/c/depot/+/10986 Reviewed-by: flokli <flokli@flokli.de> Tested-by: BuildkiteCI
Diffstat (limited to 'tvix/eval/src/vm/mod.rs')
-rw-r--r-- | tvix/eval/src/vm/mod.rs | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/tvix/eval/src/vm/mod.rs b/tvix/eval/src/vm/mod.rs index 0ca72bdf3072..32f0d0456f14 100644 --- a/tvix/eval/src/vm/mod.rs +++ b/tvix/eval/src/vm/mod.rs @@ -36,7 +36,7 @@ use crate::{ }, vm::generators::GenCo, warnings::{EvalWarning, WarningKind}, - NixString, + NixString, SourceCode, }; use generators::{call_functor, Generator, GeneratorState}; @@ -85,15 +85,18 @@ impl<T, S: GetSpan, IO> WithSpan<T, S, IO> for Result<T, ErrorKind> { match self { Ok(something) => Ok(something), Err(kind) => { - let mut error = Error::new(kind, top_span.get_span()); + let mut error = Error::new(kind, top_span.get_span(), vm.source.clone()); // Wrap the top-level error in chaining errors for each element // of the frame stack. for frame in vm.frames.iter().rev() { match frame { Frame::CallFrame { span, .. } => { - error = - Error::new(ErrorKind::BytecodeError(Box::new(error)), span.span()); + error = Error::new( + ErrorKind::BytecodeError(Box::new(error)), + span.span(), + vm.source.clone(), + ); } Frame::Generator { name, span, .. } => { error = Error::new( @@ -102,6 +105,7 @@ impl<T, S: GetSpan, IO> WithSpan<T, S, IO> for Result<T, ErrorKind> { gen_type: name, }, span.span(), + vm.source.clone(), ); } } @@ -275,6 +279,10 @@ struct VM<'o, IO> { // TODO: should probably be based on a file hash pub import_cache: ImportCache, + /// Data structure holding all source code evaluated in this VM, + /// used for pretty error reporting. + source: SourceCode, + /// Parsed Nix search path, which is used to resolve `<...>` /// references. nix_search_path: NixSearchPath, @@ -333,6 +341,7 @@ where nix_search_path: NixSearchPath, io_handle: IO, observer: &'o mut dyn RuntimeObserver, + source: SourceCode, globals: Rc<GlobalsMap>, reasonable_span: LightSpan, ) -> Self { @@ -342,6 +351,7 @@ where observer, globals, reasonable_span, + source, frames: vec![], stack: vec![], with_stack: vec![], @@ -1315,6 +1325,7 @@ pub fn run_lambda<IO>( nix_search_path: NixSearchPath, io_handle: IO, observer: &mut dyn RuntimeObserver, + source: SourceCode, globals: Rc<GlobalsMap>, lambda: Rc<Lambda>, strict: bool, @@ -1334,6 +1345,7 @@ where nix_search_path, io_handle, observer, + source, globals, root_span.into(), ); |