about summary refs log tree commit diff
path: root/tvix/eval/src/errors.rs
diff options
context:
space:
mode:
authorVincent Ambo <mail@tazj.in>2023-03-12T21·30+0300
committerclbot <clbot@tvl.fyi>2023-03-17T19·31+0000
commit3fa6b13c1e8cbd7a007365dbac0ffc30d03d8472 (patch)
tree5aa4b1692bc71730408dae780b172b777e4bf815 /tvix/eval/src/errors.rs
parent5095e4f2696ef85ee7c6ae0515eb8d1586459f8c (diff)
feat(tvix/eval): track span of first force in a thunk blackhole r/6025
This is step 1 towards being able to use all 4 spans that we know when
dealing with infinite recursion. It tracks the span at which the
force of a thunk was first requested when constructing a blackhole, so
that we can highlight the spans of the first and second forces.

These are actually the least relevant spans, but the easiest to put in
place, more coming soon.

Change-Id: I4c7e82f6211b98756439d4148a4191457cc46807
Reviewed-on: https://cl.tvl.fyi/c/depot/+/8269
Autosubmit: tazjin <tazjin@tvl.su>
Tested-by: BuildkiteCI
Reviewed-by: flokli <flokli@flokli.de>
Diffstat (limited to 'tvix/eval/src/errors.rs')
-rw-r--r--tvix/eval/src/errors.rs25
1 files changed, 21 insertions, 4 deletions
diff --git a/tvix/eval/src/errors.rs b/tvix/eval/src/errors.rs
index 5e890c68a74c..76a3da3ff52f 100644
--- a/tvix/eval/src/errors.rs
+++ b/tvix/eval/src/errors.rs
@@ -77,7 +77,9 @@ pub enum ErrorKind {
     NotCallable(&'static str),
 
     /// Infinite recursion encountered while forcing thunks.
-    InfiniteRecursion,
+    InfiniteRecursion {
+        first_force: Span,
+    },
 
     ParseErrors(Vec<rnix::parser::ParseError>),
 
@@ -354,7 +356,7 @@ to a missing value in the attribute set(s) included via `with`."#,
                 )
             }
 
-            ErrorKind::InfiniteRecursion => write!(f, "infinite recursion encountered"),
+            ErrorKind::InfiniteRecursion { .. } => write!(f, "infinite recursion encountered"),
 
             // Errors themselves ignored here & handled in Self::spans instead
             ErrorKind::ParseErrors(_) => write!(f, "failed to parse Nix code:"),
@@ -754,7 +756,7 @@ impl Error {
             | ErrorKind::UnknownDynamicVariable(_)
             | ErrorKind::VariableAlreadyDefined(_)
             | ErrorKind::NotCallable(_)
-            | ErrorKind::InfiniteRecursion
+            | ErrorKind::InfiniteRecursion { .. }
             | ErrorKind::ParseErrors(_)
             | ErrorKind::NativeError { .. }
             | ErrorKind::BytecodeError(_)
@@ -797,7 +799,7 @@ impl Error {
             ErrorKind::UnknownDynamicVariable(_) => "E011",
             ErrorKind::VariableAlreadyDefined(_) => "E012",
             ErrorKind::NotCallable(_) => "E013",
-            ErrorKind::InfiniteRecursion => "E014",
+            ErrorKind::InfiniteRecursion { .. } => "E014",
             ErrorKind::ParseErrors(_) => "E015",
             ErrorKind::DuplicateAttrsKey { .. } => "E016",
             ErrorKind::NotCoercibleToString { .. } => "E018",
@@ -869,6 +871,21 @@ impl Error {
                 ]
             }
 
+            ErrorKind::InfiniteRecursion { first_force } => {
+                vec![
+                    SpanLabel {
+                        label: Some("first requested here".into()),
+                        span: *first_force,
+                        style: SpanStyle::Secondary,
+                    },
+                    SpanLabel {
+                        label: Some("requested again here".into()),
+                        span: self.span,
+                        style: SpanStyle::Primary,
+                    },
+                ]
+            }
+
             // All other errors pretty much have the same shape.
             _ => {
                 vec![SpanLabel {