refactor: ban std.debug.assert (#10168)

* Ban `std.debug.assert`

* Create .clangd

* Update lint.yml

* Update linter.ts

* update

* lint

* Update linter.ts

* Update linter.ts

* update

* Update linter.ts

* update

* Update linter.ts

* more

* Update install.zig

* words

* Remove UB
This commit is contained in:
Jarred Sumner
2024-04-11 17:52:29 -07:00
committed by GitHub
parent 0f10d4f1be
commit 688844b472
149 changed files with 1314 additions and 1105 deletions

View File

@@ -124,7 +124,7 @@ pub fn indexOfAny(slice: string, comptime str: anytype) ?OptionalUsize {
remaining = remaining[ascii_vector_size..];
}
if (comptime Environment.allow_assert) std.debug.assert(remaining.len < ascii_vector_size);
if (comptime Environment.allow_assert) assert(remaining.len < ascii_vector_size);
}
for (remaining, 0..) |c, i| {
@@ -288,7 +288,7 @@ pub inline fn indexOf(self: string, str: string) ?usize {
const start = bun.C.memmem(self_ptr, self_len, str_ptr, str_len) orelse return null;
const i = @intFromPtr(start) - @intFromPtr(self_ptr);
std.debug.assert(i < self_len);
bun.unsafeAssert(i < self_len);
return @as(usize, @intCast(i));
}
@@ -310,7 +310,7 @@ pub const SplitIterator = struct {
/// Returns a slice of the first field. This never fails.
/// Call this only to get the first field and then use `next` to get all subsequent fields.
pub fn first(self: *Self) []const u8 {
std.debug.assert(self.index.? == 0);
bun.unsafeAssert(self.index.? == 0);
return self.next().?;
}
@@ -398,7 +398,7 @@ pub const StringOrTinyString = struct {
} = .{},
comptime {
std.debug.assert(@sizeOf(@This()) == 32);
bun.unsafeAssert(@sizeOf(@This()) == 32);
}
pub inline fn slice(this: *const StringOrTinyString) []const u8 {
@@ -979,8 +979,8 @@ pub fn eqlCaseInsensitiveASCII(a: string, b: string, comptime check_len: bool) b
if (a.len == 0) return true;
}
std.debug.assert(b.len > 0);
std.debug.assert(a.len > 0);
bun.unsafeAssert(b.len > 0);
bun.unsafeAssert(a.len > 0);
return bun.C.strncasecmp(a.ptr, b.ptr, a.len) == 0;
}
@@ -997,7 +997,7 @@ pub fn eqlLong(a_str: string, b_str: string, comptime check_len: bool) bool {
return false;
}
} else {
if (comptime Environment.allow_assert) std.debug.assert(b_str.len == a_str.len);
if (comptime Environment.allow_assert) assert(b_str.len == a_str.len);
}
const end = b_str.ptr + len;
@@ -1116,7 +1116,7 @@ pub inline fn appendUTF8MachineWordToUTF16MachineWord(output: *[@sizeOf(usize) /
pub inline fn copyU8IntoU16(output_: []u16, input_: []const u8) void {
const output = output_;
const input = input_;
if (comptime Environment.allow_assert) std.debug.assert(input.len <= output.len);
if (comptime Environment.allow_assert) assert(input.len <= output.len);
// https://zig.godbolt.org/z/9rTn1orcY
@@ -1136,7 +1136,7 @@ pub fn copyU8IntoU16WithAlignment(comptime alignment: u21, output_: []align(alig
var output = output_;
var input = input_;
const word = @sizeOf(usize) / 2;
if (comptime Environment.allow_assert) std.debug.assert(input.len <= output.len);
if (comptime Environment.allow_assert) assert(input.len <= output.len);
// un-aligned data access is slow
// so we attempt to align the data
@@ -1159,7 +1159,7 @@ pub fn copyU8IntoU16WithAlignment(comptime alignment: u21, output_: []align(alig
// pub inline fn copy(output_: []u8, input_: []const u8) void {
// var output = output_;
// var input = input_;
// if (comptime Environment.allow_assert) std.debug.assert(input.len <= output.len);
// if (comptime Environment.allow_assert) assert(input.len <= output.len);
// if (input.len > @sizeOf(usize) * 4) {
// comptime var i: usize = 0;
@@ -1182,10 +1182,10 @@ pub fn copyU8IntoU16WithAlignment(comptime alignment: u21, output_: []align(alig
// }
pub inline fn copyU16IntoU8(output_: []u8, comptime InputType: type, input_: InputType) void {
if (comptime Environment.allow_assert) std.debug.assert(input_.len <= output_.len);
if (comptime Environment.allow_assert) assert(input_.len <= output_.len);
var output = output_;
var input = input_;
if (comptime Environment.allow_assert) std.debug.assert(input.len <= output.len);
if (comptime Environment.allow_assert) assert(input.len <= output.len);
// https://zig.godbolt.org/z/9rTn1orcY
@@ -1445,7 +1445,7 @@ pub fn toUTF16Alloc(allocator: std.mem.Allocator, bytes: []const u8, comptime fa
const replacement = strings.convertUTF8BytesIntoUTF16(&sequence);
if (comptime fail_if_invalid) {
if (replacement.fail) {
if (comptime Environment.allow_assert) std.debug.assert(replacement.code_point == unicode_replacement);
if (comptime Environment.allow_assert) assert(replacement.code_point == unicode_replacement);
return error.InvalidByteSequence;
}
}
@@ -1480,7 +1480,7 @@ pub fn toUTF16Alloc(allocator: std.mem.Allocator, bytes: []const u8, comptime fa
const replacement = strings.convertUTF8BytesIntoUTF16(&sequence);
if (comptime fail_if_invalid) {
if (replacement.fail) {
if (comptime Environment.allow_assert) std.debug.assert(replacement.code_point == unicode_replacement);
if (comptime Environment.allow_assert) assert(replacement.code_point == unicode_replacement);
return error.InvalidByteSequence;
}
}
@@ -1579,7 +1579,7 @@ pub fn toUTF16AllocNoTrim(allocator: std.mem.Allocator, bytes: []const u8, compt
const replacement = strings.convertUTF8BytesIntoUTF16(&sequence);
if (comptime fail_if_invalid) {
if (replacement.fail) {
if (comptime Environment.allow_assert) std.debug.assert(replacement.code_point == unicode_replacement);
if (comptime Environment.allow_assert) assert(replacement.code_point == unicode_replacement);
return error.InvalidByteSequence;
}
}
@@ -1614,7 +1614,7 @@ pub fn toUTF16AllocNoTrim(allocator: std.mem.Allocator, bytes: []const u8, compt
const replacement = strings.convertUTF8BytesIntoUTF16(&sequence);
if (comptime fail_if_invalid) {
if (replacement.fail) {
if (comptime Environment.allow_assert) std.debug.assert(replacement.code_point == unicode_replacement);
if (comptime Environment.allow_assert) assert(replacement.code_point == unicode_replacement);
return error.InvalidByteSequence;
}
}
@@ -1710,13 +1710,13 @@ pub fn utf16Codepoint(comptime Type: type, input: Type) UTF16Replacement {
/// an assertion, and PosixToWinNormalizer can help make an absolute path
/// contain a drive letter.
pub fn isWindowsAbsolutePathMissingDriveLetter(comptime T: type, chars: []const T) bool {
std.debug.assert(bun.path.Platform.windows.isAbsoluteT(T, chars));
std.debug.assert(chars.len > 0);
bun.unsafeAssert(bun.path.Platform.windows.isAbsoluteT(T, chars));
bun.unsafeAssert(chars.len > 0);
// 'C:\hello' -> false
if (!(chars[0] == '/' or chars[0] == '\\')) {
std.debug.assert(chars.len > 2);
std.debug.assert(chars[1] == ':');
bun.unsafeAssert(chars.len > 2);
bun.unsafeAssert(chars[1] == ':');
return false;
}
@@ -1744,9 +1744,9 @@ pub fn isWindowsAbsolutePathMissingDriveLetter(comptime T: type, chars: []const
}
pub fn fromWPath(buf: []u8, utf16: []const u16) [:0]const u8 {
std.debug.assert(buf.len > 0);
bun.unsafeAssert(buf.len > 0);
const encode_into_result = copyUTF16IntoUTF8(buf[0 .. buf.len - 1], []const u16, utf16, false);
std.debug.assert(encode_into_result.written < buf.len);
bun.unsafeAssert(encode_into_result.written < buf.len);
buf[encode_into_result.written] = 0;
return buf[0..encode_into_result.written :0];
}
@@ -1780,7 +1780,7 @@ pub fn addNTPathPrefixIfNeeded(wbuf: []u16, utf16: []const u16) [:0]const u16 {
pub const toNTDir = toNTPath;
pub fn toExtendedPathNormalized(wbuf: []u16, utf8: []const u8) [:0]const u16 {
std.debug.assert(wbuf.len > 4);
bun.unsafeAssert(wbuf.len > 4);
wbuf[0..4].* = bun.windows.nt_maxpath_prefix;
return wbuf[0 .. toWPathNormalized(wbuf[4..], utf8).len + 4 :0];
}
@@ -1807,7 +1807,7 @@ pub fn toWPathNormalized(wbuf: []u16, utf8: []const u8) [:0]const u16 {
}
pub fn normalizeSlashesOnly(buf: []u8, utf8: []const u8, comptime desired_slash: u8) []const u8 {
comptime std.debug.assert(desired_slash == '/' or desired_slash == '\\');
comptime bun.unsafeAssert(desired_slash == '/' or desired_slash == '\\');
const undesired_slash = if (desired_slash == '/') '\\' else '/';
if (bun.strings.containsChar(utf8, undesired_slash)) {
@@ -1866,7 +1866,7 @@ pub fn assertIsValidWindowsPath(comptime T: type, path: []const T) void {
}
pub fn toWPathMaybeDir(wbuf: []u16, utf8: []const u8, comptime add_trailing_lash: bool) [:0]const u16 {
std.debug.assert(wbuf.len > 0);
bun.unsafeAssert(wbuf.len > 0);
var result = bun.simdutf.convert.utf8.to.utf16.with_errors.le(
utf8,
@@ -1938,7 +1938,7 @@ pub fn toUTF8ListWithType(list_: std.ArrayList(u8), comptime Type: type, utf16:
// which uses 3 bytes for invalid surrogates, causing the length to not
// match from simdutf.
// if (Environment.allow_assert) {
// std.debug.assert(buf.items.len == length);
// bun.unsafeAssert(buf.items.len == length);
// }
return buf;
@@ -2035,7 +2035,7 @@ pub fn allocateLatin1IntoUTF8WithList(list_: std.ArrayList(u8), offset_into_list
try list.ensureUnusedCapacity(latin1.len);
while (latin1.len > 0) {
if (comptime Environment.allow_assert) std.debug.assert(i < list.capacity);
if (comptime Environment.allow_assert) assert(i < list.capacity);
var buf = list.items.ptr[i..list.capacity];
inner: {
@@ -2056,7 +2056,7 @@ pub fn allocateLatin1IntoUTF8WithList(list_: std.ArrayList(u8), offset_into_list
if (mask > 0) {
const first_set_byte = @ctz(mask) / 8;
if (comptime Environment.allow_assert) std.debug.assert(latin1[first_set_byte] >= 127);
if (comptime Environment.allow_assert) assert(latin1[first_set_byte] >= 127);
buf[0..size].* = @as([size]u8, @bitCast(bytes));
buf = buf[first_set_byte..];
@@ -2076,7 +2076,7 @@ pub fn allocateLatin1IntoUTF8WithList(list_: std.ArrayList(u8), offset_into_list
if (mask > 0) {
const first_set_byte = @ctz(mask) / 8;
if (comptime Environment.allow_assert) std.debug.assert(latin1[first_set_byte] >= 127);
if (comptime Environment.allow_assert) assert(latin1[first_set_byte] >= 127);
buf[0..size].* = @as([size]u8, @bitCast(bytes));
buf = buf[first_set_byte..];
@@ -2103,7 +2103,7 @@ pub fn allocateLatin1IntoUTF8WithList(list_: std.ArrayList(u8), offset_into_list
if (mask > 0) {
const first_set_byte = @ctz(mask) / 8;
if (comptime Environment.allow_assert) std.debug.assert(latin1[first_set_byte] >= 127);
if (comptime Environment.allow_assert) assert(latin1[first_set_byte] >= 127);
buf[0..size].* = @as([size]u8, @bitCast(bytes));
latin1 = latin1[first_set_byte..];
@@ -2117,7 +2117,7 @@ pub fn allocateLatin1IntoUTF8WithList(list_: std.ArrayList(u8), offset_into_list
}
{
if (comptime Environment.allow_assert) std.debug.assert(latin1.len < 8);
if (comptime Environment.allow_assert) assert(latin1.len < 8);
const end = latin1.ptr + latin1.len;
while (latin1.ptr != end and latin1[0] < 128) {
buf[0] = latin1[0];
@@ -2167,13 +2167,13 @@ pub const UTF16Replacement = struct {
// This variation matches WebKit behavior.
pub fn convertUTF8BytesIntoUTF16(sequence: *const [4]u8) UTF16Replacement {
if (comptime Environment.allow_assert) std.debug.assert(sequence[0] > 127);
if (comptime Environment.allow_assert) assert(sequence[0] > 127);
const len = wtf8ByteSequenceLengthWithInvalid(sequence[0]);
switch (len) {
2 => {
if (comptime Environment.allow_assert) {
std.debug.assert(sequence[0] >= 0xC0);
std.debug.assert(sequence[0] <= 0xDF);
bun.assert(sequence[0] >= 0xC0);
bun.assert(sequence[0] <= 0xDF);
}
if (sequence[1] < 0x80 or sequence[1] > 0xBF) {
return .{ .len = 1, .fail = true };
@@ -2182,8 +2182,8 @@ pub fn convertUTF8BytesIntoUTF16(sequence: *const [4]u8) UTF16Replacement {
},
3 => {
if (comptime Environment.allow_assert) {
std.debug.assert(sequence[0] >= 0xE0);
std.debug.assert(sequence[0] <= 0xEF);
bun.assert(sequence[0] >= 0xE0);
bun.assert(sequence[0] <= 0xEF);
}
switch (sequence[0]) {
0xE0 => {
@@ -2295,7 +2295,7 @@ pub fn copyLatin1IntoUTF8StopOnNonASCII(buf_: []u8, comptime Type: type, latin1_
if (mask > 0) {
const first_set_byte = @ctz(mask) / 8;
if (comptime Environment.allow_assert) std.debug.assert(latin1[first_set_byte] >= 127);
if (comptime Environment.allow_assert) assert(latin1[first_set_byte] >= 127);
buf = buf[first_set_byte..];
latin1 = latin1[first_set_byte..];
@@ -2313,9 +2313,9 @@ pub fn copyLatin1IntoUTF8StopOnNonASCII(buf_: []u8, comptime Type: type, latin1_
buf[0..size].* = @as([size]u8, @bitCast(bytes));
if (comptime Environment.allow_assert) std.debug.assert(mask > 0);
if (comptime Environment.allow_assert) assert(mask > 0);
const first_set_byte = @ctz(mask) / 8;
if (comptime Environment.allow_assert) std.debug.assert(latin1[first_set_byte] >= 127);
if (comptime Environment.allow_assert) assert(latin1[first_set_byte] >= 127);
buf = buf[first_set_byte..];
latin1 = latin1[first_set_byte..];
@@ -2344,7 +2344,7 @@ pub fn copyLatin1IntoUTF8StopOnNonASCII(buf_: []u8, comptime Type: type, latin1_
if (mask > 0) {
const first_set_byte = @ctz(mask) / 8;
if (comptime stop) return .{ .written = std.math.maxInt(u32), .read = std.math.maxInt(u32) };
if (comptime Environment.allow_assert) std.debug.assert(latin1[first_set_byte] >= 127);
if (comptime Environment.allow_assert) assert(latin1[first_set_byte] >= 127);
buf = buf[first_set_byte..];
latin1 = latin1[first_set_byte..];
@@ -2359,7 +2359,7 @@ pub fn copyLatin1IntoUTF8StopOnNonASCII(buf_: []u8, comptime Type: type, latin1_
{
const end = latin1.ptr + @min(buf.len, latin1.len);
if (comptime Environment.allow_assert) std.debug.assert(@intFromPtr(latin1.ptr + 8) > @intFromPtr(end));
if (comptime Environment.allow_assert) assert(@intFromPtr(latin1.ptr + 8) > @intFromPtr(end));
const start_ptr = @intFromPtr(buf.ptr);
const start_ptr_latin1 = @intFromPtr(latin1.ptr);
@@ -2657,7 +2657,7 @@ pub fn escapeHTMLForLatin1Input(allocator: std.mem.Allocator, latin1: []const u8
// pass #1: scan for any characters that need escaping
// assume most strings won't need any escaping, so don't actually allocate the buffer
scan_and_allocate_lazily: while (remaining.len >= ascii_vector_size) {
if (comptime Environment.allow_assert) std.debug.assert(!any_needs_escape);
if (comptime Environment.allow_assert) assert(!any_needs_escape);
const vec: AsciiVector = remaining[0..ascii_vector_size].*;
if (@reduce(.Max, @as(AsciiVectorU1, @bitCast((vec == vecs[0]))) |
@as(AsciiVectorU1, @bitCast((vec == vecs[1]))) |
@@ -2665,7 +2665,7 @@ pub fn escapeHTMLForLatin1Input(allocator: std.mem.Allocator, latin1: []const u8
@as(AsciiVectorU1, @bitCast((vec == vecs[3]))) |
@as(AsciiVectorU1, @bitCast((vec == vecs[4])))) == 1)
{
if (comptime Environment.allow_assert) std.debug.assert(buf.capacity == 0);
if (comptime Environment.allow_assert) assert(buf.capacity == 0);
buf = try std.ArrayList(u8).initCapacity(allocator, latin1.len + 6);
const copy_len = @intFromPtr(remaining.ptr) - @intFromPtr(latin1.ptr);
@@ -2776,7 +2776,7 @@ pub fn escapeHTMLForLatin1Input(allocator: std.mem.Allocator, latin1: []const u8
scan_and_allocate_lazily: while (ptr != end) : (ptr += 1) {
switch (ptr[0]) {
'"', '&', '\'', '<', '>' => |c| {
if (comptime Environment.allow_assert) std.debug.assert(buf.capacity == 0);
if (comptime Environment.allow_assert) assert(buf.capacity == 0);
buf = try std.ArrayList(u8).initCapacity(allocator, latin1.len + @as(usize, Scalar.lengths[c]));
const copy_len = @intFromPtr(ptr) - @intFromPtr(latin1.ptr);
@@ -2814,7 +2814,7 @@ pub fn escapeHTMLForLatin1Input(allocator: std.mem.Allocator, latin1: []const u8
}
if (!any_needs_escape) {
if (comptime Environment.allow_assert) std.debug.assert(buf.capacity == 0);
if (comptime Environment.allow_assert) assert(buf.capacity == 0);
return Escaped(u8){ .original = {} };
}
@@ -2908,7 +2908,7 @@ pub fn escapeHTMLForUTF16Input(allocator: std.mem.Allocator, utf16: []const u16)
// pass #1: scan for any characters that need escaping
// assume most strings won't need any escaping, so don't actually allocate the buffer
scan_and_allocate_lazily: while (remaining.len >= ascii_u16_vector_size) {
if (comptime Environment.allow_assert) std.debug.assert(!any_needs_escape);
if (comptime Environment.allow_assert) assert(!any_needs_escape);
const vec: AsciiU16Vector = remaining[0..ascii_u16_vector_size].*;
if (@reduce(.Max, @as(AsciiVectorU16U1, @bitCast(vec > @as(AsciiU16Vector, @splat(@as(u16, 127))))) |
@as(AsciiVectorU16U1, @bitCast((vec == vecs[0]))) |
@@ -2941,7 +2941,7 @@ pub fn escapeHTMLForUTF16Input(allocator: std.mem.Allocator, utf16: []const u16)
continue :scan_and_allocate_lazily;
}
if (comptime Environment.allow_assert) std.debug.assert(@intFromPtr(remaining.ptr + i) >= @intFromPtr(utf16.ptr));
if (comptime Environment.allow_assert) assert(@intFromPtr(remaining.ptr + i) >= @intFromPtr(utf16.ptr));
const to_copy = std.mem.sliceAsBytes(utf16)[0 .. @intFromPtr(remaining.ptr + i) - @intFromPtr(utf16.ptr)];
const to_copy_16 = std.mem.bytesAsSlice(u16, to_copy);
buf = try std.ArrayList(u16).initCapacity(allocator, utf16.len + 6);
@@ -3053,7 +3053,7 @@ pub fn escapeHTMLForUTF16Input(allocator: std.mem.Allocator, utf16: []const u16)
switch (ptr[0]) {
'"', '&', '\'', '<', '>' => |c| {
buf = try std.ArrayList(u16).initCapacity(allocator, utf16.len + @as(usize, Scalar.lengths[c]));
if (comptime Environment.allow_assert) std.debug.assert(@intFromPtr(ptr) >= @intFromPtr(utf16.ptr));
if (comptime Environment.allow_assert) assert(@intFromPtr(ptr) >= @intFromPtr(utf16.ptr));
const to_copy = std.mem.sliceAsBytes(utf16)[0 .. @intFromPtr(ptr) - @intFromPtr(utf16.ptr)];
const to_copy_16 = std.mem.bytesAsSlice(u16, to_copy);
@@ -3486,7 +3486,7 @@ pub inline fn wtf8ByteSequenceLengthWithInvalid(first_byte: u8) u3 {
/// which was a clone of golang's "utf8.DecodeRune" that was modified to decode using WTF-8 instead.
/// Asserts a multi-byte codepoint
pub inline fn decodeWTF8RuneTMultibyte(p: *const [4]u8, len: u3, comptime T: type, comptime zero: T) T {
if (comptime Environment.allow_assert) std.debug.assert(len > 1);
if (comptime Environment.allow_assert) assert(len > 1);
const s1 = p[1];
if ((s1 & 0xC0) != 0x80) return zero;
@@ -3680,10 +3680,10 @@ pub fn firstNonASCIIWithType(comptime Type: type, slice: Type) ?u32 {
if (mask > 0) {
const first_set_byte = @ctz(mask) / 8;
if (comptime Environment.allow_assert) {
std.debug.assert(remaining[first_set_byte] > 127);
if (comptime Environment.isDebug) {
bun.assert(remaining[first_set_byte] > 127);
for (0..first_set_byte) |j| {
std.debug.assert(remaining[j] <= 127);
bun.assert(remaining[j] <= 127);
}
}
@@ -3697,10 +3697,10 @@ pub fn firstNonASCIIWithType(comptime Type: type, slice: Type) ?u32 {
if (mask > 0) {
const first_set_byte = @ctz(mask) / 8;
if (comptime Environment.allow_assert) {
std.debug.assert(remaining[first_set_byte] > 127);
if (comptime Environment.isDebug) {
bun.assert(remaining[first_set_byte] > 127);
for (0..first_set_byte) |j| {
std.debug.assert(remaining[j] <= 127);
bun.assert(remaining[j] <= 127);
}
}
@@ -3728,8 +3728,8 @@ pub fn firstNonASCIIWithType(comptime Type: type, slice: Type) ?u32 {
if (comptime Environment.enableSIMD) {
// these assertions exist more so for LLVM
std.debug.assert(remaining.len < ascii_vector_size);
std.debug.assert(@intFromPtr(remaining.ptr + ascii_vector_size) > @intFromPtr(remaining_end));
bun.unsafeAssert(remaining.len < ascii_vector_size);
bun.unsafeAssert(@intFromPtr(remaining.ptr + ascii_vector_size) > @intFromPtr(remaining_end));
}
if (remaining.len >= size) {
@@ -3741,10 +3741,10 @@ pub fn firstNonASCIIWithType(comptime Type: type, slice: Type) ?u32 {
if (mask > 0) {
remaining.len -= @intFromPtr(remaining.ptr) - @intFromPtr(remaining_start);
const first_set_byte = @ctz(mask) / 8;
if (comptime Environment.allow_assert) {
std.debug.assert(remaining[first_set_byte] > 127);
if (comptime Environment.isDebug) {
bun.unsafeAssert(remaining[first_set_byte] > 127);
for (0..first_set_byte) |j| {
std.debug.assert(remaining[j] <= 127);
bun.unsafeAssert(remaining[j] <= 127);
}
}
@@ -3757,7 +3757,7 @@ pub fn firstNonASCIIWithType(comptime Type: type, slice: Type) ?u32 {
}
}
if (comptime Environment.allow_assert) std.debug.assert(remaining.len < 8);
if (comptime Environment.allow_assert) assert(remaining.len < 8);
for (remaining) |*char| {
if (char.* > 127) {
@@ -3794,7 +3794,7 @@ pub fn indexOfNewlineOrNonASCIIOrANSI(slice_: []const u8, offset: u32) ?u32 {
remaining = remaining[ascii_vector_size..];
}
if (comptime Environment.allow_assert) std.debug.assert(remaining.len < ascii_vector_size);
if (comptime Environment.allow_assert) assert(remaining.len < ascii_vector_size);
}
for (remaining) |*char_| {
@@ -3842,7 +3842,7 @@ pub fn indexOfNewlineOrNonASCIICheckStart(slice_: []const u8, offset: u32, compt
remaining = remaining[ascii_vector_size..];
}
if (comptime Environment.allow_assert) std.debug.assert(remaining.len < ascii_vector_size);
if (comptime Environment.allow_assert) assert(remaining.len < ascii_vector_size);
}
for (remaining) |*char_| {
@@ -3877,7 +3877,7 @@ pub fn containsNewlineOrNonASCIIOrQuote(slice_: []const u8) bool {
remaining = remaining[ascii_vector_size..];
}
if (comptime Environment.allow_assert) std.debug.assert(remaining.len < ascii_vector_size);
if (comptime Environment.allow_assert) assert(remaining.len < ascii_vector_size);
}
for (remaining) |*char_| {
@@ -3939,8 +3939,8 @@ pub fn indexOfCharZ(sliceZ: [:0]const u8, char: u8) ?u63 {
const ptr = bun.C.strchr(sliceZ.ptr, char) orelse return null;
const pos = @intFromPtr(ptr) - @intFromPtr(sliceZ.ptr);
if (comptime Environment.allow_assert)
std.debug.assert(@intFromPtr(sliceZ.ptr) <= @intFromPtr(ptr) and
if (comptime Environment.isDebug)
bun.assert(@intFromPtr(sliceZ.ptr) <= @intFromPtr(ptr) and
@intFromPtr(ptr) < @intFromPtr(sliceZ.ptr + sliceZ.len) and
pos <= sliceZ.len);
@@ -3961,8 +3961,8 @@ pub fn indexOfCharUsize(slice: []const u8, char: u8) ?usize {
const ptr = bun.C.memchr(slice.ptr, char, slice.len) orelse return null;
const i = @intFromPtr(ptr) - @intFromPtr(slice.ptr);
std.debug.assert(i < slice.len);
std.debug.assert(slice[i] == char);
bun.assert(i < slice.len);
bun.assert(slice[i] == char);
return i;
}
@@ -4114,8 +4114,8 @@ fn byte2hex(char: u8) u8 {
pub fn encodeBytesToHex(destination: []u8, source: []const u8) usize {
if (comptime Environment.allow_assert) {
std.debug.assert(destination.len > 0);
std.debug.assert(source.len > 0);
bun.unsafeAssert(destination.len > 0);
bun.unsafeAssert(source.len > 0);
}
const to_write = if (destination.len < source.len * 2)
destination.len - destination.len % 2
@@ -4410,7 +4410,7 @@ pub fn firstNonASCII16(comptime Slice: type, slice: Slice) ?u32 {
remaining.len -= (@intFromPtr(remaining.ptr) - @intFromPtr(remaining_start)) / 2;
}
std.debug.assert(remaining.len < ascii_u16_vector_size);
bun.unsafeAssert(remaining.len < ascii_u16_vector_size);
}
var i: usize = (@intFromPtr(remaining.ptr) - @intFromPtr(remaining_start)) / 2;
@@ -4472,7 +4472,7 @@ test "indexOfNotChar" {
for (0..yes.len) |i| {
@memset(yes, 'a');
yes[i] = 'b';
if (comptime Environment.allow_assert) std.debug.assert(indexOfNotChar(&yes, 'a').? == i);
if (comptime Environment.allow_assert) assert(indexOfNotChar(&yes, 'a').? == i);
i += 1;
}
}
@@ -4731,7 +4731,7 @@ pub fn isASCIIHexDigit(c: u8) bool {
}
pub fn toASCIIHexValue(character: u8) u8 {
if (comptime Environment.allow_assert) std.debug.assert(isASCIIHexDigit(character));
if (comptime Environment.isDebug) assert(isASCIIHexDigit(character));
return switch (character) {
0...('A' - 1) => character - '0',
else => (character - 'A' + 10) & 0xF,
@@ -5111,20 +5111,20 @@ pub fn moveAllSlices(comptime Type: type, container: *Type, from: string, to: st
pub fn moveSlice(slice: string, from: string, to: string) string {
if (comptime Environment.allow_assert) {
std.debug.assert(from.len <= to.len and from.len >= slice.len);
bun.unsafeAssert(from.len <= to.len and from.len >= slice.len);
// assert we are in bounds
std.debug.assert(
bun.unsafeAssert(
(@intFromPtr(from.ptr) + from.len) >=
@intFromPtr(slice.ptr) + slice.len and
(@intFromPtr(from.ptr) <= @intFromPtr(slice.ptr)),
);
std.debug.assert(eqlLong(from, to[0..from.len], false)); // data should be identical
bun.unsafeAssert(eqlLong(from, to[0..from.len], false)); // data should be identical
}
const ptr_offset = @intFromPtr(slice.ptr) - @intFromPtr(from.ptr);
const result = to[ptr_offset..][0..slice.len];
if (comptime Environment.allow_assert) std.debug.assert(eqlLong(slice, result, false)); // data should be identical
if (comptime Environment.allow_assert) assert(eqlLong(slice, result, false)); // data should be identical
return result;
}
@@ -5237,7 +5237,7 @@ pub fn cloneNormalizingSeparators(
const base = withoutTrailingSlash(input);
var tokenized = std.mem.tokenize(u8, base, std.fs.path.sep_str);
var buf = try allocator.alloc(u8, base.len + 2);
if (comptime Environment.allow_assert) std.debug.assert(base.len > 0);
if (comptime Environment.allow_assert) assert(base.len > 0);
if (base[0] == std.fs.path.sep) {
buf[0] = std.fs.path.sep;
}
@@ -5298,7 +5298,7 @@ pub fn concatWithLength(
@memcpy(remain[0..arg.len], arg);
remain = remain[arg.len..];
}
std.debug.assert(remain.len == 0); // all bytes should be used
bun.unsafeAssert(remain.len == 0); // all bytes should be used
return out;
}
@@ -5372,7 +5372,7 @@ pub fn concatIfNeeded(
remain = remain[arg.len..];
}
std.debug.assert(remain.len == 0);
bun.unsafeAssert(remain.len == 0);
}
/// This will simply ignore invalid UTF-8 and just do it
@@ -6304,3 +6304,5 @@ pub fn withoutPrefixComptime(input: []const u8, comptime prefix: []const u8) []c
// extern "C" bool icu_hasBinaryProperty(UChar32 cp, unsigned int prop)
extern fn icu_hasBinaryProperty(c: u32, which: c_uint) bool;
const assert = bun.assert;