Fixed inplace problem in list_set

This commit is contained in:
Chad Stearns 2020-09-13 15:04:34 -04:00
parent 9351746952
commit 30b7545da0
2 changed files with 12 additions and 5 deletions

View file

@ -1877,6 +1877,8 @@ fn run_low_level<'a, 'ctx, 'env>(
ListSetInPlace => { ListSetInPlace => {
let (list_symbol, list_layout) = load_symbol_and_layout(env, scope, &args[0]); let (list_symbol, list_layout) = load_symbol_and_layout(env, scope, &args[0]);
let output_inplace = get_inplace_from_layout(layout);
list_set( list_set(
parent, parent,
&[ &[
@ -1886,6 +1888,7 @@ fn run_low_level<'a, 'ctx, 'env>(
], ],
env, env,
InPlace::InPlace, InPlace::InPlace,
output_inplace,
) )
} }
ListSet => { ListSet => {
@ -1897,8 +1900,10 @@ fn run_low_level<'a, 'ctx, 'env>(
(load_symbol_and_layout(env, scope, &args[2])), (load_symbol_and_layout(env, scope, &args[2])),
]; ];
let in_place = || list_set(parent, arguments, env, InPlace::InPlace); let output_inplace = get_inplace_from_layout(layout);
let clone = || list_set(parent, arguments, env, InPlace::Clone);
let in_place = || list_set(parent, arguments, env, InPlace::InPlace, output_inplace);
let clone = || list_set(parent, arguments, env, InPlace::Clone, output_inplace);
let empty = || list_symbol; let empty = || list_symbol;
maybe_inplace_list( maybe_inplace_list(

View file

@ -642,7 +642,8 @@ pub fn list_set<'a, 'ctx, 'env>(
parent: FunctionValue<'ctx>, parent: FunctionValue<'ctx>,
args: &[(BasicValueEnum<'ctx>, &'a Layout<'a>)], args: &[(BasicValueEnum<'ctx>, &'a Layout<'a>)],
env: &Env<'a, 'ctx, 'env>, env: &Env<'a, 'ctx, 'env>,
inplace: InPlace, input_inplace: InPlace,
output_inplace: InPlace,
) -> BasicValueEnum<'ctx> { ) -> BasicValueEnum<'ctx> {
let builder = env.builder; let builder = env.builder;
@ -664,14 +665,15 @@ pub fn list_set<'a, 'ctx, 'env>(
let ctx = env.context; let ctx = env.context;
let elem_type = basic_type_from_layout(env.arena, ctx, elem_layout, env.ptr_bytes); let elem_type = basic_type_from_layout(env.arena, ctx, elem_layout, env.ptr_bytes);
let ptr_type = get_ptr_type(&elem_type, AddressSpace::Generic); let ptr_type = get_ptr_type(&elem_type, AddressSpace::Generic);
let (new_wrapper, array_data_ptr) = match inplace {
let (new_wrapper, array_data_ptr) = match input_inplace {
InPlace::InPlace => ( InPlace::InPlace => (
original_wrapper, original_wrapper,
load_list_ptr(builder, original_wrapper, ptr_type), load_list_ptr(builder, original_wrapper, ptr_type),
), ),
InPlace::Clone => clone_nonempty_list( InPlace::Clone => clone_nonempty_list(
env, env,
inplace, output_inplace,
list_len, list_len,
load_list_ptr(builder, original_wrapper, ptr_type), load_list_ptr(builder, original_wrapper, ptr_type),
elem_layout, elem_layout,