mirror of
https://github.com/roc-lang/roc.git
synced 2025-10-02 08:11:12 +00:00
Show unified variables as a tree
This commit is contained in:
parent
2cc8e95198
commit
21661275d8
1 changed files with 24 additions and 8 deletions
|
@ -275,11 +275,24 @@ pub fn unify_pool(
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(debug_assertions)]
|
#[cfg(debug_assertions)]
|
||||||
fn debug_print_unified_types(subs: &mut Subs, ctx: &Context, before_unified: bool) {
|
fn debug_print_unified_types(subs: &mut Subs, ctx: &Context, opt_outcome: Option<&Outcome>) {
|
||||||
|
static mut UNIFICATION_DEPTH: usize = 0;
|
||||||
|
|
||||||
if std::env::var("ROC_PRINT_UNIFICATIONS").is_ok() {
|
if std::env::var("ROC_PRINT_UNIFICATIONS").is_ok() {
|
||||||
let time = if before_unified { "START" } else { "END" };
|
let prefix = match opt_outcome {
|
||||||
// if true, print the types that are unified.
|
None => "❔",
|
||||||
//
|
Some(outcome) if outcome.mismatches.is_empty() => "✅",
|
||||||
|
Some(_) => "❌",
|
||||||
|
};
|
||||||
|
|
||||||
|
let depth = unsafe { UNIFICATION_DEPTH };
|
||||||
|
let indent = 2;
|
||||||
|
let (use_depth, new_depth) = if opt_outcome.is_none() {
|
||||||
|
(depth, depth + indent)
|
||||||
|
} else {
|
||||||
|
(depth - indent, depth - indent)
|
||||||
|
};
|
||||||
|
|
||||||
// NOTE: names are generated here (when creating an error type) and that modifies names
|
// NOTE: names are generated here (when creating an error type) and that modifies names
|
||||||
// generated by pretty_print.rs. So many test will fail with changes in variable names when
|
// generated by pretty_print.rs. So many test will fail with changes in variable names when
|
||||||
// this block runs.
|
// this block runs.
|
||||||
|
@ -294,8 +307,9 @@ fn debug_print_unified_types(subs: &mut Subs, ctx: &Context, before_unified: boo
|
||||||
let content_2 = subs.get(ctx.second).content;
|
let content_2 = subs.get(ctx.second).content;
|
||||||
let mode = if ctx.mode.is_eq() { "~" } else { "+=" };
|
let mode = if ctx.mode.is_eq() { "~" } else { "+=" };
|
||||||
eprintln!(
|
eprintln!(
|
||||||
"{}({:?}-{:?}): {:?} {:?} {} {:?} {:?}",
|
"{}{}({:?}-{:?}): {:?} {:?} {} {:?} {:?}",
|
||||||
time,
|
" ".repeat(use_depth),
|
||||||
|
prefix,
|
||||||
ctx.first,
|
ctx.first,
|
||||||
ctx.second,
|
ctx.second,
|
||||||
ctx.first,
|
ctx.first,
|
||||||
|
@ -304,12 +318,14 @@ fn debug_print_unified_types(subs: &mut Subs, ctx: &Context, before_unified: boo
|
||||||
ctx.second,
|
ctx.second,
|
||||||
roc_types::subs::SubsFmtContent(&content_2, subs),
|
roc_types::subs::SubsFmtContent(&content_2, subs),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
unsafe { UNIFICATION_DEPTH = new_depth };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn unify_context(subs: &mut Subs, pool: &mut Pool, ctx: Context) -> Outcome {
|
fn unify_context(subs: &mut Subs, pool: &mut Pool, ctx: Context) -> Outcome {
|
||||||
#[cfg(debug_assertions)]
|
#[cfg(debug_assertions)]
|
||||||
debug_print_unified_types(subs, &ctx, true);
|
debug_print_unified_types(subs, &ctx, None);
|
||||||
|
|
||||||
let result = match &ctx.first_desc.content {
|
let result = match &ctx.first_desc.content {
|
||||||
FlexVar(opt_name) => unify_flex(subs, &ctx, opt_name, None, &ctx.second_desc.content),
|
FlexVar(opt_name) => unify_flex(subs, &ctx, opt_name, None, &ctx.second_desc.content),
|
||||||
|
@ -349,7 +365,7 @@ fn unify_context(subs: &mut Subs, pool: &mut Pool, ctx: Context) -> Outcome {
|
||||||
};
|
};
|
||||||
|
|
||||||
#[cfg(debug_assertions)]
|
#[cfg(debug_assertions)]
|
||||||
debug_print_unified_types(subs, &ctx, false);
|
debug_print_unified_types(subs, &ctx, Some(&result));
|
||||||
|
|
||||||
result
|
result
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue