mirror of
https://github.com/roc-lang/roc.git
synced 2025-10-02 00:01:16 +00:00
Thread ret_layout through CallByName
This commit is contained in:
parent
c450a67421
commit
632d4eca92
5 changed files with 121 additions and 13 deletions
|
@ -1119,7 +1119,7 @@ fn decide_to_branching<'a>(
|
|||
let fail = (fail_stores, &*env.arena.alloc(fail_expr));
|
||||
let pass = (pass_stores, &*env.arena.alloc(pass_expr));
|
||||
|
||||
let condition = boolean_all(env.arena, tests);
|
||||
let condition = boolean_all(env.arena, tests, &ret_layout);
|
||||
|
||||
let branch_symbol = env.fresh_symbol();
|
||||
let stores = [(branch_symbol, Layout::Builtin(Builtin::Bool), condition)];
|
||||
|
@ -1199,7 +1199,11 @@ fn decide_to_branching<'a>(
|
|||
}
|
||||
}
|
||||
|
||||
fn boolean_all<'a>(arena: &'a Bump, tests: Vec<(Expr<'a>, Expr<'a>, Layout<'a>)>) -> Expr<'a> {
|
||||
fn boolean_all<'a>(
|
||||
arena: &'a Bump,
|
||||
tests: Vec<(Expr<'a>, Expr<'a>, Layout<'a>)>,
|
||||
ret_layout: &Layout<'a>,
|
||||
) -> Expr<'a> {
|
||||
let mut expr = Expr::Bool(true);
|
||||
|
||||
for (lhs, rhs, layout) in tests.into_iter().rev() {
|
||||
|
@ -1210,6 +1214,7 @@ fn boolean_all<'a>(arena: &'a Bump, tests: Vec<(Expr<'a>, Expr<'a>, Layout<'a>)>
|
|||
(test, Layout::Builtin(Builtin::Bool)),
|
||||
(expr, Layout::Builtin(Builtin::Bool)),
|
||||
]),
|
||||
ret_layout.clone(),
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -138,7 +138,7 @@ pub enum Expr<'a> {
|
|||
|
||||
// Functions
|
||||
FunctionPointer(Symbol),
|
||||
CallByName(Symbol, &'a [(Expr<'a>, Layout<'a>)]),
|
||||
CallByName(Symbol, &'a [(Expr<'a>, Layout<'a>)], Layout<'a>),
|
||||
CallByPointer(&'a Expr<'a>, &'a [Expr<'a>], Layout<'a>),
|
||||
|
||||
// Exactly two conditional branches, e.g. if/else
|
||||
|
@ -1303,7 +1303,7 @@ fn call_by_name<'a>(
|
|||
Some(specialization) => {
|
||||
opt_specialize_body = None;
|
||||
|
||||
// a specialization with this type hash already exists, use its symbol
|
||||
// a specialization with this type hash already exists, so use its symbol
|
||||
specialization.0
|
||||
}
|
||||
None => {
|
||||
|
@ -1354,13 +1354,18 @@ fn call_by_name<'a>(
|
|||
let mut args = Vec::with_capacity_in(loc_args.len(), env.arena);
|
||||
|
||||
for (var, loc_arg) in loc_args {
|
||||
let layout = Layout::from_var(&env.arena, var, &env.subs, env.pointer_size)
|
||||
.unwrap_or_else(|err| panic!("TODO gracefully handle bad layout: {:?}", err));
|
||||
let layout =
|
||||
Layout::from_var(&env.arena, var, &env.subs, env.pointer_size).unwrap_or_else(|err| {
|
||||
panic!("TODO gracefully handle bad function arg layout: {:?}", err)
|
||||
});
|
||||
|
||||
args.push((from_can(env, loc_arg.value, procs, None), layout));
|
||||
}
|
||||
|
||||
Expr::CallByName(specialized_proc_name, args.into_bump_slice())
|
||||
let ret_layout = Layout::from_var(&env.arena, ret_var, &env.subs, env.pointer_size)
|
||||
.unwrap_or_else(|err| panic!("TODO gracefully handle bad function ret layout: {:?}", err));
|
||||
|
||||
Expr::CallByName(specialized_proc_name, args.into_bump_slice(), ret_layout)
|
||||
}
|
||||
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
|
@ -1704,5 +1709,6 @@ pub fn specialize_equality<'a>(
|
|||
Expr::CallByName(
|
||||
symbol,
|
||||
arena.alloc([(lhs, layout.clone()), (rhs, layout.clone())]),
|
||||
Layout::Builtin(Builtin::Bool),
|
||||
)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue