make Str.fromUtf8 in-place

This commit is contained in:
Folkert 2021-10-03 12:13:17 +02:00
parent 9e97a09a87
commit 018348bd83
6 changed files with 49 additions and 14 deletions

View file

@ -4848,7 +4848,7 @@ fn run_low_level<'a, 'ctx, 'env>(
let original_wrapper = load_symbol(scope, &args[0]).into_struct_value();
str_from_utf8(env, parent, original_wrapper)
str_from_utf8(env, parent, original_wrapper, update_mode)
}
StrFromUtf8Range => {
debug_assert_eq!(args.len(), 2);

View file

@ -17,13 +17,13 @@ use morphic_lib::UpdateMode;
use roc_builtins::bitcode;
use roc_mono::layout::{Builtin, Layout, LayoutIds};
fn pass_update_mode<'a, 'ctx, 'env>(
pub fn pass_update_mode<'a, 'ctx, 'env>(
env: &Env<'a, 'ctx, 'env>,
update_mode: UpdateMode,
) -> BasicValueEnum<'ctx> {
match update_mode {
UpdateMode::Immutable => env.context.bool_type().const_zero().into(),
UpdateMode::InPlace => env.context.bool_type().const_int(1, false).into(),
UpdateMode::Immutable => env.context.i8_type().const_zero().into(),
UpdateMode::InPlace => env.context.i8_type().const_int(1, false).into(),
}
}

View file

@ -1,9 +1,12 @@
use crate::llvm::bitcode::{call_bitcode_fn, call_void_bitcode_fn};
use crate::llvm::build::{complex_bitcast, Env, Scope};
use crate::llvm::build_list::{allocate_list, call_bitcode_fn_returns_list, store_list};
use crate::llvm::build_list::{
allocate_list, call_bitcode_fn_returns_list, pass_update_mode, store_list,
};
use inkwell::builder::Builder;
use inkwell::values::{BasicValueEnum, FunctionValue, IntValue, PointerValue, StructValue};
use inkwell::AddressSpace;
use morphic_lib::UpdateMode;
use roc_builtins::bitcode;
use roc_module::symbol::Symbol;
use roc_mono::layout::{Builtin, Layout};
@ -350,6 +353,7 @@ pub fn str_from_utf8<'a, 'ctx, 'env>(
env: &Env<'a, 'ctx, 'env>,
_parent: FunctionValue<'ctx>,
original_wrapper: StructValue<'ctx>,
update_mode: UpdateMode,
) -> BasicValueEnum<'ctx> {
let builder = env.builder;
@ -365,6 +369,7 @@ pub fn str_from_utf8<'a, 'ctx, 'env>(
env.str_list_c_abi().into(),
"to_i128",
),
pass_update_mode(env, update_mode),
result_ptr.into(),
],
bitcode::STR_FROM_UTF8,