mirror of
https://github.com/roc-lang/roc.git
synced 2025-10-01 07:41:12 +00:00
refactor function_r branch body
This commit is contained in:
parent
0171fd0959
commit
8a1a643e3b
1 changed files with 29 additions and 39 deletions
|
@ -452,6 +452,33 @@ fn function_d<'a, 'i>(
|
||||||
function_d_finalize(env, x, c, temp)
|
function_d_finalize(env, x, c, temp)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn function_r_branch_body<'a, 'i>(
|
||||||
|
env: &mut Env<'a, 'i>,
|
||||||
|
info: &BranchInfo<'a>,
|
||||||
|
body: &'a Stmt<'a>,
|
||||||
|
) -> &'a Stmt<'a> {
|
||||||
|
let temp = function_r(env, body);
|
||||||
|
|
||||||
|
match info {
|
||||||
|
BranchInfo::None => temp,
|
||||||
|
BranchInfo::Constructor {
|
||||||
|
scrutinee,
|
||||||
|
layout,
|
||||||
|
tag_id,
|
||||||
|
} => match layout {
|
||||||
|
Layout::Union(UnionLayout::NonRecursive(_)) => temp,
|
||||||
|
Layout::Union(union_layout) if !union_layout.tag_is_null(*tag_id) => {
|
||||||
|
let ctor_info = CtorInfo {
|
||||||
|
layout: *union_layout,
|
||||||
|
id: *tag_id,
|
||||||
|
};
|
||||||
|
function_d(env, *scrutinee, &ctor_info, temp)
|
||||||
|
}
|
||||||
|
_ => temp,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn function_r<'a, 'i>(env: &mut Env<'a, 'i>, stmt: &'a Stmt<'a>) -> &'a Stmt<'a> {
|
fn function_r<'a, 'i>(env: &mut Env<'a, 'i>, stmt: &'a Stmt<'a>) -> &'a Stmt<'a> {
|
||||||
use Stmt::*;
|
use Stmt::*;
|
||||||
|
|
||||||
|
@ -468,52 +495,15 @@ fn function_r<'a, 'i>(env: &mut Env<'a, 'i>, stmt: &'a Stmt<'a>) -> &'a Stmt<'a>
|
||||||
let mut new_branches = Vec::with_capacity_in(branches.len(), arena);
|
let mut new_branches = Vec::with_capacity_in(branches.len(), arena);
|
||||||
|
|
||||||
for (tag, info, body) in branches.iter() {
|
for (tag, info, body) in branches.iter() {
|
||||||
let temp = function_r(env, body);
|
let new_body = function_r_branch_body(env, info, body);
|
||||||
|
|
||||||
let new_body = match info {
|
|
||||||
BranchInfo::None => temp,
|
|
||||||
BranchInfo::Constructor {
|
|
||||||
scrutinee,
|
|
||||||
layout,
|
|
||||||
tag_id,
|
|
||||||
} => match layout {
|
|
||||||
Layout::Union(UnionLayout::NonRecursive(_)) => temp,
|
|
||||||
Layout::Union(union_layout) if !union_layout.tag_is_null(*tag_id) => {
|
|
||||||
let ctor_info = CtorInfo {
|
|
||||||
layout: *union_layout,
|
|
||||||
id: *tag_id,
|
|
||||||
};
|
|
||||||
function_d(env, *scrutinee, &ctor_info, temp)
|
|
||||||
}
|
|
||||||
_ => temp,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
new_branches.push((*tag, info.clone(), new_body.clone()));
|
new_branches.push((*tag, info.clone(), new_body.clone()));
|
||||||
}
|
}
|
||||||
|
|
||||||
let new_default = {
|
let new_default = {
|
||||||
let (info, body) = default_branch;
|
let (info, body) = default_branch;
|
||||||
let temp = function_r(env, body);
|
|
||||||
|
|
||||||
let new_body = match info {
|
let new_body = function_r_branch_body(env, info, body);
|
||||||
BranchInfo::None => temp,
|
|
||||||
BranchInfo::Constructor {
|
|
||||||
scrutinee,
|
|
||||||
layout,
|
|
||||||
tag_id,
|
|
||||||
} => match layout {
|
|
||||||
Layout::Union(UnionLayout::NonRecursive(_)) => temp,
|
|
||||||
Layout::Union(union_layout) if !union_layout.tag_is_null(*tag_id) => {
|
|
||||||
let ctor_info = CtorInfo {
|
|
||||||
layout: *union_layout,
|
|
||||||
id: *tag_id,
|
|
||||||
};
|
|
||||||
function_d(env, *scrutinee, &ctor_info, temp)
|
|
||||||
}
|
|
||||||
_ => temp,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
(info.clone(), new_body)
|
(info.clone(), new_body)
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue