fix(tvix/eval): ensure disassembler prints continous lines correctly

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
This commit is contained in:
Vincent Ambo 2022-09-03 14:50:50 +03:00 committed by tazjin
parent fc1c50498e
commit d3421c1cb9
2 changed files with 12 additions and 4 deletions

View file

@ -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
}
}

View file

@ -44,13 +44,12 @@ impl Drop for Tracer {
fn disassemble_op(tw: &mut TabWriter<Stderr>, chunk: &Chunk, width: usize, offset: usize) {
let _ = write!(tw, "{:0width$}\t ", offset, width = width);
let span = chunk.get_span(CodeIdx(offset));
let line = chunk.get_line(CodeIdx(offset));
if offset > 0 && chunk.get_span(CodeIdx(offset - 1)) == span {
if offset > 0 && chunk.get_line(CodeIdx(offset - 1)) == line {
write!(tw, " |\t").unwrap();
} else {
let loc = chunk.codemap.look_up_span(span);
write!(tw, "{:4}\t", loc.begin.line + 1).unwrap();
write!(tw, "{:4}\t", line).unwrap();
}
let _ = match chunk.code[offset] {