mirror of
https://github.com/roc-lang/roc.git
synced 2025-07-24 06:55:15 +00:00
Merge pull request #4526 from roc-lang/reset-reuse-morphic-v2
This commit is contained in:
commit
53a2d683e6
2 changed files with 40 additions and 6 deletions
|
@ -1543,11 +1543,32 @@ fn expr_spec<'a>(
|
|||
}
|
||||
_ => unreachable!("empty array does not have a list layout"),
|
||||
},
|
||||
Reset { symbol, .. } => {
|
||||
let type_id = layout_spec(env, builder, interner, layout, &WhenRecursive::Unreachable)?;
|
||||
let value_id = env.symbols[symbol];
|
||||
Reset {
|
||||
symbol,
|
||||
update_mode,
|
||||
} => {
|
||||
let tag_value_id = env.symbols[symbol];
|
||||
|
||||
builder.add_unknown_with(block, &[value_id], type_id)
|
||||
let union_layout = match layout {
|
||||
Layout::Union(ul) => ul,
|
||||
_ => unreachable!(),
|
||||
};
|
||||
|
||||
let type_name_bytes = recursive_tag_union_name_bytes(union_layout).as_bytes();
|
||||
let type_name = TypeName(&type_name_bytes);
|
||||
|
||||
// unwrap the named wrapper
|
||||
let union_id = builder.add_unwrap_named(block, MOD_APP, type_name, tag_value_id)?;
|
||||
|
||||
let heap_cell = builder.add_get_tuple_field(block, union_id, TAG_CELL_INDEX)?;
|
||||
let union_data = builder.add_get_tuple_field(block, union_id, TAG_DATA_INDEX)?;
|
||||
|
||||
let mode = update_mode.to_bytes();
|
||||
let update_mode_var = UpdateModeVar(&mode);
|
||||
|
||||
let _unit = builder.add_update(block, update_mode_var, heap_cell)?;
|
||||
|
||||
with_new_heap_cell(builder, block, union_data)
|
||||
}
|
||||
RuntimeErrorFunction(_) => {
|
||||
let type_id = layout_spec(env, builder, interner, layout, &WhenRecursive::Unreachable)?;
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue