| ... | @@ -398,20 +398,30 @@ pub fn dumpStackTrace(stack_trace: std.builtin.StackTrace) void { | ... | @@ -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 | /// In Debug and ReleaseSafe modes, calls to this function are always | 403 | /// In Debug and ReleaseSafe modes, calls to this function are always |
| 403 | /// generated, and the `unreachable` statement triggers a panic. | 404 | /// generated, and the `unreachable` statement triggers a panic. |
| 404 | /// In ReleaseFast and ReleaseSmall modes, calls to this function are | 405 | /// |
| 405 | /// optimized away, and in fact the optimizer is able to use the assertion | 406 | /// In ReleaseFast and ReleaseSmall modes, calls to this function are optimized |
| 406 | /// in its heuristics. | 407 | /// away, and in fact the optimizer is able to use the assertion in its |
| 407 | /// Inside a test block, it is best to use the `std.testing` module rather | 408 | /// heuristics. |
| 408 | /// than this function, because this function may not detect a test failure | 409 | /// |
| 409 | /// in ReleaseFast and ReleaseSmall mode. Outside of a test block, this assert | 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 | /// function is the correct function to use. | 413 | /// function is the correct function to use. |
| 411 | pub fn assert(ok: bool) void { | 414 | pub fn assert(ok: bool) void { |
| 412 | if (!ok) unreachable; // assertion failure | 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 | pub fn panic(comptime format: []const u8, args: anytype) noreturn { | 425 | pub fn panic(comptime format: []const u8, args: anytype) noreturn { |
| 416 | @setCold(true); | 426 | @setCold(true); |
| 417 | | 427 | |