list decrement must use capacity, not length

This commit is contained in:
Folkert 2023-01-14 00:15:50 +01:00
parent 3fda3965ec
commit 437498b7ac
No known key found for this signature in database
GPG Key ID: 1F17F6FFD112B97C
3 changed files with 19 additions and 6 deletions

View File

@ -20,7 +20,7 @@ pub const RocList = extern struct {
length: usize, length: usize,
capacity: usize, capacity: usize,
pub fn len(self: RocList) usize { pub inline fn len(self: RocList) usize {
return self.length; return self.length;
} }
@ -410,9 +410,7 @@ pub fn listWithCapacity(
alignment: u32, alignment: u32,
element_width: usize, element_width: usize,
) callconv(.C) RocList { ) callconv(.C) RocList {
var output = RocList.allocate(alignment, capacity, element_width); return listReserve(RocList.empty(), alignment, capacity, element_width, .InPlace);
output.length = 0;
return output;
} }
pub fn listReserve( pub fn listReserve(

View File

@ -5,7 +5,7 @@ use crate::llvm::build::{
add_func, cast_basic_basic, get_tag_id, tag_pointer_clear_tag_id, use_roc_value, Env, add_func, cast_basic_basic, get_tag_id, tag_pointer_clear_tag_id, use_roc_value, Env,
WhenRecursive, FAST_CALL_CONV, WhenRecursive, FAST_CALL_CONV,
}; };
use crate::llvm::build_list::{incrementing_elem_loop, list_len, load_list}; use crate::llvm::build_list::{incrementing_elem_loop, list_capacity, load_list};
use crate::llvm::convert::{basic_type_from_layout, zig_str_type, RocUnion}; use crate::llvm::convert::{basic_type_from_layout, zig_str_type, RocUnion};
use bumpalo::collections::Vec; use bumpalo::collections::Vec;
use inkwell::basic_block::BasicBlock; use inkwell::basic_block::BasicBlock;
@ -758,7 +758,7 @@ fn modify_refcount_list_help<'a, 'ctx, 'env>(
let parent = fn_val; let parent = fn_val;
let original_wrapper = arg_val.into_struct_value(); let original_wrapper = arg_val.into_struct_value();
let len = list_len(builder, original_wrapper); let len = list_capacity(builder, original_wrapper);
let is_non_empty = builder.build_int_compare( let is_non_empty = builder.build_int_compare(
IntPredicate::UGT, IntPredicate::UGT,

View File

@ -235,3 +235,18 @@ fn str_concat_first_argument_not_unique() {
"# "#
)); ));
} }
#[test]
fn list_concat_empty_list_zero_sized_type() {
valgrind_test(indoc!(
r#"
(
a = List.reserve [] 11
b = []
List.concat a b
|> List.len
|> Num.toStr
)
"#
));
}