| ... | ... | @@ -398,20 +398,30 @@ pub fn dumpStackTrace(stack_trace: std.builtin.StackTrace) void { |
| 398 | 398 | } |
| 399 | 399 | } |
| 400 | 400 | |
| 401 | | /// This function invokes undefined behavior when `ok` is `false`. |
| 401 | /// Invokes detectable illegal behavior when `ok` is `false`. |
| 402 | /// |
| 402 | 403 | /// In Debug and ReleaseSafe modes, calls to this function are always |
| 403 | 404 | /// generated, and the `unreachable` statement triggers a panic. |
| 404 | | /// In ReleaseFast and ReleaseSmall modes, calls to this function are |
| 405 | | /// optimized away, and in fact the optimizer is able to use the assertion |
| 406 | | /// in its heuristics. |
| 407 | | /// Inside a test block, it is best to use the `std.testing` module rather |
| 408 | | /// than this function, because this function may not detect a test failure |
| 409 | | /// in ReleaseFast and ReleaseSmall mode. Outside of a test block, this assert |
| 405 | /// |
| 406 | /// In ReleaseFast and ReleaseSmall modes, calls to this function are optimized |
| 407 | /// away, and in fact the optimizer is able to use the assertion in its |
| 408 | /// heuristics. |
| 409 | /// |
| 410 | /// Inside a test block, it is best to use the `std.testing` module rather than |
| 411 | /// this function, because this function may not detect a test failure in |
| 412 | /// ReleaseFast and ReleaseSmall mode. Outside of a test block, this assert |
| 410 | 413 | /// function is the correct function to use. |
| 411 | 414 | pub fn assert(ok: bool) void { |
| 412 | 415 | if (!ok) unreachable; // assertion failure |
| 413 | 416 | } |
| 414 | 417 | |
| 418 | /// Invokes detectable illegal behavior when the provided slice is not mapped |
| 419 | /// or lacks read permissions. |
| 420 | pub fn assertReadable(slice: []const volatile u8) void { |
| 421 | if (!runtime_safety) return; |
| 422 | for (slice) |*byte| _ = byte.*; |
| 423 | } |
| 424 | |
| 415 | 425 | pub fn panic(comptime format: []const u8, args: anytype) noreturn { |
| 416 | 426 | @setCold(true); |
| 417 | 427 | |