mirror of
https://github.com/roc-lang/roc.git
synced 2025-08-03 11:52:19 +00:00
Determine the proc layout based on captures of an individual lambda
Previously, we determined whether a closure argument should be added to the proc layout of a compiled function by checking whether the lambda set was material at all. But, the extension for a single function should be added if and only if the function itself captures.
This commit is contained in:
parent
c3b0295a92
commit
593344f5c5
2 changed files with 39 additions and 0 deletions
|
@ -4101,6 +4101,24 @@ impl<'a> ProcLayout<'a> {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn from_raw_named(
|
||||
arena: &'a Bump,
|
||||
lambda_name: LambdaName<'a>,
|
||||
raw: RawFunctionLayout<'a>,
|
||||
captures_niche: CapturesNiche<'a>,
|
||||
) -> Self {
|
||||
match raw {
|
||||
RawFunctionLayout::Function(arguments, lambda_set, result) => {
|
||||
let arguments =
|
||||
lambda_set.extend_argument_list_for_named(arena, lambda_name, arguments);
|
||||
ProcLayout::new(arena, arguments, captures_niche, *result)
|
||||
}
|
||||
RawFunctionLayout::ZeroArgumentThunk(result) => {
|
||||
ProcLayout::new(arena, &[], CapturesNiche::no_niche(), result)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn specialize_naked_symbol<'a>(
|
||||
|
|
|
@ -1644,6 +1644,27 @@ impl<'a> LambdaSet<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn extend_argument_list_for_named(
|
||||
&self,
|
||||
arena: &'a Bump,
|
||||
lambda_name: LambdaName<'a>,
|
||||
argument_layouts: &'a [Layout<'a>],
|
||||
) -> &'a [Layout<'a>] {
|
||||
debug_assert!(self
|
||||
.set
|
||||
.contains(&(lambda_name.name, lambda_name.captures_niche.0)));
|
||||
// If we don't capture, there is nothing to extend.
|
||||
if lambda_name.captures_niche.0.is_empty() {
|
||||
argument_layouts
|
||||
} else {
|
||||
let mut arguments = Vec::with_capacity_in(argument_layouts.len() + 1, arena);
|
||||
arguments.extend(argument_layouts);
|
||||
arguments.push(Layout::LambdaSet(*self));
|
||||
|
||||
arguments.into_bump_slice()
|
||||
}
|
||||
}
|
||||
|
||||
pub fn from_var_pub(
|
||||
cache: &mut LayoutCache<'a>,
|
||||
arena: &'a Bump,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue