Put the capture niche in the lambda name instead of generating new names

This commit is contained in:
Ayaz Hafiz 2022-07-01 15:52:36 -04:00 committed by ayazhafiz
parent 1ed2e1a8e9
commit 019ebd93f7
No known key found for this signature in database
GPG key ID: B443F7A3030C9AED
20 changed files with 592 additions and 486 deletions

View file

@ -23,11 +23,13 @@ pub const STATIC_LIST_NAME: ConstName = ConstName(b"THIS IS A STATIC LIST");
const ENTRY_POINT_NAME: &[u8] = b"mainForHost";
pub fn func_name_bytes(proc: &Proc) -> [u8; SIZE] {
func_name_bytes_help(
proc.name.call_name(),
let bytes = func_name_bytes_help(
proc.name.name(),
proc.args.iter().map(|x| x.0),
proc.name.captures_niche.iter().copied(),
&proc.ret_layout,
)
);
bytes
}
#[inline(always)]
@ -65,13 +67,15 @@ impl TagUnionId {
}
}
pub fn func_name_bytes_help<'a, I>(
pub fn func_name_bytes_help<'a, I1, I2>(
symbol: Symbol,
argument_layouts: I,
argument_layouts: I2,
captures_niche: I1,
return_layout: &Layout<'a>,
) -> [u8; SIZE]
where
I: IntoIterator<Item = Layout<'a>>,
I1: IntoIterator<Item = Layout<'a>>,
I2: IntoIterator<Item = Layout<'a>>,
{
let mut name_bytes = [0u8; SIZE];
@ -86,6 +90,10 @@ where
layout.hash(&mut hasher);
}
for capture_layout in captures_niche {
capture_layout.hash(&mut hasher);
}
return_layout.hash(&mut hasher);
hasher.finish()
@ -177,13 +185,17 @@ where
match layout {
RawFunctionLayout::Function(_, _, _) => {
let it = top_level.arguments.iter().copied();
let bytes = func_name_bytes_help(*symbol, it, &top_level.result);
let bytes = func_name_bytes_help(*symbol, it, [], &top_level.result);
host_exposed_functions.push((bytes, top_level.arguments));
}
RawFunctionLayout::ZeroArgumentThunk(_) => {
let bytes =
func_name_bytes_help(*symbol, [Layout::UNIT], &top_level.result);
let bytes = func_name_bytes_help(
*symbol,
[Layout::UNIT],
[],
&top_level.result,
);
host_exposed_functions.push((bytes, top_level.arguments));
}
@ -211,6 +223,7 @@ where
let roc_main_bytes = func_name_bytes_help(
entry_point.symbol,
entry_point.layout.arguments.iter().copied(),
std::iter::empty(),
&entry_point.layout.result,
);
let roc_main = FuncName(&roc_main_bytes);
@ -635,7 +648,7 @@ fn call_spec(
match &call.call_type {
ByName {
name: symbol,
name,
ret_layout,
arg_layouts,
specialization_id,
@ -644,8 +657,9 @@ fn call_spec(
let spec_var = CalleeSpecVar(&array);
let arg_value_id = build_tuple_value(builder, env, block, call.arguments)?;
let it = arg_layouts.iter().copied();
let bytes = func_name_bytes_help(*symbol, it, ret_layout);
let args_it = arg_layouts.iter().copied();
let captures_it = name.captures_niche.iter().copied();
let bytes = func_name_bytes_help(name.name(), args_it, captures_it, ret_layout);
let name = FuncName(&bytes);
let module = MOD_APP;
builder.add_call(block, spec_var, module, name, arg_value_id)
@ -688,9 +702,14 @@ fn call_spec(
let mode = update_mode.to_bytes();
let update_mode_var = UpdateModeVar(&mode);
let it = passed_function.argument_layouts.iter().copied();
let bytes =
func_name_bytes_help(passed_function.name, it, &passed_function.return_layout);
let args_it = passed_function.argument_layouts.iter().copied();
let captures_it = passed_function.name.captures_niche.iter().copied();
let bytes = func_name_bytes_help(
passed_function.name.name(),
args_it,
captures_it,
&passed_function.return_layout,
);
let name = FuncName(&bytes);
let module = MOD_APP;