diff options
author | Vincent Ambo <mail@tazj.in> | 2022-09-01T20·50+0300 |
---|---|---|
committer | tazjin <tazjin@tvl.su> | 2022-09-08T07·59+0000 |
commit | 377ba19d75a0354c51d73dd38c4a29feefcc68e4 (patch) | |
tree | 75cc9b21752a29c5b6b35db7530540b84bb78642 /tvix/eval/src/value/thunk.rs | |
parent | 197fe37daef242596900bcab948d6fc14348f910 (diff) |
feat(tvix/eval): ensure all errors always carry a span r/4741
Previously error spans were optional because the information about code spans was not available at runtime. Now that this information has been added, the error type will always carry a span. This change is very invasive all throughout the codebase. This is due to the fact that many functions that are called *by* the VM expected to return `EvalResult`, but this no longer works as the span information is not available to those functions - only to the VM itself. To work around this the majority of these functions have been changed to return `Result<T, ErrorKind>` instead and an accompanying macro in the VM constructs the "real" error. Note that this implementatino currently has a bug where errors occuring within thunks will yield the location at which the thunk was forced, not the location at which the error occured within the code. This will be fixed soon, but the commit is large enough as is. Change-Id: Ib1ecb81a4d09d464a95ea7ea9e589f3bd08d5202 Reviewed-on: https://cl.tvl.fyi/c/depot/+/6408 Reviewed-by: sterni <sternenseemann@systemli.org> Tested-by: BuildkiteCI
Diffstat (limited to 'tvix/eval/src/value/thunk.rs')
-rw-r--r-- | tvix/eval/src/value/thunk.rs | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/tvix/eval/src/value/thunk.rs b/tvix/eval/src/value/thunk.rs index 307eb23a75f6..c2552284fe20 100644 --- a/tvix/eval/src/value/thunk.rs +++ b/tvix/eval/src/value/thunk.rs @@ -24,7 +24,7 @@ use std::{ rc::Rc, }; -use crate::{errors::ErrorKind, upvalues::UpvalueCarrier, vm::VM, EvalResult, Value}; +use crate::{errors::ErrorKind, upvalues::UpvalueCarrier, vm::VM, Value}; use super::Lambda; @@ -64,7 +64,7 @@ impl Thunk { /// to it, providing memoization) through interior mutability. In /// case of nested thunks, the intermediate thunk representations /// are replaced. - pub fn force(&self, vm: &mut VM) -> EvalResult<()> { + pub fn force(&self, vm: &mut VM) -> Result<(), ErrorKind> { // Due to mutable borrowing rules, the following code can't // easily use a match statement or something like that; it // requires a bit of manual fiddling. @@ -78,14 +78,16 @@ impl Thunk { } ThunkRepr::Evaluated(_) => return Ok(()), - ThunkRepr::Blackhole => return Err(ErrorKind::InfiniteRecursion.into()), + ThunkRepr::Blackhole => return Err(ErrorKind::InfiniteRecursion), ThunkRepr::Suspended { .. } => { if let ThunkRepr::Suspended { lambda, upvalues } = std::mem::replace(&mut *thunk_mut, ThunkRepr::Blackhole) { vm.call(lambda, upvalues, 0); - *thunk_mut = ThunkRepr::Evaluated(vm.run()?); + // TODO: find a cheap way to actually retain + // the original error span + *thunk_mut = ThunkRepr::Evaluated(vm.run().map_err(|e| e.kind)?); } } } |