diff --git a/compiler/builtins/bitcode/src/main.zig b/compiler/builtins/bitcode/src/main.zig index 257bd9e52f..e11059d2a8 100644 --- a/compiler/builtins/bitcode/src/main.zig +++ b/compiler/builtins/bitcode/src/main.zig @@ -21,7 +21,7 @@ comptime { exportStrFn(str.startsWith, "starts_with"); exportStrFn(str.endsWith, "ends_with"); exportStrFn(str.strConcat, "concat"); - exportStrFn(str.strLen, "len"); + exportStrFn(str.strNumberOfBytes, "number_of_bytes"); } // Export helpers - Must be run inside a comptime diff --git a/compiler/builtins/bitcode/src/str.zig b/compiler/builtins/bitcode/src/str.zig index 39281d1b33..ab917541a2 100644 --- a/compiler/builtins/bitcode/src/str.zig +++ b/compiler/builtins/bitcode/src/str.zig @@ -206,7 +206,7 @@ const RocStr = extern struct { // Str.numberOfBytes -pub fn strLen(string: RocStr) callconv(.C) u64 { +pub fn strNumberOfBytes(string: RocStr) callconv(.C) u64 { return string.len(); } diff --git a/compiler/builtins/src/bitcode.rs b/compiler/builtins/src/bitcode.rs index 2fbd4f6782..bf042f2848 100644 --- a/compiler/builtins/src/bitcode.rs +++ b/compiler/builtins/src/bitcode.rs @@ -29,4 +29,4 @@ pub const STR_STR_SPLIT_IN_PLACE: &str = "roc_builtins.str.str_split_in_place"; pub const STR_COUNT_GRAPEHEME_CLUSTERS: &str = "roc_builtins.str.count_grapheme_clusters"; pub const STR_STARTS_WITH: &str = "roc_builtins.str.starts_with"; pub const STR_ENDS_WITH: &str = "roc_builtins.str.ends_with"; -pub const STR_LEN: &str = "roc_builtins.str.len"; +pub const STR_NUMBER_OF_BYTES: &str = "roc_builtins.str.number_of_bytes"; diff --git a/compiler/gen/src/llvm/build.rs b/compiler/gen/src/llvm/build.rs index b428c28491..23ea78cdef 100644 --- a/compiler/gen/src/llvm/build.rs +++ b/compiler/gen/src/llvm/build.rs @@ -4,8 +4,8 @@ use crate::llvm::build_list::{ list_reverse, list_set, list_single, list_sum, list_walk, list_walk_backwards, }; use crate::llvm::build_str::{ - str_concat, str_count_graphemes, str_ends_with, str_len, str_split, str_starts_with, - CHAR_LAYOUT, + str_concat, str_count_graphemes, str_ends_with, str_number_of_bytes, str_split, + str_starts_with, CHAR_LAYOUT, }; use crate::llvm::compare::{build_eq, build_neq}; use crate::llvm::convert::{ @@ -2427,23 +2427,19 @@ fn run_low_level<'a, 'ctx, 'env>( let inplace = get_inplace_from_layout(layout); - str_concat(env, inplace, scope, parent, args[0], args[1]) + str_concat(env, inplace, scope, args[0], args[1]) } StrStartsWith => { // Str.startsWith : Str, Str -> Bool debug_assert_eq!(args.len(), 2); - let inplace = get_inplace_from_layout(layout); - - str_starts_with(env, inplace, scope, parent, args[0], args[1]) + str_starts_with(env, scope, args[0], args[1]) } StrEndsWith => { // Str.startsWith : Str, Str -> Bool debug_assert_eq!(args.len(), 2); - let inplace = get_inplace_from_layout(layout); - - str_ends_with(env, inplace, scope, parent, args[0], args[1]) + str_ends_with(env, scope, args[0], args[1]) } StrSplit => { // Str.split : Str, Str -> List Str @@ -2451,13 +2447,13 @@ fn run_low_level<'a, 'ctx, 'env>( let inplace = get_inplace_from_layout(layout); - str_split(env, scope, parent, inplace, args[0], args[1]) + str_split(env, scope, inplace, args[0], args[1]) } StrIsEmpty => { // Str.isEmpty : Str -> Str debug_assert_eq!(args.len(), 1); - let len = str_len(env, scope, args[0]); + let len = str_number_of_bytes(env, scope, args[0]); let is_zero = env.builder.build_int_compare( IntPredicate::EQ, len, @@ -2470,7 +2466,7 @@ fn run_low_level<'a, 'ctx, 'env>( // Str.countGraphemes : Str -> Int debug_assert_eq!(args.len(), 1); - str_count_graphemes(env, scope, parent, args[0]) + str_count_graphemes(env, scope, args[0]) } ListLen => { // List.len : List * -> Int diff --git a/compiler/gen/src/llvm/build_str.rs b/compiler/gen/src/llvm/build_str.rs index 209a125b13..12318c3488 100644 --- a/compiler/gen/src/llvm/build_str.rs +++ b/compiler/gen/src/llvm/build_str.rs @@ -4,7 +4,7 @@ use crate::llvm::build::{ use crate::llvm::build_list::{allocate_list, store_list}; use crate::llvm::convert::collection; use inkwell::types::BasicTypeEnum; -use inkwell::values::{BasicValueEnum, FunctionValue, IntValue, StructValue}; +use inkwell::values::{BasicValueEnum, IntValue, StructValue}; use inkwell::AddressSpace; use roc_builtins::bitcode; use roc_module::symbol::Symbol; @@ -16,7 +16,6 @@ pub static CHAR_LAYOUT: Layout = Layout::Builtin(Builtin::Int8); pub fn str_split<'a, 'ctx, 'env>( env: &Env<'a, 'ctx, 'env>, scope: &Scope<'a, 'ctx>, - _parent: FunctionValue<'ctx>, inplace: InPlace, str_symbol: Symbol, delimiter_symbol: Symbol, @@ -60,29 +59,6 @@ pub fn str_split<'a, 'ctx, 'env>( store_list(env, ret_list_ptr, segment_count) } -/* -fn cast_to_zig_str( - env: &Env<'a, 'ctx, 'env>, - str_as_struct: StructValue<'ctx>, -) -> BasicValueEnum<'ctx> { - // get the RocStr type defined by zig - let roc_str_type = env.module.get_struct_type("str.RocStr").unwrap(); - - // convert `{ *mut u8, i64 }` to `RocStr` - builder.build_bitcast(str_as_struct, roc_str_type, "convert_to_zig_rocstr"); -} - -fn cast_from_zig_str( - env: &Env<'a, 'ctx, 'env>, - str_as_struct: StructValue<'ctx>, -) -> BasicValueEnum<'ctx> { - let ret_type = BasicTypeEnum::StructType(collection(ctx, env.ptr_bytes)); - - // convert `RocStr` to `{ *mut u8, i64 }` - builder.build_bitcast(str_as_struct, ret_type, "convert_from_zig_rocstr"); -} -*/ - fn str_symbol_to_i128<'a, 'ctx, 'env>( env: &Env<'a, 'ctx, 'env>, scope: &Scope<'a, 'ctx>, @@ -144,7 +120,6 @@ pub fn str_concat<'a, 'ctx, 'env>( env: &Env<'a, 'ctx, 'env>, inplace: InPlace, scope: &Scope<'a, 'ctx>, - _parent: FunctionValue<'ctx>, str1_symbol: Symbol, str2_symbol: Symbol, ) -> BasicValueEnum<'ctx> { @@ -173,7 +148,7 @@ pub fn str_concat<'a, 'ctx, 'env>( zig_str_to_struct(env, zig_result).into() } -pub fn str_len<'a, 'ctx, 'env>( +pub fn str_number_of_bytes<'a, 'ctx, 'env>( env: &Env<'a, 'ctx, 'env>, scope: &Scope<'a, 'ctx>, str_symbol: Symbol, @@ -181,7 +156,8 @@ pub fn str_len<'a, 'ctx, 'env>( let str_i128 = str_symbol_to_i128(env, scope, str_symbol); // the builtin will always return an u64 - let length = call_bitcode_fn(env, &[str_i128.into()], &bitcode::STR_LEN).into_int_value(); + let length = + call_bitcode_fn(env, &[str_i128.into()], &bitcode::STR_NUMBER_OF_BYTES).into_int_value(); // cast to the appropriate usize of the current build env.builder @@ -191,9 +167,7 @@ pub fn str_len<'a, 'ctx, 'env>( /// Str.startsWith : Str, Str -> Bool pub fn str_starts_with<'a, 'ctx, 'env>( env: &Env<'a, 'ctx, 'env>, - _inplace: InPlace, scope: &Scope<'a, 'ctx>, - _parent: FunctionValue<'ctx>, str_symbol: Symbol, prefix_symbol: Symbol, ) -> BasicValueEnum<'ctx> { @@ -210,9 +184,7 @@ pub fn str_starts_with<'a, 'ctx, 'env>( /// Str.endsWith : Str, Str -> Bool pub fn str_ends_with<'a, 'ctx, 'env>( env: &Env<'a, 'ctx, 'env>, - _inplace: InPlace, scope: &Scope<'a, 'ctx>, - _parent: FunctionValue<'ctx>, str_symbol: Symbol, prefix_symbol: Symbol, ) -> BasicValueEnum<'ctx> { @@ -230,7 +202,6 @@ pub fn str_ends_with<'a, 'ctx, 'env>( pub fn str_count_graphemes<'a, 'ctx, 'env>( env: &Env<'a, 'ctx, 'env>, scope: &Scope<'a, 'ctx>, - _parent: FunctionValue<'ctx>, str_symbol: Symbol, ) -> BasicValueEnum<'ctx> { let str_i128 = str_symbol_to_i128(env, scope, str_symbol);