increment struct layouts ...

This commit is contained in:
Folkert 2021-01-21 20:21:45 +01:00
parent 18d04614d4
commit 2e52ed68a4

View file

@ -284,12 +284,13 @@ impl<'ctx> PointerToRefcount<'ctx> {
} }
} }
pub fn decrement_refcount_struct<'a, 'ctx, 'env>( fn modify_refcount_struct<'a, 'ctx, 'env>(
env: &Env<'a, 'ctx, 'env>, env: &Env<'a, 'ctx, 'env>,
parent: FunctionValue<'ctx>, parent: FunctionValue<'ctx>,
layout_ids: &mut LayoutIds<'a>, layout_ids: &mut LayoutIds<'a>,
value: BasicValueEnum<'ctx>, value: BasicValueEnum<'ctx>,
layouts: &[Layout<'a>], layouts: &[Layout<'a>],
mode: Mode,
) { ) {
let wrapper_struct = value.into_struct_value(); let wrapper_struct = value.into_struct_value();
@ -300,7 +301,14 @@ pub fn decrement_refcount_struct<'a, 'ctx, 'env>(
.build_extract_value(wrapper_struct, i as u32, "decrement_struct_field") .build_extract_value(wrapper_struct, i as u32, "decrement_struct_field")
.unwrap(); .unwrap();
decrement_refcount_layout(env, parent, layout_ids, field_ptr, field_layout) match mode {
Mode::Inc => {
increment_refcount_layout(env, parent, layout_ids, field_ptr, field_layout)
}
Mode::Dec => {
decrement_refcount_layout(env, parent, layout_ids, field_ptr, field_layout)
}
}
} }
} }
} }
@ -339,7 +347,7 @@ pub fn decrement_refcount_layout<'a, 'ctx, 'env>(
PhantomEmptyStruct => {} PhantomEmptyStruct => {}
Struct(layouts) => { Struct(layouts) => {
decrement_refcount_struct(env, parent, layout_ids, value, layouts); modify_refcount_struct(env, parent, layout_ids, value, layouts, Mode::Dec);
} }
RecursivePointer => todo!("TODO implement decrement layout of recursive tag union"), RecursivePointer => todo!("TODO implement decrement layout of recursive tag union"),
@ -512,6 +520,11 @@ pub fn increment_refcount_layout<'a, 'ctx, 'env>(
) )
} }
} }
Struct(layouts) => {
modify_refcount_struct(env, parent, layout_ids, value, layouts, Mode::Inc);
}
_ => {} _ => {}
} }
} }
@ -1262,7 +1275,7 @@ fn build_rec_union_help<'a, 'ctx, 'env>(
let block = env let block = env
.context .context
.append_basic_block(parent, pick("tag_id_increment", "tag_id_increment")); .append_basic_block(parent, pick("tag_id_increment", "tag_id_decrement"));
env.builder.position_at_end(block); env.builder.position_at_end(block);
let wrapper_type = basic_type_from_layout( let wrapper_type = basic_type_from_layout(