List.releaseExcessCapacity

This commit is contained in:
Folkert 2023-05-02 23:00:07 +02:00
parent 4e29652f0d
commit a48618e34a
No known key found for this signature in database
GPG key ID: 1F17F6FFD112B97C
2 changed files with 51 additions and 16 deletions

View file

@ -1330,8 +1330,6 @@ trait Backend<'a> {
layout_usize,
];
dbg!(arg_layouts);
let intrinsic = bitcode::LIST_SUBLIST.to_string();
self.build_fn_call(sym, intrinsic, &args, &arg_layouts, &list_layout);
}
@ -1382,6 +1380,43 @@ trait Backend<'a> {
ret_layout,
);
}
LowLevel::ListReleaseExcessCapacity => {
let list = args[0];
let list_layout = arg_layouts[0];
let element_layout = match self.interner().get(list_layout) {
Layout::Builtin(Builtin::List(e)) => e,
_ => unreachable!(),
};
let (element_width_int, alignment_int) =
self.interner().stack_size_and_alignment(element_layout);
let alignment = self.debug_symbol("alignment");
self.load_literal_i32(&alignment, Ord::max(alignment_int, 8) as i32);
let element_width = self.debug_symbol("element_width");
self.load_literal_i64(&element_width, element_width_int as i64);
let update_mode = self.debug_symbol("update_mode");
self.load_literal_i8(&update_mode, UpdateMode::Immutable as i8);
let layout_usize = Layout::U64;
// list: RocList,
// alignment: u32,
// element_width: usize,
// update_mode: UpdateMode,
self.build_fn_call(
sym,
bitcode::LIST_RELEASE_EXCESS_CAPACITY.to_string(),
&[list, alignment, element_width, update_mode],
&[list_layout, Layout::U32, layout_usize, Layout::U8],
ret_layout,
);
}
x => todo!("low level, {:?}", x),
}
}

View file

@ -3428,7 +3428,7 @@ fn list_starts_with_nonempty() {
}
#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))]
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm", feature = "gen-dev"))]
fn monomorphized_lists() {
assert_evals_to!(
indoc!(
@ -3525,7 +3525,7 @@ fn reserve_unchanged() {
}
#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))]
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm", feature = "gen-dev"))]
fn release_excess_capacity() {
assert_evals_to!(
indoc!(
@ -3541,7 +3541,7 @@ fn release_excess_capacity() {
}
#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))]
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm", feature = "gen-dev"))]
fn release_excess_capacity_with_len() {
assert_evals_to!(
indoc!(
@ -3557,7 +3557,7 @@ fn release_excess_capacity_with_len() {
}
#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))]
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm", feature = "gen-dev"))]
fn release_excess_capacity_empty() {
assert_evals_to!(
indoc!(
@ -3572,7 +3572,7 @@ fn release_excess_capacity_empty() {
}
#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))]
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm", feature = "gen-dev"))]
fn call_function_in_empty_list() {
assert_evals_to!(
indoc!(
@ -3588,7 +3588,7 @@ fn call_function_in_empty_list() {
}
#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))]
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm", feature = "gen-dev"))]
fn call_function_in_empty_list_unbound() {
assert_evals_to!(
indoc!(
@ -3635,7 +3635,7 @@ fn issue_3571_lowlevel_call_function_with_bool_lambda_set() {
}
#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))]
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm", feature = "gen-dev"))]
fn issue_3530_uninitialized_capacity_in_list_literal() {
assert_evals_to!(
indoc!(
@ -3650,7 +3650,7 @@ fn issue_3530_uninitialized_capacity_in_list_literal() {
}
#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))]
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm", feature = "gen-dev"))]
fn list_infer_usage() {
assert_evals_to!(
indoc!(
@ -3670,7 +3670,7 @@ fn list_infer_usage() {
}
#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))]
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm", feature = "gen-dev"))]
fn list_walk_backwards_implements_position() {
assert_evals_to!(
r#"
@ -3698,7 +3698,7 @@ fn list_walk_backwards_implements_position() {
}
#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))]
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm", feature = "gen-dev"))]
fn list_walk_backwards_until_sum() {
assert_evals_to!(
r#"List.walkBackwardsUntil [1, 2] 0 \a,b -> Continue (a + b)"#,
@ -3708,7 +3708,7 @@ fn list_walk_backwards_until_sum() {
}
#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))]
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm", feature = "gen-dev"))]
fn list_walk_backwards_until_even_prefix_sum() {
assert_evals_to!(
r#"
@ -3726,7 +3726,7 @@ fn list_walk_backwards_until_even_prefix_sum() {
}
#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))]
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm", feature = "gen-dev"))]
fn list_walk_from_until_sum() {
assert_evals_to!(
r#"List.walkFromUntil [1, 2, 3, 4] 2 0 \a,b -> Continue (a + b)"#,
@ -3736,7 +3736,7 @@ fn list_walk_from_until_sum() {
}
#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))]
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm", feature = "gen-dev"))]
fn concat_unique_to_nonunique_overlapping_issue_4697() {
assert_evals_to!(
r#"
@ -3757,7 +3757,7 @@ fn concat_unique_to_nonunique_overlapping_issue_4697() {
}
#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))]
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm", feature = "gen-dev"))]
fn list_walk_from_even_prefix_sum() {
assert_evals_to!(
r#"