Merge pull request #5365 from roc-lang/dev-backend-cli

Dev backend list tests
This commit is contained in:
Folkert de Vries 2023-05-07 14:47:39 +02:00 committed by GitHub
commit deb1e9952d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
13 changed files with 1035 additions and 351 deletions

View file

@ -1,7 +1,10 @@
const std = @import("std");
const builtin = @import("builtin");
const always_inline = std.builtin.CallOptions.Modifier.always_inline;
const Monotonic = std.builtin.AtomicOrder.Monotonic;
const DEBUG_INCDEC = false;
pub fn WithOverflow(comptime T: type) type {
return extern struct { value: T, has_overflowed: bool };
}
@ -40,7 +43,6 @@ fn testing_roc_mmap(addr: ?*anyopaque, length: c_uint, prot: c_int, flags: c_int
}
comptime {
const builtin = @import("builtin");
// During tests, use the testing allocators to satisfy these functions.
if (builtin.is_test) {
@export(testing_roc_alloc, .{ .name = "roc_alloc", .linkage = .Strong });
@ -156,7 +158,16 @@ pub fn increfRcPtrC(ptr_to_refcount: *isize, amount: isize) callconv(.C) void {
// As such, we do not need to cap incrementing.
switch (RC_TYPE) {
Refcount.normal => {
const old = @bitCast(usize, ptr_to_refcount.*);
ptr_to_refcount.* += amount;
const new = @bitCast(usize, ptr_to_refcount.*);
if (DEBUG_INCDEC and builtin.target.cpu.arch != .wasm32) {
const oldH = old - REFCOUNT_ONE + 1;
const newH = new - REFCOUNT_ONE + 1;
std.debug.print("| increment {*}: {} + {} = {}!\n", .{ ptr_to_refcount, oldH, amount, newH });
}
},
Refcount.atomic => {
_ = @atomicRmw(isize, ptr_to_refcount, std.builtin.AtomicRmwOp.Add, amount, Monotonic);
@ -246,7 +257,17 @@ inline fn decref_ptr_to_refcount(
if (refcount != REFCOUNT_MAX_ISIZE) {
switch (RC_TYPE) {
Refcount.normal => {
const old = @bitCast(usize, refcount);
refcount_ptr[0] = refcount -% 1;
const new = @bitCast(usize, refcount -% 1);
if (DEBUG_INCDEC and builtin.target.cpu.arch != .wasm32) {
const oldH = old - REFCOUNT_ONE + 1;
const newH = new - REFCOUNT_ONE + 1;
std.debug.print("| decrement {*}: {} - 1 = {}!\n", .{ refcount_ptr, oldH, newH });
}
if (refcount == REFCOUNT_ONE_ISIZE) {
dealloc(@ptrCast([*]u8, refcount_ptr) - (extra_bytes - @sizeOf(usize)), alignment);
}