diff --git a/compiler/gen/src/llvm/build_list.rs b/compiler/gen/src/llvm/build_list.rs index 5555af95cf..21addc8685 100644 --- a/compiler/gen/src/llvm/build_list.rs +++ b/compiler/gen/src/llvm/build_list.rs @@ -1393,17 +1393,12 @@ where // This helper simulates a basic for loop, where // and index increments up from 0 to some end value -fn incrementing_index_loop<'ctx, LoopFn>( +pub fn incrementing_index_loop<'ctx, LoopFn>( builder: &Builder<'ctx>, ctx: &'ctx Context, parent: FunctionValue<'ctx>, end: IntValue<'ctx>, index_name: &str, - // allocating memory for an index is costly, so sometimes - // we want to reuse an index if multiple loops happen in a - // series, such as the case in List.concat. A memory - // allocation cab be passed in to be used, and the memory - // allocation that _is_ used is the return value. mut loop_fn: LoopFn, ) -> PointerValue<'ctx> where diff --git a/compiler/gen/src/llvm/build_str.rs b/compiler/gen/src/llvm/build_str.rs index d1dbcd5416..f828699d13 100644 --- a/compiler/gen/src/llvm/build_str.rs +++ b/compiler/gen/src/llvm/build_str.rs @@ -2,8 +2,8 @@ use crate::llvm::build::{ call_bitcode_fn, load_symbol, load_symbol_and_layout, ptr_from_symbol, Env, InPlace, Scope, }; use crate::llvm::build_list::{ - allocate_list, build_basic_phi2, empty_list, incrementing_elem_loop, list_single, - load_list_ptr, store_list, + allocate_list, build_basic_phi2, empty_list, incrementing_elem_loop, incrementing_index_loop, + list_single, load_list_ptr, store_list, }; use crate::llvm::convert::{collection, ptr_int}; use inkwell::builder::Builder; @@ -51,18 +51,31 @@ pub fn str_split<'a, 'ctx, 'env>( let str: BasicValueEnum<'ctx> = panic!("Get str basic value enum"); let delimiter: BasicValueEnum<'ctx> = panic!("Get delimiter basic value enum"); -git - let delimiter_count = - call_bitcode_fn(env, &[str, delimiter], "count_delimiters_"); - build_basic_phi2( - env, + let delimiter_count = + call_bitcode_fn(env, &[str, delimiter], "count_delimiters_") + .into_int_value(); + + let ret_list_len = builder.build_int_add( + delimiter_count, + ctx.i64_type().const_int(1, false), + "ret_str_split_list_Len", + ); + + let ret_list_ptr = allocate_list(env, inplace, &CHAR_LAYOUT, ret_list_len); + + let ret_list_loop = |index| {}; + + incrementing_index_loop( + builder, + ctx, parent, - delimiter_is_longer_comparison, - if_delimiter_is_longer, - if_delimiter_is_shorter, - str_wrapper_type, - ) + ret_list_len, + "str_split_ret_list_len_index", + ret_list_loop, + ); + + empty_list(env) }, ) },