diff --git a/crates/compiler/builtins/bitcode/src/dec.zig b/crates/compiler/builtins/bitcode/src/dec.zig index b5fe2e07a8..c584e86499 100644 --- a/crates/compiler/builtins/bitcode/src/dec.zig +++ b/crates/compiler/builtins/bitcode/src/dec.zig @@ -244,8 +244,11 @@ pub const RocDec = extern struct { } pub fn abs(self: RocDec) !RocDec { - const absolute = try math.absInt(self.num); - return RocDec{ .num = absolute }; + const absolute = @abs(self.num); + if (absolute <= @as(u128, @intCast(std.math.maxInt(i128)))) { + return RocDec{ .num = @intCast(absolute) }; + } + return error.OutOfRange; } pub fn addWithOverflow(self: RocDec, other: RocDec) WithOverflow(RocDec) { @@ -314,7 +317,8 @@ pub const RocDec = extern struct { const is_answer_negative = (self_i128 < 0) != (other_i128 < 0); - const self_u128 = @as(u128, @intCast(math.absInt(self_i128) catch { + const self_u128 = @abs(self_i128); + if (self_u128 > @as(u128, @intCast(std.math.maxInt(i128)))) { if (other_i128 == 0) { return .{ .value = RocDec{ .num = 0 }, .has_overflowed = false }; } else if (other_i128 == RocDec.one_point_zero.num) { @@ -324,9 +328,10 @@ pub const RocDec = extern struct { } else { return .{ .value = RocDec.max, .has_overflowed = true }; } - })); + } - const other_u128 = @as(u128, @intCast(math.absInt(other_i128) catch { + const other_u128 = @abs(other_i128); + if (other_u128 > @as(u128, @intCast(std.math.maxInt(i128)))) { if (self_i128 == 0) { return .{ .value = RocDec{ .num = 0 }, .has_overflowed = false }; } else if (self_i128 == RocDec.one_point_zero.num) { @@ -336,7 +341,7 @@ pub const RocDec = extern struct { } else { return .{ .value = RocDec.max, .has_overflowed = true }; } - })); + } const unsigned_answer: i128 = mul_and_decimalize(self_u128, other_u128); @@ -464,7 +469,8 @@ pub const RocDec = extern struct { // // We do checked_abs because if we had -i128::MAX before, this will overflow. - const numerator_abs_i128 = math.absInt(numerator_i128) catch { + const numerator_u128 = @abs(numerator_i128); + if (numerator_u128 > @as(u128, @intCast(std.math.maxInt(i128)))) { // Currently, if you try to do multiplication on i64::MIN, panic // unless you're specifically multiplying by 0 or 1. // @@ -474,10 +480,10 @@ pub const RocDec = extern struct { } else { roc_panic("Decimal division overflow in numerator!", 0); } - }; - const numerator_u128 = @as(u128, @intCast(numerator_abs_i128)); + } - const denominator_abs_i128 = math.absInt(denominator_i128) catch { + const denominator_u128 = @abs(denominator_i128); + if (denominator_u128 > @as(u128, @intCast(std.math.maxInt(i128)))) { // Currently, if you try to do multiplication on i64::MIN, panic // unless you're specifically multiplying by 0 or 1. // @@ -487,8 +493,7 @@ pub const RocDec = extern struct { } else { roc_panic("Decimal division overflow in denominator!", 0); } - }; - const denominator_u128 = @as(u128, @intCast(denominator_abs_i128)); + } const numerator_u256: U256 = mul_u128(numerator_u128, math.pow(u128, 10, decimal_places)); const answer = div_u256_by_u128(numerator_u256, denominator_u128); @@ -516,7 +521,7 @@ pub const RocDec = extern struct { // This is dec/(b0+1), but as a multiplication. // So dec * (1/(b0+1)). This is way faster. const dec = self.num; - const tmp = @as(i128, @intCast(num_.mul_u128(math.absCast(dec), 249757942369376157886101012127821356963).hi >> (190 - 128))); + const tmp = @as(i128, @intCast(num_.mul_u128(@abs(dec), 249757942369376157886101012127821356963).hi >> (190 - 128))); const q0 = if (dec < 0) -tmp else tmp; const upper = q0 * b0; @@ -1468,7 +1473,7 @@ pub fn exportFromInt(comptime T: type, comptime name: []const u8) void { } } }.func; - @export(f, .{ .name = name ++ @typeName(T), .linkage = .Strong }); + @export(f, .{ .name = name ++ @typeName(T), .linkage = .strong }); } pub fn fromU64C(arg: u64) callconv(.C) i128 { @@ -1582,7 +1587,7 @@ pub fn exportRound(comptime T: type, comptime name: []const u8) void { return @as(T, @intCast(@divFloor(input.round().num, RocDec.one_point_zero_i128))); } }.func; - @export(f, .{ .name = name ++ @typeName(T), .linkage = .Strong }); + @export(f, .{ .name = name ++ @typeName(T), .linkage = .strong }); } pub fn exportFloor(comptime T: type, comptime name: []const u8) void { @@ -1591,7 +1596,7 @@ pub fn exportFloor(comptime T: type, comptime name: []const u8) void { return @as(T, @intCast(@divFloor(input.floor().num, RocDec.one_point_zero_i128))); } }.func; - @export(f, .{ .name = name ++ @typeName(T), .linkage = .Strong }); + @export(f, .{ .name = name ++ @typeName(T), .linkage = .strong }); } pub fn exportCeiling(comptime T: type, comptime name: []const u8) void { @@ -1600,5 +1605,5 @@ pub fn exportCeiling(comptime T: type, comptime name: []const u8) void { return @as(T, @intCast(@divFloor(input.ceiling().num, RocDec.one_point_zero_i128))); } }.func; - @export(f, .{ .name = name ++ @typeName(T), .linkage = .Strong }); + @export(f, .{ .name = name ++ @typeName(T), .linkage = .strong }); } diff --git a/crates/compiler/builtins/bitcode/src/expect.zig b/crates/compiler/builtins/bitcode/src/expect.zig index 7ae9826c1d..1fcdd3ee98 100644 --- a/crates/compiler/builtins/bitcode/src/expect.zig +++ b/crates/compiler/builtins/bitcode/src/expect.zig @@ -1,7 +1,7 @@ const std = @import("std"); const builtin = @import("builtin"); -const Atomic = std.atomic.Atomic; +const Atomic = std.atomic.Value; const O_RDWR: c_int = 2; const O_CREAT: c_int = 64; @@ -83,11 +83,10 @@ pub fn notifyParent(shared_buffer: [*]u8, tag: u32) callconv(.C) void { if (builtin.os.tag == .macos or builtin.os.tag == .linux) { const usize_ptr = @as([*]u32, @ptrCast(@alignCast(shared_buffer))); const atomic_ptr = @as(*Atomic(u32), @ptrCast(&usize_ptr[5])); - atomic_ptr.storeUnchecked(tag); + atomic_ptr.store(tag, .unordered); // wait till the parent is done before proceeding - const Ordering = std.atomic.Ordering; - while (atomic_ptr.load(Ordering.Acquire) != 0) { + while (atomic_ptr.load(.acquire) != 0) { std.atomic.spinLoopHint(); } } diff --git a/crates/compiler/builtins/bitcode/src/num.zig b/crates/compiler/builtins/bitcode/src/num.zig index 8f59ca677c..d6f17cf718 100644 --- a/crates/compiler/builtins/bitcode/src/num.zig +++ b/crates/compiler/builtins/bitcode/src/num.zig @@ -82,7 +82,7 @@ pub fn exportParseInt(comptime T: type, comptime name: []const u8) void { } } }.func; - @export(f, .{ .name = name ++ @typeName(T), .linkage = .Strong }); + @export(f, .{ .name = name ++ @typeName(T), .linkage = .strong }); } pub fn exportParseFloat(comptime T: type, comptime name: []const u8) void { @@ -95,7 +95,7 @@ pub fn exportParseFloat(comptime T: type, comptime name: []const u8) void { } } }.func; - @export(f, .{ .name = name ++ @typeName(T), .linkage = .Strong }); + @export(f, .{ .name = name ++ @typeName(T), .linkage = .strong }); } pub fn exportNumToFloatCast(comptime T: type, comptime F: type, comptime name: []const u8) void { @@ -104,7 +104,7 @@ pub fn exportNumToFloatCast(comptime T: type, comptime F: type, comptime name: [ return @floatFromInt(x); } }.func; - @export(f, .{ .name = name ++ @typeName(T), .linkage = .Strong }); + @export(f, .{ .name = name ++ @typeName(T), .linkage = .strong }); } pub fn exportPow(comptime T: type, comptime name: []const u8) void { @@ -113,7 +113,7 @@ pub fn exportPow(comptime T: type, comptime name: []const u8) void { return std.math.pow(T, base, exp); } }.func; - @export(f, .{ .name = name ++ @typeName(T), .linkage = .Strong }); + @export(f, .{ .name = name ++ @typeName(T), .linkage = .strong }); } pub fn exportIsNan(comptime T: type, comptime name: []const u8) void { @@ -122,7 +122,7 @@ pub fn exportIsNan(comptime T: type, comptime name: []const u8) void { return std.math.isNan(input); } }.func; - @export(f, .{ .name = name ++ @typeName(T), .linkage = .Strong }); + @export(f, .{ .name = name ++ @typeName(T), .linkage = .strong }); } pub fn exportIsInfinite(comptime T: type, comptime name: []const u8) void { @@ -131,7 +131,7 @@ pub fn exportIsInfinite(comptime T: type, comptime name: []const u8) void { return std.math.isInf(input); } }.func; - @export(f, .{ .name = name ++ @typeName(T), .linkage = .Strong }); + @export(f, .{ .name = name ++ @typeName(T), .linkage = .strong }); } pub fn exportIsFinite(comptime T: type, comptime name: []const u8) void { @@ -140,7 +140,7 @@ pub fn exportIsFinite(comptime T: type, comptime name: []const u8) void { return std.math.isFinite(input); } }.func; - @export(f, .{ .name = name ++ @typeName(T), .linkage = .Strong }); + @export(f, .{ .name = name ++ @typeName(T), .linkage = .strong }); } pub fn exportAsin(comptime T: type, comptime name: []const u8) void { @@ -149,7 +149,7 @@ pub fn exportAsin(comptime T: type, comptime name: []const u8) void { return std.math.asin(input); } }.func; - @export(f, .{ .name = name ++ @typeName(T), .linkage = .Strong }); + @export(f, .{ .name = name ++ @typeName(T), .linkage = .strong }); } pub fn exportAcos(comptime T: type, comptime name: []const u8) void { @@ -158,7 +158,7 @@ pub fn exportAcos(comptime T: type, comptime name: []const u8) void { return std.math.acos(input); } }.func; - @export(f, .{ .name = name ++ @typeName(T), .linkage = .Strong }); + @export(f, .{ .name = name ++ @typeName(T), .linkage = .strong }); } pub fn exportAtan(comptime T: type, comptime name: []const u8) void { @@ -167,7 +167,7 @@ pub fn exportAtan(comptime T: type, comptime name: []const u8) void { return std.math.atan(input); } }.func; - @export(f, .{ .name = name ++ @typeName(T), .linkage = .Strong }); + @export(f, .{ .name = name ++ @typeName(T), .linkage = .strong }); } pub fn exportSin(comptime T: type, comptime name: []const u8) void { @@ -176,7 +176,7 @@ pub fn exportSin(comptime T: type, comptime name: []const u8) void { return math.sin(input); } }.func; - @export(f, .{ .name = name ++ @typeName(T), .linkage = .Strong }); + @export(f, .{ .name = name ++ @typeName(T), .linkage = .strong }); } pub fn exportCos(comptime T: type, comptime name: []const u8) void { @@ -185,7 +185,7 @@ pub fn exportCos(comptime T: type, comptime name: []const u8) void { return math.cos(input); } }.func; - @export(f, .{ .name = name ++ @typeName(T), .linkage = .Strong }); + @export(f, .{ .name = name ++ @typeName(T), .linkage = .strong }); } pub fn exportTan(comptime T: type, comptime name: []const u8) void { @@ -194,7 +194,7 @@ pub fn exportTan(comptime T: type, comptime name: []const u8) void { return math.tan(input); } }.func; - @export(f, .{ .name = name ++ @typeName(T), .linkage = .Strong }); + @export(f, .{ .name = name ++ @typeName(T), .linkage = .strong }); } pub fn exportLog(comptime T: type, comptime name: []const u8) void { @@ -203,16 +203,16 @@ pub fn exportLog(comptime T: type, comptime name: []const u8) void { return @log(input); } }.func; - @export(f, .{ .name = name ++ @typeName(T), .linkage = .Strong }); + @export(f, .{ .name = name ++ @typeName(T), .linkage = .strong }); } pub fn exportFAbs(comptime T: type, comptime name: []const u8) void { const f = struct { fn func(input: T) callconv(.C) T { - return @fabs(input); + return @abs(input); } }.func; - @export(f, .{ .name = name ++ @typeName(T), .linkage = .Strong }); + @export(f, .{ .name = name ++ @typeName(T), .linkage = .strong }); } pub fn exportSqrt(comptime T: type, comptime name: []const u8) void { @@ -221,7 +221,7 @@ pub fn exportSqrt(comptime T: type, comptime name: []const u8) void { return math.sqrt(input); } }.func; - @export(f, .{ .name = name ++ @typeName(T), .linkage = .Strong }); + @export(f, .{ .name = name ++ @typeName(T), .linkage = .strong }); } pub fn exportRound(comptime F: type, comptime T: type, comptime name: []const u8) void { @@ -230,7 +230,7 @@ pub fn exportRound(comptime F: type, comptime T: type, comptime name: []const u8 return @as(T, @intFromFloat((math.round(input)))); } }.func; - @export(f, .{ .name = name ++ @typeName(T), .linkage = .Strong }); + @export(f, .{ .name = name ++ @typeName(T), .linkage = .strong }); } pub fn exportFloor(comptime F: type, comptime T: type, comptime name: []const u8) void { @@ -239,7 +239,7 @@ pub fn exportFloor(comptime F: type, comptime T: type, comptime name: []const u8 return @as(T, @intFromFloat((math.floor(input)))); } }.func; - @export(f, .{ .name = name ++ @typeName(T), .linkage = .Strong }); + @export(f, .{ .name = name ++ @typeName(T), .linkage = .strong }); } pub fn exportCeiling(comptime F: type, comptime T: type, comptime name: []const u8) void { @@ -248,7 +248,7 @@ pub fn exportCeiling(comptime F: type, comptime T: type, comptime name: []const return @as(T, @intFromFloat((math.ceil(input)))); } }.func; - @export(f, .{ .name = name ++ @typeName(T), .linkage = .Strong }); + @export(f, .{ .name = name ++ @typeName(T), .linkage = .strong }); } pub fn exportDivCeil(comptime T: type, comptime name: []const u8) void { @@ -259,7 +259,7 @@ pub fn exportDivCeil(comptime T: type, comptime name: []const u8) void { }; } }.func; - @export(f, .{ .name = name ++ @typeName(T), .linkage = .Strong }); + @export(f, .{ .name = name ++ @typeName(T), .linkage = .strong }); } pub fn ToIntCheckedResult(comptime T: type) type { @@ -280,7 +280,7 @@ pub fn exportToIntCheckingMax(comptime From: type, comptime To: type, comptime n return .{ .out_of_bounds = false, .value = @as(To, @intCast(input)) }; } }.func; - @export(f, .{ .name = name ++ @typeName(From), .linkage = .Strong }); + @export(f, .{ .name = name ++ @typeName(From), .linkage = .strong }); } pub fn exportToIntCheckingMaxAndMin(comptime From: type, comptime To: type, comptime name: []const u8) void { @@ -292,7 +292,7 @@ pub fn exportToIntCheckingMaxAndMin(comptime From: type, comptime To: type, comp return .{ .out_of_bounds = false, .value = @as(To, @intCast(input)) }; } }.func; - @export(f, .{ .name = name ++ @typeName(From), .linkage = .Strong }); + @export(f, .{ .name = name ++ @typeName(From), .linkage = .strong }); } fn isMultipleOf(comptime T: type, lhs: T, rhs: T) bool { @@ -316,7 +316,7 @@ pub fn exportIsMultipleOf(comptime T: type, comptime name: []const u8) void { return @call(.always_inline, isMultipleOf, .{ T, self, other }); } }.func; - @export(f, .{ .name = name ++ @typeName(T), .linkage = .Strong }); + @export(f, .{ .name = name ++ @typeName(T), .linkage = .strong }); } fn addWithOverflow(comptime T: type, self: T, other: T) WithOverflow(T) { @@ -339,7 +339,7 @@ pub fn exportAddWithOverflow(comptime T: type, comptime name: []const u8) void { return @call(.always_inline, addWithOverflow, .{ T, self, other }); } }.func; - @export(f, .{ .name = name ++ @typeName(T), .linkage = .Strong }); + @export(f, .{ .name = name ++ @typeName(T), .linkage = .strong }); } pub fn exportAddSaturatedInt(comptime T: type, comptime name: []const u8) void { @@ -358,7 +358,7 @@ pub fn exportAddSaturatedInt(comptime T: type, comptime name: []const u8) void { } } }.func; - @export(f, .{ .name = name ++ @typeName(T), .linkage = .Strong }); + @export(f, .{ .name = name ++ @typeName(T), .linkage = .strong }); } pub fn exportAddOrPanic(comptime T: type, comptime name: []const u8) void { @@ -372,7 +372,7 @@ pub fn exportAddOrPanic(comptime T: type, comptime name: []const u8) void { } } }.func; - @export(f, .{ .name = name ++ @typeName(T), .linkage = .Strong }); + @export(f, .{ .name = name ++ @typeName(T), .linkage = .strong }); } fn subWithOverflow(comptime T: type, self: T, other: T) WithOverflow(T) { @@ -395,7 +395,7 @@ pub fn exportSubWithOverflow(comptime T: type, comptime name: []const u8) void { return @call(.always_inline, subWithOverflow, .{ T, self, other }); } }.func; - @export(f, .{ .name = name ++ @typeName(T), .linkage = .Strong }); + @export(f, .{ .name = name ++ @typeName(T), .linkage = .strong }); } pub fn exportSubSaturatedInt(comptime T: type, comptime name: []const u8) void { @@ -415,7 +415,7 @@ pub fn exportSubSaturatedInt(comptime T: type, comptime name: []const u8) void { } } }.func; - @export(f, .{ .name = name ++ @typeName(T), .linkage = .Strong }); + @export(f, .{ .name = name ++ @typeName(T), .linkage = .strong }); } pub fn exportSubOrPanic(comptime T: type, comptime name: []const u8) void { @@ -429,7 +429,7 @@ pub fn exportSubOrPanic(comptime T: type, comptime name: []const u8) void { } } }.func; - @export(f, .{ .name = name ++ @typeName(T), .linkage = .Strong }); + @export(f, .{ .name = name ++ @typeName(T), .linkage = .strong }); } fn mulWithOverflow(comptime T: type, comptime W: type, self: T, other: T) WithOverflow(T) { @@ -440,7 +440,8 @@ fn mulWithOverflow(comptime T: type, comptime W: type, self: T, other: T) WithOv const max = std.math.maxInt(i128); const min = std.math.minInt(i128); - const self_u128 = @as(u128, @intCast(math.absInt(self) catch { + const self_u128 = @abs(self); + if (self_u128 > @as(u128, @intCast(std.math.maxInt(i128)))) { if (other == 0) { return .{ .value = 0, .has_overflowed = false }; } else if (other == 1) { @@ -450,9 +451,10 @@ fn mulWithOverflow(comptime T: type, comptime W: type, self: T, other: T) WithOv } else { return .{ .value = max, .has_overflowed = true }; } - })); + } - const other_u128 = @as(u128, @intCast(math.absInt(other) catch { + const other_u128 = @abs(other); + if (other_u128 > @as(u128, @intCast(std.math.maxInt(i128)))) { if (self == 0) { return .{ .value = 0, .has_overflowed = false }; } else if (self == 1) { @@ -462,7 +464,7 @@ fn mulWithOverflow(comptime T: type, comptime W: type, self: T, other: T) WithOv } else { return .{ .value = max, .has_overflowed = true }; } - })); + } const answer256: U256 = mul_u128(self_u128, other_u128); @@ -512,7 +514,7 @@ pub fn exportMulWithOverflow(comptime T: type, comptime W: type, comptime name: return @call(.always_inline, mulWithOverflow, .{ T, W, self, other }); } }.func; - @export(f, .{ .name = name ++ @typeName(T), .linkage = .Strong }); + @export(f, .{ .name = name ++ @typeName(T), .linkage = .strong }); } pub fn exportMulSaturatedInt(comptime T: type, comptime W: type, comptime name: []const u8) void { @@ -522,7 +524,7 @@ pub fn exportMulSaturatedInt(comptime T: type, comptime W: type, comptime name: return result.value; } }.func; - @export(f, .{ .name = name ++ @typeName(T), .linkage = .Strong }); + @export(f, .{ .name = name ++ @typeName(T), .linkage = .strong }); } pub fn exportMulWrappedInt(comptime T: type, comptime name: []const u8) void { @@ -531,7 +533,7 @@ pub fn exportMulWrappedInt(comptime T: type, comptime name: []const u8) void { return self *% other; } }.func; - @export(f, .{ .name = name ++ @typeName(T), .linkage = .Strong }); + @export(f, .{ .name = name ++ @typeName(T), .linkage = .strong }); } pub fn shiftRightZeroFillI128(self: i128, other: u8) callconv(.C) i128 { @@ -613,7 +615,7 @@ pub fn exportMulOrPanic(comptime T: type, comptime W: type, comptime name: []con } } }.func; - @export(f, .{ .name = name ++ @typeName(T), .linkage = .Strong }); + @export(f, .{ .name = name ++ @typeName(T), .linkage = .strong }); } pub fn exportCountLeadingZeroBits(comptime T: type, comptime name: []const u8) void { @@ -622,7 +624,7 @@ pub fn exportCountLeadingZeroBits(comptime T: type, comptime name: []const u8) v return @as(u8, @clz(self)); } }.func; - @export(f, .{ .name = name ++ @typeName(T), .linkage = .Strong }); + @export(f, .{ .name = name ++ @typeName(T), .linkage = .strong }); } pub fn exportCountTrailingZeroBits(comptime T: type, comptime name: []const u8) void { @@ -631,7 +633,7 @@ pub fn exportCountTrailingZeroBits(comptime T: type, comptime name: []const u8) return @as(u8, @ctz(self)); } }.func; - @export(f, .{ .name = name ++ @typeName(T), .linkage = .Strong }); + @export(f, .{ .name = name ++ @typeName(T), .linkage = .strong }); } pub fn exportCountOneBits(comptime T: type, comptime name: []const u8) void { @@ -640,7 +642,7 @@ pub fn exportCountOneBits(comptime T: type, comptime name: []const u8) void { return @as(u8, @popCount(self)); } }.func; - @export(f, .{ .name = name ++ @typeName(T), .linkage = .Strong }); + @export(f, .{ .name = name ++ @typeName(T), .linkage = .strong }); } pub fn f32ToParts(self: f32) callconv(.C) F32Parts { diff --git a/crates/compiler/builtins/bitcode/src/str.zig b/crates/compiler/builtins/bitcode/src/str.zig index c74883ea1d..172e27be9d 100644 --- a/crates/compiler/builtins/bitcode/src/str.zig +++ b/crates/compiler/builtins/bitcode/src/str.zig @@ -274,7 +274,7 @@ pub const RocStr = extern struct { const source_ptr = self.asU8ptr(); const dest_ptr = result.asU8ptrMut(); - std.mem.copy(u8, dest_ptr[0..old_length], source_ptr[0..old_length]); + @memcpy(dest_ptr[0..old_length], source_ptr[0..old_length]); @memset(dest_ptr[old_length..new_length], 0); self.decref(); @@ -290,7 +290,7 @@ pub const RocStr = extern struct { const source_ptr = self.asU8ptr(); - std.mem.copy(u8, dest_ptr[0..old_length], source_ptr[0..old_length]); + @memcpy(dest_ptr[0..old_length], source_ptr[0..old_length]); @memset(dest_ptr[old_length..new_length], 0); self.decref(); diff --git a/crates/compiler/builtins/bitcode/src/utils.zig b/crates/compiler/builtins/bitcode/src/utils.zig index 7d2fc14eae..3fc145e433 100644 --- a/crates/compiler/builtins/bitcode/src/utils.zig +++ b/crates/compiler/builtins/bitcode/src/utils.zig @@ -1,6 +1,5 @@ const std = @import("std"); const builtin = @import("builtin"); -const Monotonic = std.builtin.AtomicOrder.Monotonic; const DEBUG_INCDEC = false; const DEBUG_TESTING_ALLOC = false; @@ -181,10 +180,10 @@ const Refcount = enum { atomic, }; -const RC_TYPE = Refcount.normal; +const RC_TYPE: Refcount = .normal; pub fn increfRcPtrC(ptr_to_refcount: *isize, amount: isize) callconv(.C) void { - if (RC_TYPE == Refcount.none) return; + if (RC_TYPE == .none) return; if (DEBUG_INCDEC and builtin.target.cpu.arch != .wasm32) { std.debug.print("| increment {*}: ", .{ptr_to_refcount}); @@ -195,7 +194,7 @@ pub fn increfRcPtrC(ptr_to_refcount: *isize, amount: isize) callconv(.C) void { // Note: we assume that a refcount will never overflow. // As such, we do not need to cap incrementing. switch (RC_TYPE) { - Refcount.normal => { + .normal => { if (DEBUG_INCDEC and builtin.target.cpu.arch != .wasm32) { const old = @as(usize, @bitCast(ptr_to_refcount.*)); const new = old + @as(usize, @intCast(amount)); @@ -208,10 +207,10 @@ pub fn increfRcPtrC(ptr_to_refcount: *isize, amount: isize) callconv(.C) void { ptr_to_refcount.* += amount; }, - Refcount.atomic => { - _ = @atomicRmw(isize, ptr_to_refcount, std.builtin.AtomicRmwOp.Add, amount, Monotonic); + .atomic => { + _ = @atomicRmw(isize, ptr_to_refcount, .Add, amount, .monotonic); }, - Refcount.none => unreachable, + .none => unreachable, } } } @@ -321,7 +320,7 @@ inline fn free_ptr_to_refcount( alignment: u32, elements_refcounted: bool, ) void { - if (RC_TYPE == Refcount.none) return; + if (RC_TYPE == .none) return; const ptr_width = @sizeOf(usize); const required_space: usize = if (elements_refcounted) (2 * ptr_width) else ptr_width; const extra_bytes = @max(required_space, alignment); @@ -340,7 +339,7 @@ inline fn decref_ptr_to_refcount( element_alignment: u32, elements_refcounted: bool, ) void { - if (RC_TYPE == Refcount.none) return; + if (RC_TYPE == .none) return; if (DEBUG_INCDEC and builtin.target.cpu.arch != .wasm32) { std.debug.print("| decrement {*}: ", .{refcount_ptr}); @@ -354,7 +353,7 @@ inline fn decref_ptr_to_refcount( const refcount: isize = refcount_ptr[0]; if (refcount != REFCOUNT_MAX_ISIZE) { switch (RC_TYPE) { - Refcount.normal => { + .normal => { const old = @as(usize, @bitCast(refcount)); refcount_ptr[0] = refcount -% 1; const new = @as(usize, @bitCast(refcount -% 1)); @@ -370,13 +369,13 @@ inline fn decref_ptr_to_refcount( free_ptr_to_refcount(refcount_ptr, alignment, elements_refcounted); } }, - Refcount.atomic => { - const last = @atomicRmw(isize, &refcount_ptr[0], std.builtin.AtomicRmwOp.Sub, 1, Monotonic); + .atomic => { + const last = @atomicRmw(isize, &refcount_ptr[0], .Sub, 1, .monotonic); if (last == REFCOUNT_ONE_ISIZE) { free_ptr_to_refcount(refcount_ptr, alignment, elements_refcounted); } }, - Refcount.none => unreachable, + .none => unreachable, } } } @@ -478,7 +477,7 @@ pub fn allocateWithRefcount( const data_ptr = new_bytes + extra_bytes; const refcount_ptr = @as([*]usize, @ptrCast(@as([*]align(ptr_width) u8, @alignCast(data_ptr)) - ptr_width)); - refcount_ptr[0] = if (RC_TYPE == Refcount.none) REFCOUNT_MAX_ISIZE else REFCOUNT_ONE; + refcount_ptr[0] = if (RC_TYPE == .none) REFCOUNT_MAX_ISIZE else REFCOUNT_ONE; return data_ptr; }