From 011c13fb1780f6fcfc7a9c25c61e91b4be0d864b Mon Sep 17 00:00:00 2001 From: Luke Boswell Date: Wed, 24 Jul 2024 18:57:31 +1000 Subject: [PATCH] fixup the obivous zig errors --- crates/compiler/builtins/bitcode/src/dec.zig | 176 +++++++++--------- crates/compiler/builtins/bitcode/src/main.zig | 32 ++-- crates/compiler/builtins/bitcode/src/num.zig | 72 +++---- crates/compiler/builtins/bitcode/src/str.zig | 40 ++-- .../compiler/builtins/bitcode/src/utils.zig | 40 ++-- 5 files changed, 180 insertions(+), 180 deletions(-) diff --git a/crates/compiler/builtins/bitcode/src/dec.zig b/crates/compiler/builtins/bitcode/src/dec.zig index 5473bbdae8..b5fe2e07a8 100644 --- a/crates/compiler/builtins/bitcode/src/dec.zig +++ b/crates/compiler/builtins/bitcode/src/dec.zig @@ -32,7 +32,7 @@ pub const RocDec = extern struct { } pub fn fromF64(num: f64) ?RocDec { - var result: f64 = num * comptime @as(f64, @floatFromInt(one_point_zero_i128)); + const result: f64 = num * comptime @as(f64, @floatFromInt(one_point_zero_i128)); if (result > comptime @as(f64, @floatFromInt(math.maxInt(i128)))) { return null; @@ -42,7 +42,7 @@ pub const RocDec = extern struct { return null; } - var ret: RocDec = .{ .num = @as(i128, @intFromFloat(result)) }; + const ret: RocDec = .{ .num = @as(i128, @intFromFloat(result)) }; return ret; } @@ -61,13 +61,13 @@ pub const RocDec = extern struct { const roc_str_slice = roc_str.asSlice(); - var is_negative: bool = roc_str_slice[0] == '-'; - var initial_index: usize = if (is_negative) 1 else 0; + const is_negative: bool = roc_str_slice[0] == '-'; + const initial_index: usize = if (is_negative) 1 else 0; var point_index: ?usize = null; var index: usize = initial_index; while (index < length) { - var byte: u8 = roc_str_slice[index]; + const byte: u8 = roc_str_slice[index]; if (byte == '.' and point_index == null) { point_index = index; index += 1; @@ -85,20 +85,20 @@ pub const RocDec = extern struct { if (point_index) |pi| { before_str_length = pi; - var after_str_len = (length - 1) - pi; + const after_str_len = (length - 1) - pi; if (after_str_len > decimal_places) { // TODO: runtime exception for too many decimal places! return null; } - var diff_decimal_places = decimal_places - after_str_len; + const diff_decimal_places = decimal_places - after_str_len; - var after_str = roc_str_slice[pi + 1 .. length]; - var after_u64 = std.fmt.parseUnsigned(u64, after_str, 10) catch null; + const after_str = roc_str_slice[pi + 1 .. length]; + const after_u64 = std.fmt.parseUnsigned(u64, after_str, 10) catch null; after_val_i128 = if (after_u64) |f| @as(i128, @intCast(f)) * math.pow(i128, 10, diff_decimal_places) else null; } - var before_str = roc_str_slice[initial_index..before_str_length]; - var before_val_not_adjusted = std.fmt.parseUnsigned(i128, before_str, 10) catch null; + const before_str = roc_str_slice[initial_index..before_str_length]; + const before_val_not_adjusted = std.fmt.parseUnsigned(i128, before_str, 10) catch null; var before_val_i128: ?i128 = null; if (before_val_not_adjusted) |before| { @@ -115,7 +115,7 @@ pub const RocDec = extern struct { const dec: RocDec = blk: { if (before_val_i128) |before| { if (after_val_i128) |after| { - var answer = @addWithOverflow(before, after); + const answer = @addWithOverflow(before, after); const result = answer[0]; const overflowed = answer[1]; if (overflowed == 1) { @@ -239,7 +239,7 @@ pub const RocDec = extern struct { } pub fn negate(self: RocDec) ?RocDec { - var negated = math.negate(self.num) catch null; + const negated = math.negate(self.num) catch null; return if (negated) |n| .{ .num = n } else null; } @@ -779,8 +779,8 @@ fn div_u256_by_u128(numer: U256, denom: u128) U256 { // K X // --- // 0 K - var denom_leading_zeros = @clz(denom); - var numer_hi_leading_zeros = @clz(numer.hi); + const denom_leading_zeros = @clz(denom); + const numer_hi_leading_zeros = @clz(numer.hi); sr = 1 + N_UDWORD_BITS + denom_leading_zeros - numer_hi_leading_zeros; // 2 <= sr <= N_UTWORD_BITS - 1 // q.all = n.all << (N_UTWORD_BITS - sr); @@ -857,7 +857,7 @@ fn div_u256_by_u128(numer: U256, denom: u128) U256 { // // As an implementation of `as_u256`, we wrap a negative value around to the maximum value of U256. - var s_u128 = math.shr(u128, hi, 127); + const s_u128 = math.shr(u128, hi, 127); var s_hi: u128 = undefined; var s_lo: u128 = undefined; if (s_u128 == 1) { @@ -867,7 +867,7 @@ fn div_u256_by_u128(numer: U256, denom: u128) U256 { s_hi = 0; s_lo = 0; } - var s = .{ + const s = .{ .hi = s_hi, .lo = s_lo, }; @@ -885,8 +885,8 @@ fn div_u256_by_u128(numer: U256, denom: u128) U256 { sr -= 1; } - var hi = (q.hi << 1) | (q.lo >> (127)); - var lo = (q.lo << 1) | carry; + const hi = (q.hi << 1) | (q.lo >> (127)); + const lo = (q.lo << 1) | carry; return .{ .hi = hi, .lo = lo }; } @@ -898,122 +898,122 @@ const expectEqualSlices = testing.expectEqualSlices; const expect = testing.expect; test "fromU64" { - var dec = RocDec.fromU64(25); + const dec = RocDec.fromU64(25); try expectEqual(RocDec{ .num = 25000000000000000000 }, dec); } test "fromF64" { - var dec = RocDec.fromF64(25.5); + const dec = RocDec.fromF64(25.5); try expectEqual(RocDec{ .num = 25500000000000000000 }, dec.?); } test "fromF64 overflow" { - var dec = RocDec.fromF64(1e308); + const dec = RocDec.fromF64(1e308); try expectEqual(dec, null); } test "fromStr: empty" { - var roc_str = RocStr.init("", 0); - var dec = RocDec.fromStr(roc_str); + const roc_str = RocStr.init("", 0); + const dec = RocDec.fromStr(roc_str); try expectEqual(dec, null); } test "fromStr: 0" { - var roc_str = RocStr.init("0", 1); - var dec = RocDec.fromStr(roc_str); + const roc_str = RocStr.init("0", 1); + const dec = RocDec.fromStr(roc_str); try expectEqual(RocDec{ .num = 0 }, dec.?); } test "fromStr: 1" { - var roc_str = RocStr.init("1", 1); - var dec = RocDec.fromStr(roc_str); + const roc_str = RocStr.init("1", 1); + const dec = RocDec.fromStr(roc_str); try expectEqual(RocDec.one_point_zero, dec.?); } test "fromStr: 123.45" { - var roc_str = RocStr.init("123.45", 6); - var dec = RocDec.fromStr(roc_str); + const roc_str = RocStr.init("123.45", 6); + const dec = RocDec.fromStr(roc_str); try expectEqual(RocDec{ .num = 123450000000000000000 }, dec.?); } test "fromStr: .45" { - var roc_str = RocStr.init(".45", 3); - var dec = RocDec.fromStr(roc_str); + const roc_str = RocStr.init(".45", 3); + const dec = RocDec.fromStr(roc_str); try expectEqual(RocDec{ .num = 450000000000000000 }, dec.?); } test "fromStr: 0.45" { - var roc_str = RocStr.init("0.45", 4); - var dec = RocDec.fromStr(roc_str); + const roc_str = RocStr.init("0.45", 4); + const dec = RocDec.fromStr(roc_str); try expectEqual(RocDec{ .num = 450000000000000000 }, dec.?); } test "fromStr: 123" { - var roc_str = RocStr.init("123", 3); - var dec = RocDec.fromStr(roc_str); + const roc_str = RocStr.init("123", 3); + const dec = RocDec.fromStr(roc_str); try expectEqual(RocDec{ .num = 123000000000000000000 }, dec.?); } test "fromStr: -.45" { - var roc_str = RocStr.init("-.45", 4); - var dec = RocDec.fromStr(roc_str); + const roc_str = RocStr.init("-.45", 4); + const dec = RocDec.fromStr(roc_str); try expectEqual(RocDec{ .num = -450000000000000000 }, dec.?); } test "fromStr: -0.45" { - var roc_str = RocStr.init("-0.45", 5); - var dec = RocDec.fromStr(roc_str); + const roc_str = RocStr.init("-0.45", 5); + const dec = RocDec.fromStr(roc_str); try expectEqual(RocDec{ .num = -450000000000000000 }, dec.?); } test "fromStr: -123" { - var roc_str = RocStr.init("-123", 4); - var dec = RocDec.fromStr(roc_str); + const roc_str = RocStr.init("-123", 4); + const dec = RocDec.fromStr(roc_str); try expectEqual(RocDec{ .num = -123000000000000000000 }, dec.?); } test "fromStr: -123.45" { - var roc_str = RocStr.init("-123.45", 7); - var dec = RocDec.fromStr(roc_str); + const roc_str = RocStr.init("-123.45", 7); + const dec = RocDec.fromStr(roc_str); try expectEqual(RocDec{ .num = -123450000000000000000 }, dec.?); } test "fromStr: abc" { - var roc_str = RocStr.init("abc", 3); - var dec = RocDec.fromStr(roc_str); + const roc_str = RocStr.init("abc", 3); + const dec = RocDec.fromStr(roc_str); try expectEqual(dec, null); } test "fromStr: 123.abc" { - var roc_str = RocStr.init("123.abc", 7); - var dec = RocDec.fromStr(roc_str); + const roc_str = RocStr.init("123.abc", 7); + const dec = RocDec.fromStr(roc_str); try expectEqual(dec, null); } test "fromStr: abc.123" { - var roc_str = RocStr.init("abc.123", 7); - var dec = RocDec.fromStr(roc_str); + const roc_str = RocStr.init("abc.123", 7); + const dec = RocDec.fromStr(roc_str); try expectEqual(dec, null); } test "fromStr: .123.1" { - var roc_str = RocStr.init(".123.1", 6); - var dec = RocDec.fromStr(roc_str); + const roc_str = RocStr.init(".123.1", 6); + const dec = RocDec.fromStr(roc_str); try expectEqual(dec, null); } @@ -1226,46 +1226,46 @@ test "div: 20 / 2" { test "div: 8 / 5" { var dec: RocDec = RocDec.fromU64(8); - var res: RocDec = RocDec.fromStr(RocStr.init("1.6", 3)).?; + const res: RocDec = RocDec.fromStr(RocStr.init("1.6", 3)).?; try expectEqual(res, dec.div(RocDec.fromU64(5))); } test "div: 10 / 3" { var numer: RocDec = RocDec.fromU64(10); - var denom: RocDec = RocDec.fromU64(3); + const denom: RocDec = RocDec.fromU64(3); var roc_str = RocStr.init("3.333333333333333333", 20); errdefer roc_str.decref(); defer roc_str.decref(); - var res: RocDec = RocDec.fromStr(roc_str).?; + const res: RocDec = RocDec.fromStr(roc_str).?; try expectEqual(res, numer.div(denom)); } test "div: 341 / 341" { var number1: RocDec = RocDec.fromU64(341); - var number2: RocDec = RocDec.fromU64(341); + const number2: RocDec = RocDec.fromU64(341); try expectEqual(RocDec.fromU64(1), number1.div(number2)); } test "div: 342 / 343" { var number1: RocDec = RocDec.fromU64(342); - var number2: RocDec = RocDec.fromU64(343); - var roc_str = RocStr.init("0.997084548104956268", 20); + const number2: RocDec = RocDec.fromU64(343); + const roc_str = RocStr.init("0.997084548104956268", 20); try expectEqual(RocDec.fromStr(roc_str), number1.div(number2)); } test "div: 680 / 340" { var number1: RocDec = RocDec.fromU64(680); - var number2: RocDec = RocDec.fromU64(340); + const number2: RocDec = RocDec.fromU64(340); try expectEqual(RocDec.fromU64(2), number1.div(number2)); } test "div: 500 / 1000" { - var number1: RocDec = RocDec.fromU64(500); - var number2: RocDec = RocDec.fromU64(1000); - var roc_str = RocStr.init("0.5", 3); + const number1: RocDec = RocDec.fromU64(500); + const number2: RocDec = RocDec.fromU64(1000); + const roc_str = RocStr.init("0.5", 3); try expectEqual(RocDec.fromStr(roc_str), number1.div(number2)); } @@ -1274,35 +1274,35 @@ test "log: 1" { } test "fract: 0" { - var roc_str = RocStr.init("0", 1); + const roc_str = RocStr.init("0", 1); var dec = RocDec.fromStr(roc_str).?; try expectEqual(RocDec{ .num = 0 }, dec.fract()); } test "fract: 1" { - var roc_str = RocStr.init("1", 1); + const roc_str = RocStr.init("1", 1); var dec = RocDec.fromStr(roc_str).?; try expectEqual(RocDec{ .num = 0 }, dec.fract()); } test "fract: 123.45" { - var roc_str = RocStr.init("123.45", 6); + const roc_str = RocStr.init("123.45", 6); var dec = RocDec.fromStr(roc_str).?; try expectEqual(RocDec{ .num = 450000000000000000 }, dec.fract()); } test "fract: -123.45" { - var roc_str = RocStr.init("-123.45", 7); + const roc_str = RocStr.init("-123.45", 7); var dec = RocDec.fromStr(roc_str).?; try expectEqual(RocDec{ .num = -450000000000000000 }, dec.fract()); } test "fract: .45" { - var roc_str = RocStr.init(".45", 3); + const roc_str = RocStr.init(".45", 3); var dec = RocDec.fromStr(roc_str).?; try expectEqual(RocDec{ .num = 450000000000000000 }, dec.fract()); @@ -1316,35 +1316,35 @@ test "fract: -0.00045" { } test "trunc: 0" { - var roc_str = RocStr.init("0", 1); + const roc_str = RocStr.init("0", 1); var dec = RocDec.fromStr(roc_str).?; try expectEqual(RocDec{ .num = 0 }, dec.trunc()); } test "trunc: 1" { - var roc_str = RocStr.init("1", 1); + const roc_str = RocStr.init("1", 1); var dec = RocDec.fromStr(roc_str).?; try expectEqual(RocDec.one_point_zero, dec.trunc()); } test "trunc: 123.45" { - var roc_str = RocStr.init("123.45", 6); + const roc_str = RocStr.init("123.45", 6); var dec = RocDec.fromStr(roc_str).?; try expectEqual(RocDec{ .num = 123000000000000000000 }, dec.trunc()); } test "trunc: -123.45" { - var roc_str = RocStr.init("-123.45", 7); + const roc_str = RocStr.init("-123.45", 7); var dec = RocDec.fromStr(roc_str).?; try expectEqual(RocDec{ .num = -123000000000000000000 }, dec.trunc()); } test "trunc: .45" { - var roc_str = RocStr.init(".45", 3); + const roc_str = RocStr.init(".45", 3); var dec = RocDec.fromStr(roc_str).?; try expectEqual(RocDec{ .num = 0 }, dec.trunc()); @@ -1358,64 +1358,64 @@ test "trunc: -0.00045" { } test "round: 123.45" { - var roc_str = RocStr.init("123.45", 6); + const roc_str = RocStr.init("123.45", 6); var dec = RocDec.fromStr(roc_str).?; try expectEqual(RocDec{ .num = 123000000000000000000 }, dec.round()); } test "round: -123.45" { - var roc_str = RocStr.init("-123.45", 7); + const roc_str = RocStr.init("-123.45", 7); var dec = RocDec.fromStr(roc_str).?; try expectEqual(RocDec{ .num = -123000000000000000000 }, dec.round()); } test "round: 0.5" { - var roc_str = RocStr.init("0.5", 3); + const roc_str = RocStr.init("0.5", 3); var dec = RocDec.fromStr(roc_str).?; try expectEqual(RocDec.one_point_zero, dec.round()); } test "round: -0.5" { - var roc_str = RocStr.init("-0.5", 4); + const roc_str = RocStr.init("-0.5", 4); var dec = RocDec.fromStr(roc_str).?; try expectEqual(RocDec{ .num = -1000000000000000000 }, dec.round()); } test "powInt: 3.1 ^ 0" { - var roc_str = RocStr.init("3.1", 3); + const roc_str = RocStr.init("3.1", 3); var dec = RocDec.fromStr(roc_str).?; try expectEqual(RocDec.one_point_zero, dec.powInt(0)); } test "powInt: 3.1 ^ 1" { - var roc_str = RocStr.init("3.1", 3); + const roc_str = RocStr.init("3.1", 3); var dec = RocDec.fromStr(roc_str).?; try expectEqual(dec, dec.powInt(1)); } test "powInt: 2 ^ 2" { - var roc_str = RocStr.init("4", 1); - var dec = RocDec.fromStr(roc_str).?; + const roc_str = RocStr.init("4", 1); + const dec = RocDec.fromStr(roc_str).?; try expectEqual(dec, RocDec.two_point_zero.powInt(2)); } test "powInt: 0.5 ^ 2" { - var roc_str = RocStr.init("0.25", 4); - var dec = RocDec.fromStr(roc_str).?; + const roc_str = RocStr.init("0.25", 4); + const dec = RocDec.fromStr(roc_str).?; try expectEqual(dec, RocDec.zero_point_five.powInt(2)); } test "pow: 0.5 ^ 2.0" { - var roc_str = RocStr.init("0.25", 4); - var dec = RocDec.fromStr(roc_str).?; + const roc_str = RocStr.init("0.25", 4); + const dec = RocDec.fromStr(roc_str).?; try expectEqual(dec, RocDec.zero_point_five.pow(RocDec.two_point_zero)); } @@ -1456,7 +1456,7 @@ pub fn toF64(arg: RocDec) callconv(.C) f64 { } pub fn exportFromInt(comptime T: type, comptime name: []const u8) void { - comptime var f = struct { + const f = struct { fn func(self: T) callconv(.C) i128 { const this = @as(i128, @intCast(self)); @@ -1577,7 +1577,7 @@ pub fn mulSaturatedC(arg1: RocDec, arg2: RocDec) callconv(.C) RocDec { } pub fn exportRound(comptime T: type, comptime name: []const u8) void { - comptime var f = struct { + const f = struct { fn func(input: RocDec) callconv(.C) T { return @as(T, @intCast(@divFloor(input.round().num, RocDec.one_point_zero_i128))); } @@ -1586,7 +1586,7 @@ pub fn exportRound(comptime T: type, comptime name: []const u8) void { } pub fn exportFloor(comptime T: type, comptime name: []const u8) void { - comptime var f = struct { + const f = struct { fn func(input: RocDec) callconv(.C) T { return @as(T, @intCast(@divFloor(input.floor().num, RocDec.one_point_zero_i128))); } @@ -1595,7 +1595,7 @@ pub fn exportFloor(comptime T: type, comptime name: []const u8) void { } pub fn exportCeiling(comptime T: type, comptime name: []const u8) void { - comptime var f = struct { + const f = struct { fn func(input: RocDec) callconv(.C) T { return @as(T, @intCast(@divFloor(input.ceiling().num, RocDec.one_point_zero_i128))); } diff --git a/crates/compiler/builtins/bitcode/src/main.zig b/crates/compiler/builtins/bitcode/src/main.zig index d4ffa02357..4feed2a768 100644 --- a/crates/compiler/builtins/bitcode/src/main.zig +++ b/crates/compiler/builtins/bitcode/src/main.zig @@ -16,7 +16,7 @@ const dec = @import("dec.zig"); var FLTUSED: i32 = 0; comptime { if (builtin.os.tag == .windows) { - @export(FLTUSED, .{ .name = "_fltused", .linkage = .Weak }); + @export(FLTUSED, .{ .name = "_fltused", .linkage = .weak }); } } @@ -52,7 +52,7 @@ comptime { exportDecFn(dec.fromI128, "from_i128"); exportDecFn(dec.toStr, "to_str"); - inline for (INTEGERS) |T| { + for (INTEGERS) |T| { dec.exportFromInt(T, ROC_BUILTINS ++ ".dec.from_int."); dec.exportRound(T, ROC_BUILTINS ++ ".dec.round."); @@ -115,7 +115,7 @@ comptime { exportNumFn(num.f32FromParts, "f32_from_parts"); exportNumFn(num.f64FromParts, "f64_from_parts"); - inline for (INTEGERS, 0..) |T, i| { + for (INTEGERS, 0..) |T, i| { num.exportPow(T, ROC_BUILTINS ++ "." ++ NUM ++ ".pow_int."); num.exportDivCeil(T, ROC_BUILTINS ++ "." ++ NUM ++ ".div_ceil."); @@ -149,15 +149,15 @@ comptime { num.exportCountOneBits(T, ROC_BUILTINS ++ "." ++ NUM ++ ".count_one_bits."); } - inline for (INTEGERS) |FROM| { - inline for (INTEGERS) |TO| { + for (INTEGERS) |FROM| { + for (INTEGERS) |TO| { // We're exporting more than we need here, but that's okay. num.exportToIntCheckingMax(FROM, TO, ROC_BUILTINS ++ "." ++ NUM ++ ".int_to_" ++ @typeName(TO) ++ "_checking_max."); num.exportToIntCheckingMaxAndMin(FROM, TO, ROC_BUILTINS ++ "." ++ NUM ++ ".int_to_" ++ @typeName(TO) ++ "_checking_max_and_min."); } } - inline for (FLOATS) |T| { + for (FLOATS) |T| { num.exportAsin(T, ROC_BUILTINS ++ "." ++ NUM ++ ".asin."); num.exportAcos(T, ROC_BUILTINS ++ "." ++ NUM ++ ".acos."); num.exportAtan(T, ROC_BUILTINS ++ "." ++ NUM ++ ".atan."); @@ -210,12 +210,12 @@ comptime { exportStrFn(str.strAllocationPtr, "allocation_ptr"); exportStrFn(str.strReleaseExcessCapacity, "release_excess_capacity"); - inline for (INTEGERS) |T| { + for (INTEGERS) |T| { str.exportFromInt(T, ROC_BUILTINS ++ "." ++ STR ++ ".from_int."); num.exportParseInt(T, ROC_BUILTINS ++ "." ++ STR ++ ".to_int."); } - inline for (FLOATS) |T| { + for (FLOATS) |T| { str.exportFromFloat(T, ROC_BUILTINS ++ "." ++ STR ++ ".from_float."); num.exportParseFloat(T, ROC_BUILTINS ++ "." ++ STR ++ ".to_float."); } @@ -236,8 +236,8 @@ comptime { exportUtilsFn(utils.allocateWithRefcountC, "allocate_with_refcount"); exportUtilsFn(utils.dictPseudoSeed, "dict_pseudo_seed"); - @export(panic_utils.panic, .{ .name = "roc_builtins.utils." ++ "panic", .linkage = .Weak }); - @export(dbg_utils.dbg_impl, .{ .name = "roc_builtins.utils." ++ "dbg_impl", .linkage = .Weak }); + @export(panic_utils.panic, .{ .name = "roc_builtins.utils." ++ "panic", .linkage = .weak }); + @export(dbg_utils.dbg_impl, .{ .name = "roc_builtins.utils." ++ "dbg_impl", .linkage = .weak }); if (builtin.target.cpu.arch != .wasm32) { exportUtilsFn(expect.expectFailedStartSharedBuffer, "expect_failed_start_shared_buffer"); @@ -245,17 +245,17 @@ comptime { exportUtilsFn(expect.notifyParentExpect, "notify_parent_expect"); // sets the buffer used for expect failures - @export(expect.setSharedBuffer, .{ .name = "set_shared_buffer", .linkage = .Weak }); + @export(expect.setSharedBuffer, .{ .name = "set_shared_buffer", .linkage = .weak }); exportUtilsFn(expect.readSharedBufferEnv, "read_env_shared_buffer"); } if (builtin.target.cpu.arch == .aarch64) { - @export(__roc_force_setjmp, .{ .name = "__roc_force_setjmp", .linkage = .Weak }); - @export(__roc_force_longjmp, .{ .name = "__roc_force_longjmp", .linkage = .Weak }); + @export(__roc_force_setjmp, .{ .name = "__roc_force_setjmp", .linkage = .weak }); + @export(__roc_force_longjmp, .{ .name = "__roc_force_longjmp", .linkage = .weak }); } else if (builtin.os.tag == .windows) { - @export(__roc_force_setjmp_windows, .{ .name = "__roc_force_setjmp", .linkage = .Weak }); - @export(__roc_force_longjmp_windows, .{ .name = "__roc_force_longjmp", .linkage = .Weak }); + @export(__roc_force_setjmp_windows, .{ .name = "__roc_force_setjmp", .linkage = .weak }); + @export(__roc_force_longjmp_windows, .{ .name = "__roc_force_longjmp", .linkage = .weak }); } } @@ -370,7 +370,7 @@ comptime { // Export helpers - Must be run inside a comptime fn exportBuiltinFn(comptime func: anytype, comptime func_name: []const u8) void { - @export(func, .{ .name = "roc_builtins." ++ func_name, .linkage = .Strong }); + @export(func, .{ .name = "roc_builtins." ++ func_name, .linkage = .strong }); } fn exportNumFn(comptime func: anytype, comptime func_name: []const u8) void { exportBuiltinFn(func, "num." ++ func_name); diff --git a/crates/compiler/builtins/bitcode/src/num.zig b/crates/compiler/builtins/bitcode/src/num.zig index f980b64901..8f59ca677c 100644 --- a/crates/compiler/builtins/bitcode/src/num.zig +++ b/crates/compiler/builtins/bitcode/src/num.zig @@ -67,7 +67,7 @@ pub fn mul_u128(a: u128, b: u128) U256 { } pub fn exportParseInt(comptime T: type, comptime name: []const u8) void { - comptime var f = struct { + const f = struct { fn func(buf: RocStr) callconv(.C) NumParseResult(T) { // a radix of 0 will make zig determine the radix from the frefix: // * A prefix of "0b" implies radix=2, @@ -86,7 +86,7 @@ pub fn exportParseInt(comptime T: type, comptime name: []const u8) void { } pub fn exportParseFloat(comptime T: type, comptime name: []const u8) void { - comptime var f = struct { + const f = struct { fn func(buf: RocStr) callconv(.C) NumParseResult(T) { if (std.fmt.parseFloat(T, buf.asSlice())) |success| { return .{ .errorcode = 0, .value = success }; @@ -99,7 +99,7 @@ pub fn exportParseFloat(comptime T: type, comptime name: []const u8) void { } pub fn exportNumToFloatCast(comptime T: type, comptime F: type, comptime name: []const u8) void { - comptime var f = struct { + const f = struct { fn func(x: T) callconv(.C) F { return @floatFromInt(x); } @@ -108,7 +108,7 @@ pub fn exportNumToFloatCast(comptime T: type, comptime F: type, comptime name: [ } pub fn exportPow(comptime T: type, comptime name: []const u8) void { - comptime var f = struct { + const f = struct { fn func(base: T, exp: T) callconv(.C) T { return std.math.pow(T, base, exp); } @@ -117,7 +117,7 @@ pub fn exportPow(comptime T: type, comptime name: []const u8) void { } pub fn exportIsNan(comptime T: type, comptime name: []const u8) void { - comptime var f = struct { + const f = struct { fn func(input: T) callconv(.C) bool { return std.math.isNan(input); } @@ -126,7 +126,7 @@ pub fn exportIsNan(comptime T: type, comptime name: []const u8) void { } pub fn exportIsInfinite(comptime T: type, comptime name: []const u8) void { - comptime var f = struct { + const f = struct { fn func(input: T) callconv(.C) bool { return std.math.isInf(input); } @@ -135,7 +135,7 @@ pub fn exportIsInfinite(comptime T: type, comptime name: []const u8) void { } pub fn exportIsFinite(comptime T: type, comptime name: []const u8) void { - comptime var f = struct { + const f = struct { fn func(input: T) callconv(.C) bool { return std.math.isFinite(input); } @@ -144,7 +144,7 @@ pub fn exportIsFinite(comptime T: type, comptime name: []const u8) void { } pub fn exportAsin(comptime T: type, comptime name: []const u8) void { - comptime var f = struct { + const f = struct { fn func(input: T) callconv(.C) T { return std.math.asin(input); } @@ -153,7 +153,7 @@ pub fn exportAsin(comptime T: type, comptime name: []const u8) void { } pub fn exportAcos(comptime T: type, comptime name: []const u8) void { - comptime var f = struct { + const f = struct { fn func(input: T) callconv(.C) T { return std.math.acos(input); } @@ -162,7 +162,7 @@ pub fn exportAcos(comptime T: type, comptime name: []const u8) void { } pub fn exportAtan(comptime T: type, comptime name: []const u8) void { - comptime var f = struct { + const f = struct { fn func(input: T) callconv(.C) T { return std.math.atan(input); } @@ -171,7 +171,7 @@ pub fn exportAtan(comptime T: type, comptime name: []const u8) void { } pub fn exportSin(comptime T: type, comptime name: []const u8) void { - comptime var f = struct { + const f = struct { fn func(input: T) callconv(.C) T { return math.sin(input); } @@ -180,7 +180,7 @@ pub fn exportSin(comptime T: type, comptime name: []const u8) void { } pub fn exportCos(comptime T: type, comptime name: []const u8) void { - comptime var f = struct { + const f = struct { fn func(input: T) callconv(.C) T { return math.cos(input); } @@ -189,7 +189,7 @@ pub fn exportCos(comptime T: type, comptime name: []const u8) void { } pub fn exportTan(comptime T: type, comptime name: []const u8) void { - comptime var f = struct { + const f = struct { fn func(input: T) callconv(.C) T { return math.tan(input); } @@ -198,7 +198,7 @@ pub fn exportTan(comptime T: type, comptime name: []const u8) void { } pub fn exportLog(comptime T: type, comptime name: []const u8) void { - comptime var f = struct { + const f = struct { fn func(input: T) callconv(.C) T { return @log(input); } @@ -207,7 +207,7 @@ pub fn exportLog(comptime T: type, comptime name: []const u8) void { } pub fn exportFAbs(comptime T: type, comptime name: []const u8) void { - comptime var f = struct { + const f = struct { fn func(input: T) callconv(.C) T { return @fabs(input); } @@ -216,7 +216,7 @@ pub fn exportFAbs(comptime T: type, comptime name: []const u8) void { } pub fn exportSqrt(comptime T: type, comptime name: []const u8) void { - comptime var f = struct { + const f = struct { fn func(input: T) callconv(.C) T { return math.sqrt(input); } @@ -225,7 +225,7 @@ pub fn exportSqrt(comptime T: type, comptime name: []const u8) void { } pub fn exportRound(comptime F: type, comptime T: type, comptime name: []const u8) void { - comptime var f = struct { + const f = struct { fn func(input: F) callconv(.C) T { return @as(T, @intFromFloat((math.round(input)))); } @@ -234,7 +234,7 @@ pub fn exportRound(comptime F: type, comptime T: type, comptime name: []const u8 } pub fn exportFloor(comptime F: type, comptime T: type, comptime name: []const u8) void { - comptime var f = struct { + const f = struct { fn func(input: F) callconv(.C) T { return @as(T, @intFromFloat((math.floor(input)))); } @@ -243,7 +243,7 @@ pub fn exportFloor(comptime F: type, comptime T: type, comptime name: []const u8 } pub fn exportCeiling(comptime F: type, comptime T: type, comptime name: []const u8) void { - comptime var f = struct { + const f = struct { fn func(input: F) callconv(.C) T { return @as(T, @intFromFloat((math.ceil(input)))); } @@ -252,7 +252,7 @@ pub fn exportCeiling(comptime F: type, comptime T: type, comptime name: []const } pub fn exportDivCeil(comptime T: type, comptime name: []const u8) void { - comptime var f = struct { + const f = struct { fn func(a: T, b: T) callconv(.C) T { return math.divCeil(T, a, b) catch { roc_panic("Integer division by 0!", 0); @@ -272,7 +272,7 @@ pub fn ToIntCheckedResult(comptime T: type) type { } pub fn exportToIntCheckingMax(comptime From: type, comptime To: type, comptime name: []const u8) void { - comptime var f = struct { + const f = struct { fn func(input: From) callconv(.C) ToIntCheckedResult(To) { if (input > std.math.maxInt(To)) { return .{ .out_of_bounds = true, .value = 0 }; @@ -284,7 +284,7 @@ pub fn exportToIntCheckingMax(comptime From: type, comptime To: type, comptime n } pub fn exportToIntCheckingMaxAndMin(comptime From: type, comptime To: type, comptime name: []const u8) void { - comptime var f = struct { + const f = struct { fn func(input: From) callconv(.C) ToIntCheckedResult(To) { if (input > std.math.maxInt(To) or input < std.math.minInt(To)) { return .{ .out_of_bounds = true, .value = 0 }; @@ -311,7 +311,7 @@ fn isMultipleOf(comptime T: type, lhs: T, rhs: T) bool { } pub fn exportIsMultipleOf(comptime T: type, comptime name: []const u8) void { - comptime var f = struct { + const f = struct { fn func(self: T, other: T) callconv(.C) bool { return @call(.always_inline, isMultipleOf, .{ T, self, other }); } @@ -334,7 +334,7 @@ fn addWithOverflow(comptime T: type, self: T, other: T) WithOverflow(T) { } pub fn exportAddWithOverflow(comptime T: type, comptime name: []const u8) void { - comptime var f = struct { + const f = struct { fn func(self: T, other: T) callconv(.C) WithOverflow(T) { return @call(.always_inline, addWithOverflow, .{ T, self, other }); } @@ -343,7 +343,7 @@ pub fn exportAddWithOverflow(comptime T: type, comptime name: []const u8) void { } pub fn exportAddSaturatedInt(comptime T: type, comptime name: []const u8) void { - comptime var f = struct { + const f = struct { fn func(self: T, other: T) callconv(.C) T { const result = addWithOverflow(T, self, other); if (result.has_overflowed) { @@ -362,7 +362,7 @@ pub fn exportAddSaturatedInt(comptime T: type, comptime name: []const u8) void { } pub fn exportAddOrPanic(comptime T: type, comptime name: []const u8) void { - comptime var f = struct { + const f = struct { fn func(self: T, other: T) callconv(.C) T { const result = addWithOverflow(T, self, other); if (result.has_overflowed) { @@ -390,7 +390,7 @@ fn subWithOverflow(comptime T: type, self: T, other: T) WithOverflow(T) { } pub fn exportSubWithOverflow(comptime T: type, comptime name: []const u8) void { - comptime var f = struct { + const f = struct { fn func(self: T, other: T) callconv(.C) WithOverflow(T) { return @call(.always_inline, subWithOverflow, .{ T, self, other }); } @@ -399,7 +399,7 @@ pub fn exportSubWithOverflow(comptime T: type, comptime name: []const u8) void { } pub fn exportSubSaturatedInt(comptime T: type, comptime name: []const u8) void { - comptime var f = struct { + const f = struct { fn func(self: T, other: T) callconv(.C) T { const result = subWithOverflow(T, self, other); if (result.has_overflowed) { @@ -419,7 +419,7 @@ pub fn exportSubSaturatedInt(comptime T: type, comptime name: []const u8) void { } pub fn exportSubOrPanic(comptime T: type, comptime name: []const u8) void { - comptime var f = struct { + const f = struct { fn func(self: T, other: T) callconv(.C) T { const result = subWithOverflow(T, self, other); if (result.has_overflowed) { @@ -507,7 +507,7 @@ fn mulWithOverflow(comptime T: type, comptime W: type, self: T, other: T) WithOv } pub fn exportMulWithOverflow(comptime T: type, comptime W: type, comptime name: []const u8) void { - comptime var f = struct { + const f = struct { fn func(self: T, other: T) callconv(.C) WithOverflow(T) { return @call(.always_inline, mulWithOverflow, .{ T, W, self, other }); } @@ -516,7 +516,7 @@ pub fn exportMulWithOverflow(comptime T: type, comptime W: type, comptime name: } pub fn exportMulSaturatedInt(comptime T: type, comptime W: type, comptime name: []const u8) void { - comptime var f = struct { + const f = struct { fn func(self: T, other: T) callconv(.C) T { const result = @call(.always_inline, mulWithOverflow, .{ T, W, self, other }); return result.value; @@ -526,7 +526,7 @@ pub fn exportMulSaturatedInt(comptime T: type, comptime W: type, comptime name: } pub fn exportMulWrappedInt(comptime T: type, comptime name: []const u8) void { - comptime var f = struct { + const f = struct { fn func(self: T, other: T) callconv(.C) T { return self *% other; } @@ -603,7 +603,7 @@ pub fn greaterThanOrEqualU128(self: u128, other: u128) callconv(.C) bool { } pub fn exportMulOrPanic(comptime T: type, comptime W: type, comptime name: []const u8) void { - comptime var f = struct { + const f = struct { fn func(self: T, other: T) callconv(.C) T { const result = @call(.always_inline, mulWithOverflow, .{ T, W, self, other }); if (result.has_overflowed) { @@ -617,7 +617,7 @@ pub fn exportMulOrPanic(comptime T: type, comptime W: type, comptime name: []con } pub fn exportCountLeadingZeroBits(comptime T: type, comptime name: []const u8) void { - comptime var f = struct { + const f = struct { fn func(self: T) callconv(.C) u8 { return @as(u8, @clz(self)); } @@ -626,7 +626,7 @@ pub fn exportCountLeadingZeroBits(comptime T: type, comptime name: []const u8) v } pub fn exportCountTrailingZeroBits(comptime T: type, comptime name: []const u8) void { - comptime var f = struct { + const f = struct { fn func(self: T) callconv(.C) u8 { return @as(u8, @ctz(self)); } @@ -635,7 +635,7 @@ pub fn exportCountTrailingZeroBits(comptime T: type, comptime name: []const u8) } pub fn exportCountOneBits(comptime T: type, comptime name: []const u8) void { - comptime var f = struct { + const f = struct { fn func(self: T) callconv(.C) u8 { return @as(u8, @popCount(self)); } diff --git a/crates/compiler/builtins/bitcode/src/str.zig b/crates/compiler/builtins/bitcode/src/str.zig index 1fbac1b800..c74883ea1d 100644 --- a/crates/compiler/builtins/bitcode/src/str.zig +++ b/crates/compiler/builtins/bitcode/src/str.zig @@ -212,7 +212,7 @@ pub const RocStr = extern struct { // just return the bytes return str; } else { - var new_str = RocStr.allocateBig(str.length, str.length); + const new_str = RocStr.allocateBig(str.length, str.length); var old_bytes: [*]u8 = @as([*]u8, @ptrCast(str.bytes)); var new_bytes: [*]u8 = @as([*]u8, @ptrCast(new_str.bytes)); @@ -554,13 +554,13 @@ pub fn strNumberOfBytes(string: RocStr) callconv(.C) usize { // Str.fromInt pub fn exportFromInt(comptime T: type, comptime name: []const u8) void { - comptime var f = struct { + const f = struct { fn func(int: T) callconv(.C) RocStr { return @call(.always_inline, strFromIntHelp, .{ T, int }); } }.func; - @export(f, .{ .name = name ++ @typeName(T), .linkage = .Strong }); + @export(f, .{ .name = name ++ @typeName(T), .linkage = .strong }); } fn strFromIntHelp(comptime T: type, int: T) RocStr { @@ -568,9 +568,9 @@ fn strFromIntHelp(comptime T: type, int: T) RocStr { const size = comptime blk: { // the string representation of the minimum i128 value uses at most 40 characters var buf: [40]u8 = undefined; - var resultMin = std.fmt.bufPrint(&buf, "{}", .{std.math.minInt(T)}) catch unreachable; - var resultMax = std.fmt.bufPrint(&buf, "{}", .{std.math.maxInt(T)}) catch unreachable; - var result = if (resultMin.len > resultMax.len) resultMin.len else resultMax.len; + const resultMin = std.fmt.bufPrint(&buf, "{}", .{std.math.minInt(T)}) catch unreachable; + const resultMax = std.fmt.bufPrint(&buf, "{}", .{std.math.maxInt(T)}) catch unreachable; + const result = if (resultMin.len > resultMax.len) resultMin.len else resultMax.len; break :blk result; }; @@ -582,13 +582,13 @@ fn strFromIntHelp(comptime T: type, int: T) RocStr { // Str.fromFloat pub fn exportFromFloat(comptime T: type, comptime name: []const u8) void { - comptime var f = struct { + const f = struct { fn func(float: T) callconv(.C) RocStr { return @call(.always_inline, strFromFloatHelp, .{ T, float }); } }.func; - @export(f, .{ .name = name ++ @typeName(T), .linkage = .Strong }); + @export(f, .{ .name = name ++ @typeName(T), .linkage = .strong }); } fn strFromFloatHelp(comptime T: type, float: T) RocStr { @@ -662,7 +662,7 @@ test "strSplitHelp: empty delimiter" { strSplitHelp(array_ptr, str, delimiter); - var expected = [1]RocStr{ + const expected = [1]RocStr{ str, }; @@ -696,7 +696,7 @@ test "strSplitHelp: no delimiter" { strSplitHelp(array_ptr, str, delimiter); - var expected = [1]RocStr{ + const expected = [1]RocStr{ str, }; @@ -735,7 +735,7 @@ test "strSplitHelp: empty start" { const one = RocStr.init("a", 1); - var expected = [2]RocStr{ + const expected = [2]RocStr{ RocStr.empty(), one, }; @@ -777,7 +777,7 @@ test "strSplitHelp: empty end" { const one = RocStr.init("1", 1); const two = RocStr.init("2", 1); - var expected = [3]RocStr{ + const expected = [3]RocStr{ one, two, RocStr.empty(), }; @@ -813,7 +813,7 @@ test "strSplitHelp: string equals delimiter" { strSplitHelp(array_ptr, str_delimiter, str_delimiter); - var expected = [2]RocStr{ RocStr.empty(), RocStr.empty() }; + const expected = [2]RocStr{ RocStr.empty(), RocStr.empty() }; defer { for (array) |rocStr| { @@ -851,7 +851,7 @@ test "strSplitHelp: delimiter on sides" { const ghi_arr = "ghi"; const ghi = RocStr.init(ghi_arr, ghi_arr.len); - var expected = [3]RocStr{ + const expected = [3]RocStr{ RocStr.empty(), ghi, RocStr.empty(), }; @@ -892,7 +892,7 @@ test "strSplitHelp: three pieces" { const b = RocStr.init("b", 1); const c = RocStr.init("c", 1); - var expected_array = [array_len]RocStr{ + const expected_array = [array_len]RocStr{ a, b, c, }; @@ -928,7 +928,7 @@ test "strSplitHelp: overlapping delimiter 1" { strSplitHelp(array_ptr, str, delimiter); - var expected = [2]RocStr{ + const expected = [2]RocStr{ RocStr.empty(), RocStr.init("a", 1), }; @@ -953,7 +953,7 @@ test "strSplitHelp: overlapping delimiter 2" { strSplitHelp(array_ptr, str, delimiter); - var expected = [3]RocStr{ + const expected = [3]RocStr{ RocStr.empty(), RocStr.empty(), RocStr.empty(), @@ -1364,7 +1364,7 @@ fn strJoinWith(list: RocListStr, separator: RocStr) RocStr { total_size += separator.len() * (len - 1); var result = RocStr.allocate(total_size); - var result_ptr = result.asU8ptrMut(); + const result_ptr = result.asU8ptrMut(); var offset: usize = 0; for (slice[0 .. len - 1]) |substr| { @@ -1943,7 +1943,7 @@ pub fn strTrimEnd(input_string: RocStr) callconv(.C) RocStr { fn countLeadingWhitespaceBytes(string: RocStr) usize { var byte_count: usize = 0; - var bytes = string.asU8ptr()[0..string.len()]; + const bytes = string.asU8ptr()[0..string.len()]; var iter = unicode.Utf8View.initUnchecked(bytes).iterator(); while (iter.nextCodepoint()) |codepoint| { if (isWhitespace(codepoint)) { @@ -1959,7 +1959,7 @@ fn countLeadingWhitespaceBytes(string: RocStr) usize { fn countTrailingWhitespaceBytes(string: RocStr) usize { var byte_count: usize = 0; - var bytes = string.asU8ptr()[0..string.len()]; + const bytes = string.asU8ptr()[0..string.len()]; var iter = ReverseUtf8View.initUnchecked(bytes).iterator(); while (iter.nextCodepoint()) |codepoint| { if (isWhitespace(codepoint)) { diff --git a/crates/compiler/builtins/bitcode/src/utils.zig b/crates/compiler/builtins/bitcode/src/utils.zig index 78d18b95bf..7d2fc14eae 100644 --- a/crates/compiler/builtins/bitcode/src/utils.zig +++ b/crates/compiler/builtins/bitcode/src/utils.zig @@ -56,20 +56,20 @@ fn testing_roc_dbg(loc: *anyopaque, message: *anyopaque, src: *anyopaque) callco comptime { // During tests, use the testing allocators to satisfy these functions. if (builtin.is_test) { - @export(testing_roc_alloc, .{ .name = "roc_alloc", .linkage = .Strong }); - @export(testing_roc_realloc, .{ .name = "roc_realloc", .linkage = .Strong }); - @export(testing_roc_dealloc, .{ .name = "roc_dealloc", .linkage = .Strong }); - @export(testing_roc_panic, .{ .name = "roc_panic", .linkage = .Strong }); - @export(testing_roc_dbg, .{ .name = "roc_dbg", .linkage = .Strong }); + @export(testing_roc_alloc, .{ .name = "roc_alloc", .linkage = .strong }); + @export(testing_roc_realloc, .{ .name = "roc_realloc", .linkage = .strong }); + @export(testing_roc_dealloc, .{ .name = "roc_dealloc", .linkage = .strong }); + @export(testing_roc_panic, .{ .name = "roc_panic", .linkage = .strong }); + @export(testing_roc_dbg, .{ .name = "roc_dbg", .linkage = .strong }); if (builtin.os.tag == .macos or builtin.os.tag == .linux) { - @export(testing_roc_getppid, .{ .name = "roc_getppid", .linkage = .Strong }); - @export(testing_roc_mmap, .{ .name = "roc_mmap", .linkage = .Strong }); - @export(testing_roc_shm_open, .{ .name = "roc_shm_open", .linkage = .Strong }); + @export(testing_roc_getppid, .{ .name = "roc_getppid", .linkage = .strong }); + @export(testing_roc_mmap, .{ .name = "roc_mmap", .linkage = .strong }); + @export(testing_roc_shm_open, .{ .name = "roc_shm_open", .linkage = .strong }); } if (builtin.os.tag == .windows) { - @export(roc_getppid_windows_stub, .{ .name = "roc_getppid", .linkage = .Strong }); + @export(roc_getppid_windows_stub, .{ .name = "roc_getppid", .linkage = .strong }); } } } @@ -225,7 +225,7 @@ pub fn decrefRcPtrC( // (NOT the start of the data, or the start of the allocation) // this is of course unsafe, but we trust what we get from the llvm side - var bytes = @as([*]isize, @ptrCast(bytes_or_null)); + const bytes = @as([*]isize, @ptrCast(bytes_or_null)); return @call(.always_inline, decref_ptr_to_refcount, .{ bytes, alignment, elements_refcounted }); } @@ -246,7 +246,7 @@ pub fn decrefDataPtrC( alignment: u32, elements_refcounted: bool, ) callconv(.C) void { - var bytes = bytes_or_null orelse return; + const bytes = bytes_or_null orelse return; const data_ptr = @intFromPtr(bytes); const tag_mask: usize = if (@sizeOf(usize) == 8) 0b111 else 0b11; @@ -262,7 +262,7 @@ pub fn increfDataPtrC( bytes_or_null: ?[*]u8, inc_amount: isize, ) callconv(.C) void { - var bytes = bytes_or_null orelse return; + const bytes = bytes_or_null orelse return; const ptr = @intFromPtr(bytes); const tag_mask: usize = if (@sizeOf(usize) == 8) 0b111 else 0b11; @@ -278,7 +278,7 @@ pub fn freeDataPtrC( alignment: u32, elements_refcounted: bool, ) callconv(.C) void { - var bytes = bytes_or_null orelse return; + const bytes = bytes_or_null orelse return; const ptr = @intFromPtr(bytes); const tag_mask: usize = if (@sizeOf(usize) == 8) 0b111 else 0b11; @@ -295,7 +295,7 @@ pub fn freeRcPtrC( alignment: u32, elements_refcounted: bool, ) callconv(.C) void { - var bytes = bytes_or_null orelse return; + const bytes = bytes_or_null orelse return; return free_ptr_to_refcount(bytes, alignment, elements_refcounted); } @@ -309,7 +309,7 @@ pub fn decref( return; } - var bytes = bytes_or_null orelse return; + const bytes = bytes_or_null orelse return; const isizes: [*]isize = @as([*]isize, @ptrCast(@alignCast(bytes))); @@ -371,7 +371,7 @@ inline fn decref_ptr_to_refcount( } }, Refcount.atomic => { - var last = @atomicRmw(isize, &refcount_ptr[0], std.builtin.AtomicRmwOp.Sub, 1, Monotonic); + const last = @atomicRmw(isize, &refcount_ptr[0], std.builtin.AtomicRmwOp.Sub, 1, Monotonic); if (last == REFCOUNT_ONE_ISIZE) { free_ptr_to_refcount(refcount_ptr, alignment, elements_refcounted); } @@ -384,7 +384,7 @@ inline fn decref_ptr_to_refcount( pub fn isUnique( bytes_or_null: ?[*]u8, ) callconv(.C) bool { - var bytes = bytes_or_null orelse return true; + const bytes = bytes_or_null orelse return true; const ptr = @intFromPtr(bytes); const tag_mask: usize = if (@sizeOf(usize) == 8) 0b111 else 0b11; @@ -470,7 +470,7 @@ pub fn allocateWithRefcount( const extra_bytes = @max(required_space, element_alignment); const length = extra_bytes + data_bytes; - var new_bytes: [*]u8 = alloc(length, alignment) orelse unreachable; + const new_bytes: [*]u8 = alloc(length, alignment) orelse unreachable; if (DEBUG_ALLOC and builtin.target.cpu.arch != .wasm32) { std.debug.print("+ allocated {*} ({} bytes with alignment {})\n", .{ new_bytes, data_bytes, alignment }); @@ -529,14 +529,14 @@ pub const UpdateMode = enum(u8) { test "increfC, refcounted data" { var mock_rc: isize = REFCOUNT_ONE_ISIZE + 17; - var ptr_to_refcount: *isize = &mock_rc; + const ptr_to_refcount: *isize = &mock_rc; increfRcPtrC(ptr_to_refcount, 2); try std.testing.expectEqual(mock_rc, REFCOUNT_ONE_ISIZE + 19); } test "increfC, static data" { var mock_rc: isize = REFCOUNT_MAX_ISIZE; - var ptr_to_refcount: *isize = &mock_rc; + const ptr_to_refcount: *isize = &mock_rc; increfRcPtrC(ptr_to_refcount, 2); try std.testing.expectEqual(mock_rc, REFCOUNT_MAX_ISIZE); }