make our quirks assert use `std.debug.assert` in debug builds (#9838)

This fixes an issue I have on both macOS and Linux (ARM and x86_64)
where stack traces are broken for inlined functions. They don't point to
the proper location in the source code, making debugging difficult.

Release builds use the same previous function.

cc @qwerasd205
pull/9839/head
Mitchell Hashimoto 2025-12-07 14:17:30 -08:00 committed by GitHub
commit ddca4a8412
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 14 additions and 3 deletions

View File

@ -7,6 +7,7 @@
//! [1]: https://github.com/WebKit/WebKit/blob/main/Source/WebCore/page/Quirks.cpp //! [1]: https://github.com/WebKit/WebKit/blob/main/Source/WebCore/page/Quirks.cpp
const std = @import("std"); const std = @import("std");
const builtin = @import("builtin");
const font = @import("font/main.zig"); const font = @import("font/main.zig");
@ -41,6 +42,16 @@ pub fn disableDefaultFontFeatures(face: *const font.Face) bool {
/// is negligible, but we have some asserts inside tight loops and hotpaths /// is negligible, but we have some asserts inside tight loops and hotpaths
/// that cause significant overhead (as much as 15-20%) when they don't get /// that cause significant overhead (as much as 15-20%) when they don't get
/// optimized out. /// optimized out.
pub inline fn inlineAssert(ok: bool) void { pub const inlineAssert: fn (bool) void = switch (builtin.mode) {
if (!ok) unreachable; // In debug builds we just use std.debug.assert because this
} // fixes up stack traces. `inline` causes broken stack traces. This
// is probably a Zig compiler bug but until it is fixed we have to
// do this for development sanity.
.Debug => std.debug.assert,
.ReleaseSmall, .ReleaseSafe, .ReleaseFast => (struct {
inline fn assert(ok: bool) void {
if (!ok) unreachable;
}
}).assert,
};