Merge remote-tracking branch 'origin/main' into glue-getters-rtfeldman

This commit is contained in:
Folkert 2023-02-22 21:11:39 +01:00
commit 0d4135c57a
No known key found for this signature in database
GPG key ID: 1F17F6FFD112B97C
95 changed files with 5408 additions and 1860 deletions

View file

@ -39,8 +39,8 @@ use roc_debug_flags::dbg_do;
use roc_debug_flags::ROC_PRINT_LLVM_FN_VERIFICATION;
use roc_module::symbol::{Interns, ModuleId, Symbol};
use roc_mono::ir::{
BranchInfo, CallType, CrashTag, EntryPoint, GlueLayouts, JoinPointId, ListLiteralElement,
ModifyRc, OptLevel, ProcLayout, SingleEntryPoint,
BranchInfo, CallType, CrashTag, EntryPoint, GlueLayouts, HostExposedLambdaSet, JoinPointId,
ListLiteralElement, ModifyRc, OptLevel, ProcLayout, SingleEntryPoint,
};
use roc_mono::layout::{
Builtin, InLayout, LambdaName, LambdaSet, Layout, LayoutIds, LayoutInterner, Niche,
@ -3979,7 +3979,8 @@ fn expose_function_to_host_help_c_abi_v2<'a, 'ctx, 'env>(
// In C, this is modelled as a function returning void
(
&params[..],
&param_types[..param_types.len().saturating_sub(1)],
// &param_types[..param_types.len().saturating_sub(1)],
&param_types[..],
)
}
_ => (&params[..], &param_types[..]),
@ -4977,23 +4978,21 @@ fn expose_alias_to_host<'a, 'ctx, 'env>(
mod_solutions: &'a ModSolutions,
fn_name: &str,
alias_symbol: Symbol,
exposed_function_symbol: Symbol,
top_level: ProcLayout<'a>,
layout: RawFunctionLayout<'a>,
hels: &HostExposedLambdaSet<'a>,
) {
match layout {
match hels.raw_function_layout {
RawFunctionLayout::Function(arguments, closure, result) => {
// define closure size and return value size, e.g.
//
// * roc__mainForHost_1_Update_size() -> i64
// * roc__mainForHost_1_Update_result_size() -> i64
let it = top_level.arguments.iter().copied();
let it = hels.proc_layout.arguments.iter().copied();
let bytes = roc_alias_analysis::func_name_bytes_help(
exposed_function_symbol,
hels.symbol,
it,
Niche::NONE,
top_level.result,
hels.proc_layout.result,
);
let func_name = FuncName(&bytes);
let func_solutions = mod_solutions.func_solutions(func_name).unwrap();
@ -5009,17 +5008,17 @@ fn expose_alias_to_host<'a, 'ctx, 'env>(
function_value_by_func_spec(
env,
*func_spec,
exposed_function_symbol,
top_level.arguments,
hels.symbol,
hels.proc_layout.arguments,
Niche::NONE,
top_level.result,
hels.proc_layout.result,
)
}
None => {
// morphic did not generate a specialization for this function,
// therefore it must actually be unused.
// An example is our closure callers
panic!("morphic did not specialize {:?}", exposed_function_symbol);
panic!("morphic did not specialize {:?}", hels.symbol);
}
};
@ -5274,11 +5273,9 @@ fn build_proc<'a, 'ctx, 'env>(
/* no host, or exposing types is not supported */
}
Binary | BinaryDev => {
for (alias_name, (id, generated_function, top_level, layout)) in aliases.iter()
{
for (alias_name, hels) in aliases.iter() {
let ident_string = proc.name.name().as_str(&env.interns);
// let fn_name: String = format!("{}_1", ident_string);
let fn_name: String = format!("{}_{}", ident_string, id.0);
let fn_name: String = format!("{}_{}", ident_string, hels.id.0);
expose_alias_to_host(
env,
@ -5286,9 +5283,7 @@ fn build_proc<'a, 'ctx, 'env>(
mod_solutions,
&fn_name,
*alias_name,
*generated_function,
*top_level,
*layout,
hels,
)
}
}

View file

@ -1345,11 +1345,16 @@ fn build_rec_union_recursive_decrement<'a, 'ctx, 'env>(
union_layout,
UnionLayout::NullableUnwrapped { .. } | UnionLayout::NonNullableUnwrapped { .. }
) {
debug_assert_eq!(cases.len(), 1);
debug_assert!(cases.len() <= 1, "{cases:?}");
// in this case, don't switch, because the `else` branch below would try to read the (nonexistent) tag id
let (_, only_branch) = cases.pop().unwrap();
env.builder.build_unconditional_branch(only_branch);
if cases.is_empty() {
// The only other layout doesn't need refcounting. Pass through.
builder.build_return(None);
} else {
// in this case, don't switch, because the `else` branch below would try to read the (nonexistent) tag id
let (_, only_branch) = cases.pop().unwrap();
env.builder.build_unconditional_branch(only_branch);
}
} else {
let default_block = env.context.append_basic_block(parent, "switch_default");
@ -1372,6 +1377,7 @@ fn build_rec_union_recursive_decrement<'a, 'ctx, 'env>(
}
}
#[derive(Debug)]
struct UnionLayoutTags<'a> {
nullable_id: Option<u16>,
tags: &'a [&'a [InLayout<'a>]],