mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-29 23:04:49 +00:00
shift store_pattern over to decision_tree
This commit is contained in:
parent
e32a06b088
commit
ed28b02b57
7 changed files with 39 additions and 32 deletions
|
@ -1078,11 +1078,15 @@ pub fn optimize_when<'a>(
|
|||
.into_iter()
|
||||
.enumerate()
|
||||
.map(|(index, (pattern, guard, branch))| {
|
||||
((guard, pattern, index as u64), (index as u64, branch))
|
||||
let has_guard = !guard.is_none();
|
||||
(
|
||||
(guard, pattern.clone(), index as u64),
|
||||
(index as u64, branch, pattern, has_guard),
|
||||
)
|
||||
})
|
||||
.unzip();
|
||||
|
||||
let indexed_branches: Vec<(u64, Stmt<'a>)> = _indexed_branches;
|
||||
let indexed_branches: Vec<_> = _indexed_branches;
|
||||
|
||||
let decision_tree = compile(patterns);
|
||||
let decider = tree_to_decider(decision_tree);
|
||||
|
@ -1094,7 +1098,14 @@ pub fn optimize_when<'a>(
|
|||
let mut choices = MutMap::default();
|
||||
let mut jumps = Vec::new();
|
||||
|
||||
for (index, branch) in indexed_branches.into_iter() {
|
||||
for (index, mut branch, pattern, has_guard) in indexed_branches.into_iter() {
|
||||
// bind the fields referenced in the pattern. For guards this happens separately, so
|
||||
// the pattern variables are defined when evaluating the guard.
|
||||
if !has_guard {
|
||||
branch =
|
||||
crate::ir::store_pattern(env, procs, layout_cache, &pattern, cond_symbol, branch);
|
||||
}
|
||||
|
||||
let ((branch_index, choice), opt_jump) = create_choices(&target_counts, index, branch);
|
||||
|
||||
if let Some((index, body)) = opt_jump {
|
||||
|
|
|
@ -5096,8 +5096,6 @@ fn from_can_when<'a>(
|
|||
jump,
|
||||
);
|
||||
|
||||
// let new_guard_stmt = store_pattern(env, procs, layout_cache, &pattern, cond_symbol, guard_stmt);
|
||||
|
||||
(
|
||||
pattern.clone(),
|
||||
Guard::Guard {
|
||||
|
@ -5108,9 +5106,7 @@ fn from_can_when<'a>(
|
|||
branch_stmt,
|
||||
)
|
||||
} else {
|
||||
let new_branch_stmt =
|
||||
store_pattern(env, procs, layout_cache, &pattern, cond_symbol, branch_stmt);
|
||||
(pattern, Guard::NoGuard, new_branch_stmt)
|
||||
(pattern, Guard::NoGuard, branch_stmt)
|
||||
}
|
||||
});
|
||||
let mono_branches = Vec::from_iter_in(it, arena);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue