Merge pull request #4603 from roc-lang/dbg-fixes

Dbg fixes
This commit is contained in:
Richard Feldman 2022-11-25 15:10:22 -05:00 committed by GitHub
commit 695bb7e353
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 28 additions and 12 deletions

View File

@ -1065,12 +1065,20 @@ pub fn canonicalize_expr<'a>(
output.union(output1);
output.union(output2);
// the symbol is used to bind the condition `x = condition`, and identify this `dbg`.
// That would cause issues if we dbg a variable, like `dbg y`, because in the IR we
// cannot alias variables. Hence, we make the dbg use that same variable `y`
let symbol = match &loc_condition.value {
Expr::Var(symbol, _) => *symbol,
_ => scope.gen_unique_symbol(),
};
(
Dbg {
loc_condition: Box::new(loc_condition),
loc_continuation: Box::new(loc_continuation),
variable: var_store.fresh(),
symbol: scope.gen_unique_symbol(),
symbol,
},
output,
)

View File

@ -6570,16 +6570,24 @@ pub fn from_can<'a>(
let expr = Expr::Call(call);
let mut stmt = Stmt::Let(dbg_symbol, expr, dbg_layout, env.arena.alloc(rest));
stmt = with_hole(
env,
loc_condition.value,
variable,
procs,
layout_cache,
dbg_symbol,
env.arena.alloc(stmt),
let symbol_is_reused = matches!(
can_reuse_symbol(env, procs, &loc_condition.value, variable),
ReuseSymbol::Value(_)
);
// skip evaluating the condition if it's just a symbol
if !symbol_is_reused {
stmt = with_hole(
env,
loc_condition.value,
variable,
procs,
layout_cache,
dbg_symbol,
env.arena.alloc(stmt),
);
}
stmt
}

View File

@ -499,7 +499,7 @@ fn render_dbg_failure<'a>(
let data = expectations.get_mut(&module_id).unwrap();
let current = match data.dbgs.get(&dbg_symbol) {
None => panic!("region {failure_region:?} not in list of expects"),
None => panic!("region {failure_region:?} not in list of dbgs"),
Some(current) => current,
};
let failure_region = current.region;

View File

@ -185,8 +185,8 @@ impl<'a> Renderer<'a> {
writer,
"\u{001b}[36m[{} {}:{}] \u{001b}[0m",
self.filename.display(),
line_col_region.start.line,
line_col_region.start.column
line_col_region.start.line + 1,
line_col_region.start.column + 1
)?;
let expr = expressions[0];