expose decref_pointer_check_NULL

This commit is contained in:
Folkert 2021-09-10 20:42:25 +02:00
parent ac75badbe4
commit 5e68d31afc
4 changed files with 32 additions and 0 deletions

View file

@ -110,6 +110,7 @@ const utils = @import("utils.zig");
comptime {
exportUtilsFn(utils.test_panic, "test_panic");
exportUtilsFn(utils.decrefC, "decref");
exportUtilsFn(utils.decrefCheckNullC, "decref_check_null");
@export(utils.panic, .{ .name = "roc_builtins.utils." ++ "panic", .linkage = .Weak });
}

View file

@ -117,6 +117,15 @@ pub fn decrefC(
return @call(.{ .modifier = always_inline }, decref_ptr_to_refcount, .{ bytes, alignment });
}
pub fn decrefCheckNullC(
bytes_or_null: ?[*]isize,
alignment: u32,
) callconv(.C) void {
if (bytes_or_null) |bytes| {
return @call(.{ .modifier = always_inline }, decref_ptr_to_refcount, .{ bytes, alignment });
}
}
pub fn decref(
bytes_or_null: ?[*]u8,
data_bytes: usize,

View file

@ -83,3 +83,4 @@ pub const DEC_DIV: &str = "roc_builtins.dec.div";
pub const UTILS_TEST_PANIC: &str = "roc_builtins.utils.test_panic";
pub const UTILS_DECREF: &str = "roc_builtins.utils.decref";
pub const UTILS_DECREF_CHECK_NULL: &str = "roc_builtins.utils.decref_check_null";

View file

@ -250,6 +250,27 @@ pub fn decref_pointer<'a, 'ctx, 'env>(
);
}
/// Assumes a pointer to the refcount
pub fn decref_pointer_check_null<'a, 'ctx, 'env>(
env: &Env<'a, 'ctx, 'env>,
pointer: PointerValue<'ctx>,
alignment: u32,
) {
let alignment = env.context.i32_type().const_int(alignment as _, false);
call_void_bitcode_fn(
env,
&[
env.builder.build_bitcast(
pointer,
env.ptr_int().ptr_type(AddressSpace::Generic),
"to_isize_ptr",
),
alignment.into(),
],
roc_builtins::bitcode::UTILS_DECREF_CHECK_NULL,
);
}
fn modify_refcount_struct<'a, 'ctx, 'env>(
env: &Env<'a, 'ctx, 'env>,
layout_ids: &mut LayoutIds<'a>,