mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-28 14:24:45 +00:00
check for staticness when incrementing
This commit is contained in:
parent
5690794dc9
commit
6d941e242e
1 changed files with 19 additions and 6 deletions
|
@ -119,19 +119,32 @@ impl<'ctx> PointerToRefcount<'ctx> {
|
|||
let builder = env.builder;
|
||||
let refcount_type = ptr_int(env.context, env.ptr_bytes);
|
||||
|
||||
let max = builder.build_int_compare(
|
||||
let is_static_allocation = builder.build_int_compare(
|
||||
IntPredicate::EQ,
|
||||
refcount,
|
||||
refcount_type.const_int(REFCOUNT_MAX as u64, false),
|
||||
"refcount_max_check",
|
||||
);
|
||||
|
||||
let block = env.builder.get_insert_block().expect("to be in a function");
|
||||
let parent = block.get_parent().unwrap();
|
||||
|
||||
let modify_block = env.context.append_basic_block(parent, "inc_str_modify");
|
||||
let cont_block = env.context.append_basic_block(parent, "inc_str_cont");
|
||||
|
||||
env.builder
|
||||
.build_conditional_branch(is_static_allocation, cont_block, modify_block);
|
||||
|
||||
{
|
||||
env.builder.position_at_end(modify_block);
|
||||
|
||||
let incremented = builder.build_int_add(refcount, amount, "increment_refcount");
|
||||
self.set_refcount(env, incremented);
|
||||
|
||||
let new_refcount = builder
|
||||
.build_select(max, refcount, incremented, "select_refcount")
|
||||
.into_int_value();
|
||||
env.builder.build_unconditional_branch(cont_block);
|
||||
}
|
||||
|
||||
self.set_refcount(env, new_refcount);
|
||||
env.builder.position_at_end(cont_block);
|
||||
}
|
||||
|
||||
pub fn decrement<'a, 'env>(&self, env: &Env<'a, 'ctx, 'env>, layout: &Layout<'a>) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue