morphic + reset/reuse

This commit is contained in:
Folkert 2022-11-15 22:02:11 +01:00
parent 2cc9c32c37
commit 5aa29c4e8b
No known key found for this signature in database
GPG key ID: 1F17F6FFD112B97C
2 changed files with 40 additions and 6 deletions

View file

@ -1053,7 +1053,16 @@ pub fn build_exp_expr<'a, 'ctx, 'env>(
load_roc_value(env, *layout, value.into_pointer_value(), "load_boxed_value")
}
Reset { symbol, .. } => {
Reset {
symbol,
update_mode,
} => {
let bytes = update_mode.to_bytes();
let update_var = UpdateModeVar(&bytes);
let update_mode = func_spec_solutions
.update_mode(update_var)
.unwrap_or(UpdateMode::Immutable);
let (tag_ptr, layout) = load_symbol_and_layout(scope, symbol);
let tag_ptr = tag_ptr.into_pointer_value();
@ -1070,7 +1079,11 @@ pub fn build_exp_expr<'a, 'ctx, 'env>(
let refcount_ptr =
PointerToRefcount::from_ptr_to_data(env, tag_pointer_clear_tag_id(env, tag_ptr));
let is_unique = refcount_ptr.is_1(env);
let is_unique = match update_mode {
UpdateMode::InPlace => env.context.bool_type().const_int(1, false),
UpdateMode::Immutable => refcount_ptr.is_1(env),
};
env.builder
.build_conditional_branch(is_unique, then_block, else_block);