diff --git a/lib/std/builtin.zig b/lib/std/builtin.zig index 91ef1c38f9..763db8448c 100644 --- a/lib/std/builtin.zig +++ b/lib/std/builtin.zig @@ -607,8 +607,16 @@ pub const Type = union(enum) { /// The type of the sentinel is the element type of the pointer, which is /// the value of the `child` field in this struct. However there is no way - /// to refer to that type here, so we use pointer to `anyopaque`. - sentinel: ?*const anyopaque, + /// to refer to that type here, so we use `*const anyopaque`. + /// See also: `sentinel` + sentinel_ptr: ?*const anyopaque, + + /// Loads the pointer type's sentinel value from `sentinel_ptr`. + /// Returns `null` if the pointer type has no sentinel. + pub inline fn sentinel(comptime ptr: Pointer) ?ptr.child { + const sp: *const ptr.child = @ptrCast(@alignCast(ptr.sentinel_ptr orelse return null)); + return sp.*; + } /// This data structure is used by the Zig language code generation and /// therefore must be kept in sync with the compiler implementation. @@ -628,8 +636,16 @@ pub const Type = union(enum) { /// The type of the sentinel is the element type of the array, which is /// the value of the `child` field in this struct. However there is no way - /// to refer to that type here, so we use pointer to `anyopaque`. - sentinel: ?*const anyopaque, + /// to refer to that type here, so we use `*const anyopaque`. + /// See also: `sentinel`. + sentinel_ptr: ?*const anyopaque, + + /// Loads the array type's sentinel value from `sentinel_ptr`. + /// Returns `null` if the array type has no sentinel. + pub inline fn sentinel(comptime arr: Array) ?arr.child { + const sp: *const arr.child = @ptrCast(@alignCast(arr.sentinel_ptr orelse return null)); + return sp.*; + } }; /// This data structure is used by the Zig language code generation and @@ -645,9 +661,20 @@ pub const Type = union(enum) { pub const StructField = struct { name: [:0]const u8, type: type, - default_value: ?*const anyopaque, + /// The type of the default value is the type of this struct field, which + /// is the value of the `type` field in this struct. However there is no + /// way to refer to that type here, so we use `*const anyopaque`. + /// See also: `defaultValue`. + default_value_ptr: ?*const anyopaque, is_comptime: bool, alignment: comptime_int, + + /// Loads the field's default value from `default_value_ptr`. + /// Returns `null` if the field has no default value. + pub inline fn defaultValue(comptime sf: StructField) ?sf.type { + const dp: *const sf.type = @ptrCast(@alignCast(sf.default_value_ptr orelse return null)); + return dp.*; + } }; /// This data structure is used by the Zig language code generation and