| ... | ... | @@ -761,91 +761,18 @@ pub const TestFn = struct { |
| 761 | 761 | func: *const fn () anyerror!void, |
| 762 | 762 | }; |
| 763 | 763 | |
| 764 | | const old_version = std.SemanticVersion.parse("0.14.0-dev.1659+4ceefca14") catch unreachable; |
| 765 | | const is_old = @import("builtin").zig_version.order(old_version) != .gt; |
| 766 | | |
| 767 | 764 | /// This function type is used by the Zig language code generation and |
| 768 | 765 | /// therefore must be kept in sync with the compiler implementation. |
| 769 | | pub const PanicFn = if (is_old) |
| 770 | | fn ([]const u8, ?*StackTrace, ?usize) noreturn |
| 771 | | else |
| 772 | | fn (PanicCause, ?*StackTrace, ?usize) noreturn; |
| 766 | pub const PanicFn = fn (PanicCause, ?*StackTrace, ?usize) noreturn; |
| 773 | 767 | |
| 774 | 768 | /// The entry point for auto-generated calls by the compiler. |
| 775 | | pub const panic: PanicFn = if (is_old) |
| 776 | | defaultPanicOld |
| 777 | | else if (@hasDecl(root, "panic")) |
| 769 | pub const panic: PanicFn = if (@hasDecl(root, "panic")) |
| 778 | 770 | root.panic |
| 779 | 771 | else if (@hasDecl(root, "os") and @hasDecl(root.os, "panic")) |
| 780 | 772 | root.os.panic |
| 781 | 773 | else |
| 782 | 774 | std.debug.defaultPanic; |
| 783 | 775 | |
| 784 | | pub fn defaultPanicOld( |
| 785 | | msg: []const u8, |
| 786 | | trace: ?*const std.builtin.StackTrace, |
| 787 | | first_trace_addr: ?usize, |
| 788 | | ) noreturn { |
| 789 | | @branchHint(.cold); |
| 790 | | std.debug.print("old panic: {s}\n", .{msg}); |
| 791 | | _ = trace; |
| 792 | | _ = first_trace_addr; |
| 793 | | @trap(); |
| 794 | | } |
| 795 | | |
| 796 | | pub fn panicSentinelMismatch(expected: anytype, actual: @TypeOf(expected)) noreturn { |
| 797 | | @branchHint(.cold); |
| 798 | | std.debug.panicExtra(null, @returnAddress(), "sentinel mismatch: expected {any}, found {any}", .{ expected, actual }); |
| 799 | | } |
| 800 | | |
| 801 | | pub fn panicUnwrapError(st: ?*StackTrace, err: anyerror) noreturn { |
| 802 | | @branchHint(.cold); |
| 803 | | std.debug.panicExtra(st, @returnAddress(), "attempt to unwrap error: {s}", .{@errorName(err)}); |
| 804 | | } |
| 805 | | |
| 806 | | pub fn panicOutOfBounds(index: usize, len: usize) noreturn { |
| 807 | | @branchHint(.cold); |
| 808 | | std.debug.panicExtra(null, @returnAddress(), "index out of bounds: index {d}, len {d}", .{ index, len }); |
| 809 | | } |
| 810 | | |
| 811 | | pub fn panicStartGreaterThanEnd(start: usize, end: usize) noreturn { |
| 812 | | @branchHint(.cold); |
| 813 | | std.debug.panicExtra(null, @returnAddress(), "start index {d} is larger than end index {d}", .{ start, end }); |
| 814 | | } |
| 815 | | |
| 816 | | pub fn panicInactiveUnionField(active: anytype, wanted: @TypeOf(active)) noreturn { |
| 817 | | @branchHint(.cold); |
| 818 | | std.debug.panicExtra(null, @returnAddress(), "access of union field '{s}' while field '{s}' is active", .{ @tagName(wanted), @tagName(active) }); |
| 819 | | } |
| 820 | | |
| 821 | | pub const panic_messages = struct { |
| 822 | | pub const unreach = "reached unreachable code"; |
| 823 | | pub const unwrap_null = "attempt to use null value"; |
| 824 | | pub const cast_to_null = "cast causes pointer to be null"; |
| 825 | | pub const incorrect_alignment = "incorrect alignment"; |
| 826 | | pub const invalid_error_code = "invalid error code"; |
| 827 | | pub const cast_truncated_data = "integer cast truncated bits"; |
| 828 | | pub const negative_to_unsigned = "attempt to cast negative value to unsigned integer"; |
| 829 | | pub const integer_overflow = "integer overflow"; |
| 830 | | pub const shl_overflow = "left shift overflowed bits"; |
| 831 | | pub const shr_overflow = "right shift overflowed bits"; |
| 832 | | pub const divide_by_zero = "division by zero"; |
| 833 | | pub const exact_division_remainder = "exact division produced remainder"; |
| 834 | | pub const inactive_union_field = "access of inactive union field"; |
| 835 | | pub const integer_part_out_of_bounds = "integer part of floating point value out of bounds"; |
| 836 | | pub const corrupt_switch = "switch on corrupt value"; |
| 837 | | pub const shift_rhs_too_big = "shift amount is greater than the type size"; |
| 838 | | pub const invalid_enum_value = "invalid enum value"; |
| 839 | | pub const sentinel_mismatch = "sentinel mismatch"; |
| 840 | | pub const unwrap_error = "attempt to unwrap error"; |
| 841 | | pub const index_out_of_bounds = "index out of bounds"; |
| 842 | | pub const start_index_greater_than_end = "start index is larger than end index"; |
| 843 | | pub const for_len_mismatch = "for loop over objects with non-equal lengths"; |
| 844 | | pub const memcpy_len_mismatch = "@memcpy arguments have non-equal lengths"; |
| 845 | | pub const memcpy_alias = "@memcpy arguments alias"; |
| 846 | | pub const noreturn_returned = "'noreturn' function returned"; |
| 847 | | }; |
| 848 | | |
| 849 | 776 | /// This data structure is used by the Zig language code generation and |
| 850 | 777 | /// therefore must be kept in sync with the compiler implementation. |
| 851 | 778 | pub const PanicCause = union(enum) { |