add src and location to dbg

This commit is contained in:
Brendan Hansknecht 2023-12-01 20:24:23 -08:00
parent 4587c4ebc5
commit 3966d63e2f
No known key found for this signature in database
GPG key ID: 0EA784685083E75B
21 changed files with 385 additions and 119 deletions

View file

@ -631,10 +631,14 @@ fn specialize_drops_stmt<'a, 'i>(
),
}),
Stmt::Dbg {
source_location,
source,
symbol,
variable,
remainder,
} => arena.alloc(Stmt::Dbg {
source_location,
source,
symbol: *symbol,
variable: *variable,
remainder: specialize_drops_stmt(

View file

@ -689,6 +689,8 @@ fn insert_refcount_operations_stmt<'v, 'a>(
})
}
Stmt::Dbg {
source_location,
source,
symbol,
variable,
remainder,
@ -703,6 +705,8 @@ fn insert_refcount_operations_stmt<'v, 'a>(
);
arena.alloc(Stmt::Dbg {
source_location,
source,
symbol: *symbol,
variable: *variable,
remainder: newer_remainder,

View file

@ -1531,6 +1531,10 @@ pub enum Stmt<'a> {
remainder: &'a Stmt<'a>,
},
Dbg {
/// The location this dbg is in source as a printable string.
source_location: &'a str,
/// The source code of the expression being debugged.
source: &'a str,
/// The expression we're displaying
symbol: Symbol,
/// The specialized variable of the expression
@ -4602,6 +4606,8 @@ pub fn with_hole<'a>(
Expect { .. } => unreachable!("I think this is unreachable"),
ExpectFx { .. } => unreachable!("I think this is unreachable"),
Dbg {
source_location,
source,
loc_message,
loc_continuation,
variable: cond_variable,
@ -4621,6 +4627,8 @@ pub fn with_hole<'a>(
env,
procs,
layout_cache,
&*arena.alloc(source_location),
&*arena.alloc(source),
dbg_symbol,
*loc_message,
cond_variable,
@ -5892,8 +5900,10 @@ fn compile_dbg<'a>(
env: &mut Env<'a, '_>,
procs: &mut Procs<'a>,
layout_cache: &mut LayoutCache<'a>,
source_location: &'a str,
source: &'a str,
dbg_symbol: Symbol,
loc_condition: Loc<roc_can::expr::Expr>,
loc_message: Loc<roc_can::expr::Expr>,
variable: Variable,
continuation: Stmt<'a>,
) -> Stmt<'a> {
@ -5904,6 +5914,8 @@ fn compile_dbg<'a>(
.fresh_unnamed_flex_var();
let dbg_stmt = Stmt::Dbg {
source_location,
source,
symbol: dbg_symbol,
variable: spec_var,
remainder: env.arena.alloc(continuation),
@ -5914,17 +5926,17 @@ fn compile_dbg<'a>(
store_specialized_expectation_lookups(env, [variable], &[spec_var]);
let symbol_is_reused = matches!(
can_reuse_symbol(env, layout_cache, procs, &loc_condition.value, variable),
can_reuse_symbol(env, layout_cache, procs, &loc_message.value, variable),
ReuseSymbol::Value(_)
);
// skip evaluating the condition if it's just a symbol
// skip evaluating the message if it's just a symbol
if symbol_is_reused {
dbg_stmt
} else {
with_hole(
env,
loc_condition.value,
loc_message.value,
variable,
procs,
layout_cache,
@ -7137,6 +7149,8 @@ pub fn from_can<'a>(
}
Dbg {
source_location,
source,
loc_message,
loc_continuation,
variable: cond_variable,
@ -7148,6 +7162,8 @@ pub fn from_can<'a>(
env,
procs,
layout_cache,
&*env.arena.alloc(source_location),
&*env.arena.alloc(source),
dbg_symbol,
*loc_message,
cond_variable,
@ -7621,6 +7637,8 @@ fn substitute_in_stmt_help<'a>(
}
Dbg {
source_location,
source,
symbol,
variable,
remainder,
@ -7629,6 +7647,8 @@ fn substitute_in_stmt_help<'a>(
substitute_in_stmt_help(arena, remainder, subs).unwrap_or(remainder);
let expect = Dbg {
source_location,
source,
symbol: substitute(subs, *symbol).unwrap_or(*symbol),
variable: *variable,
remainder: new_remainder,

View file

@ -651,6 +651,8 @@ fn insert_reset_reuse_operations_stmt<'a, 'i>(
})
}
Stmt::Dbg {
source_location,
source,
symbol,
variable,
remainder,
@ -666,6 +668,8 @@ fn insert_reset_reuse_operations_stmt<'a, 'i>(
);
arena.alloc(Stmt::Dbg {
source_location,
source,
symbol: *symbol,
variable: *variable,
remainder: new_remainder,

View file

@ -330,6 +330,8 @@ fn insert_jumps<'a>(
}
Dbg {
source_location,
source,
symbol,
variable,
remainder,
@ -342,6 +344,8 @@ fn insert_jumps<'a>(
needle_result,
) {
Some(cont) => Some(arena.alloc(Dbg {
source_location,
source,
symbol: *symbol,
variable: *variable,
remainder: cont,
@ -1020,10 +1024,14 @@ impl<'a> TrmcEnv<'a> {
remainder: arena.alloc(self.walk_stmt(env, remainder)),
},
Stmt::Dbg {
source_location,
source,
symbol,
variable,
remainder,
} => Stmt::Dbg {
source_location,
source,
symbol: *symbol,
variable: *variable,
remainder: arena.alloc(self.walk_stmt(env, remainder)),