about summary refs log tree commit diff
path: root/tvix/eval/src/chunk.rs
diff options
context:
space:
mode:
Diffstat (limited to 'tvix/eval/src/chunk.rs')
-rw-r--r--tvix/eval/src/chunk.rs9
1 files changed, 9 insertions, 0 deletions
diff --git a/tvix/eval/src/chunk.rs b/tvix/eval/src/chunk.rs
index defa409f18d6..c89e6ef84810 100644
--- a/tvix/eval/src/chunk.rs
+++ b/tvix/eval/src/chunk.rs
@@ -77,4 +77,13 @@ impl Chunk {
 
         panic!("compiler error: chunk missing span for offset {}", offset.0);
     }
+
+    /// Retrieve the line from which the instruction at `offset` was
+    /// compiled. Only available when the chunk carries a codemap,
+    /// i.e. when the disassembler is enabled.
+    #[cfg(feature = "disassembler")]
+    pub fn get_line(&self, offset: CodeIdx) -> usize {
+        let span = self.get_span(offset);
+        self.codemap.look_up_span(span).begin.line + 1
+    }
 }