mirror of
https://github.com/roc-lang/roc.git
synced 2025-08-02 19:32:17 +00:00
toplevel debug
This commit is contained in:
parent
928495072c
commit
5ea8d96f3e
5 changed files with 70 additions and 10 deletions
|
@ -1600,6 +1600,25 @@ pub(crate) fn sort_can_defs_new(
|
|||
declarations.push_expect_fx(preceding_comment, name, Loc::at(region, condition));
|
||||
}
|
||||
|
||||
let it = dbgs
|
||||
.conditions
|
||||
.into_iter()
|
||||
.zip(dbgs.regions)
|
||||
.zip(dbgs.preceding_comment);
|
||||
|
||||
for ((condition, region), preceding_comment) in it {
|
||||
// an `dbg` does not have a user-defined name, but we'll need a name to call the function we generate
|
||||
let name = scope.gen_unique_symbol();
|
||||
let variable = var_store.fresh();
|
||||
|
||||
declarations.push_dbg(
|
||||
preceding_comment,
|
||||
name,
|
||||
variable,
|
||||
Loc::at(region, condition),
|
||||
);
|
||||
}
|
||||
|
||||
for (symbol, alias) in aliases.into_iter() {
|
||||
output.aliases.insert(symbol, alias);
|
||||
}
|
||||
|
|
|
@ -2398,6 +2398,25 @@ impl Declarations {
|
|||
index
|
||||
}
|
||||
|
||||
pub fn push_dbg(
|
||||
&mut self,
|
||||
preceding_comment: Region,
|
||||
name: Symbol,
|
||||
variable: Variable,
|
||||
loc_expr: Loc<Expr>,
|
||||
) -> usize {
|
||||
let index = self.declarations.len();
|
||||
|
||||
self.declarations.push(DeclarationTag::Dbg);
|
||||
self.variables.push(variable);
|
||||
self.symbols.push(Loc::at(preceding_comment, name));
|
||||
self.annotations.push(None);
|
||||
|
||||
self.expressions.push(loc_expr);
|
||||
|
||||
index
|
||||
}
|
||||
|
||||
pub fn push_value_def(
|
||||
&mut self,
|
||||
symbol: Loc<Symbol>,
|
||||
|
@ -2572,6 +2591,10 @@ impl Declarations {
|
|||
MutualRecursion { .. } => {
|
||||
// the self of this group will be treaded individually by later iterations
|
||||
}
|
||||
Dbg => {
|
||||
let loc_expr = &self.expressions[index];
|
||||
collector.visit_expr(&loc_expr.value, loc_expr.region, var);
|
||||
}
|
||||
Expectation => {
|
||||
let loc_expr =
|
||||
toplevel_expect_to_inline_expect_pure(self.expressions[index].clone());
|
||||
|
@ -2598,6 +2621,7 @@ pub enum DeclarationTag {
|
|||
Value,
|
||||
Expectation,
|
||||
ExpectationFx,
|
||||
Dbg,
|
||||
Function(Index<Loc<FunctionDef>>),
|
||||
Recursive(Index<Loc<FunctionDef>>),
|
||||
TailRecursive(Index<Loc<FunctionDef>>),
|
||||
|
@ -2615,7 +2639,7 @@ impl DeclarationTag {
|
|||
match self {
|
||||
Function(_) | Recursive(_) | TailRecursive(_) => 1,
|
||||
Value => 1,
|
||||
Expectation | ExpectationFx => 1,
|
||||
Expectation | ExpectationFx | Dbg => 1,
|
||||
Destructure(_) => 1,
|
||||
MutualRecursion { length, .. } => length as usize + 1,
|
||||
}
|
||||
|
|
|
@ -615,6 +615,7 @@ pub fn canonicalize_module_defs<'a>(
|
|||
}
|
||||
Expectation => { /* ignore */ }
|
||||
ExpectationFx => { /* ignore */ }
|
||||
Dbg => { /* ignore */ }
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -757,15 +758,7 @@ pub fn canonicalize_module_defs<'a>(
|
|||
MutualRecursion { .. } => {
|
||||
// the declarations of this group will be treaded individually by later iterations
|
||||
}
|
||||
Expectation => {
|
||||
let loc_expr = &mut declarations.expressions[index];
|
||||
fix_values_captured_in_closure_expr(
|
||||
&mut loc_expr.value,
|
||||
&mut fix_closures_no_capture_symbols,
|
||||
&mut fix_closures_closure_captures,
|
||||
);
|
||||
}
|
||||
ExpectationFx => {
|
||||
Expectation | ExpectationFx | Dbg => {
|
||||
let loc_expr = &mut declarations.expressions[index];
|
||||
fix_values_captured_in_closure_expr(
|
||||
&mut loc_expr.value,
|
||||
|
|
|
@ -57,6 +57,12 @@ pub fn walk_decls<V: Visitor>(visitor: &mut V, decls: &Declarations) {
|
|||
|
||||
visitor.visit_expr(&loc_condition.value, loc_condition.region, Variable::BOOL);
|
||||
}
|
||||
Dbg => {
|
||||
let loc_condition = &decls.expressions[index];
|
||||
let expr_var = decls.variables[index];
|
||||
|
||||
visitor.visit_expr(&loc_condition.value, loc_condition.region, expr_var);
|
||||
}
|
||||
Function(function_index)
|
||||
| Recursive(function_index)
|
||||
| TailRecursive(function_index) => {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue