diff options
author | Vincent Ambo <mail@tazj.in> | 2022-09-03T11·50+0300 |
---|---|---|
committer | tazjin <tazjin@tvl.su> | 2022-09-08T20·17+0000 |
commit | d3421c1cb9fc52a583b888e5040ea6d60a4d02ac (patch) | |
tree | f272c6bae888a5ccfad080c24a402f4fe495b960 /tvix/eval/src/chunk.rs | |
parent | fc1c50498e81292948ce641bc8289130dba79c61 (diff) |
fix(tvix/eval): ensure disassembler prints continous lines correctly r/4767
There can be different spans on the same line, so the previous implementation would duplicate line numbers unnecessarily. Change-Id: I8d8db77177aee0d834a6ec3584641e1bd5f31c3e Reviewed-on: https://cl.tvl.fyi/c/depot/+/6434 Reviewed-by: sterni <sternenseemann@systemli.org> Tested-by: BuildkiteCI
Diffstat (limited to 'tvix/eval/src/chunk.rs')
-rw-r--r-- | tvix/eval/src/chunk.rs | 9 |
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 + } } |