Use list element width for List.withCapacity

This commit is contained in:
Ahmad Sattar 2023-01-28 02:02:32 +01:00
parent f80edb6ed6
commit a1e2c3f64b
No known key found for this signature in database
GPG key ID: 6EAC5AB400A49604
2 changed files with 12 additions and 2 deletions

View file

@ -1269,6 +1269,7 @@ impl<
dst: &Symbol,
capacity: Symbol,
capacity_layout: InLayout<'a>,
element_layout: InLayout<'a>,
ret_layout: &InLayout<'a>,
) {
// List alignment argument (u32).
@ -1282,7 +1283,7 @@ impl<
// Load element_width argument (usize).
let u64_layout = Layout::U64;
let element_width = self.layout_interner.stack_size(*ret_layout);
let element_width = self.layout_interner.stack_size(element_layout);
self.load_literal(
&Symbol::DEV_TMP2,
&u64_layout,

View file

@ -21,6 +21,7 @@ use roc_mono::layout::{
Builtin, InLayout, Layout, LayoutId, LayoutIds, LayoutInterner, STLayoutInterner, TagIdIntType,
UnionLayout,
};
use roc_mono::list_element_layout;
mod generic64;
mod object_builder;
@ -685,7 +686,14 @@ trait Backend<'a> {
args.len(),
"ListWithCapacity: expected to have exactly one argument"
);
self.build_list_with_capacity(sym, args[0], arg_layouts[0], ret_layout)
let element_layout = list_element_layout!(self.interner(), *ret_layout);
self.build_list_with_capacity(
sym,
args[0],
arg_layouts[0],
element_layout,
ret_layout,
)
}
LowLevel::ListReserve => {
debug_assert_eq!(
@ -948,6 +956,7 @@ trait Backend<'a> {
dst: &Symbol,
capacity: Symbol,
capacity_layout: InLayout<'a>,
element_layout: InLayout<'a>,
ret_layout: &InLayout<'a>,
);