authorgravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2025-01-15 17:34:12+00:00
committergravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2025-01-16 12:49:58+00:00
log9804cc8bc6fe83b2a0cd5b61b8d2fc5d458cb221
treed2f7a675b37c8f94db9b1015589a3b37805e2ac6
parent89a9cabafd745034871ea014b06bd3bad0505f4a
signaturelock-open Commit is signed but in an unrecognized format.

all: update to `std.builtin.Type.{Pointer,Array,StructField}` field renames


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