| author | |
| committer | |
| log | 9804cc8bc6fe83b2a0cd5b61b8d2fc5d458cb221 |
| tree | d2f7a675b37c8f94db9b1015589a3b37805e2ac6 |
| parent | 89a9cabafd745034871ea014b06bd3bad0505f4a |
| signature | Commit is signed but in an unrecognized format. |
26 files changed, 117 insertions(+), 153 deletions(-)
lib/std/Build/Step/Options.zig+1-3| ... | ... | @@ -318,9 +318,7 @@ fn printStruct(options: *Options, out: anytype, comptime T: type, comptime val: |
| 318 | 318 | try out.print(" {p_}: {s}", .{ std.zig.fmtId(field.name), type_name }); |
| 319 | 319 | } |
| 320 | 320 | |
| 321 | if (field.default_value != null) { | |
| 322 | const default_value = @as(*field.type, @ptrCast(@alignCast(@constCast(field.default_value.?)))).*; | |
| 323 | ||
| 321 | if (field.defaultValue()) |default_value| { | |
| 324 | 322 | try out.writeAll(" = "); |
| 325 | 323 | switch (@typeInfo(@TypeOf(default_value))) { |
| 326 | 324 | .@"enum" => try out.print(".{s},\n", .{@tagName(default_value)}), |
lib/std/crypto/phc_encoding.zig+1-1| ... | ... | @@ -164,7 +164,7 @@ pub fn deserialize(comptime HashResult: type, str: []const u8) Error!HashResult |
| 164 | 164 | // with default values |
| 165 | 165 | var expected_fields: usize = 0; |
| 166 | 166 | inline for (comptime meta.fields(HashResult)) |p| { |
| 167 | if (@typeInfo(p.type) != .optional and p.default_value == null) { | |
| 167 | if (@typeInfo(p.type) != .optional and p.default_value_ptr == null) { | |
| 168 | 168 | expected_fields += 1; |
| 169 | 169 | } |
| 170 | 170 | } |
lib/std/enums.zig+1-1| ... | ... | @@ -19,7 +19,7 @@ pub fn EnumFieldStruct(comptime E: type, comptime Data: type, comptime field_def |
| 19 | 19 | struct_field.* = .{ |
| 20 | 20 | .name = enum_field.name ++ "", |
| 21 | 21 | .type = Data, |
| 22 | .default_value = if (field_default) |d| @as(?*const anyopaque, @ptrCast(&d)) else null, | |
| 22 | .default_value_ptr = if (field_default) |d| @as(?*const anyopaque, @ptrCast(&d)) else null, | |
| 23 | 23 | .is_comptime = false, |
| 24 | 24 | .alignment = if (@sizeOf(Data) > 0) @alignOf(Data) else 0, |
| 25 | 25 | }; |
lib/std/fmt.zig+1-1| ... | ... | @@ -633,7 +633,7 @@ pub fn formatType( |
| 633 | 633 | .many, .c => { |
| 634 | 634 | if (actual_fmt.len == 0) |
| 635 | 635 | @compileError("cannot format pointer without a specifier (i.e. {s} or {*})"); |
| 636 | if (ptr_info.sentinel) |_| { | |
| 636 | if (ptr_info.sentinel() != null) { | |
| 637 | 637 | return formatType(mem.span(value), actual_fmt, options, writer, max_depth); |
| 638 | 638 | } |
| 639 | 639 | if (actual_fmt[0] == 's' and ptr_info.child == u8) { |
lib/std/io.zig+1-1| ... | ... | @@ -805,7 +805,7 @@ pub fn PollFiles(comptime StreamEnum: type) type { |
| 805 | 805 | struct_field.* = .{ |
| 806 | 806 | .name = enum_field.name ++ "", |
| 807 | 807 | .type = fs.File, |
| 808 | .default_value = null, | |
| 808 | .default_value_ptr = null, | |
| 809 | 809 | .is_comptime = false, |
| 810 | 810 | .alignment = @alignOf(fs.File), |
| 811 | 811 | }; |
lib/std/json/static.zig+9-11| ... | ... | @@ -476,9 +476,8 @@ pub fn innerParse( |
| 476 | 476 | arraylist.appendAssumeCapacity(try innerParse(ptrInfo.child, allocator, source, options)); |
| 477 | 477 | } |
| 478 | 478 | |
| 479 | if (ptrInfo.sentinel) |some| { | |
| 480 | const sentinel_value = @as(*align(1) const ptrInfo.child, @ptrCast(some)).*; | |
| 481 | return try arraylist.toOwnedSliceSentinel(sentinel_value); | |
| 479 | if (ptrInfo.sentinel()) |s| { | |
| 480 | return try arraylist.toOwnedSliceSentinel(s); | |
| 482 | 481 | } |
| 483 | 482 | |
| 484 | 483 | return try arraylist.toOwnedSlice(); |
| ... | ... | @@ -487,11 +486,11 @@ pub fn innerParse( |
| 487 | 486 | if (ptrInfo.child != u8) return error.UnexpectedToken; |
| 488 | 487 | |
| 489 | 488 | // Dynamic length string. |
| 490 | if (ptrInfo.sentinel) |sentinel_ptr| { | |
| 489 | if (ptrInfo.sentinel()) |s| { | |
| 491 | 490 | // Use our own array list so we can append the sentinel. |
| 492 | 491 | var value_list = ArrayList(u8).init(allocator); |
| 493 | 492 | _ = try source.allocNextIntoArrayList(&value_list, .alloc_always); |
| 494 | return try value_list.toOwnedSliceSentinel(@as(*const u8, @ptrCast(sentinel_ptr)).*); | |
| 493 | return try value_list.toOwnedSliceSentinel(s); | |
| 495 | 494 | } |
| 496 | 495 | if (ptrInfo.is_const) { |
| 497 | 496 | switch (try source.nextAllocMax(allocator, options.allocate.?, options.max_value_len.?)) { |
| ... | ... | @@ -714,8 +713,8 @@ pub fn innerParseFromValue( |
| 714 | 713 | .slice => { |
| 715 | 714 | switch (source) { |
| 716 | 715 | .array => |array| { |
| 717 | const r = if (ptrInfo.sentinel) |sentinel_ptr| | |
| 718 | try allocator.allocSentinel(ptrInfo.child, array.items.len, @as(*align(1) const ptrInfo.child, @ptrCast(sentinel_ptr)).*) | |
| 716 | const r = if (ptrInfo.sentinel()) |sentinel| | |
| 717 | try allocator.allocSentinel(ptrInfo.child, array.items.len, sentinel) | |
| 719 | 718 | else |
| 720 | 719 | try allocator.alloc(ptrInfo.child, array.items.len); |
| 721 | 720 | |
| ... | ... | @@ -729,8 +728,8 @@ pub fn innerParseFromValue( |
| 729 | 728 | if (ptrInfo.child != u8) return error.UnexpectedToken; |
| 730 | 729 | // Dynamic length string. |
| 731 | 730 | |
| 732 | const r = if (ptrInfo.sentinel) |sentinel_ptr| | |
| 733 | try allocator.allocSentinel(ptrInfo.child, s.len, @as(*align(1) const ptrInfo.child, @ptrCast(sentinel_ptr)).*) | |
| 731 | const r = if (ptrInfo.sentinel()) |sentinel| | |
| 732 | try allocator.allocSentinel(ptrInfo.child, s.len, sentinel) | |
| 734 | 733 | else |
| 735 | 734 | try allocator.alloc(ptrInfo.child, s.len); |
| 736 | 735 | @memcpy(r[0..], s); |
| ... | ... | @@ -787,8 +786,7 @@ fn sliceToEnum(comptime T: type, slice: []const u8) !T { |
| 787 | 786 | fn fillDefaultStructValues(comptime T: type, r: *T, fields_seen: *[@typeInfo(T).@"struct".fields.len]bool) !void { |
| 788 | 787 | inline for (@typeInfo(T).@"struct".fields, 0..) |field, i| { |
| 789 | 788 | if (!fields_seen[i]) { |
| 790 | if (field.default_value) |default_ptr| { | |
| 791 | const default = @as(*align(1) const field.type, @ptrCast(default_ptr)).*; | |
| 789 | if (field.defaultValue()) |default| { | |
| 792 | 790 | @field(r, field.name) = default; |
| 793 | 791 | } else { |
| 794 | 792 | return error.MissingField; |
lib/std/json/stringify.zig+1-1| ... | ... | @@ -642,7 +642,7 @@ pub fn WriteStream( |
| 642 | 642 | }, |
| 643 | 643 | }, |
| 644 | 644 | .many, .slice => { |
| 645 | if (ptr_info.size == .many and ptr_info.sentinel == null) | |
| 645 | if (ptr_info.size == .many and ptr_info.sentinel() == null) | |
| 646 | 646 | @compileError("unable to stringify type '" ++ @typeName(T) ++ "' without sentinel"); |
| 647 | 647 | const slice = if (ptr_info.size == .many) std.mem.span(value) else value; |
| 648 | 648 |
lib/std/mem.zig+31-44| ... | ... | @@ -263,8 +263,8 @@ pub fn zeroes(comptime T: type) T { |
| 263 | 263 | .pointer => |ptr_info| { |
| 264 | 264 | switch (ptr_info.size) { |
| 265 | 265 | .slice => { |
| 266 | if (ptr_info.sentinel) |sentinel| { | |
| 267 | if (ptr_info.child == u8 and @as(*const u8, @ptrCast(sentinel)).* == 0) { | |
| 266 | if (ptr_info.sentinel()) |sentinel| { | |
| 267 | if (ptr_info.child == u8 and sentinel == 0) { | |
| 268 | 268 | return ""; // A special case for the most common use-case: null-terminated strings. |
| 269 | 269 | } |
| 270 | 270 | @compileError("Can't set a sentinel slice to zero. This would require allocating memory."); |
| ... | ... | @@ -282,11 +282,7 @@ pub fn zeroes(comptime T: type) T { |
| 282 | 282 | } |
| 283 | 283 | }, |
| 284 | 284 | .array => |info| { |
| 285 | if (info.sentinel) |sentinel_ptr| { | |
| 286 | const sentinel = @as(*align(1) const info.child, @ptrCast(sentinel_ptr)).*; | |
| 287 | return [_:sentinel]info.child{zeroes(info.child)} ** info.len; | |
| 288 | } | |
| 289 | return [_]info.child{zeroes(info.child)} ** info.len; | |
| 285 | return @splat(zeroes(info.child)); | |
| 290 | 286 | }, |
| 291 | 287 | .vector => |info| { |
| 292 | 288 | return @splat(zeroes(info.child)); |
| ... | ... | @@ -456,9 +452,8 @@ pub fn zeroInit(comptime T: type, init: anytype) T { |
| 456 | 452 | @field(value, field.name) = @field(init, field.name); |
| 457 | 453 | }, |
| 458 | 454 | } |
| 459 | } else if (field.default_value) |default_value_ptr| { | |
| 460 | const default_value = @as(*align(1) const field.type, @ptrCast(default_value_ptr)).*; | |
| 461 | @field(value, field.name) = default_value; | |
| 455 | } else if (field.defaultValue()) |val| { | |
| 456 | @field(value, field.name) = val; | |
| 462 | 457 | } else { |
| 463 | 458 | switch (@typeInfo(field.type)) { |
| 464 | 459 | .@"struct" => { |
| ... | ... | @@ -782,10 +777,10 @@ fn Span(comptime T: type) type { |
| 782 | 777 | var new_ptr_info = ptr_info; |
| 783 | 778 | switch (ptr_info.size) { |
| 784 | 779 | .c => { |
| 785 | new_ptr_info.sentinel = &@as(ptr_info.child, 0); | |
| 780 | new_ptr_info.sentinel_ptr = &@as(ptr_info.child, 0); | |
| 786 | 781 | new_ptr_info.is_allowzero = false; |
| 787 | 782 | }, |
| 788 | .many => if (ptr_info.sentinel == null) @compileError("invalid type given to std.mem.span: " ++ @typeName(T)), | |
| 783 | .many => if (ptr_info.sentinel() == null) @compileError("invalid type given to std.mem.span: " ++ @typeName(T)), | |
| 789 | 784 | .one, .slice => @compileError("invalid type given to std.mem.span: " ++ @typeName(T)), |
| 790 | 785 | } |
| 791 | 786 | new_ptr_info.size = .slice; |
| ... | ... | @@ -822,8 +817,7 @@ pub fn span(ptr: anytype) Span(@TypeOf(ptr)) { |
| 822 | 817 | const Result = Span(@TypeOf(ptr)); |
| 823 | 818 | const l = len(ptr); |
| 824 | 819 | const ptr_info = @typeInfo(Result).pointer; |
| 825 | if (ptr_info.sentinel) |s_ptr| { | |
| 826 | const s = @as(*align(1) const ptr_info.child, @ptrCast(s_ptr)).*; | |
| 820 | if (ptr_info.sentinel()) |s| { | |
| 827 | 821 | return ptr[0..l :s]; |
| 828 | 822 | } else { |
| 829 | 823 | return ptr[0..l]; |
| ... | ... | @@ -853,12 +847,11 @@ fn SliceTo(comptime T: type, comptime end: std.meta.Elem(T)) type { |
| 853 | 847 | // The return type must only be sentinel terminated if we are guaranteed |
| 854 | 848 | // to find the value searched for, which is only the case if it matches |
| 855 | 849 | // the sentinel of the type passed. |
| 856 | if (array_info.sentinel) |sentinel_ptr| { | |
| 857 | const sentinel = @as(*align(1) const array_info.child, @ptrCast(sentinel_ptr)).*; | |
| 858 | if (end == sentinel) { | |
| 859 | new_ptr_info.sentinel = &end; | |
| 850 | if (array_info.sentinel()) |s| { | |
| 851 | if (end == s) { | |
| 852 | new_ptr_info.sentinel_ptr = &end; | |
| 860 | 853 | } else { |
| 861 | new_ptr_info.sentinel = null; | |
| 854 | new_ptr_info.sentinel_ptr = null; | |
| 862 | 855 | } |
| 863 | 856 | } |
| 864 | 857 | }, |
| ... | ... | @@ -868,17 +861,16 @@ fn SliceTo(comptime T: type, comptime end: std.meta.Elem(T)) type { |
| 868 | 861 | // The return type must only be sentinel terminated if we are guaranteed |
| 869 | 862 | // to find the value searched for, which is only the case if it matches |
| 870 | 863 | // the sentinel of the type passed. |
| 871 | if (ptr_info.sentinel) |sentinel_ptr| { | |
| 872 | const sentinel = @as(*align(1) const ptr_info.child, @ptrCast(sentinel_ptr)).*; | |
| 873 | if (end == sentinel) { | |
| 874 | new_ptr_info.sentinel = &end; | |
| 864 | if (ptr_info.sentinel()) |s| { | |
| 865 | if (end == s) { | |
| 866 | new_ptr_info.sentinel_ptr = &end; | |
| 875 | 867 | } else { |
| 876 | new_ptr_info.sentinel = null; | |
| 868 | new_ptr_info.sentinel_ptr = null; | |
| 877 | 869 | } |
| 878 | 870 | } |
| 879 | 871 | }, |
| 880 | 872 | .c => { |
| 881 | new_ptr_info.sentinel = &end; | |
| 873 | new_ptr_info.sentinel_ptr = &end; | |
| 882 | 874 | // C pointers are always allowzero, but we don't want the return type to be. |
| 883 | 875 | assert(new_ptr_info.is_allowzero); |
| 884 | 876 | new_ptr_info.is_allowzero = false; |
| ... | ... | @@ -906,8 +898,7 @@ pub fn sliceTo(ptr: anytype, comptime end: std.meta.Elem(@TypeOf(ptr))) SliceTo( |
| 906 | 898 | const Result = SliceTo(@TypeOf(ptr), end); |
| 907 | 899 | const length = lenSliceTo(ptr, end); |
| 908 | 900 | const ptr_info = @typeInfo(Result).pointer; |
| 909 | if (ptr_info.sentinel) |s_ptr| { | |
| 910 | const s = @as(*align(1) const ptr_info.child, @ptrCast(s_ptr)).*; | |
| 901 | if (ptr_info.sentinel()) |s| { | |
| 911 | 902 | return ptr[0..length :s]; |
| 912 | 903 | } else { |
| 913 | 904 | return ptr[0..length]; |
| ... | ... | @@ -959,9 +950,8 @@ fn lenSliceTo(ptr: anytype, comptime end: std.meta.Elem(@TypeOf(ptr))) usize { |
| 959 | 950 | .pointer => |ptr_info| switch (ptr_info.size) { |
| 960 | 951 | .one => switch (@typeInfo(ptr_info.child)) { |
| 961 | 952 | .array => |array_info| { |
| 962 | if (array_info.sentinel) |sentinel_ptr| { | |
| 963 | const sentinel = @as(*align(1) const array_info.child, @ptrCast(sentinel_ptr)).*; | |
| 964 | if (sentinel == end) { | |
| 953 | if (array_info.sentinel()) |s| { | |
| 954 | if (s == end) { | |
| 965 | 955 | return indexOfSentinel(array_info.child, end, ptr); |
| 966 | 956 | } |
| 967 | 957 | } |
| ... | ... | @@ -969,16 +959,15 @@ fn lenSliceTo(ptr: anytype, comptime end: std.meta.Elem(@TypeOf(ptr))) usize { |
| 969 | 959 | }, |
| 970 | 960 | else => {}, |
| 971 | 961 | }, |
| 972 | .many => if (ptr_info.sentinel) |sentinel_ptr| { | |
| 973 | const sentinel = @as(*align(1) const ptr_info.child, @ptrCast(sentinel_ptr)).*; | |
| 974 | if (sentinel == end) { | |
| 962 | .many => if (ptr_info.sentinel()) |s| { | |
| 963 | if (s == end) { | |
| 975 | 964 | return indexOfSentinel(ptr_info.child, end, ptr); |
| 976 | 965 | } |
| 977 | 966 | // We're looking for something other than the sentinel, |
| 978 | 967 | // but iterating past the sentinel would be a bug so we need |
| 979 | 968 | // to check for both. |
| 980 | 969 | var i: usize = 0; |
| 981 | while (ptr[i] != end and ptr[i] != sentinel) i += 1; | |
| 970 | while (ptr[i] != end and ptr[i] != s) i += 1; | |
| 982 | 971 | return i; |
| 983 | 972 | }, |
| 984 | 973 | .c => { |
| ... | ... | @@ -986,10 +975,9 @@ fn lenSliceTo(ptr: anytype, comptime end: std.meta.Elem(@TypeOf(ptr))) usize { |
| 986 | 975 | return indexOfSentinel(ptr_info.child, end, ptr); |
| 987 | 976 | }, |
| 988 | 977 | .slice => { |
| 989 | if (ptr_info.sentinel) |sentinel_ptr| { | |
| 990 | const sentinel = @as(*align(1) const ptr_info.child, @ptrCast(sentinel_ptr)).*; | |
| 991 | if (sentinel == end) { | |
| 992 | return indexOfSentinel(ptr_info.child, sentinel, ptr); | |
| 978 | if (ptr_info.sentinel()) |s| { | |
| 979 | if (s == end) { | |
| 980 | return indexOfSentinel(ptr_info.child, s, ptr); | |
| 993 | 981 | } |
| 994 | 982 | } |
| 995 | 983 | return indexOfScalar(ptr_info.child, ptr, end) orelse ptr.len; |
| ... | ... | @@ -1040,9 +1028,8 @@ pub fn len(value: anytype) usize { |
| 1040 | 1028 | switch (@typeInfo(@TypeOf(value))) { |
| 1041 | 1029 | .pointer => |info| switch (info.size) { |
| 1042 | 1030 | .many => { |
| 1043 | const sentinel_ptr = info.sentinel orelse | |
| 1031 | const sentinel = info.sentinel() orelse | |
| 1044 | 1032 | @compileError("invalid type given to std.mem.len: " ++ @typeName(@TypeOf(value))); |
| 1045 | const sentinel = @as(*align(1) const info.child, @ptrCast(sentinel_ptr)).*; | |
| 1046 | 1033 | return indexOfSentinel(info.child, sentinel, value); |
| 1047 | 1034 | }, |
| 1048 | 1035 | .c => { |
| ... | ... | @@ -3587,7 +3574,7 @@ fn ReverseIterator(comptime T: type) type { |
| 3587 | 3574 | var new_ptr_info = ptr_info; |
| 3588 | 3575 | new_ptr_info.size = .many; |
| 3589 | 3576 | new_ptr_info.child = array_info.child; |
| 3590 | new_ptr_info.sentinel = array_info.sentinel; | |
| 3577 | new_ptr_info.sentinel_ptr = array_info.sentinel_ptr; | |
| 3591 | 3578 | break :blk @Type(.{ .pointer = new_ptr_info }); |
| 3592 | 3579 | }, |
| 3593 | 3580 | else => {}, |
| ... | ... | @@ -3608,7 +3595,7 @@ fn ReverseIterator(comptime T: type) type { |
| 3608 | 3595 | var ptr = @typeInfo(Pointer).pointer; |
| 3609 | 3596 | ptr.size = .one; |
| 3610 | 3597 | ptr.child = Element; |
| 3611 | ptr.sentinel = null; | |
| 3598 | ptr.sentinel_ptr = null; | |
| 3612 | 3599 | break :ptr ptr; |
| 3613 | 3600 | } }); |
| 3614 | 3601 | return struct { |
| ... | ... | @@ -3979,7 +3966,7 @@ fn CopyPtrAttrs( |
| 3979 | 3966 | .alignment = info.alignment, |
| 3980 | 3967 | .address_space = info.address_space, |
| 3981 | 3968 | .child = child, |
| 3982 | .sentinel = null, | |
| 3969 | .sentinel_ptr = null, | |
| 3983 | 3970 | }, |
| 3984 | 3971 | }); |
| 3985 | 3972 | } |
| ... | ... | @@ -4547,7 +4534,7 @@ fn AlignedSlice(comptime AttributeSource: type, comptime new_alignment: usize) t |
| 4547 | 4534 | .alignment = new_alignment, |
| 4548 | 4535 | .address_space = info.address_space, |
| 4549 | 4536 | .child = info.child, |
| 4550 | .sentinel = null, | |
| 4537 | .sentinel_ptr = null, | |
| 4551 | 4538 | }, |
| 4552 | 4539 | }); |
| 4553 | 4540 | } |
lib/std/mem/Allocator.zig+1-1| ... | ... | @@ -307,7 +307,7 @@ pub fn reallocAdvanced( |
| 307 | 307 | pub fn free(self: Allocator, memory: anytype) void { |
| 308 | 308 | const Slice = @typeInfo(@TypeOf(memory)).pointer; |
| 309 | 309 | const bytes = mem.sliceAsBytes(memory); |
| 310 | const bytes_len = bytes.len + if (Slice.sentinel != null) @sizeOf(Slice.child) else 0; | |
| 310 | const bytes_len = bytes.len + if (Slice.sentinel() != null) @sizeOf(Slice.child) else 0; | |
| 311 | 311 | if (bytes_len == 0) return; |
| 312 | 312 | const non_const_ptr = @constCast(bytes.ptr); |
| 313 | 313 | // TODO: https://github.com/ziglang/zig/issues/4298 |
lib/std/meta.zig+8-17| ... | ... | @@ -132,21 +132,12 @@ test Elem { |
| 132 | 132 | /// Result is always comptime-known. |
| 133 | 133 | pub inline fn sentinel(comptime T: type) ?Elem(T) { |
| 134 | 134 | switch (@typeInfo(T)) { |
| 135 | .array => |info| { | |
| 136 | const sentinel_ptr = info.sentinel orelse return null; | |
| 137 | return @as(*const info.child, @ptrCast(sentinel_ptr)).*; | |
| 138 | }, | |
| 135 | .array => |info| return info.sentinel(), | |
| 139 | 136 | .pointer => |info| { |
| 140 | 137 | switch (info.size) { |
| 141 | .many, .slice => { | |
| 142 | const sentinel_ptr = info.sentinel orelse return null; | |
| 143 | return @as(*align(1) const info.child, @ptrCast(sentinel_ptr)).*; | |
| 144 | }, | |
| 138 | .many, .slice => return info.sentinel(), | |
| 145 | 139 | .one => switch (@typeInfo(info.child)) { |
| 146 | .array => |array_info| { | |
| 147 | const sentinel_ptr = array_info.sentinel orelse return null; | |
| 148 | return @as(*align(1) const array_info.child, @ptrCast(sentinel_ptr)).*; | |
| 149 | }, | |
| 140 | .array => |array_info| return array_info.sentinel(), | |
| 150 | 141 | else => {}, |
| 151 | 142 | }, |
| 152 | 143 | else => {}, |
| ... | ... | @@ -190,11 +181,11 @@ pub fn Sentinel(comptime T: type, comptime sentinel_val: Elem(T)) type { |
| 190 | 181 | .array = .{ |
| 191 | 182 | .len = array_info.len, |
| 192 | 183 | .child = array_info.child, |
| 193 | .sentinel = @as(?*const anyopaque, @ptrCast(&sentinel_val)), | |
| 184 | .sentinel_ptr = @as(?*const anyopaque, @ptrCast(&sentinel_val)), | |
| 194 | 185 | }, |
| 195 | 186 | }), |
| 196 | 187 | .is_allowzero = info.is_allowzero, |
| 197 | .sentinel = info.sentinel, | |
| 188 | .sentinel_ptr = info.sentinel_ptr, | |
| 198 | 189 | }, |
| 199 | 190 | }), |
| 200 | 191 | else => {}, |
| ... | ... | @@ -208,7 +199,7 @@ pub fn Sentinel(comptime T: type, comptime sentinel_val: Elem(T)) type { |
| 208 | 199 | .address_space = info.address_space, |
| 209 | 200 | .child = info.child, |
| 210 | 201 | .is_allowzero = info.is_allowzero, |
| 211 | .sentinel = @as(?*const anyopaque, @ptrCast(&sentinel_val)), | |
| 202 | .sentinel_ptr = @as(?*const anyopaque, @ptrCast(&sentinel_val)), | |
| 212 | 203 | }, |
| 213 | 204 | }), |
| 214 | 205 | else => {}, |
| ... | ... | @@ -226,7 +217,7 @@ pub fn Sentinel(comptime T: type, comptime sentinel_val: Elem(T)) type { |
| 226 | 217 | .address_space = ptr_info.address_space, |
| 227 | 218 | .child = ptr_info.child, |
| 228 | 219 | .is_allowzero = ptr_info.is_allowzero, |
| 229 | .sentinel = @as(?*const anyopaque, @ptrCast(&sentinel_val)), | |
| 220 | .sentinel_ptr = @as(?*const anyopaque, @ptrCast(&sentinel_val)), | |
| 230 | 221 | }, |
| 231 | 222 | }), |
| 232 | 223 | }, |
| ... | ... | @@ -1018,7 +1009,7 @@ fn CreateUniqueTuple(comptime N: comptime_int, comptime types: [N]type) type { |
| 1018 | 1009 | tuple_fields[i] = .{ |
| 1019 | 1010 | .name = std.fmt.bufPrintZ(&num_buf, "{d}", .{i}) catch unreachable, |
| 1020 | 1011 | .type = T, |
| 1021 | .default_value = null, | |
| 1012 | .default_value_ptr = null, | |
| 1022 | 1013 | .is_comptime = false, |
| 1023 | 1014 | .alignment = 0, |
| 1024 | 1015 | }; |
lib/std/meta/trailer_flags.zig+1-1| ... | ... | @@ -25,7 +25,7 @@ pub fn TrailerFlags(comptime Fields: type) type { |
| 25 | 25 | fields[i] = Type.StructField{ |
| 26 | 26 | .name = struct_field.name, |
| 27 | 27 | .type = ?struct_field.type, |
| 28 | .default_value = &@as(?struct_field.type, null), | |
| 28 | .default_value_ptr = &@as(?struct_field.type, null), | |
| 29 | 29 | .is_comptime = false, |
| 30 | 30 | .alignment = @alignOf(?struct_field.type), |
| 31 | 31 | }; |
lib/std/multi_array_list.zig+1-1| ... | ... | @@ -571,7 +571,7 @@ pub fn MultiArrayList(comptime T: type) type { |
| 571 | 571 | for (&entry_fields, sizes.fields) |*entry_field, i| entry_field.* = .{ |
| 572 | 572 | .name = fields[i].name ++ "_ptr", |
| 573 | 573 | .type = *fields[i].type, |
| 574 | .default_value = null, | |
| 574 | .default_value_ptr = null, | |
| 575 | 575 | .is_comptime = fields[i].is_comptime, |
| 576 | 576 | .alignment = fields[i].alignment, |
| 577 | 577 | }; |
lib/std/zig/c_translation.zig+2-5| ... | ... | @@ -180,10 +180,7 @@ pub fn sizeof(target: anytype) usize { |
| 180 | 180 | // specially handled here. |
| 181 | 181 | if (ptr.size == .one and ptr.is_const and @typeInfo(ptr.child) == .array) { |
| 182 | 182 | const array_info = @typeInfo(ptr.child).array; |
| 183 | if ((array_info.child == u8 or array_info.child == u16) and | |
| 184 | array_info.sentinel != null and | |
| 185 | @as(*align(1) const array_info.child, @ptrCast(array_info.sentinel.?)).* == 0) | |
| 186 | { | |
| 183 | if ((array_info.child == u8 or array_info.child == u16) and array_info.sentinel() == 0) { | |
| 187 | 184 | // length of the string plus one for the null terminator. |
| 188 | 185 | return (array_info.len + 1) * @sizeOf(array_info.child); |
| 189 | 186 | } |
| ... | ... | @@ -348,7 +345,7 @@ pub fn FlexibleArrayType(comptime SelfType: type, comptime ElementType: type) ty |
| 348 | 345 | .address_space = .generic, |
| 349 | 346 | .child = ElementType, |
| 350 | 347 | .is_allowzero = true, |
| 351 | .sentinel = null, | |
| 348 | .sentinel_ptr = null, | |
| 352 | 349 | } }); |
| 353 | 350 | }, |
| 354 | 351 | else => |info| @compileError("Invalid self type \"" ++ @tagName(info) ++ "\" for flexible array getter: " ++ @typeName(SelfType)), |
src/InternPool.zig+3-3| ... | ... | @@ -1134,7 +1134,7 @@ const Local = struct { |
| 1134 | 1134 | for (&new_fields, elem_fields) |*new_field, elem_field| new_field.* = .{ |
| 1135 | 1135 | .name = elem_field.name, |
| 1136 | 1136 | .type = *[len]elem_field.type, |
| 1137 | .default_value = null, | |
| 1137 | .default_value_ptr = null, | |
| 1138 | 1138 | .is_comptime = false, |
| 1139 | 1139 | .alignment = 0, |
| 1140 | 1140 | }; |
| ... | ... | @@ -1162,9 +1162,9 @@ const Local = struct { |
| 1162 | 1162 | .address_space = .generic, |
| 1163 | 1163 | .child = elem_field.type, |
| 1164 | 1164 | .is_allowzero = false, |
| 1165 | .sentinel = null, | |
| 1165 | .sentinel_ptr = null, | |
| 1166 | 1166 | } }), |
| 1167 | .default_value = null, | |
| 1167 | .default_value_ptr = null, | |
| 1168 | 1168 | .is_comptime = false, |
| 1169 | 1169 | .alignment = 0, |
| 1170 | 1170 | }; |
src/Value.zig+1-4| ... | ... | @@ -4641,10 +4641,7 @@ pub fn interpret(val: Value, comptime T: type, pt: Zcu.PerThread) error{ OutOfMe |
| 4641 | 4641 | @field(result, field.name) = if (struct_obj.nameIndex(ip, field_name_ip)) |field_idx| f: { |
| 4642 | 4642 | const field_val = try val.fieldValue(pt, field_idx); |
| 4643 | 4643 | break :f try field_val.interpret(field.type, pt); |
| 4644 | } else if (field.default_value) |ptr| f: { | |
| 4645 | const typed_ptr: *const field.type = @ptrCast(@alignCast(ptr)); | |
| 4646 | break :f typed_ptr.*; | |
| 4647 | } else return error.TypeMismatch; | |
| 4644 | } else (field.defaultValue() orelse return error.TypeMismatch); | |
| 4648 | 4645 | } |
| 4649 | 4646 | return result; |
| 4650 | 4647 | }, |
src/codegen/llvm/Builder.zig+2-2| ... | ... | @@ -8463,7 +8463,7 @@ pub const Metadata = enum(u32) { |
| 8463 | 8463 | field.* = .{ |
| 8464 | 8464 | .name = name, |
| 8465 | 8465 | .type = []const u8, |
| 8466 | .default_value = null, | |
| 8466 | .default_value_ptr = null, | |
| 8467 | 8467 | .is_comptime = false, |
| 8468 | 8468 | .alignment = 0, |
| 8469 | 8469 | }; |
| ... | ... | @@ -8474,7 +8474,7 @@ pub const Metadata = enum(u32) { |
| 8474 | 8474 | field.* = .{ |
| 8475 | 8475 | .name = name, |
| 8476 | 8476 | .type = std.fmt.Formatter(format), |
| 8477 | .default_value = null, | |
| 8477 | .default_value_ptr = null, | |
| 8478 | 8478 | .is_comptime = false, |
| 8479 | 8479 | .alignment = 0, |
| 8480 | 8480 | }; |
test/behavior/tuple.zig+3-3| ... | ... | @@ -141,14 +141,14 @@ test "array-like initializer for tuple types" { |
| 141 | 141 | .{ |
| 142 | 142 | .name = "0", |
| 143 | 143 | .type = i32, |
| 144 | .default_value = null, | |
| 144 | .default_value_ptr = null, | |
| 145 | 145 | .is_comptime = false, |
| 146 | 146 | .alignment = @alignOf(i32), |
| 147 | 147 | }, |
| 148 | 148 | .{ |
| 149 | 149 | .name = "1", |
| 150 | 150 | .type = u8, |
| 151 | .default_value = null, | |
| 151 | .default_value_ptr = null, | |
| 152 | 152 | .is_comptime = false, |
| 153 | 153 | .alignment = @alignOf(u8), |
| 154 | 154 | }, |
| ... | ... | @@ -330,7 +330,7 @@ test "zero sized struct in tuple handled correctly" { |
| 330 | 330 | .fields = &.{.{ |
| 331 | 331 | .name = "0", |
| 332 | 332 | .type = struct {}, |
| 333 | .default_value = null, | |
| 333 | .default_value_ptr = null, | |
| 334 | 334 | .is_comptime = false, |
| 335 | 335 | .alignment = 0, |
| 336 | 336 | }}, |
test/behavior/tuple_declarations.zig+2-2| ... | ... | @@ -20,13 +20,13 @@ test "tuple declaration type info" { |
| 20 | 20 | |
| 21 | 21 | try expectEqualStrings(info.fields[0].name, "0"); |
| 22 | 22 | try expect(info.fields[0].type == u32); |
| 23 | try expect(@as(*const u32, @ptrCast(@alignCast(info.fields[0].default_value))).* == 1); | |
| 23 | try expect(info.fields[0].defaultValue() == 1); | |
| 24 | 24 | try expect(info.fields[0].is_comptime); |
| 25 | 25 | try expect(info.fields[0].alignment == @alignOf(u32)); |
| 26 | 26 | |
| 27 | 27 | try expectEqualStrings(info.fields[1].name, "1"); |
| 28 | 28 | try expect(info.fields[1].type == []const u8); |
| 29 | try expect(info.fields[1].default_value == null); | |
| 29 | try expect(info.fields[1].defaultValue() == null); | |
| 30 | 30 | try expect(!info.fields[1].is_comptime); |
| 31 | 31 | try expect(info.fields[1].alignment == @alignOf([]const u8)); |
| 32 | 32 | } |
test/behavior/type.zig+18-18| ... | ... | @@ -118,21 +118,21 @@ test "Type.Array" { |
| 118 | 118 | .array = .{ |
| 119 | 119 | .len = 123, |
| 120 | 120 | .child = u8, |
| 121 | .sentinel = null, | |
| 121 | .sentinel_ptr = null, | |
| 122 | 122 | }, |
| 123 | 123 | })); |
| 124 | 124 | try testing.expect([2]u32 == @Type(.{ |
| 125 | 125 | .array = .{ |
| 126 | 126 | .len = 2, |
| 127 | 127 | .child = u32, |
| 128 | .sentinel = null, | |
| 128 | .sentinel_ptr = null, | |
| 129 | 129 | }, |
| 130 | 130 | })); |
| 131 | 131 | try testing.expect([2:0]u32 == @Type(.{ |
| 132 | 132 | .array = .{ |
| 133 | 133 | .len = 2, |
| 134 | 134 | .child = u32, |
| 135 | .sentinel = &@as(u32, 0), | |
| 135 | .sentinel_ptr = &@as(u32, 0), | |
| 136 | 136 | }, |
| 137 | 137 | })); |
| 138 | 138 | try testTypes(&[_]type{ [1]u8, [30]usize, [7]bool }); |
| ... | ... | @@ -148,7 +148,7 @@ test "@Type create slice with null sentinel" { |
| 148 | 148 | .alignment = 8, |
| 149 | 149 | .address_space = .generic, |
| 150 | 150 | .child = *i32, |
| 151 | .sentinel = null, | |
| 151 | .sentinel_ptr = null, | |
| 152 | 152 | }, |
| 153 | 153 | }); |
| 154 | 154 | try testing.expect(Slice == []align(8) const *i32); |
| ... | ... | @@ -266,10 +266,10 @@ test "Type.Struct" { |
| 266 | 266 | try testing.expectEqual(Type.ContainerLayout.auto, infoA.layout); |
| 267 | 267 | try testing.expectEqualSlices(u8, "x", infoA.fields[0].name); |
| 268 | 268 | try testing.expectEqual(u8, infoA.fields[0].type); |
| 269 | try testing.expectEqual(@as(?*const anyopaque, null), infoA.fields[0].default_value); | |
| 269 | try testing.expectEqual(@as(?*const anyopaque, null), infoA.fields[0].default_value_ptr); | |
| 270 | 270 | try testing.expectEqualSlices(u8, "y", infoA.fields[1].name); |
| 271 | 271 | try testing.expectEqual(u32, infoA.fields[1].type); |
| 272 | try testing.expectEqual(@as(?*const anyopaque, null), infoA.fields[1].default_value); | |
| 272 | try testing.expectEqual(@as(?*const anyopaque, null), infoA.fields[1].default_value_ptr); | |
| 273 | 273 | try testing.expectEqualSlices(Type.Declaration, &.{}, infoA.decls); |
| 274 | 274 | try testing.expectEqual(@as(bool, false), infoA.is_tuple); |
| 275 | 275 | |
| ... | ... | @@ -284,10 +284,10 @@ test "Type.Struct" { |
| 284 | 284 | try testing.expectEqual(Type.ContainerLayout.@"extern", infoB.layout); |
| 285 | 285 | try testing.expectEqualSlices(u8, "x", infoB.fields[0].name); |
| 286 | 286 | try testing.expectEqual(u8, infoB.fields[0].type); |
| 287 | try testing.expectEqual(@as(?*const anyopaque, null), infoB.fields[0].default_value); | |
| 287 | try testing.expectEqual(@as(?*const anyopaque, null), infoB.fields[0].default_value_ptr); | |
| 288 | 288 | try testing.expectEqualSlices(u8, "y", infoB.fields[1].name); |
| 289 | 289 | try testing.expectEqual(u32, infoB.fields[1].type); |
| 290 | try testing.expectEqual(@as(u32, 5), @as(*align(1) const u32, @ptrCast(infoB.fields[1].default_value.?)).*); | |
| 290 | try testing.expectEqual(@as(u32, 5), infoB.fields[1].defaultValue().?); | |
| 291 | 291 | try testing.expectEqual(@as(usize, 0), infoB.decls.len); |
| 292 | 292 | try testing.expectEqual(@as(bool, false), infoB.is_tuple); |
| 293 | 293 | |
| ... | ... | @@ -296,10 +296,10 @@ test "Type.Struct" { |
| 296 | 296 | try testing.expectEqual(Type.ContainerLayout.@"packed", infoC.layout); |
| 297 | 297 | try testing.expectEqualSlices(u8, "x", infoC.fields[0].name); |
| 298 | 298 | try testing.expectEqual(u8, infoC.fields[0].type); |
| 299 | try testing.expectEqual(@as(u8, 3), @as(*const u8, @ptrCast(infoC.fields[0].default_value.?)).*); | |
| 299 | try testing.expectEqual(@as(u8, 3), infoC.fields[0].defaultValue().?); | |
| 300 | 300 | try testing.expectEqualSlices(u8, "y", infoC.fields[1].name); |
| 301 | 301 | try testing.expectEqual(u32, infoC.fields[1].type); |
| 302 | try testing.expectEqual(@as(u32, 5), @as(*align(1) const u32, @ptrCast(infoC.fields[1].default_value.?)).*); | |
| 302 | try testing.expectEqual(@as(u32, 5), infoC.fields[1].defaultValue().?); | |
| 303 | 303 | try testing.expectEqual(@as(usize, 0), infoC.decls.len); |
| 304 | 304 | try testing.expectEqual(@as(bool, false), infoC.is_tuple); |
| 305 | 305 | |
| ... | ... | @@ -309,10 +309,10 @@ test "Type.Struct" { |
| 309 | 309 | try testing.expectEqual(Type.ContainerLayout.auto, infoD.layout); |
| 310 | 310 | try testing.expectEqualSlices(u8, "x", infoD.fields[0].name); |
| 311 | 311 | try testing.expectEqual(comptime_int, infoD.fields[0].type); |
| 312 | try testing.expectEqual(@as(comptime_int, 3), @as(*const comptime_int, @ptrCast(infoD.fields[0].default_value.?)).*); | |
| 312 | try testing.expectEqual(@as(comptime_int, 3), infoD.fields[0].defaultValue().?); | |
| 313 | 313 | try testing.expectEqualSlices(u8, "y", infoD.fields[1].name); |
| 314 | 314 | try testing.expectEqual(comptime_int, infoD.fields[1].type); |
| 315 | try testing.expectEqual(@as(comptime_int, 5), @as(*const comptime_int, @ptrCast(infoD.fields[1].default_value.?)).*); | |
| 315 | try testing.expectEqual(@as(comptime_int, 5), infoD.fields[1].defaultValue().?); | |
| 316 | 316 | try testing.expectEqual(@as(usize, 0), infoD.decls.len); |
| 317 | 317 | try testing.expectEqual(@as(bool, false), infoD.is_tuple); |
| 318 | 318 | |
| ... | ... | @@ -322,10 +322,10 @@ test "Type.Struct" { |
| 322 | 322 | try testing.expectEqual(Type.ContainerLayout.auto, infoE.layout); |
| 323 | 323 | try testing.expectEqualSlices(u8, "0", infoE.fields[0].name); |
| 324 | 324 | try testing.expectEqual(comptime_int, infoE.fields[0].type); |
| 325 | try testing.expectEqual(@as(comptime_int, 1), @as(*const comptime_int, @ptrCast(infoE.fields[0].default_value.?)).*); | |
| 325 | try testing.expectEqual(@as(comptime_int, 1), infoE.fields[0].defaultValue().?); | |
| 326 | 326 | try testing.expectEqualSlices(u8, "1", infoE.fields[1].name); |
| 327 | 327 | try testing.expectEqual(comptime_int, infoE.fields[1].type); |
| 328 | try testing.expectEqual(@as(comptime_int, 2), @as(*const comptime_int, @ptrCast(infoE.fields[1].default_value.?)).*); | |
| 328 | try testing.expectEqual(@as(comptime_int, 2), infoE.fields[1].defaultValue().?); | |
| 329 | 329 | try testing.expectEqual(@as(usize, 0), infoE.decls.len); |
| 330 | 330 | try testing.expectEqual(@as(bool, true), infoE.is_tuple); |
| 331 | 331 | |
| ... | ... | @@ -582,7 +582,7 @@ test "reified struct field name from optional payload" { |
| 582 | 582 | .fields = &.{.{ |
| 583 | 583 | .name = name, |
| 584 | 584 | .type = u8, |
| 585 | .default_value = null, | |
| 585 | .default_value_ptr = null, | |
| 586 | 586 | .is_comptime = false, |
| 587 | 587 | .alignment = 1, |
| 588 | 588 | }}, |
| ... | ... | @@ -628,7 +628,7 @@ test "reified struct uses @alignOf" { |
| 628 | 628 | .{ |
| 629 | 629 | .name = "globals", |
| 630 | 630 | .type = modules.mach.globals, |
| 631 | .default_value = null, | |
| 631 | .default_value_ptr = null, | |
| 632 | 632 | .is_comptime = false, |
| 633 | 633 | .alignment = @alignOf(modules.mach.globals), |
| 634 | 634 | }, |
| ... | ... | @@ -688,7 +688,7 @@ test "empty struct assigned to reified struct field" { |
| 688 | 688 | .fields = &.{.{ |
| 689 | 689 | .name = "components", |
| 690 | 690 | .type = @TypeOf(modules.components), |
| 691 | .default_value = null, | |
| 691 | .default_value_ptr = null, | |
| 692 | 692 | .is_comptime = false, |
| 693 | 693 | .alignment = @alignOf(@TypeOf(modules.components)), |
| 694 | 694 | }}, |
| ... | ... | @@ -738,7 +738,7 @@ test "struct field names sliced at comptime from larger string" { |
| 738 | 738 | .alignment = 0, |
| 739 | 739 | .name = name ++ "", |
| 740 | 740 | .type = usize, |
| 741 | .default_value = null, | |
| 741 | .default_value_ptr = null, | |
| 742 | 742 | .is_comptime = false, |
| 743 | 743 | }}; |
| 744 | 744 | } |
test/behavior/type_info.zig+16-16| ... | ... | @@ -84,7 +84,7 @@ fn testPointer() !void { |
| 84 | 84 | try expect(u32_ptr_info.pointer.is_volatile == false); |
| 85 | 85 | try expect(u32_ptr_info.pointer.alignment == @alignOf(u32)); |
| 86 | 86 | try expect(u32_ptr_info.pointer.child == u32); |
| 87 | try expect(u32_ptr_info.pointer.sentinel == null); | |
| 87 | try expect(u32_ptr_info.pointer.sentinel() == null); | |
| 88 | 88 | } |
| 89 | 89 | |
| 90 | 90 | test "type info: unknown length pointer type info" { |
| ... | ... | @@ -98,7 +98,7 @@ fn testUnknownLenPtr() !void { |
| 98 | 98 | try expect(u32_ptr_info.pointer.size == .many); |
| 99 | 99 | try expect(u32_ptr_info.pointer.is_const == true); |
| 100 | 100 | try expect(u32_ptr_info.pointer.is_volatile == true); |
| 101 | try expect(u32_ptr_info.pointer.sentinel == null); | |
| 101 | try expect(u32_ptr_info.pointer.sentinel() == null); | |
| 102 | 102 | try expect(u32_ptr_info.pointer.alignment == @alignOf(f64)); |
| 103 | 103 | try expect(u32_ptr_info.pointer.child == f64); |
| 104 | 104 | } |
| ... | ... | @@ -114,9 +114,9 @@ fn testNullTerminatedPtr() !void { |
| 114 | 114 | try expect(ptr_info.pointer.size == .many); |
| 115 | 115 | try expect(ptr_info.pointer.is_const == false); |
| 116 | 116 | try expect(ptr_info.pointer.is_volatile == false); |
| 117 | try expect(@as(*const u8, @ptrCast(ptr_info.pointer.sentinel.?)).* == 0); | |
| 117 | try expect(ptr_info.pointer.sentinel().? == 0); | |
| 118 | 118 | |
| 119 | try expect(@typeInfo([:0]u8).pointer.sentinel != null); | |
| 119 | try expect(@typeInfo([:0]u8).pointer.sentinel() != null); | |
| 120 | 120 | } |
| 121 | 121 | |
| 122 | 122 | test "type info: slice type info" { |
| ... | ... | @@ -145,14 +145,14 @@ fn testArray() !void { |
| 145 | 145 | try expect(info == .array); |
| 146 | 146 | try expect(info.array.len == 42); |
| 147 | 147 | try expect(info.array.child == u8); |
| 148 | try expect(info.array.sentinel == null); | |
| 148 | try expect(info.array.sentinel() == null); | |
| 149 | 149 | } |
| 150 | 150 | |
| 151 | 151 | { |
| 152 | 152 | const info = @typeInfo([10:0]u8); |
| 153 | 153 | try expect(info.array.len == 10); |
| 154 | 154 | try expect(info.array.child == u8); |
| 155 | try expect(@as(*const u8, @ptrCast(info.array.sentinel.?)).* == @as(u8, 0)); | |
| 155 | try expect(info.array.sentinel().? == @as(u8, 0)); | |
| 156 | 156 | try expect(@sizeOf([10:0]u8) == info.array.len + 1); |
| 157 | 157 | } |
| 158 | 158 | } |
| ... | ... | @@ -292,8 +292,8 @@ fn testStruct() !void { |
| 292 | 292 | try expect(unpacked_struct_info.@"struct".is_tuple == false); |
| 293 | 293 | try expect(unpacked_struct_info.@"struct".backing_integer == null); |
| 294 | 294 | try expect(unpacked_struct_info.@"struct".fields[0].alignment == @alignOf(u32)); |
| 295 | try expect(@as(*align(1) const u32, @ptrCast(unpacked_struct_info.@"struct".fields[0].default_value.?)).* == 4); | |
| 296 | try expect(mem.eql(u8, "foobar", @as(*align(1) const *const [6:0]u8, @ptrCast(unpacked_struct_info.@"struct".fields[1].default_value.?)).*)); | |
| 295 | try expect(unpacked_struct_info.@"struct".fields[0].defaultValue().? == 4); | |
| 296 | try expect(mem.eql(u8, "foobar", unpacked_struct_info.@"struct".fields[1].defaultValue().?)); | |
| 297 | 297 | } |
| 298 | 298 | |
| 299 | 299 | const TestStruct = struct { |
| ... | ... | @@ -315,8 +315,8 @@ fn testPackedStruct() !void { |
| 315 | 315 | try expect(struct_info.@"struct".fields.len == 4); |
| 316 | 316 | try expect(struct_info.@"struct".fields[0].alignment == 0); |
| 317 | 317 | try expect(struct_info.@"struct".fields[2].type == f32); |
| 318 | try expect(struct_info.@"struct".fields[2].default_value == null); | |
| 319 | try expect(@as(*align(1) const u32, @ptrCast(struct_info.@"struct".fields[3].default_value.?)).* == 4); | |
| 318 | try expect(struct_info.@"struct".fields[2].defaultValue() == null); | |
| 319 | try expect(struct_info.@"struct".fields[3].defaultValue().? == 4); | |
| 320 | 320 | try expect(struct_info.@"struct".fields[3].alignment == 0); |
| 321 | 321 | try expect(struct_info.@"struct".decls.len == 1); |
| 322 | 322 | } |
| ... | ... | @@ -380,7 +380,7 @@ fn testFunction() !void { |
| 380 | 380 | try expect(foo_ptr_fn_info.pointer.address_space == .generic); |
| 381 | 381 | try expect(foo_ptr_fn_info.pointer.child == foo_fn_type); |
| 382 | 382 | try expect(!foo_ptr_fn_info.pointer.is_allowzero); |
| 383 | try expect(foo_ptr_fn_info.pointer.sentinel == null); | |
| 383 | try expect(foo_ptr_fn_info.pointer.sentinel() == null); | |
| 384 | 384 | |
| 385 | 385 | // Avoid looking at `typeInfoFooAligned` on targets which don't support function alignment. |
| 386 | 386 | switch (builtin.target.cpu.arch) { |
| ... | ... | @@ -408,7 +408,7 @@ fn testFunction() !void { |
| 408 | 408 | try expect(aligned_foo_ptr_fn_info.pointer.address_space == .generic); |
| 409 | 409 | try expect(aligned_foo_ptr_fn_info.pointer.child == aligned_foo_fn_type); |
| 410 | 410 | try expect(!aligned_foo_ptr_fn_info.pointer.is_allowzero); |
| 411 | try expect(aligned_foo_ptr_fn_info.pointer.sentinel == null); | |
| 411 | try expect(aligned_foo_ptr_fn_info.pointer.sentinel() == null); | |
| 412 | 412 | } |
| 413 | 413 | |
| 414 | 414 | extern fn typeInfoFoo(a: usize, b: bool, ...) callconv(.c) usize; |
| ... | ... | @@ -517,7 +517,7 @@ test "type info: TypeId -> Type impl cast" { |
| 517 | 517 | |
| 518 | 518 | test "sentinel of opaque pointer type" { |
| 519 | 519 | const c_void_info = @typeInfo(*anyopaque); |
| 520 | try expect(c_void_info.pointer.sentinel == null); | |
| 520 | try expect(c_void_info.pointer.sentinel_ptr == null); | |
| 521 | 521 | } |
| 522 | 522 | |
| 523 | 523 | test "@typeInfo does not force declarations into existence" { |
| ... | ... | @@ -601,9 +601,9 @@ test "typeInfo resolves usingnamespace declarations" { |
| 601 | 601 | try expectEqualStrings(decls[1].name, "f1"); |
| 602 | 602 | } |
| 603 | 603 | |
| 604 | test "value from struct @typeInfo default_value can be loaded at comptime" { | |
| 604 | test "value from struct @typeInfo default_value_ptr can be loaded at comptime" { | |
| 605 | 605 | comptime { |
| 606 | const a = @typeInfo(@TypeOf(.{ .foo = @as(u8, 1) })).@"struct".fields[0].default_value; | |
| 606 | const a = @typeInfo(@TypeOf(.{ .foo = @as(u8, 1) })).@"struct".fields[0].default_value_ptr; | |
| 607 | 607 | try expect(@as(*const u8, @ptrCast(a)).* == 1); |
| 608 | 608 | } |
| 609 | 609 | } |
| ... | ... | @@ -646,7 +646,7 @@ test "@typeInfo decls ignore dependency loops" { |
| 646 | 646 | |
| 647 | 647 | test "type info of tuple of string literal default value" { |
| 648 | 648 | const struct_field = @typeInfo(@TypeOf(.{"hi"})).@"struct".fields[0]; |
| 649 | const value = @as(*align(1) const *const [2:0]u8, @ptrCast(struct_field.default_value.?)).*; | |
| 649 | const value = struct_field.defaultValue().?; | |
| 650 | 650 | comptime std.debug.assert(value[0] == 'h'); |
| 651 | 651 | } |
| 652 | 652 |
test/cases/compile_errors/invalid_pointer_with_reify_type.zig+1-1| ... | ... | @@ -7,7 +7,7 @@ export fn entry() void { |
| 7 | 7 | .address_space = .generic, |
| 8 | 8 | .child = u8, |
| 9 | 9 | .is_allowzero = false, |
| 10 | .sentinel = &@as(u8, 0), | |
| 10 | .sentinel_ptr = &@as(u8, 0), | |
| 11 | 11 | } }); |
| 12 | 12 | } |
| 13 | 13 |
test/cases/compile_errors/non_scalar_sentinel.zig+3-3| ... | ... | @@ -12,7 +12,7 @@ comptime { |
| 12 | 12 | } |
| 13 | 13 | |
| 14 | 14 | comptime { |
| 15 | _ = @Type(.{ .array = .{ .child = S, .len = 0, .sentinel = &sentinel } }); | |
| 15 | _ = @Type(.{ .array = .{ .child = S, .len = 0, .sentinel_ptr = &sentinel } }); | |
| 16 | 16 | } |
| 17 | 17 | comptime { |
| 18 | 18 | _ = @Type(.{ .pointer = .{ |
| ... | ... | @@ -23,7 +23,7 @@ comptime { |
| 23 | 23 | .address_space = .generic, |
| 24 | 24 | .child = S, |
| 25 | 25 | .is_allowzero = false, |
| 26 | .sentinel = &sentinel, | |
| 26 | .sentinel_ptr = &sentinel, | |
| 27 | 27 | } }); |
| 28 | 28 | } |
| 29 | 29 | comptime { |
| ... | ... | @@ -35,7 +35,7 @@ comptime { |
| 35 | 35 | .address_space = .generic, |
| 36 | 36 | .child = S, |
| 37 | 37 | .is_allowzero = false, |
| 38 | .sentinel = &sentinel, | |
| 38 | .sentinel_ptr = &sentinel, | |
| 39 | 39 | } }); |
| 40 | 40 | } |
| 41 | 41 |
test/cases/compile_errors/packed_struct_field_alignment_unavailable_for_reify_type.zig+1-3| ... | ... | @@ -1,11 +1,9 @@ |
| 1 | 1 | export fn entry() void { |
| 2 | 2 | _ = @Type(.{ .@"struct" = .{ .layout = .@"packed", .fields = &.{ |
| 3 | .{ .name = "one", .type = u4, .default_value = null, .is_comptime = false, .alignment = 2 }, | |
| 3 | .{ .name = "one", .type = u4, .default_value_ptr = null, .is_comptime = false, .alignment = 2 }, | |
| 4 | 4 | }, .decls = &.{}, .is_tuple = false } }); |
| 5 | 5 | } |
| 6 | 6 | |
| 7 | 7 | // error |
| 8 | // backend=stage2 | |
| 9 | // target=native | |
| 10 | 8 | // |
| 11 | 9 | // :2:9: error: alignment in a packed struct field must be set to 0 |
test/cases/compile_errors/reify_struct.zig+5-7| ... | ... | @@ -4,7 +4,7 @@ comptime { |
| 4 | 4 | .fields = &.{.{ |
| 5 | 5 | .name = "foo", |
| 6 | 6 | .type = u32, |
| 7 | .default_value = null, | |
| 7 | .default_value_ptr = null, | |
| 8 | 8 | .is_comptime = false, |
| 9 | 9 | .alignment = 4, |
| 10 | 10 | }}, |
| ... | ... | @@ -18,7 +18,7 @@ comptime { |
| 18 | 18 | .fields = &.{.{ |
| 19 | 19 | .name = "3", |
| 20 | 20 | .type = u32, |
| 21 | .default_value = null, | |
| 21 | .default_value_ptr = null, | |
| 22 | 22 | .is_comptime = false, |
| 23 | 23 | .alignment = 4, |
| 24 | 24 | }}, |
| ... | ... | @@ -32,7 +32,7 @@ comptime { |
| 32 | 32 | .fields = &.{.{ |
| 33 | 33 | .name = "0", |
| 34 | 34 | .type = u32, |
| 35 | .default_value = null, | |
| 35 | .default_value_ptr = null, | |
| 36 | 36 | .is_comptime = true, |
| 37 | 37 | .alignment = 4, |
| 38 | 38 | }}, |
| ... | ... | @@ -46,7 +46,7 @@ comptime { |
| 46 | 46 | .fields = &.{.{ |
| 47 | 47 | .name = "0", |
| 48 | 48 | .type = u32, |
| 49 | .default_value = null, | |
| 49 | .default_value_ptr = null, | |
| 50 | 50 | .is_comptime = true, |
| 51 | 51 | .alignment = 4, |
| 52 | 52 | }}, |
| ... | ... | @@ -60,7 +60,7 @@ comptime { |
| 60 | 60 | .fields = &.{.{ |
| 61 | 61 | .name = "0", |
| 62 | 62 | .type = u32, |
| 63 | .default_value = null, | |
| 63 | .default_value_ptr = null, | |
| 64 | 64 | .is_comptime = true, |
| 65 | 65 | .alignment = 4, |
| 66 | 66 | }}, |
| ... | ... | @@ -70,8 +70,6 @@ comptime { |
| 70 | 70 | } |
| 71 | 71 | |
| 72 | 72 | // error |
| 73 | // backend=stage2 | |
| 74 | // target=native | |
| 75 | 73 | // |
| 76 | 74 | // :2:5: error: tuple cannot have non-numeric field 'foo' |
| 77 | 75 | // :16:5: error: tuple field name '3' does not match field index 0 |
test/cases/compile_errors/reify_type_with_invalid_field_alignment.zig+2-2| ... | ... | @@ -17,7 +17,7 @@ comptime { |
| 17 | 17 | .fields = &.{.{ |
| 18 | 18 | .name = "0", |
| 19 | 19 | .type = u32, |
| 20 | .default_value = null, | |
| 20 | .default_value_ptr = null, | |
| 21 | 21 | .is_comptime = true, |
| 22 | 22 | .alignment = 5, |
| 23 | 23 | }}, |
| ... | ... | @@ -36,7 +36,7 @@ comptime { |
| 36 | 36 | .address_space = .generic, |
| 37 | 37 | .child = u8, |
| 38 | 38 | .is_allowzero = false, |
| 39 | .sentinel = null, | |
| 39 | .sentinel_ptr = null, | |
| 40 | 40 | }, |
| 41 | 41 | }); |
| 42 | 42 | } |
test/cases/compile_errors/reify_type_with_undefined.zig+1-1| ... | ... | @@ -1,5 +1,5 @@ |
| 1 | 1 | comptime { |
| 2 | _ = @Type(.{ .array = .{ .len = 0, .child = u8, .sentinel = undefined } }); | |
| 2 | _ = @Type(.{ .array = .{ .len = 0, .child = u8, .sentinel_ptr = undefined } }); | |
| 3 | 3 | } |
| 4 | 4 | comptime { |
| 5 | 5 | _ = @Type(.{ |