mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-30 23:31:12 +00:00
cleanup
This commit is contained in:
parent
e05753afd8
commit
78309f2607
3 changed files with 9 additions and 6 deletions
|
@ -228,13 +228,13 @@ fn to_decision_tree(raw_branches: Vec<Branch>) -> DecisionTree {
|
||||||
// get the `_decision_tree` without cloning
|
// get the `_decision_tree` without cloning
|
||||||
decision_edges.pop().unwrap().1
|
decision_edges.pop().unwrap().1
|
||||||
}
|
}
|
||||||
(_, []) => helper(path, decision_edges, None),
|
(_, []) => break_out_guard(path, decision_edges, None),
|
||||||
([], _) => {
|
([], _) => {
|
||||||
// should be guaranteed by the patterns
|
// should be guaranteed by the patterns
|
||||||
debug_assert!(!fallback.is_empty());
|
debug_assert!(!fallback.is_empty());
|
||||||
to_decision_tree(fallback)
|
to_decision_tree(fallback)
|
||||||
}
|
}
|
||||||
(_, _) => helper(
|
(_, _) => break_out_guard(
|
||||||
path,
|
path,
|
||||||
decision_edges,
|
decision_edges,
|
||||||
Some(Box::new(to_decision_tree(fallback))),
|
Some(Box::new(to_decision_tree(fallback))),
|
||||||
|
@ -244,7 +244,8 @@ fn to_decision_tree(raw_branches: Vec<Branch>) -> DecisionTree {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn helper<'a>(
|
/// Give a guard it's own Decision
|
||||||
|
fn break_out_guard<'a>(
|
||||||
path: Vec<PathInstruction>,
|
path: Vec<PathInstruction>,
|
||||||
mut edges: Vec<(GuardedTest<'a>, DecisionTree<'a>)>,
|
mut edges: Vec<(GuardedTest<'a>, DecisionTree<'a>)>,
|
||||||
default: Option<Box<DecisionTree<'a>>>,
|
default: Option<Box<DecisionTree<'a>>>,
|
||||||
|
@ -261,7 +262,7 @@ fn helper<'a>(
|
||||||
Some(index) => {
|
Some(index) => {
|
||||||
let (a, b) = edges.split_at_mut(index + 1);
|
let (a, b) = edges.split_at_mut(index + 1);
|
||||||
|
|
||||||
let new_default = helper(path.clone(), b.to_vec(), default);
|
let new_default = break_out_guard(path.clone(), b.to_vec(), default);
|
||||||
|
|
||||||
let mut left = a.to_vec();
|
let mut left = a.to_vec();
|
||||||
let guard = left.pop().unwrap();
|
let guard = left.pop().unwrap();
|
||||||
|
|
|
@ -5098,6 +5098,8 @@ fn from_can_when<'a>(
|
||||||
|
|
||||||
let new_guard_stmt =
|
let new_guard_stmt =
|
||||||
store_pattern(env, procs, layout_cache, &pattern, cond_symbol, guard_stmt);
|
store_pattern(env, procs, layout_cache, &pattern, cond_symbol, guard_stmt);
|
||||||
|
|
||||||
|
dbg!(symbol);
|
||||||
(
|
(
|
||||||
pattern,
|
pattern,
|
||||||
Guard::Guard {
|
Guard::Guard {
|
||||||
|
|
|
@ -510,8 +510,8 @@ fn if_guard_multiple() {
|
||||||
f = \n ->
|
f = \n ->
|
||||||
when Identity n 0 is
|
when Identity n 0 is
|
||||||
Identity x _ if x == 0 -> x + 0
|
Identity x _ if x == 0 -> x + 0
|
||||||
Identity x _ if x == 1 -> x + 0
|
# Identity x _ if x == 1 -> x + 0
|
||||||
Identity x _ if x == 2 -> x + 0
|
# Identity x _ if x == 2 -> x + 0
|
||||||
Identity x _ -> x - x
|
Identity x _ -> x - x
|
||||||
|
|
||||||
{ a: f 0, b: f 1, c: f 2, d: f 4 }
|
{ a: f 0, b: f 1, c: f 2, d: f 4 }
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue