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 builder = env.builder;
|
||||||
let refcount_type = ptr_int(env.context, env.ptr_bytes);
|
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,
|
IntPredicate::EQ,
|
||||||
refcount,
|
refcount,
|
||||||
refcount_type.const_int(REFCOUNT_MAX as u64, false),
|
refcount_type.const_int(REFCOUNT_MAX as u64, false),
|
||||||
"refcount_max_check",
|
"refcount_max_check",
|
||||||
);
|
);
|
||||||
let incremented = builder.build_int_add(refcount, amount, "increment_refcount");
|
|
||||||
|
|
||||||
let new_refcount = builder
|
let block = env.builder.get_insert_block().expect("to be in a function");
|
||||||
.build_select(max, refcount, incremented, "select_refcount")
|
let parent = block.get_parent().unwrap();
|
||||||
.into_int_value();
|
|
||||||
|
|
||||||
self.set_refcount(env, new_refcount);
|
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);
|
||||||
|
|
||||||
|
env.builder.build_unconditional_branch(cont_block);
|
||||||
|
}
|
||||||
|
|
||||||
|
env.builder.position_at_end(cont_block);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn decrement<'a, 'env>(&self, env: &Env<'a, 'ctx, 'env>, layout: &Layout<'a>) {
|
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