Add List.concat implementation for generic64

This commit is contained in:
Ahmad Sattar 2023-01-28 02:07:38 +01:00
parent a1e2c3f64b
commit f6b8a27955
No known key found for this signature in database
GPG Key ID: 6EAC5AB400A49604
3 changed files with 104 additions and 9 deletions

View File

@ -1652,6 +1652,82 @@ impl<
self.free_symbol(&Symbol::DEV_TMP5);
}
fn build_list_concat(
&mut self,
dst: &Symbol,
args: &'a [Symbol],
arg_layouts: &[InLayout<'a>],
element_layout: InLayout<'a>,
ret_layout: &InLayout<'a>,
) {
let list_a = args[0];
let list_a_layout = arg_layouts[0];
let list_b = args[1];
let list_b_layout = arg_layouts[1];
// Load list alignment argument (u32).
let u32_layout = Layout::U32;
let list_alignment = self.layout_interner.alignment_bytes(*ret_layout);
self.load_literal(
&Symbol::DEV_TMP,
&u32_layout,
&Literal::Int((list_alignment as i128).to_ne_bytes()),
);
// Load element_width argument (usize).
let u64_layout = Layout::U64;
let element_width = self.layout_interner.stack_size(element_layout);
self.load_literal(
&Symbol::DEV_TMP2,
&u64_layout,
&Literal::Int((element_width as i128).to_ne_bytes()),
);
// Setup the return location.
let base_offset = self
.storage_manager
.claim_stack_area(dst, self.layout_interner.stack_size(*ret_layout));
let lowlevel_args = bumpalo::vec![
in self.env.arena;
list_a,
list_b,
// alignment
Symbol::DEV_TMP,
// element_width
Symbol::DEV_TMP2,
];
let lowlevel_arg_layouts = bumpalo::vec![
in self.env.arena;
list_a_layout,
list_b_layout,
u32_layout,
u64_layout
];
self.build_fn_call(
&Symbol::DEV_TMP3,
bitcode::LIST_CONCAT.to_string(),
&lowlevel_args,
&lowlevel_arg_layouts,
ret_layout,
);
self.free_symbol(&Symbol::DEV_TMP);
self.free_symbol(&Symbol::DEV_TMP2);
// Return list value from fn call
self.storage_manager.copy_symbol_to_stack_offset(
self.layout_interner,
&mut self.buf,
base_offset,
&Symbol::DEV_TMP3,
ret_layout,
);
self.free_symbol(&Symbol::DEV_TMP3);
}
fn build_ptr_cast(&mut self, dst: &Symbol, src: &Symbol) {
let dst_reg = self.storage_manager.claim_general_reg(&mut self.buf, dst);
self.storage_manager

View File

@ -727,6 +727,15 @@ trait Backend<'a> {
);
self.build_list_replace_unsafe(sym, args, arg_layouts, ret_layout)
}
LowLevel::ListConcat => {
debug_assert_eq!(
2,
args.len(),
"ListConcat: expected to have exactly two arguments"
);
let element_layout = list_element_layout!(self.interner(), *ret_layout);
self.build_list_concat(sym, args, arg_layouts, element_layout, ret_layout)
}
LowLevel::StrConcat => self.build_fn_call(
sym,
bitcode::STR_CONCAT.to_string(),
@ -996,6 +1005,16 @@ trait Backend<'a> {
ret_layout: &InLayout<'a>,
);
/// build_list_concat returns a new list containing the two argument lists concatenated.
fn build_list_concat(
&mut self,
dst: &Symbol,
args: &'a [Symbol],
arg_layouts: &[InLayout<'a>],
element_layout: InLayout<'a>,
ret_layout: &InLayout<'a>,
);
/// build_refcount_getptr loads the pointer to the reference count of src into dst.
fn build_ptr_cast(&mut self, dst: &Symbol, src: &Symbol);

View File

@ -1601,7 +1601,7 @@ fn list_reverse_empty_list() {
}
#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))]
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm", feature = "gen-dev"))]
fn list_concat_two_empty_lists() {
assert_evals_to!(
"List.concat [] []",
@ -1611,7 +1611,7 @@ fn list_concat_two_empty_lists() {
}
#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))]
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm", feature = "gen-dev"))]
fn list_concat_two_empty_lists_of_int() {
assert_evals_to!(
indoc!(
@ -1633,7 +1633,7 @@ fn list_concat_two_empty_lists_of_int() {
}
#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))]
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm", feature = "gen-dev"))]
fn list_concat_second_list_is_empty() {
assert_evals_to!(
"List.concat [12, 13] []",
@ -1643,7 +1643,7 @@ fn list_concat_second_list_is_empty() {
}
#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))]
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm", feature = "gen-dev"))]
fn list_concat_first_list_is_empty() {
assert_evals_to!(
"List.concat [] [23, 24]",
@ -1653,7 +1653,7 @@ fn list_concat_first_list_is_empty() {
}
#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))]
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm", feature = "gen-dev"))]
fn list_concat_two_non_empty_lists() {
assert_evals_to!(
"List.concat [1, 2] [3, 4]",
@ -1679,7 +1679,7 @@ fn list_concat_two_bigger_non_empty_lists() {
}
#[allow(dead_code)]
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))]
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm", feature = "gen-dev"))]
fn assert_concat_worked(num_elems1: i64, num_elems2: i64) {
let vec1: Vec<i64> = (0..num_elems1)
.map(|i| 12345 % (i + num_elems1 + num_elems2 + 1))
@ -1701,7 +1701,7 @@ fn assert_concat_worked(num_elems1: i64, num_elems2: i64) {
}
#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))]
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm", feature = "gen-dev"))]
fn list_concat_empty_list() {
assert_concat_worked(0, 0);
assert_concat_worked(1, 0);
@ -1725,7 +1725,7 @@ fn list_concat_empty_list() {
}
#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))]
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm", feature = "gen-dev"))]
fn list_concat_nonempty_lists() {
assert_concat_worked(1, 1);
assert_concat_worked(1, 2);
@ -1741,7 +1741,7 @@ fn list_concat_nonempty_lists() {
}
#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))]
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm", feature = "gen-dev"))]
fn list_concat_large() {
with_larger_debug_stack(|| {
// these values produce mono ASTs so large that