diff --git a/bootstrap.c b/bootstrap.c index e1684df19a13..a37834f46373 100644 --- a/bootstrap.c +++ b/bootstrap.c @@ -141,6 +141,7 @@ int main(int argc, char **argv) { "pub const skip_non_native = false;\n" "pub const force_gpa = false;\n" "pub const dev = .core;\n" + "pub const value_interpret_mode = .direct;\n" , zig_version); if (written < 100) panic("unable to write to config.zig file"); diff --git a/build.zig b/build.zig index dcc84509f9a8..a513a993998f 100644 --- a/build.zig +++ b/build.zig @@ -9,6 +9,7 @@ const fs = std.fs; const InstallDirectoryOptions = std.Build.InstallDirectoryOptions; const assert = std.debug.assert; const DevEnv = @import("src/dev.zig").Env; +const ValueInterpretMode = enum { direct, by_name }; const zig_version: std.SemanticVersion = .{ .major = 0, .minor = 14, .patch = 0 }; const stack_size = 46 * 1024 * 1024; @@ -177,6 +178,7 @@ pub fn build(b: *std.Build) !void { const strip = b.option(bool, "strip", "Omit debug information"); const valgrind = b.option(bool, "valgrind", "Enable valgrind integration"); const pie = b.option(bool, "pie", "Produce a Position Independent Executable"); + const value_interpret_mode = b.option(ValueInterpretMode, "value-interpret-mode", "How the compiler translates between 'std.builtin' types and its internal datastructures") orelse .direct; const value_tracing = b.option(bool, "value-tracing", "Enable extra state tracking to help troubleshoot bugs in the compiler (using the std.debug.Trace API)") orelse false; const mem_leak_frames: u32 = b.option(u32, "mem-leak-frames", "How many stack frames to print when a memory leak occurs. Tests get 2x this amount.") orelse blk: { @@ -234,6 +236,7 @@ pub fn build(b: *std.Build) !void { exe_options.addOption(bool, "llvm_has_xtensa", llvm_has_xtensa); exe_options.addOption(bool, "force_gpa", force_gpa); exe_options.addOption(DevEnv, "dev", b.option(DevEnv, "dev", "Build a compiler with a reduced feature set for development of specific features") orelse if (only_c) .bootstrap else .full); + exe_options.addOption(ValueInterpretMode, "value_interpret_mode", value_interpret_mode); if (link_libc) { exe.root_module.link_libc = true; @@ -620,6 +623,23 @@ fn addWasiUpdateStep(b: *std.Build, version: [:0]const u8) !void { exe_options.addOption(bool, "value_tracing", false); exe_options.addOption(DevEnv, "dev", .bootstrap); + // zig1 chooses to interpret values by name. The tradeoff is as follows: + // + // * We lose a small amount of performance. This is essentially irrelevant for zig1. + // + // * We lose the ability to perform trivial renames on certain `std.builtin` types without + // zig1.wasm updates. For instance, we cannot rename an enum from PascalCase fields to + // snake_case fields without an update. + // + // * We gain the ability to add and remove fields to and from `std.builtin` types without + // zig1.wasm updates. For instance, we can add a new tag to `CallingConvention` without + // an update. + // + // Because field renames only happen when we apply a breaking change to the language (which + // is becoming progressively rarer), but tags may be added to or removed from target-dependent + // types over time in response to new targets coming into use, we gain more than we lose here. + exe_options.addOption(ValueInterpretMode, "value_interpret_mode", .by_name); + const run_opt = b.addSystemCommand(&.{ "wasm-opt", "-Oz", diff --git a/lib/std/Build/Step/ConfigHeader.zig b/lib/std/Build/Step/ConfigHeader.zig index 895f50f5d05b..fe16532dc362 100644 --- a/lib/std/Build/Step/ConfigHeader.zig +++ b/lib/std/Build/Step/ConfigHeader.zig @@ -144,13 +144,13 @@ fn putValue(config_header: *ConfigHeader, field_name: []const u8, comptime T: ty .pointer => |ptr| { switch (@typeInfo(ptr.child)) { .array => |array| { - if (ptr.size == .One and array.child == u8) { + if (ptr.size == .one and array.child == u8) { try config_header.values.put(field_name, .{ .string = v }); return; } }, .int => { - if (ptr.size == .Slice and ptr.child == u8) { + if (ptr.size == .slice and ptr.child == u8) { try config_header.values.put(field_name, .{ .string = v }); return; } diff --git a/lib/std/Build/Step/Options.zig b/lib/std/Build/Step/Options.zig index 44228bef2084..dd09c0b5c070 100644 --- a/lib/std/Build/Step/Options.zig +++ b/lib/std/Build/Step/Options.zig @@ -172,7 +172,7 @@ fn printType(options: *Options, out: anytype, comptime T: type, value: T, indent return; }, .pointer => |p| { - if (p.size != .Slice) { + if (p.size != .slice) { @compileError("Non-slice pointers are not yet supported in build options"); } @@ -318,9 +318,7 @@ fn printStruct(options: *Options, out: anytype, comptime T: type, comptime val: try out.print(" {p_}: {s}", .{ std.zig.fmtId(field.name), type_name }); } - if (field.default_value != null) { - const default_value = @as(*field.type, @ptrCast(@alignCast(@constCast(field.default_value.?)))).*; - + if (field.defaultValue()) |default_value| { try out.writeAll(" = "); switch (@typeInfo(@TypeOf(default_value))) { .@"enum" => try out.print(".{s},\n", .{@tagName(default_value)}), diff --git a/lib/std/Progress.zig b/lib/std/Progress.zig index 513a9393673b..24f58e1c685b 100644 --- a/lib/std/Progress.zig +++ b/lib/std/Progress.zig @@ -1366,7 +1366,7 @@ fn maybeUpdateSize(resize_flag: bool) void { } } -fn handleSigWinch(sig: i32, info: *const posix.siginfo_t, ctx_ptr: ?*anyopaque) callconv(.C) void { +fn handleSigWinch(sig: i32, info: *const posix.siginfo_t, ctx_ptr: ?*anyopaque) callconv(.c) void { _ = info; _ = ctx_ptr; assert(sig == posix.SIG.WINCH); diff --git a/lib/std/Random.zig b/lib/std/Random.zig index c700f7d0f39f..8c68bdf6daef 100644 --- a/lib/std/Random.zig +++ b/lib/std/Random.zig @@ -35,7 +35,7 @@ fillFn: *const fn (ptr: *anyopaque, buf: []u8) void, pub fn init(pointer: anytype, comptime fillFn: fn (ptr: @TypeOf(pointer), buf: []u8) void) Random { const Ptr = @TypeOf(pointer); assert(@typeInfo(Ptr) == .pointer); // Must be a pointer - assert(@typeInfo(Ptr).pointer.size == .One); // Must be a single-item pointer + assert(@typeInfo(Ptr).pointer.size == .one); // Must be a single-item pointer assert(@typeInfo(@typeInfo(Ptr).pointer.child) == .@"struct"); // Must point to a struct const gen = struct { fn fill(ptr: *anyopaque, buf: []u8) void { diff --git a/lib/std/builtin.zig b/lib/std/builtin.zig index eda7f0ff4f5e..763db8448cdf 100644 --- a/lib/std/builtin.zig +++ b/lib/std/builtin.zig @@ -607,16 +607,24 @@ 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. pub const Size = enum(u2) { - One, - Many, - Slice, - C, + one, + many, + slice, + c, }; }; @@ -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 diff --git a/lib/std/c.zig b/lib/std/c.zig index e31d90c79f67..70af17aa2e9f 100644 --- a/lib/std/c.zig +++ b/lib/std/c.zig @@ -2733,8 +2733,8 @@ pub const Sigaction = switch (native_os) { => if (builtin.target.isMusl()) linux.Sigaction else if (builtin.target.ptrBitWidth() == 64) extern struct { - pub const handler_fn = *align(1) const fn (i32) callconv(.C) void; - pub const sigaction_fn = *const fn (i32, *const siginfo_t, ?*anyopaque) callconv(.C) void; + pub const handler_fn = *align(1) const fn (i32) callconv(.c) void; + pub const sigaction_fn = *const fn (i32, *const siginfo_t, ?*anyopaque) callconv(.c) void; flags: c_uint, handler: extern union { @@ -2742,10 +2742,10 @@ pub const Sigaction = switch (native_os) { sigaction: ?sigaction_fn, }, mask: sigset_t, - restorer: ?*const fn () callconv(.C) void = null, + restorer: ?*const fn () callconv(.c) void = null, } else extern struct { - pub const handler_fn = *align(1) const fn (i32) callconv(.C) void; - pub const sigaction_fn = *const fn (i32, *const siginfo_t, ?*anyopaque) callconv(.C) void; + pub const handler_fn = *align(1) const fn (i32) callconv(.c) void; + pub const sigaction_fn = *const fn (i32, *const siginfo_t, ?*anyopaque) callconv(.c) void; flags: c_uint, handler: extern union { @@ -2753,12 +2753,12 @@ pub const Sigaction = switch (native_os) { sigaction: ?sigaction_fn, }, mask: sigset_t, - restorer: ?*const fn () callconv(.C) void = null, + restorer: ?*const fn () callconv(.c) void = null, __resv: [1]c_int = .{0}, }, .s390x => if (builtin.abi == .gnu) extern struct { - pub const handler_fn = *align(1) const fn (i32) callconv(.C) void; - pub const sigaction_fn = *const fn (i32, *const siginfo_t, ?*anyopaque) callconv(.C) void; + pub const handler_fn = *align(1) const fn (i32) callconv(.c) void; + pub const sigaction_fn = *const fn (i32, *const siginfo_t, ?*anyopaque) callconv(.c) void; handler: extern union { handler: ?handler_fn, @@ -2766,15 +2766,15 @@ pub const Sigaction = switch (native_os) { }, __glibc_reserved0: c_int = 0, flags: c_uint, - restorer: ?*const fn () callconv(.C) void = null, + restorer: ?*const fn () callconv(.c) void = null, mask: sigset_t, } else linux.Sigaction, else => linux.Sigaction, }, .emscripten => emscripten.Sigaction, .netbsd, .macos, .ios, .tvos, .watchos, .visionos => extern struct { - pub const handler_fn = *align(1) const fn (i32) callconv(.C) void; - pub const sigaction_fn = *const fn (i32, *const siginfo_t, ?*anyopaque) callconv(.C) void; + pub const handler_fn = *align(1) const fn (i32) callconv(.c) void; + pub const sigaction_fn = *const fn (i32, *const siginfo_t, ?*anyopaque) callconv(.c) void; handler: extern union { handler: ?handler_fn, @@ -2784,8 +2784,8 @@ pub const Sigaction = switch (native_os) { flags: c_uint, }, .dragonfly, .freebsd => extern struct { - pub const handler_fn = *align(1) const fn (i32) callconv(.C) void; - pub const sigaction_fn = *const fn (i32, *const siginfo_t, ?*anyopaque) callconv(.C) void; + pub const handler_fn = *align(1) const fn (i32) callconv(.c) void; + pub const sigaction_fn = *const fn (i32, *const siginfo_t, ?*anyopaque) callconv(.c) void; /// signal handler handler: extern union { @@ -2798,8 +2798,8 @@ pub const Sigaction = switch (native_os) { mask: sigset_t, }, .solaris, .illumos => extern struct { - pub const handler_fn = *align(1) const fn (i32) callconv(.C) void; - pub const sigaction_fn = *const fn (i32, *const siginfo_t, ?*anyopaque) callconv(.C) void; + pub const handler_fn = *align(1) const fn (i32) callconv(.c) void; + pub const sigaction_fn = *const fn (i32, *const siginfo_t, ?*anyopaque) callconv(.c) void; /// signal options flags: c_uint, @@ -2812,8 +2812,8 @@ pub const Sigaction = switch (native_os) { mask: sigset_t, }, .haiku => extern struct { - pub const handler_fn = *align(1) const fn (i32) callconv(.C) void; - pub const sigaction_fn = *const fn (i32, *const siginfo_t, ?*anyopaque) callconv(.C) void; + pub const handler_fn = *align(1) const fn (i32) callconv(.c) void; + pub const sigaction_fn = *const fn (i32, *const siginfo_t, ?*anyopaque) callconv(.c) void; /// signal handler handler: extern union { @@ -2831,8 +2831,8 @@ pub const Sigaction = switch (native_os) { userdata: *allowzero anyopaque = undefined, }, .openbsd => extern struct { - pub const handler_fn = *align(1) const fn (i32) callconv(.C) void; - pub const sigaction_fn = *const fn (i32, *const siginfo_t, ?*anyopaque) callconv(.C) void; + pub const handler_fn = *align(1) const fn (i32) callconv(.c) void; + pub const sigaction_fn = *const fn (i32, *const siginfo_t, ?*anyopaque) callconv(.c) void; /// signal handler handler: extern union { @@ -6410,7 +6410,7 @@ pub const EAI = switch (native_os) { else => void, }; -pub const dl_iterate_phdr_callback = *const fn (info: *dl_phdr_info, size: usize, data: ?*anyopaque) callconv(.C) c_int; +pub const dl_iterate_phdr_callback = *const fn (info: *dl_phdr_info, size: usize, data: ?*anyopaque) callconv(.c) c_int; pub const Stat = switch (native_os) { .linux => switch (native_arch) { @@ -9396,7 +9396,7 @@ pub extern "c" fn futimens(fd: fd_t, times: *const [2]timespec) c_int; pub extern "c" fn pthread_create( noalias newthread: *pthread_t, noalias attr: ?*const pthread_attr_t, - start_routine: *const fn (?*anyopaque) callconv(.C) ?*anyopaque, + start_routine: *const fn (?*anyopaque) callconv(.c) ?*anyopaque, noalias arg: ?*anyopaque, ) E; pub extern "c" fn pthread_attr_init(attr: *pthread_attr_t) E; @@ -9408,13 +9408,13 @@ pub extern "c" fn pthread_self() pthread_t; pub extern "c" fn pthread_join(thread: pthread_t, arg_return: ?*?*anyopaque) E; pub extern "c" fn pthread_detach(thread: pthread_t) E; pub extern "c" fn pthread_atfork( - prepare: ?*const fn () callconv(.C) void, - parent: ?*const fn () callconv(.C) void, - child: ?*const fn () callconv(.C) void, + prepare: ?*const fn () callconv(.c) void, + parent: ?*const fn () callconv(.c) void, + child: ?*const fn () callconv(.c) void, ) c_int; pub extern "c" fn pthread_key_create( key: *pthread_key_t, - destructor: ?*const fn (value: *anyopaque) callconv(.C) void, + destructor: ?*const fn (value: *anyopaque) callconv(.c) void, ) E; pub extern "c" fn pthread_key_delete(key: pthread_key_t) E; pub extern "c" fn pthread_getspecific(key: pthread_key_t) ?*anyopaque; @@ -9530,12 +9530,12 @@ pub extern "c" fn pthread_cond_signal(cond: *pthread_cond_t) E; pub extern "c" fn pthread_cond_broadcast(cond: *pthread_cond_t) E; pub extern "c" fn pthread_cond_destroy(cond: *pthread_cond_t) E; -pub extern "c" fn pthread_rwlock_destroy(rwl: *pthread_rwlock_t) callconv(.C) E; -pub extern "c" fn pthread_rwlock_rdlock(rwl: *pthread_rwlock_t) callconv(.C) E; -pub extern "c" fn pthread_rwlock_wrlock(rwl: *pthread_rwlock_t) callconv(.C) E; -pub extern "c" fn pthread_rwlock_tryrdlock(rwl: *pthread_rwlock_t) callconv(.C) E; -pub extern "c" fn pthread_rwlock_trywrlock(rwl: *pthread_rwlock_t) callconv(.C) E; -pub extern "c" fn pthread_rwlock_unlock(rwl: *pthread_rwlock_t) callconv(.C) E; +pub extern "c" fn pthread_rwlock_destroy(rwl: *pthread_rwlock_t) callconv(.c) E; +pub extern "c" fn pthread_rwlock_rdlock(rwl: *pthread_rwlock_t) callconv(.c) E; +pub extern "c" fn pthread_rwlock_wrlock(rwl: *pthread_rwlock_t) callconv(.c) E; +pub extern "c" fn pthread_rwlock_tryrdlock(rwl: *pthread_rwlock_t) callconv(.c) E; +pub extern "c" fn pthread_rwlock_trywrlock(rwl: *pthread_rwlock_t) callconv(.c) E; +pub extern "c" fn pthread_rwlock_unlock(rwl: *pthread_rwlock_t) callconv(.c) E; pub const pthread_t = *opaque {}; pub const FILE = opaque {}; diff --git a/lib/std/c/darwin.zig b/lib/std/c/darwin.zig index 77a1b09311b6..4dc12828b270 100644 --- a/lib/std/c/darwin.zig +++ b/lib/std/c/darwin.zig @@ -379,7 +379,7 @@ pub const MACH_MSG_TYPE = enum(mach_msg_type_name_t) { }; extern "c" var mach_task_self_: mach_port_t; -pub fn mach_task_self() callconv(.C) mach_port_t { +pub fn mach_task_self() callconv(.c) mach_port_t { return mach_task_self_; } @@ -873,7 +873,7 @@ pub const DISPATCH_TIME_FOREVER = ~@as(dispatch_time_t, 0); pub extern "c" fn dispatch_time(when: dispatch_time_t, delta: i64) dispatch_time_t; const dispatch_once_t = usize; -const dispatch_function_t = fn (?*anyopaque) callconv(.C) void; +const dispatch_function_t = fn (?*anyopaque) callconv(.c) void; pub extern fn dispatch_once_f( predicate: *dispatch_once_t, context: ?*anyopaque, diff --git a/lib/std/c/dragonfly.zig b/lib/std/c/dragonfly.zig index 5840fc22694c..cb33fc1e5649 100644 --- a/lib/std/c/dragonfly.zig +++ b/lib/std/c/dragonfly.zig @@ -156,7 +156,7 @@ pub const E = enum(u16) { pub const BADSIG = SIG.ERR; -pub const sig_t = *const fn (i32) callconv(.C) void; +pub const sig_t = *const fn (i32) callconv(.c) void; pub const cmsghdr = extern struct { len: socklen_t, diff --git a/lib/std/crypto/phc_encoding.zig b/lib/std/crypto/phc_encoding.zig index ba48a9954f6a..ee814861b323 100644 --- a/lib/std/crypto/phc_encoding.zig +++ b/lib/std/crypto/phc_encoding.zig @@ -164,7 +164,7 @@ pub fn deserialize(comptime HashResult: type, str: []const u8) Error!HashResult // with default values var expected_fields: usize = 0; inline for (comptime meta.fields(HashResult)) |p| { - if (@typeInfo(p.type) != .optional and p.default_value == null) { + if (@typeInfo(p.type) != .optional and p.default_value_ptr == null) { expected_fields += 1; } } diff --git a/lib/std/crypto/tlcsprng.zig b/lib/std/crypto/tlcsprng.zig index 672d6c2ecb9f..bad4df2ea85b 100644 --- a/lib/std/crypto/tlcsprng.zig +++ b/lib/std/crypto/tlcsprng.zig @@ -133,7 +133,7 @@ fn setupPthreadAtforkAndFill(buffer: []u8) void { return initAndFill(buffer); } -fn childAtForkHandler() callconv(.C) void { +fn childAtForkHandler() callconv(.c) void { // The atfork handler is global, this function may be called after // fork()-ing threads that never initialized the CSPRNG context. if (wipe_mem.len == 0) return; diff --git a/lib/std/debug.zig b/lib/std/debug.zig index e8855f5d1ad3..3664bd0cef07 100644 --- a/lib/std/debug.zig +++ b/lib/std/debug.zig @@ -1269,7 +1269,7 @@ fn resetSegfaultHandler() void { updateSegfaultHandler(&act); } -fn handleSegfaultPosix(sig: i32, info: *const posix.siginfo_t, ctx_ptr: ?*anyopaque) callconv(.C) noreturn { +fn handleSegfaultPosix(sig: i32, info: *const posix.siginfo_t, ctx_ptr: ?*anyopaque) callconv(.c) noreturn { // Reset to the default handler so that if a segfault happens in this handler it will crash // the process. Also when this handler returns, the original instruction will be repeated // and the resulting segfault will crash the process rather than continually dump stack traces. diff --git a/lib/std/enums.zig b/lib/std/enums.zig index aebfe2a18a7c..cb928ac02301 100644 --- a/lib/std/enums.zig +++ b/lib/std/enums.zig @@ -19,7 +19,7 @@ pub fn EnumFieldStruct(comptime E: type, comptime Data: type, comptime field_def struct_field.* = .{ .name = enum_field.name ++ "", .type = Data, - .default_value = if (field_default) |d| @as(?*const anyopaque, @ptrCast(&d)) else null, + .default_value_ptr = if (field_default) |d| @as(?*const anyopaque, @ptrCast(&d)) else null, .is_comptime = false, .alignment = if (@sizeOf(Data) > 0) @alignOf(Data) else 0, }; diff --git a/lib/std/fmt.zig b/lib/std/fmt.zig index 2b5e78975e97..2316b32d5d55 100644 --- a/lib/std/fmt.zig +++ b/lib/std/fmt.zig @@ -434,7 +434,7 @@ pub fn formatAddress(value: anytype, options: FormatOptions, writer: anytype) @T switch (@typeInfo(T)) { .pointer => |info| { try writer.writeAll(@typeName(info.child) ++ "@"); - if (info.size == .Slice) + if (info.size == .slice) try formatInt(@intFromPtr(value.ptr), 16, .lower, FormatOptions{}, writer) else try formatInt(@intFromPtr(value), 16, .lower, FormatOptions{}, writer); @@ -460,12 +460,12 @@ pub fn defaultSpec(comptime T: type) [:0]const u8 { switch (@typeInfo(T)) { .array, .vector => return ANY, .pointer => |ptr_info| switch (ptr_info.size) { - .One => switch (@typeInfo(ptr_info.child)) { + .one => switch (@typeInfo(ptr_info.child)) { .array => return ANY, else => {}, }, - .Many, .C => return "*", - .Slice => return ANY, + .many, .c => return "*", + .slice => return ANY, }, .optional => |info| return "?" ++ defaultSpec(info.child), .error_union => |info| return "!" ++ defaultSpec(info.payload), @@ -624,16 +624,16 @@ pub fn formatType( try writer.writeAll(" }"); }, .pointer => |ptr_info| switch (ptr_info.size) { - .One => switch (@typeInfo(ptr_info.child)) { + .one => switch (@typeInfo(ptr_info.child)) { .array, .@"enum", .@"union", .@"struct" => { return formatType(value.*, actual_fmt, options, writer, max_depth); }, else => return format(writer, "{s}@{x}", .{ @typeName(ptr_info.child), @intFromPtr(value) }), }, - .Many, .C => { + .many, .c => { if (actual_fmt.len == 0) @compileError("cannot format pointer without a specifier (i.e. {s} or {*})"); - if (ptr_info.sentinel) |_| { + if (ptr_info.sentinel() != null) { return formatType(mem.span(value), actual_fmt, options, writer, max_depth); } if (actual_fmt[0] == 's' and ptr_info.child == u8) { @@ -641,7 +641,7 @@ pub fn formatType( } invalidFmtError(fmt, value); }, - .Slice => { + .slice => { if (actual_fmt.len == 0) @compileError("cannot format slice without a specifier (i.e. {s} or {any})"); if (max_depth == 0) { diff --git a/lib/std/hash/auto_hash.zig b/lib/std/hash/auto_hash.zig index d9d3b1836d73..7ecd1860e460 100644 --- a/lib/std/hash/auto_hash.zig +++ b/lib/std/hash/auto_hash.zig @@ -23,13 +23,13 @@ pub fn hashPointer(hasher: anytype, key: anytype, comptime strat: HashStrategy) const info = @typeInfo(@TypeOf(key)); switch (info.pointer.size) { - .One => switch (strat) { + .one => switch (strat) { .Shallow => hash(hasher, @intFromPtr(key), .Shallow), .Deep => hash(hasher, key.*, .Shallow), .DeepRecursive => hash(hasher, key.*, .DeepRecursive), }, - .Slice => { + .slice => { switch (strat) { .Shallow => { hashPointer(hasher, key.ptr, .Shallow); @@ -40,8 +40,8 @@ pub fn hashPointer(hasher: anytype, key: anytype, comptime strat: HashStrategy) hash(hasher, key.len, .Shallow); }, - .Many, - .C, + .many, + .c, => switch (strat) { .Shallow => hash(hasher, @intFromPtr(key), .Shallow), else => @compileError( @@ -167,7 +167,7 @@ pub fn hash(hasher: anytype, key: anytype, comptime strat: HashStrategy) void { inline fn typeContainsSlice(comptime K: type) bool { return switch (@typeInfo(K)) { - .pointer => |info| info.size == .Slice, + .pointer => |info| info.size == .slice, inline .@"struct", .@"union" => |info| { inline for (info.fields) |field| { diff --git a/lib/std/io.zig b/lib/std/io.zig index 7336d85cd1f4..bd9b0042b98f 100644 --- a/lib/std/io.zig +++ b/lib/std/io.zig @@ -805,7 +805,7 @@ pub fn PollFiles(comptime StreamEnum: type) type { struct_field.* = .{ .name = enum_field.name ++ "", .type = fs.File, - .default_value = null, + .default_value_ptr = null, .is_comptime = false, .alignment = @alignOf(fs.File), }; diff --git a/lib/std/io/fixed_buffer_stream.zig b/lib/std/io/fixed_buffer_stream.zig index 7750c29fc8c0..bfc25eb6ac54 100644 --- a/lib/std/io/fixed_buffer_stream.zig +++ b/lib/std/io/fixed_buffer_stream.zig @@ -118,14 +118,14 @@ fn Slice(comptime T: type) type { .pointer => |ptr_info| { var new_ptr_info = ptr_info; switch (ptr_info.size) { - .Slice => {}, - .One => switch (@typeInfo(ptr_info.child)) { + .slice => {}, + .one => switch (@typeInfo(ptr_info.child)) { .array => |info| new_ptr_info.child = info.child, else => @compileError("invalid type given to fixedBufferStream"), }, else => @compileError("invalid type given to fixedBufferStream"), } - new_ptr_info.size = .Slice; + new_ptr_info.size = .slice; return @Type(.{ .pointer = new_ptr_info }); }, else => @compileError("invalid type given to fixedBufferStream"), diff --git a/lib/std/json/static.zig b/lib/std/json/static.zig index 15cb5bc75a16..9cdb6226f269 100644 --- a/lib/std/json/static.zig +++ b/lib/std/json/static.zig @@ -451,12 +451,12 @@ pub fn innerParse( .pointer => |ptrInfo| { switch (ptrInfo.size) { - .One => { + .one => { const r: *ptrInfo.child = try allocator.create(ptrInfo.child); r.* = try innerParse(ptrInfo.child, allocator, source, options); return r; }, - .Slice => { + .slice => { switch (try source.peekNextTokenType()) { .array_begin => { _ = try source.next(); @@ -476,9 +476,8 @@ pub fn innerParse( arraylist.appendAssumeCapacity(try innerParse(ptrInfo.child, allocator, source, options)); } - if (ptrInfo.sentinel) |some| { - const sentinel_value = @as(*align(1) const ptrInfo.child, @ptrCast(some)).*; - return try arraylist.toOwnedSliceSentinel(sentinel_value); + if (ptrInfo.sentinel()) |s| { + return try arraylist.toOwnedSliceSentinel(s); } return try arraylist.toOwnedSlice(); @@ -487,11 +486,11 @@ pub fn innerParse( if (ptrInfo.child != u8) return error.UnexpectedToken; // Dynamic length string. - if (ptrInfo.sentinel) |sentinel_ptr| { + if (ptrInfo.sentinel()) |s| { // Use our own array list so we can append the sentinel. var value_list = ArrayList(u8).init(allocator); _ = try source.allocNextIntoArrayList(&value_list, .alloc_always); - return try value_list.toOwnedSliceSentinel(@as(*const u8, @ptrCast(sentinel_ptr)).*); + return try value_list.toOwnedSliceSentinel(s); } if (ptrInfo.is_const) { switch (try source.nextAllocMax(allocator, options.allocate.?, options.max_value_len.?)) { @@ -706,16 +705,16 @@ pub fn innerParseFromValue( .pointer => |ptrInfo| { switch (ptrInfo.size) { - .One => { + .one => { const r: *ptrInfo.child = try allocator.create(ptrInfo.child); r.* = try innerParseFromValue(ptrInfo.child, allocator, source, options); return r; }, - .Slice => { + .slice => { switch (source) { .array => |array| { - const r = if (ptrInfo.sentinel) |sentinel_ptr| - try allocator.allocSentinel(ptrInfo.child, array.items.len, @as(*align(1) const ptrInfo.child, @ptrCast(sentinel_ptr)).*) + const r = if (ptrInfo.sentinel()) |sentinel| + try allocator.allocSentinel(ptrInfo.child, array.items.len, sentinel) else try allocator.alloc(ptrInfo.child, array.items.len); @@ -729,8 +728,8 @@ pub fn innerParseFromValue( if (ptrInfo.child != u8) return error.UnexpectedToken; // Dynamic length string. - const r = if (ptrInfo.sentinel) |sentinel_ptr| - try allocator.allocSentinel(ptrInfo.child, s.len, @as(*align(1) const ptrInfo.child, @ptrCast(sentinel_ptr)).*) + const r = if (ptrInfo.sentinel()) |sentinel| + try allocator.allocSentinel(ptrInfo.child, s.len, sentinel) else try allocator.alloc(ptrInfo.child, s.len); @memcpy(r[0..], s); @@ -787,8 +786,7 @@ fn sliceToEnum(comptime T: type, slice: []const u8) !T { fn fillDefaultStructValues(comptime T: type, r: *T, fields_seen: *[@typeInfo(T).@"struct".fields.len]bool) !void { inline for (@typeInfo(T).@"struct".fields, 0..) |field, i| { if (!fields_seen[i]) { - if (field.default_value) |default_ptr| { - const default = @as(*align(1) const field.type, @ptrCast(default_ptr)).*; + if (field.defaultValue()) |default| { @field(r, field.name) = default; } else { return error.MissingField; diff --git a/lib/std/json/stringify.zig b/lib/std/json/stringify.zig index 9bc0e564a1ad..db2ba853180d 100644 --- a/lib/std/json/stringify.zig +++ b/lib/std/json/stringify.zig @@ -631,7 +631,7 @@ pub fn WriteStream( }, .error_set => return self.stringValue(@errorName(value)), .pointer => |ptr_info| switch (ptr_info.size) { - .One => switch (@typeInfo(ptr_info.child)) { + .one => switch (@typeInfo(ptr_info.child)) { .array => { // Coerce `*[N]T` to `[]const T`. const Slice = []const std.meta.Elem(ptr_info.child); @@ -641,10 +641,10 @@ pub fn WriteStream( return self.write(value.*); }, }, - .Many, .Slice => { - if (ptr_info.size == .Many and ptr_info.sentinel == null) + .many, .slice => { + if (ptr_info.size == .many and ptr_info.sentinel() == null) @compileError("unable to stringify type '" ++ @typeName(T) ++ "' without sentinel"); - const slice = if (ptr_info.size == .Many) std.mem.span(value) else value; + const slice = if (ptr_info.size == .many) std.mem.span(value) else value; if (ptr_info.child == u8) { // This is a []const u8, or some similar Zig string. diff --git a/lib/std/mem.zig b/lib/std/mem.zig index 583f6eb00a57..28288620f61b 100644 --- a/lib/std/mem.zig +++ b/lib/std/mem.zig @@ -262,9 +262,9 @@ pub fn zeroes(comptime T: type) T { }, .pointer => |ptr_info| { switch (ptr_info.size) { - .Slice => { - if (ptr_info.sentinel) |sentinel| { - if (ptr_info.child == u8 and @as(*const u8, @ptrCast(sentinel)).* == 0) { + .slice => { + if (ptr_info.sentinel()) |sentinel| { + if (ptr_info.child == u8 and sentinel == 0) { return ""; // A special case for the most common use-case: null-terminated strings. } @compileError("Can't set a sentinel slice to zero. This would require allocating memory."); @@ -272,21 +272,17 @@ pub fn zeroes(comptime T: type) T { return &[_]ptr_info.child{}; } }, - .C => { + .c => { return null; }, - .One, .Many => { + .one, .many => { if (ptr_info.is_allowzero) return @ptrFromInt(0); @compileError("Only nullable and allowzero pointers can be set to zero."); }, } }, .array => |info| { - if (info.sentinel) |sentinel_ptr| { - const sentinel = @as(*align(1) const info.child, @ptrCast(sentinel_ptr)).*; - return [_:sentinel]info.child{zeroes(info.child)} ** info.len; - } - return [_]info.child{zeroes(info.child)} ** info.len; + return @splat(zeroes(info.child)); }, .vector => |info| { return @splat(zeroes(info.child)); @@ -456,9 +452,8 @@ pub fn zeroInit(comptime T: type, init: anytype) T { @field(value, field.name) = @field(init, field.name); }, } - } else if (field.default_value) |default_value_ptr| { - const default_value = @as(*align(1) const field.type, @ptrCast(default_value_ptr)).*; - @field(value, field.name) = default_value; + } else if (field.defaultValue()) |val| { + @field(value, field.name) = val; } else { switch (@typeInfo(field.type)) { .@"struct" => { @@ -781,14 +776,14 @@ fn Span(comptime T: type) type { .pointer => |ptr_info| { var new_ptr_info = ptr_info; switch (ptr_info.size) { - .C => { - new_ptr_info.sentinel = &@as(ptr_info.child, 0); + .c => { + new_ptr_info.sentinel_ptr = &@as(ptr_info.child, 0); new_ptr_info.is_allowzero = false; }, - .Many => if (ptr_info.sentinel == null) @compileError("invalid type given to std.mem.span: " ++ @typeName(T)), - .One, .Slice => @compileError("invalid type given to std.mem.span: " ++ @typeName(T)), + .many => if (ptr_info.sentinel() == null) @compileError("invalid type given to std.mem.span: " ++ @typeName(T)), + .one, .slice => @compileError("invalid type given to std.mem.span: " ++ @typeName(T)), } - new_ptr_info.size = .Slice; + new_ptr_info.size = .slice; return @Type(.{ .pointer = new_ptr_info }); }, else => {}, @@ -822,8 +817,7 @@ pub fn span(ptr: anytype) Span(@TypeOf(ptr)) { const Result = Span(@TypeOf(ptr)); const l = len(ptr); const ptr_info = @typeInfo(Result).pointer; - if (ptr_info.sentinel) |s_ptr| { - const s = @as(*align(1) const ptr_info.child, @ptrCast(s_ptr)).*; + if (ptr_info.sentinel()) |s| { return ptr[0..l :s]; } else { return ptr[0..l]; @@ -845,40 +839,38 @@ fn SliceTo(comptime T: type, comptime end: std.meta.Elem(T)) type { }, .pointer => |ptr_info| { var new_ptr_info = ptr_info; - new_ptr_info.size = .Slice; + new_ptr_info.size = .slice; switch (ptr_info.size) { - .One => switch (@typeInfo(ptr_info.child)) { + .one => switch (@typeInfo(ptr_info.child)) { .array => |array_info| { new_ptr_info.child = array_info.child; // The return type must only be sentinel terminated if we are guaranteed // to find the value searched for, which is only the case if it matches // the sentinel of the type passed. - if (array_info.sentinel) |sentinel_ptr| { - const sentinel = @as(*align(1) const array_info.child, @ptrCast(sentinel_ptr)).*; - if (end == sentinel) { - new_ptr_info.sentinel = &end; + if (array_info.sentinel()) |s| { + if (end == s) { + new_ptr_info.sentinel_ptr = &end; } else { - new_ptr_info.sentinel = null; + new_ptr_info.sentinel_ptr = null; } } }, else => {}, }, - .Many, .Slice => { + .many, .slice => { // The return type must only be sentinel terminated if we are guaranteed // to find the value searched for, which is only the case if it matches // the sentinel of the type passed. - if (ptr_info.sentinel) |sentinel_ptr| { - const sentinel = @as(*align(1) const ptr_info.child, @ptrCast(sentinel_ptr)).*; - if (end == sentinel) { - new_ptr_info.sentinel = &end; + if (ptr_info.sentinel()) |s| { + if (end == s) { + new_ptr_info.sentinel_ptr = &end; } else { - new_ptr_info.sentinel = null; + new_ptr_info.sentinel_ptr = null; } } }, - .C => { - new_ptr_info.sentinel = &end; + .c => { + new_ptr_info.sentinel_ptr = &end; // C pointers are always allowzero, but we don't want the return type to be. assert(new_ptr_info.is_allowzero); new_ptr_info.is_allowzero = false; @@ -906,8 +898,7 @@ pub fn sliceTo(ptr: anytype, comptime end: std.meta.Elem(@TypeOf(ptr))) SliceTo( const Result = SliceTo(@TypeOf(ptr), end); const length = lenSliceTo(ptr, end); const ptr_info = @typeInfo(Result).pointer; - if (ptr_info.sentinel) |s_ptr| { - const s = @as(*align(1) const ptr_info.child, @ptrCast(s_ptr)).*; + if (ptr_info.sentinel()) |s| { return ptr[0..length :s]; } else { return ptr[0..length]; @@ -957,11 +948,10 @@ test sliceTo { fn lenSliceTo(ptr: anytype, comptime end: std.meta.Elem(@TypeOf(ptr))) usize { switch (@typeInfo(@TypeOf(ptr))) { .pointer => |ptr_info| switch (ptr_info.size) { - .One => switch (@typeInfo(ptr_info.child)) { + .one => switch (@typeInfo(ptr_info.child)) { .array => |array_info| { - if (array_info.sentinel) |sentinel_ptr| { - const sentinel = @as(*align(1) const array_info.child, @ptrCast(sentinel_ptr)).*; - if (sentinel == end) { + if (array_info.sentinel()) |s| { + if (s == end) { return indexOfSentinel(array_info.child, end, ptr); } } @@ -969,27 +959,25 @@ fn lenSliceTo(ptr: anytype, comptime end: std.meta.Elem(@TypeOf(ptr))) usize { }, else => {}, }, - .Many => if (ptr_info.sentinel) |sentinel_ptr| { - const sentinel = @as(*align(1) const ptr_info.child, @ptrCast(sentinel_ptr)).*; - if (sentinel == end) { + .many => if (ptr_info.sentinel()) |s| { + if (s == end) { return indexOfSentinel(ptr_info.child, end, ptr); } // We're looking for something other than the sentinel, // but iterating past the sentinel would be a bug so we need // to check for both. var i: usize = 0; - while (ptr[i] != end and ptr[i] != sentinel) i += 1; + while (ptr[i] != end and ptr[i] != s) i += 1; return i; }, - .C => { + .c => { assert(ptr != null); return indexOfSentinel(ptr_info.child, end, ptr); }, - .Slice => { - if (ptr_info.sentinel) |sentinel_ptr| { - const sentinel = @as(*align(1) const ptr_info.child, @ptrCast(sentinel_ptr)).*; - if (sentinel == end) { - return indexOfSentinel(ptr_info.child, sentinel, ptr); + .slice => { + if (ptr_info.sentinel()) |s| { + if (s == end) { + return indexOfSentinel(ptr_info.child, s, ptr); } } return indexOfScalar(ptr_info.child, ptr, end) orelse ptr.len; @@ -1039,13 +1027,12 @@ test lenSliceTo { pub fn len(value: anytype) usize { switch (@typeInfo(@TypeOf(value))) { .pointer => |info| switch (info.size) { - .Many => { - const sentinel_ptr = info.sentinel orelse + .many => { + const sentinel = info.sentinel() orelse @compileError("invalid type given to std.mem.len: " ++ @typeName(@TypeOf(value))); - const sentinel = @as(*align(1) const info.child, @ptrCast(sentinel_ptr)).*; return indexOfSentinel(info.child, sentinel, value); }, - .C => { + .c => { assert(value != null); return indexOfSentinel(info.child, 0, value); }, @@ -3582,19 +3569,19 @@ fn ReverseIterator(comptime T: type) type { const Pointer = blk: { switch (@typeInfo(T)) { .pointer => |ptr_info| switch (ptr_info.size) { - .One => switch (@typeInfo(ptr_info.child)) { + .one => switch (@typeInfo(ptr_info.child)) { .array => |array_info| { var new_ptr_info = ptr_info; - new_ptr_info.size = .Many; + new_ptr_info.size = .many; new_ptr_info.child = array_info.child; - new_ptr_info.sentinel = array_info.sentinel; + new_ptr_info.sentinel_ptr = array_info.sentinel_ptr; break :blk @Type(.{ .pointer = new_ptr_info }); }, else => {}, }, - .Slice => { + .slice => { var new_ptr_info = ptr_info; - new_ptr_info.size = .Many; + new_ptr_info.size = .many; break :blk @Type(.{ .pointer = new_ptr_info }); }, else => {}, @@ -3606,9 +3593,9 @@ fn ReverseIterator(comptime T: type) type { const Element = std.meta.Elem(Pointer); const ElementPointer = @Type(.{ .pointer = ptr: { var ptr = @typeInfo(Pointer).pointer; - ptr.size = .One; + ptr.size = .one; ptr.child = Element; - ptr.sentinel = null; + ptr.sentinel_ptr = null; break :ptr ptr; } }); return struct { @@ -3912,7 +3899,7 @@ pub fn alignPointerOffset(ptr: anytype, align_to: usize) ?usize { const T = @TypeOf(ptr); const info = @typeInfo(T); - if (info != .pointer or info.pointer.size != .Many) + if (info != .pointer or info.pointer.size != .many) @compileError("expected many item pointer, got " ++ @typeName(T)); // Do nothing if the pointer is already well-aligned. @@ -3979,16 +3966,16 @@ fn CopyPtrAttrs( .alignment = info.alignment, .address_space = info.address_space, .child = child, - .sentinel = null, + .sentinel_ptr = null, }, }); } fn AsBytesReturnType(comptime P: type) type { const pointer = @typeInfo(P).pointer; - assert(pointer.size == .One); + assert(pointer.size == .one); const size = @sizeOf(pointer.child); - return CopyPtrAttrs(P, .One, [size]u8); + return CopyPtrAttrs(P, .one, [size]u8); } /// Given a pointer to a single item, returns a slice of the underlying bytes, preserving pointer attributes. @@ -4071,7 +4058,7 @@ test toBytes { } fn BytesAsValueReturnType(comptime T: type, comptime B: type) type { - return CopyPtrAttrs(B, .One, T); + return CopyPtrAttrs(B, .one, T); } /// Given a pointer to an array of bytes, returns a pointer to a value of the specified type @@ -4150,7 +4137,7 @@ test bytesToValue { } fn BytesAsSliceReturnType(comptime T: type, comptime bytesType: type) type { - return CopyPtrAttrs(bytesType, .Slice, T); + return CopyPtrAttrs(bytesType, .slice, T); } /// Given a slice of bytes, returns a slice of the specified type @@ -4162,7 +4149,7 @@ pub fn bytesAsSlice(comptime T: type, bytes: anytype) BytesAsSliceReturnType(T, return &[0]T{}; } - const cast_target = CopyPtrAttrs(@TypeOf(bytes), .Many, T); + const cast_target = CopyPtrAttrs(@TypeOf(bytes), .many, T); return @as(cast_target, @ptrCast(bytes))[0..@divExact(bytes.len, @sizeOf(T))]; } @@ -4237,7 +4224,7 @@ test "bytesAsSlice preserves pointer attributes" { } fn SliceAsBytesReturnType(comptime Slice: type) type { - return CopyPtrAttrs(Slice, .Slice, u8); + return CopyPtrAttrs(Slice, .slice, u8); } /// Given a slice, returns a slice of the underlying bytes, preserving pointer attributes. @@ -4251,7 +4238,7 @@ pub fn sliceAsBytes(slice: anytype) SliceAsBytesReturnType(@TypeOf(slice)) { // it may be equal to zero and fail a null check if (slice.len == 0 and std.meta.sentinel(Slice) == null) return &[0]u8{}; - const cast_target = CopyPtrAttrs(Slice, .Many, u8); + const cast_target = CopyPtrAttrs(Slice, .many, u8); return @as(cast_target, @ptrCast(slice))[0 .. slice.len * @sizeOf(std.meta.Elem(Slice))]; } @@ -4540,14 +4527,14 @@ fn AlignedSlice(comptime AttributeSource: type, comptime new_alignment: usize) t const info = @typeInfo(AttributeSource).pointer; return @Type(.{ .pointer = .{ - .size = .Slice, + .size = .slice, .is_const = info.is_const, .is_volatile = info.is_volatile, .is_allowzero = info.is_allowzero, .alignment = new_alignment, .address_space = info.address_space, .child = info.child, - .sentinel = null, + .sentinel_ptr = null, }, }); } diff --git a/lib/std/mem/Allocator.zig b/lib/std/mem/Allocator.zig index 8aea197d6ae8..c6b03691275b 100644 --- a/lib/std/mem/Allocator.zig +++ b/lib/std/mem/Allocator.zig @@ -110,7 +110,7 @@ pub fn create(self: Allocator, comptime T: type) Error!*T { /// have the same address and alignment property. pub fn destroy(self: Allocator, ptr: anytype) void { const info = @typeInfo(@TypeOf(ptr)).pointer; - if (info.size != .One) @compileError("ptr must be a single item pointer"); + if (info.size != .one) @compileError("ptr must be a single item pointer"); const T = info.child; if (@sizeOf(T) == 0) return; const non_const_ptr = @as([*]u8, @ptrCast(@constCast(ptr))); @@ -307,7 +307,7 @@ pub fn reallocAdvanced( pub fn free(self: Allocator, memory: anytype) void { const Slice = @typeInfo(@TypeOf(memory)).pointer; const bytes = mem.sliceAsBytes(memory); - const bytes_len = bytes.len + if (Slice.sentinel != null) @sizeOf(Slice.child) else 0; + const bytes_len = bytes.len + if (Slice.sentinel() != null) @sizeOf(Slice.child) else 0; if (bytes_len == 0) return; const non_const_ptr = @constCast(bytes.ptr); // TODO: https://github.com/ziglang/zig/issues/4298 diff --git a/lib/std/meta.zig b/lib/std/meta.zig index 44bfb65f8a04..08c858968266 100644 --- a/lib/std/meta.zig +++ b/lib/std/meta.zig @@ -103,12 +103,12 @@ pub fn Elem(comptime T: type) type { .array => |info| return info.child, .vector => |info| return info.child, .pointer => |info| switch (info.size) { - .One => switch (@typeInfo(info.child)) { + .one => switch (@typeInfo(info.child)) { .array => |array_info| return array_info.child, .vector => |vector_info| return vector_info.child, else => {}, }, - .Many, .C, .Slice => return info.child, + .many, .c, .slice => return info.child, }, .optional => |info| return Elem(info.child), else => {}, @@ -132,21 +132,12 @@ test Elem { /// Result is always comptime-known. pub inline fn sentinel(comptime T: type) ?Elem(T) { switch (@typeInfo(T)) { - .array => |info| { - const sentinel_ptr = info.sentinel orelse return null; - return @as(*const info.child, @ptrCast(sentinel_ptr)).*; - }, + .array => |info| return info.sentinel(), .pointer => |info| { switch (info.size) { - .Many, .Slice => { - const sentinel_ptr = info.sentinel orelse return null; - return @as(*align(1) const info.child, @ptrCast(sentinel_ptr)).*; - }, - .One => switch (@typeInfo(info.child)) { - .array => |array_info| { - const sentinel_ptr = array_info.sentinel orelse return null; - return @as(*align(1) const array_info.child, @ptrCast(sentinel_ptr)).*; - }, + .many, .slice => return info.sentinel(), + .one => switch (@typeInfo(info.child)) { + .array => |array_info| return array_info.sentinel(), else => {}, }, else => {}, @@ -178,7 +169,7 @@ fn testSentinel() !void { pub fn Sentinel(comptime T: type, comptime sentinel_val: Elem(T)) type { switch (@typeInfo(T)) { .pointer => |info| switch (info.size) { - .One => switch (@typeInfo(info.child)) { + .one => switch (@typeInfo(info.child)) { .array => |array_info| return @Type(.{ .pointer = .{ .size = info.size, @@ -190,16 +181,16 @@ pub fn Sentinel(comptime T: type, comptime sentinel_val: Elem(T)) type { .array = .{ .len = array_info.len, .child = array_info.child, - .sentinel = @as(?*const anyopaque, @ptrCast(&sentinel_val)), + .sentinel_ptr = @as(?*const anyopaque, @ptrCast(&sentinel_val)), }, }), .is_allowzero = info.is_allowzero, - .sentinel = info.sentinel, + .sentinel_ptr = info.sentinel_ptr, }, }), else => {}, }, - .Many, .Slice => return @Type(.{ + .many, .slice => return @Type(.{ .pointer = .{ .size = info.size, .is_const = info.is_const, @@ -208,14 +199,14 @@ pub fn Sentinel(comptime T: type, comptime sentinel_val: Elem(T)) type { .address_space = info.address_space, .child = info.child, .is_allowzero = info.is_allowzero, - .sentinel = @as(?*const anyopaque, @ptrCast(&sentinel_val)), + .sentinel_ptr = @as(?*const anyopaque, @ptrCast(&sentinel_val)), }, }), else => {}, }, .optional => |info| switch (@typeInfo(info.child)) { .pointer => |ptr_info| switch (ptr_info.size) { - .Many => return @Type(.{ + .many => return @Type(.{ .optional = .{ .child = @Type(.{ .pointer = .{ @@ -226,7 +217,7 @@ pub fn Sentinel(comptime T: type, comptime sentinel_val: Elem(T)) type { .address_space = ptr_info.address_space, .child = ptr_info.child, .is_allowzero = ptr_info.is_allowzero, - .sentinel = @as(?*const anyopaque, @ptrCast(&sentinel_val)), + .sentinel_ptr = @as(?*const anyopaque, @ptrCast(&sentinel_val)), }, }), }, @@ -786,8 +777,8 @@ pub fn eql(a: anytype, b: @TypeOf(a)) bool { }, .pointer => |info| { return switch (info.size) { - .One, .Many, .C => a == b, - .Slice => a.ptr == b.ptr and a.len == b.len, + .one, .many, .c => a == b, + .slice => a.ptr == b.ptr and a.len == b.len, }; }, .optional => { @@ -1018,7 +1009,7 @@ fn CreateUniqueTuple(comptime N: comptime_int, comptime types: [N]type) type { tuple_fields[i] = .{ .name = std.fmt.bufPrintZ(&num_buf, "{d}", .{i}) catch unreachable, .type = T, - .default_value = null, + .default_value_ptr = null, .is_comptime = false, .alignment = 0, }; @@ -1090,7 +1081,7 @@ test "Tuple deduplication" { test "ArgsTuple forwarding" { const T1 = std.meta.Tuple(&.{ u32, f32, i8 }); const T2 = std.meta.ArgsTuple(fn (u32, f32, i8) void); - const T3 = std.meta.ArgsTuple(fn (u32, f32, i8) callconv(.C) noreturn); + const T3 = std.meta.ArgsTuple(fn (u32, f32, i8) callconv(.c) noreturn); if (T1 != T2) { @compileError("std.meta.ArgsTuple produces different types than std.meta.Tuple"); @@ -1144,8 +1135,8 @@ test hasFn { pub inline fn hasMethod(comptime T: type, comptime name: []const u8) bool { return switch (@typeInfo(T)) { .pointer => |P| switch (P.size) { - .One => hasFn(P.child, name), - .Many, .Slice, .C => false, + .one => hasFn(P.child, name), + .many, .slice, .c => false, }, else => hasFn(T, name), }; @@ -1200,12 +1191,12 @@ pub inline fn hasUniqueRepresentation(comptime T: type) bool { .int => |info| @sizeOf(T) * 8 == info.bits, - .pointer => |info| info.size != .Slice, + .pointer => |info| info.size != .slice, .optional => |info| switch (@typeInfo(info.child)) { .pointer => |ptr| !ptr.is_allowzero and switch (ptr.size) { - .Slice, .C => false, - .One, .Many => true, + .slice, .c => false, + .one, .many => true, }, else => false, }, diff --git a/lib/std/meta/trailer_flags.zig b/lib/std/meta/trailer_flags.zig index e00d32c78919..186dd2be140a 100644 --- a/lib/std/meta/trailer_flags.zig +++ b/lib/std/meta/trailer_flags.zig @@ -25,7 +25,7 @@ pub fn TrailerFlags(comptime Fields: type) type { fields[i] = Type.StructField{ .name = struct_field.name, .type = ?struct_field.type, - .default_value = &@as(?struct_field.type, null), + .default_value_ptr = &@as(?struct_field.type, null), .is_comptime = false, .alignment = @alignOf(?struct_field.type), }; diff --git a/lib/std/multi_array_list.zig b/lib/std/multi_array_list.zig index f92861721119..f8d32a42d2b1 100644 --- a/lib/std/multi_array_list.zig +++ b/lib/std/multi_array_list.zig @@ -571,7 +571,7 @@ pub fn MultiArrayList(comptime T: type) type { for (&entry_fields, sizes.fields) |*entry_field, i| entry_field.* = .{ .name = fields[i].name ++ "_ptr", .type = *fields[i].type, - .default_value = null, + .default_value_ptr = null, .is_comptime = fields[i].is_comptime, .alignment = fields[i].alignment, }; diff --git a/lib/std/os/emscripten.zig b/lib/std/os/emscripten.zig index 6c6a34ac47ef..ad7a3f65c1ce 100644 --- a/lib/std/os/emscripten.zig +++ b/lib/std/os/emscripten.zig @@ -12,7 +12,7 @@ const c = std.c; pub const FILE = c.FILE; var __stack_chk_guard: usize = 0; -fn __stack_chk_fail() callconv(.C) void { +fn __stack_chk_fail() callconv(.c) void { std.debug.print("stack smashing detected: terminated\n", .{}); emscripten_force_exit(127); } @@ -547,8 +547,8 @@ pub const SIG = struct { }; pub const Sigaction = extern struct { - pub const handler_fn = *align(1) const fn (i32) callconv(.C) void; - pub const sigaction_fn = *const fn (i32, *const siginfo_t, ?*anyopaque) callconv(.C) void; + pub const handler_fn = *align(1) const fn (i32) callconv(.c) void; + pub const sigaction_fn = *const fn (i32, *const siginfo_t, ?*anyopaque) callconv(.c) void; handler: extern union { handler: ?handler_fn, @@ -556,7 +556,7 @@ pub const Sigaction = extern struct { }, mask: sigset_t, flags: c_uint, - restorer: ?*const fn () callconv(.C) void = null, + restorer: ?*const fn () callconv(.c) void = null, }; pub const sigset_t = [1024 / 32]u32; @@ -909,23 +909,23 @@ pub const LOG = struct { pub const INFO = 512; }; -pub const em_callback_func = ?*const fn () callconv(.C) void; -pub const em_arg_callback_func = ?*const fn (?*anyopaque) callconv(.C) void; -pub const em_str_callback_func = ?*const fn ([*:0]const u8) callconv(.C) void; +pub const em_callback_func = ?*const fn () callconv(.c) void; +pub const em_arg_callback_func = ?*const fn (?*anyopaque) callconv(.c) void; +pub const em_str_callback_func = ?*const fn ([*:0]const u8) callconv(.c) void; pub extern "c" fn emscripten_async_wget(url: [*:0]const u8, file: [*:0]const u8, onload: em_str_callback_func, onerror: em_str_callback_func) void; -pub const em_async_wget_onload_func = ?*const fn (?*anyopaque, ?*anyopaque, c_int) callconv(.C) void; +pub const em_async_wget_onload_func = ?*const fn (?*anyopaque, ?*anyopaque, c_int) callconv(.c) void; pub extern "c" fn emscripten_async_wget_data(url: [*:0]const u8, arg: ?*anyopaque, onload: em_async_wget_onload_func, onerror: em_arg_callback_func) void; -pub const em_async_wget2_onload_func = ?*const fn (c_uint, ?*anyopaque, [*:0]const u8) callconv(.C) void; -pub const em_async_wget2_onstatus_func = ?*const fn (c_uint, ?*anyopaque, c_int) callconv(.C) void; +pub const em_async_wget2_onload_func = ?*const fn (c_uint, ?*anyopaque, [*:0]const u8) callconv(.c) void; +pub const em_async_wget2_onstatus_func = ?*const fn (c_uint, ?*anyopaque, c_int) callconv(.c) void; pub extern "c" fn emscripten_async_wget2(url: [*:0]const u8, file: [*:0]const u8, requesttype: [*:0]const u8, param: [*:0]const u8, arg: ?*anyopaque, onload: em_async_wget2_onload_func, onerror: em_async_wget2_onstatus_func, onprogress: em_async_wget2_onstatus_func) c_int; -pub const em_async_wget2_data_onload_func = ?*const fn (c_uint, ?*anyopaque, ?*anyopaque, c_uint) callconv(.C) void; -pub const em_async_wget2_data_onerror_func = ?*const fn (c_uint, ?*anyopaque, c_int, [*:0]const u8) callconv(.C) void; -pub const em_async_wget2_data_onprogress_func = ?*const fn (c_uint, ?*anyopaque, c_int, c_int) callconv(.C) void; +pub const em_async_wget2_data_onload_func = ?*const fn (c_uint, ?*anyopaque, ?*anyopaque, c_uint) callconv(.c) void; +pub const em_async_wget2_data_onerror_func = ?*const fn (c_uint, ?*anyopaque, c_int, [*:0]const u8) callconv(.c) void; +pub const em_async_wget2_data_onprogress_func = ?*const fn (c_uint, ?*anyopaque, c_int, c_int) callconv(.c) void; pub extern "c" fn emscripten_async_wget2_data(url: [*:0]const u8, requesttype: [*:0]const u8, param: [*:0]const u8, arg: ?*anyopaque, free: c_int, onload: em_async_wget2_data_onload_func, onerror: em_async_wget2_data_onerror_func, onprogress: em_async_wget2_data_onprogress_func) c_int; pub extern "c" fn emscripten_async_wget2_abort(handle: c_int) void; @@ -944,8 +944,8 @@ pub extern "c" fn emscripten_pause_main_loop() void; pub extern "c" fn emscripten_resume_main_loop() void; pub extern "c" fn emscripten_cancel_main_loop() void; -pub const em_socket_callback = ?*const fn (c_int, ?*anyopaque) callconv(.C) void; -pub const em_socket_error_callback = ?*const fn (c_int, c_int, [*:0]const u8, ?*anyopaque) callconv(.C) void; +pub const em_socket_callback = ?*const fn (c_int, ?*anyopaque) callconv(.c) void; +pub const em_socket_error_callback = ?*const fn (c_int, c_int, [*:0]const u8, ?*anyopaque) callconv(.c) void; pub extern "c" fn emscripten_set_socket_error_callback(userData: ?*anyopaque, callback: em_socket_error_callback) void; pub extern "c" fn emscripten_set_socket_open_callback(userData: ?*anyopaque, callback: em_socket_callback) void; @@ -968,11 +968,11 @@ pub extern "c" fn emscripten_set_canvas_size(width: c_int, height: c_int) void; pub extern "c" fn emscripten_get_canvas_size(width: *c_int, height: *c_int, isFullscreen: *c_int) void; pub extern "c" fn emscripten_get_now() f64; pub extern "c" fn emscripten_random() f32; -pub const em_idb_onload_func = ?*const fn (?*anyopaque, ?*anyopaque, c_int) callconv(.C) void; +pub const em_idb_onload_func = ?*const fn (?*anyopaque, ?*anyopaque, c_int) callconv(.c) void; pub extern "c" fn emscripten_idb_async_load(db_name: [*:0]const u8, file_id: [*:0]const u8, arg: ?*anyopaque, onload: em_idb_onload_func, onerror: em_arg_callback_func) void; pub extern "c" fn emscripten_idb_async_store(db_name: [*:0]const u8, file_id: [*:0]const u8, ptr: ?*anyopaque, num: c_int, arg: ?*anyopaque, onstore: em_arg_callback_func, onerror: em_arg_callback_func) void; pub extern "c" fn emscripten_idb_async_delete(db_name: [*:0]const u8, file_id: [*:0]const u8, arg: ?*anyopaque, ondelete: em_arg_callback_func, onerror: em_arg_callback_func) void; -pub const em_idb_exists_func = ?*const fn (?*anyopaque, c_int) callconv(.C) void; +pub const em_idb_exists_func = ?*const fn (?*anyopaque, c_int) callconv(.c) void; pub extern "c" fn emscripten_idb_async_exists(db_name: [*:0]const u8, file_id: [*:0]const u8, arg: ?*anyopaque, oncheck: em_idb_exists_func, onerror: em_arg_callback_func) void; pub extern "c" fn emscripten_idb_load(db_name: [*:0]const u8, file_id: [*:0]const u8, pbuffer: *?*anyopaque, pnum: *c_int, perror: *c_int) void; pub extern "c" fn emscripten_idb_store(db_name: [*:0]const u8, file_id: [*:0]const u8, buffer: *anyopaque, num: c_int, perror: *c_int) void; @@ -983,13 +983,13 @@ pub extern "c" fn emscripten_idb_store_blob(db_name: [*:0]const u8, file_id: [*: pub extern "c" fn emscripten_idb_read_from_blob(blob: c_int, start: c_int, num: c_int, buffer: ?*anyopaque) void; pub extern "c" fn emscripten_idb_free_blob(blob: c_int) void; pub extern "c" fn emscripten_run_preload_plugins(file: [*:0]const u8, onload: em_str_callback_func, onerror: em_str_callback_func) c_int; -pub const em_run_preload_plugins_data_onload_func = ?*const fn (?*anyopaque, [*:0]const u8) callconv(.C) void; +pub const em_run_preload_plugins_data_onload_func = ?*const fn (?*anyopaque, [*:0]const u8) callconv(.c) void; pub extern "c" fn emscripten_run_preload_plugins_data(data: [*]u8, size: c_int, suffix: [*:0]const u8, arg: ?*anyopaque, onload: em_run_preload_plugins_data_onload_func, onerror: em_arg_callback_func) void; pub extern "c" fn emscripten_lazy_load_code() void; pub const worker_handle = c_int; pub extern "c" fn emscripten_create_worker(url: [*:0]const u8) worker_handle; pub extern "c" fn emscripten_destroy_worker(worker: worker_handle) void; -pub const em_worker_callback_func = ?*const fn ([*]u8, c_int, ?*anyopaque) callconv(.C) void; +pub const em_worker_callback_func = ?*const fn ([*]u8, c_int, ?*anyopaque) callconv(.c) void; pub extern "c" fn emscripten_call_worker(worker: worker_handle, funcname: [*:0]const u8, data: [*]u8, size: c_int, callback: em_worker_callback_func, arg: ?*anyopaque) void; pub extern "c" fn emscripten_worker_respond(data: [*]u8, size: c_int) void; pub extern "c" fn emscripten_worker_respond_provisionally(data: [*]u8, size: c_int) void; @@ -1003,10 +1003,10 @@ pub extern "c" fn emscripten_get_preloaded_image_data_from_FILE(file: *FILE, w: pub extern "c" fn emscripten_log(flags: c_int, format: [*:0]const u8, ...) void; pub extern "c" fn emscripten_get_callstack(flags: c_int, out: ?[*]u8, maxbytes: c_int) c_int; pub extern "c" fn emscripten_print_double(x: f64, to: ?[*]u8, max: c_int) c_int; -pub const em_scan_func = ?*const fn (?*anyopaque, ?*anyopaque) callconv(.C) void; +pub const em_scan_func = ?*const fn (?*anyopaque, ?*anyopaque) callconv(.c) void; pub extern "c" fn emscripten_scan_registers(func: em_scan_func) void; pub extern "c" fn emscripten_scan_stack(func: em_scan_func) void; -pub const em_dlopen_callback = ?*const fn (?*anyopaque, ?*anyopaque) callconv(.C) void; +pub const em_dlopen_callback = ?*const fn (?*anyopaque, ?*anyopaque) callconv(.c) void; pub extern "c" fn emscripten_dlopen(filename: [*:0]const u8, flags: c_int, user_data: ?*anyopaque, onsuccess: em_dlopen_callback, onerror: em_arg_callback_func) void; pub extern "c" fn emscripten_dlopen_promise(filename: [*:0]const u8, flags: c_int) em_promise_t; pub extern "c" fn emscripten_throw_number(number: f64) void; @@ -1024,7 +1024,7 @@ pub const struct__em_promise = opaque {}; pub const em_promise_t = ?*struct__em_promise; pub const enum_em_promise_result_t = c_uint; pub const em_promise_result_t = enum_em_promise_result_t; -pub const em_promise_callback_t = ?*const fn (?*?*anyopaque, ?*anyopaque, ?*anyopaque) callconv(.C) em_promise_result_t; +pub const em_promise_callback_t = ?*const fn (?*?*anyopaque, ?*anyopaque, ?*anyopaque) callconv(.c) em_promise_result_t; pub extern "c" fn emscripten_promise_create() em_promise_t; pub extern "c" fn emscripten_promise_destroy(promise: em_promise_t) void; diff --git a/lib/std/os/linux.zig b/lib/std/os/linux.zig index 85a98a574f66..09d82b8a6181 100644 --- a/lib/std/os/linux.zig +++ b/lib/std/os/linux.zig @@ -67,7 +67,7 @@ pub const syscall_pipe = syscall_bits.syscall_pipe; pub const syscall_fork = syscall_bits.syscall_fork; pub fn clone( - func: *const fn (arg: usize) callconv(.C) u8, + func: *const fn (arg: usize) callconv(.c) u8, stack: usize, flags: u32, arg: usize, @@ -77,14 +77,14 @@ pub fn clone( ) usize { // Can't directly call a naked function; cast to C calling convention first. return @as(*const fn ( - *const fn (arg: usize) callconv(.C) u8, + *const fn (arg: usize) callconv(.c) u8, usize, u32, usize, ?*i32, usize, ?*i32, - ) callconv(.C) usize, @ptrCast(&syscall_bits.clone))(func, stack, flags, arg, ptid, tp, ctid); + ) callconv(.c) usize, @ptrCast(&syscall_bits.clone))(func, stack, flags, arg, ptid, tp, ctid); } pub const ARCH = arch_bits.ARCH; @@ -494,7 +494,7 @@ pub const getauxval = if (extern_getauxval) struct { extern fn getauxval(index: usize) usize; }.getauxval else getauxvalImpl; -fn getauxvalImpl(index: usize) callconv(.C) usize { +fn getauxvalImpl(index: usize) callconv(.c) usize { const auxv = elf_aux_maybe orelse return 0; var i: usize = 0; while (auxv[i].a_type != std.elf.AT_NULL) : (i += 1) { @@ -1485,7 +1485,7 @@ pub fn flock(fd: fd_t, operation: i32) usize { } // We must follow the C calling convention when we call into the VDSO -const VdsoClockGettime = *align(1) const fn (clockid_t, *timespec) callconv(.C) usize; +const VdsoClockGettime = *align(1) const fn (clockid_t, *timespec) callconv(.c) usize; var vdso_clock_gettime: ?VdsoClockGettime = &init_vdso_clock_gettime; pub fn clock_gettime(clk_id: clockid_t, tp: *timespec) usize { @@ -1502,7 +1502,7 @@ pub fn clock_gettime(clk_id: clockid_t, tp: *timespec) usize { return syscall2(.clock_gettime, @intFromEnum(clk_id), @intFromPtr(tp)); } -fn init_vdso_clock_gettime(clk: clockid_t, ts: *timespec) callconv(.C) usize { +fn init_vdso_clock_gettime(clk: clockid_t, ts: *timespec) callconv(.c) usize { const ptr: ?VdsoClockGettime = @ptrFromInt(vdso.lookup(VDSO.CGT_VER, VDSO.CGT_SYM)); // Note that we may not have a VDSO at all, update the stub address anyway // so that clock_gettime will fall back on the good old (and slow) syscall @@ -5070,8 +5070,8 @@ pub const all_mask: sigset_t = [_]u32{0xffffffff} ** @typeInfo(sigset_t).array.l pub const app_mask: sigset_t = [2]u32{ 0xfffffffc, 0x7fffffff } ++ [_]u32{0xffffffff} ** 30; const k_sigaction_funcs = struct { - const handler = ?*align(1) const fn (i32) callconv(.C) void; - const restorer = *const fn () callconv(.C) void; + const handler = ?*align(1) const fn (i32) callconv(.c) void; + const restorer = *const fn () callconv(.c) void; }; pub const k_sigaction = switch (native_arch) { @@ -5097,8 +5097,8 @@ pub const k_sigaction = switch (native_arch) { /// Renamed from `sigaction` to `Sigaction` to avoid conflict with the syscall. pub const Sigaction = extern struct { - pub const handler_fn = *align(1) const fn (i32) callconv(.C) void; - pub const sigaction_fn = *const fn (i32, *const siginfo_t, ?*anyopaque) callconv(.C) void; + pub const handler_fn = *align(1) const fn (i32) callconv(.c) void; + pub const sigaction_fn = *const fn (i32, *const siginfo_t, ?*anyopaque) callconv(.c) void; handler: extern union { handler: ?handler_fn, @@ -5106,7 +5106,7 @@ pub const Sigaction = extern struct { }, mask: sigset_t, flags: c_uint, - restorer: ?*const fn () callconv(.C) void = null, + restorer: ?*const fn () callconv(.c) void = null, }; const sigset_len = @typeInfo(sigset_t).array.len; diff --git a/lib/std/os/linux/sparc64.zig b/lib/std/os/linux/sparc64.zig index d81e6fb40a78..17df65feb72d 100644 --- a/lib/std/os/linux/sparc64.zig +++ b/lib/std/os/linux/sparc64.zig @@ -233,7 +233,7 @@ pub const restore = restore_rt; // Need to use C ABI here instead of naked // to prevent an infinite loop when calling rt_sigreturn. -pub fn restore_rt() callconv(.C) void { +pub fn restore_rt() callconv(.c) void { return asm volatile ("t 0x6d" : : [number] "{g1}" (@intFromEnum(SYS.rt_sigreturn)), diff --git a/lib/std/os/plan9.zig b/lib/std/os/plan9.zig index 0c48493b4cd6..90f45ef7fb48 100644 --- a/lib/std/os/plan9.zig +++ b/lib/std/os/plan9.zig @@ -186,8 +186,8 @@ pub const empty_sigset = 0; pub const siginfo_t = c_long; // TODO plan9 doesn't have sigaction_fn. Sigaction is not a union, but we include it here to be compatible. pub const Sigaction = extern struct { - pub const handler_fn = *const fn (i32) callconv(.C) void; - pub const sigaction_fn = *const fn (i32, *const siginfo_t, ?*anyopaque) callconv(.C) void; + pub const handler_fn = *const fn (i32) callconv(.c) void; + pub const sigaction_fn = *const fn (i32, *const siginfo_t, ?*anyopaque) callconv(.c) void; handler: extern union { handler: ?handler_fn, diff --git a/lib/std/os/uefi/tables/boot_services.zig b/lib/std/os/uefi/tables/boot_services.zig index 04d912753b16..4ef346db4100 100644 --- a/lib/std/os/uefi/tables/boot_services.zig +++ b/lib/std/os/uefi/tables/boot_services.zig @@ -149,11 +149,11 @@ pub const BootServices = extern struct { /// Installs one or more protocol interfaces into the boot services environment // TODO: use callconv(cc) instead once that works - installMultipleProtocolInterfaces: *const fn (handle: *Handle, ...) callconv(.C) Status, + installMultipleProtocolInterfaces: *const fn (handle: *Handle, ...) callconv(.c) Status, /// Removes one or more protocol interfaces into the boot services environment // TODO: use callconv(cc) instead once that works - uninstallMultipleProtocolInterfaces: *const fn (handle: *Handle, ...) callconv(.C) Status, + uninstallMultipleProtocolInterfaces: *const fn (handle: *Handle, ...) callconv(.c) Status, /// Computes and returns a 32-bit CRC for a data buffer. calculateCrc32: *const fn (data: [*]const u8, data_size: usize, *u32) callconv(cc) Status, diff --git a/lib/std/posix.zig b/lib/std/posix.zig index 100500bec40c..f07421fdc19b 100644 --- a/lib/std/posix.zig +++ b/lib/std/posix.zig @@ -5552,7 +5552,7 @@ pub fn dl_iterate_phdr( if (builtin.link_libc) { switch (system.dl_iterate_phdr(struct { - fn callbackC(info: *dl_phdr_info, size: usize, data: ?*anyopaque) callconv(.C) c_int { + fn callbackC(info: *dl_phdr_info, size: usize, data: ?*anyopaque) callconv(.c) c_int { const context_ptr: *const Context = @ptrCast(@alignCast(data)); callback(info, size, context_ptr.*) catch |err| return @intFromError(err); return 0; diff --git a/lib/std/posix/test.zig b/lib/std/posix/test.zig index dba7dcde6d9c..653637c0a7cc 100644 --- a/lib/std/posix/test.zig +++ b/lib/std/posix/test.zig @@ -849,7 +849,7 @@ test "sigaction" { const S = struct { var handler_called_count: u32 = 0; - fn handler(sig: i32, info: *const posix.siginfo_t, ctx_ptr: ?*anyopaque) callconv(.C) void { + fn handler(sig: i32, info: *const posix.siginfo_t, ctx_ptr: ?*anyopaque) callconv(.c) void { _ = ctx_ptr; // Check that we received the correct signal. switch (native_os) { diff --git a/lib/std/testing.zig b/lib/std/testing.zig index fb75672fbd4f..4d334b340796 100644 --- a/lib/std/testing.zig +++ b/lib/std/testing.zig @@ -100,13 +100,13 @@ fn expectEqualInner(comptime T: type, expected: T, actual: T) !void { .pointer => |pointer| { switch (pointer.size) { - .One, .Many, .C => { + .one, .many, .c => { if (actual != expected) { print("expected {*}, found {*}\n", .{ expected, actual }); return error.TestExpectedEqual; } }, - .Slice => { + .slice => { if (actual.ptr != expected.ptr) { print("expected slice ptr {*}, found {*}\n", .{ expected.ptr, actual.ptr }); return error.TestExpectedEqual; @@ -726,13 +726,13 @@ fn expectEqualDeepInner(comptime T: type, expected: T, actual: T) error{TestExpe .pointer => |pointer| { switch (pointer.size) { // We have no idea what is behind those pointers, so the best we can do is `==` check. - .C, .Many => { + .c, .many => { if (actual != expected) { print("expected {*}, found {*}\n", .{ expected, actual }); return error.TestExpectedEqual; } }, - .One => { + .one => { // Length of those pointers are runtime value, so the best we can do is `==` check. switch (@typeInfo(pointer.child)) { .@"fn", .@"opaque" => { @@ -744,7 +744,7 @@ fn expectEqualDeepInner(comptime T: type, expected: T, actual: T) error{TestExpe else => try expectEqualDeep(expected.*, actual.*), } }, - .Slice => { + .slice => { if (expected.len != actual.len) { print("Slice len not the same, expected {d}, found {d}\n", .{ expected.len, actual.len }); return error.TestExpectedEqual; diff --git a/lib/std/zig/Ast.zig b/lib/std/zig/Ast.zig index 335168322f55..3f69ce5aeb6b 100644 --- a/lib/std/zig/Ast.zig +++ b/lib/std/zig/Ast.zig @@ -2157,14 +2157,13 @@ fn fullFnProtoComponents(tree: Ast, info: full.FnProto.Components) full.FnProto fn fullPtrTypeComponents(tree: Ast, info: full.PtrType.Components) full.PtrType { const token_tags = tree.tokens.items(.tag); - const Size = std.builtin.Type.Pointer.Size; - const size: Size = switch (token_tags[info.main_token]) { + const size: std.builtin.Type.Pointer.Size = switch (token_tags[info.main_token]) { .asterisk, .asterisk_asterisk, - => .One, + => .one, .l_bracket => switch (token_tags[info.main_token + 1]) { - .asterisk => if (token_tags[info.main_token + 2] == .identifier) Size.C else Size.Many, - else => Size.Slice, + .asterisk => if (token_tags[info.main_token + 2] == .identifier) .c else .many, + else => .slice, }, else => unreachable, }; @@ -2180,7 +2179,7 @@ fn fullPtrTypeComponents(tree: Ast, info: full.PtrType.Components) full.PtrType // positives. Therefore, start after a sentinel if there is one and // skip over any align node and bit range nodes. var i = if (info.sentinel != 0) tree.lastToken(info.sentinel) + 1 else switch (size) { - .Many, .C => info.main_token + 1, + .many, .c => info.main_token + 1, else => info.main_token, }; const end = tree.firstToken(info.child_type); diff --git a/lib/std/zig/AstGen.zig b/lib/std/zig/AstGen.zig index 2936f9bc3de4..aeb4b7a311c7 100644 --- a/lib/std/zig/AstGen.zig +++ b/lib/std/zig/AstGen.zig @@ -3917,7 +3917,7 @@ fn ptrType( node: Ast.Node.Index, ptr_info: Ast.full.PtrType, ) InnerError!Zir.Inst.Ref { - if (ptr_info.size == .C and ptr_info.allowzero_token != null) { + if (ptr_info.size == .c and ptr_info.allowzero_token != null) { return gz.astgen.failTok(ptr_info.allowzero_token.?, "C pointers always allow address zero", .{}); } @@ -3946,7 +3946,7 @@ fn ptrType( .{ .rl = .{ .ty = elem_type } }, ptr_info.ast.sentinel, switch (ptr_info.size) { - .Slice => .slice_sentinel, + .slice => .slice_sentinel, else => .pointer_sentinel, }, ); diff --git a/lib/std/zig/c_translation.zig b/lib/std/zig/c_translation.zig index 39f7fa9a113f..92a20ac62d01 100644 --- a/lib/std/zig/c_translation.zig +++ b/lib/std/zig/c_translation.zig @@ -170,7 +170,7 @@ pub fn sizeof(target: anytype) usize { } }, .pointer => |ptr| { - if (ptr.size == .Slice) { + if (ptr.size == .slice) { @compileError("Cannot use C sizeof on slice type " ++ @typeName(T)); } // for strings, sizeof("a") returns 2. @@ -178,12 +178,9 @@ pub fn sizeof(target: anytype) usize { // in the .array case above, but strings remain literals // and are therefore always pointers, so they need to be // specially handled here. - if (ptr.size == .One and ptr.is_const and @typeInfo(ptr.child) == .array) { + if (ptr.size == .one and ptr.is_const and @typeInfo(ptr.child) == .array) { const array_info = @typeInfo(ptr.child).array; - if ((array_info.child == u8 or array_info.child == u16) and - array_info.sentinel != null and - @as(*align(1) const array_info.child, @ptrCast(array_info.sentinel.?)).* == 0) - { + if ((array_info.child == u8 or array_info.child == u16) and array_info.sentinel() == 0) { // length of the string plus one for the null terminator. return (array_info.len + 1) * @sizeOf(array_info.child); } @@ -341,14 +338,14 @@ pub fn FlexibleArrayType(comptime SelfType: type, comptime ElementType: type) ty switch (@typeInfo(SelfType)) { .pointer => |ptr| { return @Type(.{ .pointer = .{ - .size = .C, + .size = .c, .is_const = ptr.is_const, .is_volatile = ptr.is_volatile, .alignment = @alignOf(ElementType), .address_space = .generic, .child = ElementType, .is_allowzero = true, - .sentinel = null, + .sentinel_ptr = null, } }); }, else => |info| @compileError("Invalid self type \"" ++ @tagName(info) ++ "\" for flexible array getter: " ++ @typeName(SelfType)), diff --git a/lib/std/zig/parser_test.zig b/lib/std/zig/parser_test.zig index 526181654472..f87d2827396a 100644 --- a/lib/std/zig/parser_test.zig +++ b/lib/std/zig/parser_test.zig @@ -552,7 +552,7 @@ test "zig fmt: trailing comma in fn parameter list" { \\pub fn f( \\ a: i32, \\ b: i32, - \\) callconv(.C) i32 {} + \\) callconv(.c) i32 {} \\pub fn f( \\ a: i32, \\ b: i32, @@ -560,15 +560,15 @@ test "zig fmt: trailing comma in fn parameter list" { \\pub fn f( \\ a: i32, \\ b: i32, - \\) align(8) callconv(.C) i32 {} + \\) align(8) callconv(.c) i32 {} \\pub fn f( \\ a: i32, \\ b: i32, - \\) align(8) linksection(".text") callconv(.C) i32 {} + \\) align(8) linksection(".text") callconv(.c) i32 {} \\pub fn f( \\ a: i32, \\ b: i32, - \\) linksection(".text") callconv(.C) i32 {} + \\) linksection(".text") callconv(.c) i32 {} \\ ); } diff --git a/lib/std/zig/render.zig b/lib/std/zig/render.zig index b71c94e71fd2..2f0fd57e46f7 100644 --- a/lib/std/zig/render.zig +++ b/lib/std/zig/render.zig @@ -938,7 +938,7 @@ fn renderArrayType( fn renderPtrType(r: *Render, ptr_type: Ast.full.PtrType, space: Space) Error!void { const tree = r.tree; switch (ptr_type.size) { - .One => { + .one => { // Since ** tokens exist and the same token is shared by two // nested pointer types, we check to see if we are the parent // in such a relationship. If so, skip rendering anything for @@ -951,7 +951,7 @@ fn renderPtrType(r: *Render, ptr_type: Ast.full.PtrType, space: Space) Error!voi } try renderToken(r, ptr_type.ast.main_token, .none); // asterisk }, - .Many => { + .many => { if (ptr_type.ast.sentinel == 0) { try renderToken(r, ptr_type.ast.main_token, .none); // lbracket try renderToken(r, ptr_type.ast.main_token + 1, .none); // asterisk @@ -964,13 +964,13 @@ fn renderPtrType(r: *Render, ptr_type: Ast.full.PtrType, space: Space) Error!voi try renderToken(r, tree.lastToken(ptr_type.ast.sentinel) + 1, .none); // rbracket } }, - .C => { + .c => { try renderToken(r, ptr_type.ast.main_token, .none); // lbracket try renderToken(r, ptr_type.ast.main_token + 1, .none); // asterisk try renderToken(r, ptr_type.ast.main_token + 2, .none); // c try renderToken(r, ptr_type.ast.main_token + 3, .none); // rbracket }, - .Slice => { + .slice => { if (ptr_type.ast.sentinel == 0) { try renderToken(r, ptr_type.ast.main_token, .none); // lbracket try renderToken(r, ptr_type.ast.main_token + 1, .none); // rbracket diff --git a/lib/std/zig/system/x86.zig b/lib/std/zig/system/x86.zig index c268c7da6b25..7bd1148e13e9 100644 --- a/lib/std/zig/system/x86.zig +++ b/lib/std/zig/system/x86.zig @@ -475,7 +475,7 @@ const CpuidLeaf = packed struct { /// This is a workaround for the C backend until zig has the ability to put /// C code in inline assembly. -extern fn zig_x86_cpuid(leaf_id: u32, subid: u32, eax: *u32, ebx: *u32, ecx: *u32, edx: *u32) callconv(.C) void; +extern fn zig_x86_cpuid(leaf_id: u32, subid: u32, eax: *u32, ebx: *u32, ecx: *u32, edx: *u32) callconv(.c) void; fn cpuid(leaf_id: u32, subid: u32) CpuidLeaf { // valid for both x86 and x86_64 @@ -502,7 +502,7 @@ fn cpuid(leaf_id: u32, subid: u32) CpuidLeaf { /// This is a workaround for the C backend until zig has the ability to put /// C code in inline assembly. -extern fn zig_x86_get_xcr0() callconv(.C) u32; +extern fn zig_x86_get_xcr0() callconv(.c) u32; // Read control register 0 (XCR0). Used to detect features such as AVX. fn getXCR0() u32 { diff --git a/src/InternPool.zig b/src/InternPool.zig index 30a0dd087c62..36ddfda857d3 100644 --- a/src/InternPool.zig +++ b/src/InternPool.zig @@ -1134,7 +1134,7 @@ const Local = struct { for (&new_fields, elem_fields) |*new_field, elem_field| new_field.* = .{ .name = elem_field.name, .type = *[len]elem_field.type, - .default_value = null, + .default_value_ptr = null, .is_comptime = false, .alignment = 0, }; @@ -1162,9 +1162,9 @@ const Local = struct { .address_space = .generic, .child = elem_field.type, .is_allowzero = false, - .sentinel = null, + .sentinel_ptr = null, } }), - .default_value = null, + .default_value_ptr = null, .is_comptime = false, .alignment = 0, }; @@ -1176,17 +1176,17 @@ const Local = struct { } }); } - pub fn addOne(mutable: Mutable) Allocator.Error!PtrElem(.{ .size = .One }) { + pub fn addOne(mutable: Mutable) Allocator.Error!PtrElem(.{ .size = .one }) { try mutable.ensureUnusedCapacity(1); return mutable.addOneAssumeCapacity(); } - pub fn addOneAssumeCapacity(mutable: Mutable) PtrElem(.{ .size = .One }) { + pub fn addOneAssumeCapacity(mutable: Mutable) PtrElem(.{ .size = .one }) { const index = mutable.mutate.len; assert(index < mutable.list.header().capacity); mutable.mutate.len = index + 1; const mutable_view = mutable.view().slice(); - var ptr: PtrElem(.{ .size = .One }) = undefined; + var ptr: PtrElem(.{ .size = .one }) = undefined; inline for (fields) |field| { @field(ptr, @tagName(field)) = &mutable_view.items(field)[index]; } @@ -1206,7 +1206,7 @@ const Local = struct { pub fn appendSliceAssumeCapacity( mutable: Mutable, - slice: PtrElem(.{ .size = .Slice, .is_const = true }), + slice: PtrElem(.{ .size = .slice, .is_const = true }), ) void { if (fields.len == 0) return; const start = mutable.mutate.len; @@ -1253,17 +1253,17 @@ const Local = struct { return ptr_array; } - pub fn addManyAsSlice(mutable: Mutable, len: usize) Allocator.Error!PtrElem(.{ .size = .Slice }) { + pub fn addManyAsSlice(mutable: Mutable, len: usize) Allocator.Error!PtrElem(.{ .size = .slice }) { try mutable.ensureUnusedCapacity(len); return mutable.addManyAsSliceAssumeCapacity(len); } - pub fn addManyAsSliceAssumeCapacity(mutable: Mutable, len: usize) PtrElem(.{ .size = .Slice }) { + pub fn addManyAsSliceAssumeCapacity(mutable: Mutable, len: usize) PtrElem(.{ .size = .slice }) { const start = mutable.mutate.len; assert(len <= mutable.list.header().capacity - start); mutable.mutate.len = @intCast(start + len); const mutable_view = mutable.view().slice(); - var slice: PtrElem(.{ .size = .Slice }) = undefined; + var slice: PtrElem(.{ .size = .slice }) = undefined; inline for (fields) |field| { @field(slice, @tagName(field)) = mutable_view.items(field)[start..][0..len]; } @@ -2060,7 +2060,7 @@ pub const Key = union(enum) { }; pub const Flags = packed struct(u32) { - size: Size = .One, + size: Size = .one, /// `none` indicates the ABI alignment of the pointee_type. In this /// case, this field *must* be set to `none`, otherwise the /// `InternPool` equality and hashing functions will return incorrect @@ -4891,7 +4891,7 @@ pub const Index = enum(u32) { checkField(name ++ ".?", info.child); }, .pointer => |info| { - assert(info.size == .Slice); + assert(info.size == .slice); checkConfig(name ++ ".len"); checkField(name ++ "[0]", info.child); }, @@ -5016,7 +5016,7 @@ pub const static_keys = [_]Key{ .{ .ptr_type = .{ .child = .u8_type, .flags = .{ - .size = .Many, + .size = .many, }, } }, @@ -5024,7 +5024,7 @@ pub const static_keys = [_]Key{ .{ .ptr_type = .{ .child = .u8_type, .flags = .{ - .size = .Many, + .size = .many, .is_const = true, }, } }, @@ -5034,7 +5034,7 @@ pub const static_keys = [_]Key{ .child = .u8_type, .sentinel = .zero_u8, .flags = .{ - .size = .Many, + .size = .many, .is_const = true, }, } }, @@ -5043,7 +5043,7 @@ pub const static_keys = [_]Key{ .{ .ptr_type = .{ .child = .comptime_int_type, .flags = .{ - .size = .One, + .size = .one, .is_const = true, }, } }, @@ -5052,7 +5052,7 @@ pub const static_keys = [_]Key{ .{ .ptr_type = .{ .child = .u8_type, .flags = .{ - .size = .Slice, + .size = .slice, .is_const = true, }, } }, @@ -5062,7 +5062,7 @@ pub const static_keys = [_]Key{ .child = .u8_type, .sentinel = .zero_u8, .flags = .{ - .size = .Slice, + .size = .slice, .is_const = true, }, } }, @@ -6749,7 +6749,7 @@ pub fn indexToKey(ip: *const InternPool, index: Index) Key { const many_ptr_item = many_ptr_unwrapped.getItem(ip); assert(many_ptr_item.tag == .type_pointer); var ptr_info = extraData(many_ptr_unwrapped.getExtra(ip), Tag.TypePointer, many_ptr_item.data); - ptr_info.flags.size = .Slice; + ptr_info.flags.size = .slice; return .{ .ptr_type = ptr_info }; }, @@ -7572,10 +7572,10 @@ pub fn get(ip: *InternPool, gpa: Allocator, tid: Zcu.PerThread.Id, key: Key) All assert(ptr_type.child != .none); assert(ptr_type.sentinel == .none or ip.typeOf(ptr_type.sentinel) == ptr_type.child); - if (ptr_type.flags.size == .Slice) { + if (ptr_type.flags.size == .slice) { gop.cancel(); var new_key = key; - new_key.ptr_type.flags.size = .Many; + new_key.ptr_type.flags.size = .many; const ptr_type_index = try ip.get(gpa, tid, new_key); gop = try ip.getOrPutKey(gpa, tid, key); @@ -7588,7 +7588,7 @@ pub fn get(ip: *InternPool, gpa: Allocator, tid: Zcu.PerThread.Id, key: Key) All } var ptr_type_adjusted = ptr_type; - if (ptr_type.flags.size == .C) ptr_type_adjusted.flags.is_allowzero = true; + if (ptr_type.flags.size == .c) ptr_type_adjusted.flags.is_allowzero = true; items.appendAssumeCapacity(.{ .tag = .type_pointer, @@ -7731,8 +7731,8 @@ pub fn get(ip: *InternPool, gpa: Allocator, tid: Zcu.PerThread.Id, key: Key) All }, .slice => |slice| { - assert(ip.indexToKey(slice.ty).ptr_type.flags.size == .Slice); - assert(ip.indexToKey(ip.typeOf(slice.ptr)).ptr_type.flags.size == .Many); + assert(ip.indexToKey(slice.ty).ptr_type.flags.size == .slice); + assert(ip.indexToKey(ip.typeOf(slice.ptr)).ptr_type.flags.size == .many); items.appendAssumeCapacity(.{ .tag = .ptr_slice, .data = try addExtra(extra, PtrSlice{ @@ -7745,7 +7745,7 @@ pub fn get(ip: *InternPool, gpa: Allocator, tid: Zcu.PerThread.Id, key: Key) All .ptr => |ptr| { const ptr_type = ip.indexToKey(ptr.ty).ptr_type; - assert(ptr_type.flags.size != .Slice); + assert(ptr_type.flags.size != .slice); items.appendAssumeCapacity(switch (ptr.base_addr) { .nav => |nav| .{ .tag = .ptr_nav, @@ -7804,9 +7804,9 @@ pub fn get(ip: *InternPool, gpa: Allocator, tid: Zcu.PerThread.Id, key: Key) All .arr_elem, .field => |base_index| { const base_ptr_type = ip.indexToKey(ip.typeOf(base_index.base)).ptr_type; switch (ptr.base_addr) { - .arr_elem => assert(base_ptr_type.flags.size == .Many), + .arr_elem => assert(base_ptr_type.flags.size == .many), .field => { - assert(base_ptr_type.flags.size == .One); + assert(base_ptr_type.flags.size == .one); switch (ip.indexToKey(base_ptr_type.child)) { .tuple_type => |tuple_type| { assert(ptr.base_addr == .field); @@ -7823,7 +7823,7 @@ pub fn get(ip: *InternPool, gpa: Allocator, tid: Zcu.PerThread.Id, key: Key) All }, .ptr_type => |slice_type| { assert(ptr.base_addr == .field); - assert(slice_type.flags.size == .Slice); + assert(slice_type.flags.size == .slice); assert(base_index.index < 2); }, else => unreachable, @@ -10314,12 +10314,12 @@ pub fn getCoerced( } }); if (ip.isPointerType(new_ty)) switch (ip.indexToKey(new_ty).ptr_type.flags.size) { - .One, .Many, .C => return ip.get(gpa, tid, .{ .ptr = .{ + .one, .many, .c => return ip.get(gpa, tid, .{ .ptr = .{ .ty = new_ty, .base_addr = .int, .byte_offset = 0, } }), - .Slice => return ip.get(gpa, tid, .{ .slice = .{ + .slice => return ip.get(gpa, tid, .{ .slice = .{ .ty = new_ty, .ptr = try ip.get(gpa, tid, .{ .ptr = .{ .ty = ip.slicePtrType(new_ty), @@ -10408,7 +10408,7 @@ pub fn getCoerced( }, else => {}, }, - .slice => |slice| if (ip.isPointerType(new_ty) and ip.indexToKey(new_ty).ptr_type.flags.size == .Slice) + .slice => |slice| if (ip.isPointerType(new_ty) and ip.indexToKey(new_ty).ptr_type.flags.size == .slice) return ip.get(gpa, tid, .{ .slice = .{ .ty = new_ty, .ptr = try ip.getCoerced(gpa, tid, slice.ptr, ip.slicePtrType(new_ty)), @@ -10416,7 +10416,7 @@ pub fn getCoerced( } }) else if (ip.isIntegerType(new_ty)) return ip.getCoerced(gpa, tid, slice.ptr, new_ty), - .ptr => |ptr| if (ip.isPointerType(new_ty) and ip.indexToKey(new_ty).ptr_type.flags.size != .Slice) + .ptr => |ptr| if (ip.isPointerType(new_ty) and ip.indexToKey(new_ty).ptr_type.flags.size != .slice) return ip.get(gpa, tid, .{ .ptr = .{ .ty = new_ty, .base_addr = ptr.base_addr, @@ -10433,12 +10433,12 @@ pub fn getCoerced( .opt => |opt| switch (ip.indexToKey(new_ty)) { .ptr_type => |ptr_type| return switch (opt.val) { .none => switch (ptr_type.flags.size) { - .One, .Many, .C => try ip.get(gpa, tid, .{ .ptr = .{ + .one, .many, .c => try ip.get(gpa, tid, .{ .ptr = .{ .ty = new_ty, .base_addr = .int, .byte_offset = 0, } }), - .Slice => try ip.get(gpa, tid, .{ .slice = .{ + .slice => try ip.get(gpa, tid, .{ .slice = .{ .ty = new_ty, .ptr = try ip.get(gpa, tid, .{ .ptr = .{ .ty = ip.slicePtrType(new_ty), diff --git a/src/Sema.zig b/src/Sema.zig index 4a62e495c7f7..8d8f4590959a 100644 --- a/src/Sema.zig +++ b/src/Sema.zig @@ -2479,7 +2479,7 @@ fn typeSupportsFieldAccess(zcu: *const Zcu, ty: Type, field_name: InternPool.Nul .array => return field_name.eqlSlice("len", ip), .pointer => { const ptr_info = ty.ptrInfo(zcu); - if (ptr_info.flags.size == .Slice) { + if (ptr_info.flags.size == .slice) { return field_name.eqlSlice("ptr", ip) or field_name.eqlSlice("len", ip); } else if (Type.fromInterned(ptr_info.child).zigTypeTag(zcu) == .array) { return field_name.eqlSlice("len", ip); @@ -2713,8 +2713,18 @@ fn analyzeValueAsCallconv( src: LazySrcLoc, unresolved_val: Value, ) !std.builtin.CallingConvention { + return interpretBuiltinType(sema, block, src, unresolved_val, std.builtin.CallingConvention); +} + +fn interpretBuiltinType( + sema: *Sema, + block: *Block, + src: LazySrcLoc, + unresolved_val: Value, + comptime T: type, +) !T { const resolved_val = try sema.resolveLazyValue(unresolved_val); - return resolved_val.interpret(std.builtin.CallingConvention, sema.pt) catch |err| switch (err) { + return resolved_val.interpret(T, sema.pt) catch |err| switch (err) { error.OutOfMemory => |e| return e, error.UndefinedValue => return sema.failWithUseOfUndef(block, src), error.TypeMismatch => @panic("std.builtin is corrupt"), @@ -3653,7 +3663,7 @@ fn indexablePtrLenOrNone( const zcu = pt.zcu; const operand_ty = sema.typeOf(operand); try checkMemOperand(sema, block, src, operand_ty); - if (operand_ty.ptrSize(zcu) == .Many) return .none; + if (operand_ty.ptrSize(zcu) == .many) return .none; const field_name = try zcu.intern_pool.getOrPutString(sema.gpa, pt.tid, "len", .no_embedded_nulls); return sema.fieldVal(block, src, operand, field_name, src); } @@ -4544,7 +4554,7 @@ fn zirCoercePtrElemTy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileE assert(ptr_ty.zigTypeTag(zcu) == .pointer); // validated by a previous instruction const elem_ty = ptr_ty.childType(zcu); switch (ptr_ty.ptrSize(zcu)) { - .One => { + .one => { const uncoerced_ty = sema.typeOf(uncoerced_val); if (elem_ty.zigTypeTag(zcu) == .array and elem_ty.childType(zcu).toIntern() == uncoerced_ty.toIntern()) { // We're trying to initialize a *[1]T with a reference to a T - don't perform any coercion. @@ -4557,7 +4567,7 @@ fn zirCoercePtrElemTy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileE return sema.coerce(block, elem_ty, uncoerced_val, src); } }, - .Slice, .Many => { + .slice, .many => { // Our goal is to coerce `uncoerced_val` to an array of `elem_ty`. const val_ty = sema.typeOf(uncoerced_val); switch (val_ty.zigTypeTag(zcu)) { @@ -4573,7 +4583,7 @@ fn zirCoercePtrElemTy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileE }); return sema.coerce(block, want_ty, uncoerced_val, src); }, - .C => { + .c => { // There's nothing meaningful to do here, because we don't know if this is meant to be a // single-pointer or a many-pointer. return uncoerced_val; @@ -4685,7 +4695,7 @@ fn zirValidateArrayInitRefTy( assert(ptr_ty.zigTypeTag(zcu) == .pointer); // validated by a previous instruction switch (zcu.intern_pool.indexToKey(ptr_ty.toIntern())) { .ptr_type => |ptr_type| switch (ptr_type.flags.size) { - .Slice, .Many => { + .slice, .many => { // Use array of correct length const arr_ty = try pt.arrayType(.{ .len = extra.elem_count, @@ -5502,9 +5512,9 @@ fn zirValidateDeref(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErr if (operand_ty.zigTypeTag(zcu) != .pointer) { return sema.fail(block, src, "cannot dereference non-pointer type '{}'", .{operand_ty.fmt(pt)}); } else switch (operand_ty.ptrSize(zcu)) { - .One, .C => {}, - .Many => return sema.fail(block, src, "index syntax required for unknown-length pointer type '{}'", .{operand_ty.fmt(pt)}), - .Slice => return sema.fail(block, src, "index syntax required for slice type '{}'", .{operand_ty.fmt(pt)}), + .one, .c => {}, + .many => return sema.fail(block, src, "index syntax required for unknown-length pointer type '{}'", .{operand_ty.fmt(pt)}), + .slice => return sema.fail(block, src, "index syntax required for slice type '{}'", .{operand_ty.fmt(pt)}), } if ((try sema.typeHasOnePossibleValue(operand_ty.childType(zcu))) != null) { @@ -6521,7 +6531,7 @@ fn zirExport(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void return sema.fail(block, ptr_src, "expected pointer type, found '{}'", .{ptr_ty.fmt(pt)}); } const ptr_ty_info = ptr_ty.ptrInfo(zcu); - if (ptr_ty_info.flags.size == .Slice) { + if (ptr_ty_info.flags.size == .slice) { return sema.fail(block, ptr_src, "export target cannot be slice", .{}); } if (ptr_ty_info.packed_offset.host_size != 0) { @@ -7271,7 +7281,7 @@ fn checkCallArgumentCount( .@"fn" => break :func_ty callee_ty, .pointer => { const ptr_info = callee_ty.ptrInfo(zcu); - if (ptr_info.flags.size == .One and Type.fromInterned(ptr_info.child).zigTypeTag(zcu) == .@"fn") { + if (ptr_info.flags.size == .one and Type.fromInterned(ptr_info.child).zigTypeTag(zcu) == .@"fn") { break :func_ty Type.fromInterned(ptr_info.child); } }, @@ -7350,7 +7360,7 @@ fn callBuiltin( .@"fn" => break :func_ty callee_ty, .pointer => { const ptr_info = callee_ty.ptrInfo(zcu); - if (ptr_info.flags.size == .One and Type.fromInterned(ptr_info.child).zigTypeTag(zcu) == .@"fn") { + if (ptr_info.flags.size == .one and Type.fromInterned(ptr_info.child).zigTypeTag(zcu) == .@"fn") { break :func_ty Type.fromInterned(ptr_info.child); } }, @@ -8344,8 +8354,8 @@ fn zirIndexablePtrElemType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Com }; try sema.checkMemOperand(block, src, ptr_ty); const elem_ty = switch (ptr_ty.ptrSize(zcu)) { - .Slice, .Many, .C => ptr_ty.childType(zcu), - .One => ptr_ty.childType(zcu).childType(zcu), + .slice, .many, .c => ptr_ty.childType(zcu), + .one => ptr_ty.childType(zcu).childType(zcu), }; return Air.internedToRef(elem_ty.toIntern()); } @@ -8943,7 +8953,7 @@ fn zirOptionalPayload( const result_ty = switch (operand_ty.zigTypeTag(zcu)) { .optional => operand_ty.optionalChild(zcu), .pointer => t: { - if (operand_ty.ptrSize(zcu) != .C) { + if (operand_ty.ptrSize(zcu) != .c) { return sema.failWithExpectedOptionalType(block, src, operand_ty); } // TODO https://github.com/ziglang/zig/issues/6597 @@ -13972,7 +13982,7 @@ fn zirHasField(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai const has_field = hf: { switch (ip.indexToKey(ty.toIntern())) { .ptr_type => |ptr_type| switch (ptr_type.flags.size) { - .Slice => { + .slice => { if (field_name.eqlSlice("ptr", ip)) break :hf true; if (field_name.eqlSlice("len", ip)) break :hf true; break :hf false; @@ -14797,7 +14807,7 @@ fn zirArrayCat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai const slice_ty = try pt.ptrTypeSema(.{ .child = resolved_elem_ty.toIntern(), .flags = .{ - .size = .Slice, + .size = .slice, .address_space = ptr_as, }, }); @@ -14925,7 +14935,7 @@ fn getArrayCatInfo(sema: *Sema, block: *Block, src: LazySrcLoc, operand: Air.Ins .pointer => { const ptr_info = operand_ty.ptrInfo(zcu); switch (ptr_info.flags.size) { - .Slice => { + .slice => { const val = try sema.resolveConstDefinedValue(block, src, operand, .{ .simple = .slice_cat_operand }); return Type.ArrayInfo{ .elem_type = Type.fromInterned(ptr_info.child), @@ -14936,12 +14946,12 @@ fn getArrayCatInfo(sema: *Sema, block: *Block, src: LazySrcLoc, operand: Air.Ins .len = try val.sliceLen(pt), }; }, - .One => { + .one => { if (Type.fromInterned(ptr_info.child).zigTypeTag(zcu) == .array) { return Type.fromInterned(ptr_info.child).arrayInfo(zcu); } }, - .C, .Many => {}, + .c, .many => {}, } }, .@"struct" => { @@ -16610,7 +16620,7 @@ fn analyzeArithmetic( if (lhs_zig_ty_tag == .pointer) { if (rhs_zig_ty_tag == .pointer) { - if (lhs_ty.ptrSize(zcu) != .Slice and rhs_ty.ptrSize(zcu) != .Slice) { + if (lhs_ty.ptrSize(zcu) != .slice and rhs_ty.ptrSize(zcu) != .slice) { if (zir_tag != .sub) { return sema.failWithInvalidPtrArithmetic(block, src, "pointer-pointer", "subtraction"); } @@ -16662,8 +16672,8 @@ fn analyzeArithmetic( } } else { switch (lhs_ty.ptrSize(zcu)) { - .One, .Slice => {}, - .Many, .C => { + .one, .slice => {}, + .many, .c => { const air_tag: Air.Inst.Tag = switch (zir_tag) { .add => .ptr_add, .sub => .ptr_sub, @@ -17160,7 +17170,7 @@ fn analyzePtrArithmetic( const opt_off_val = try sema.resolveDefinedValue(block, offset_src, offset); const ptr_ty = sema.typeOf(ptr); const ptr_info = ptr_ty.ptrInfo(zcu); - assert(ptr_info.flags.size == .Many or ptr_info.flags.size == .C); + assert(ptr_info.flags.size == .many or ptr_info.flags.size == .c); const new_ptr_ty = t: { // Calculate the new pointer alignment. @@ -18092,7 +18102,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai const slice_ty = (try pt.ptrTypeSema(.{ .child = param_info_ty.toIntern(), .flags = .{ - .size = .Slice, + .size = .slice, .is_const = true, }, })).toIntern(); @@ -18335,7 +18345,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai const slice_errors_ty = try pt.ptrTypeSema(.{ .child = error_field_ty.toIntern(), .flags = .{ - .size = .Slice, + .size = .slice, .is_const = true, }, }); @@ -18462,7 +18472,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai const slice_ty = (try pt.ptrTypeSema(.{ .child = enum_field_ty.toIntern(), .flags = .{ - .size = .Slice, + .size = .slice, .is_const = true, }, })).toIntern(); @@ -18575,7 +18585,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai const slice_ty = (try pt.ptrTypeSema(.{ .child = union_field_ty.toIntern(), .flags = .{ - .size = .Slice, + .size = .slice, .is_const = true, }, })).toIntern(); @@ -18770,7 +18780,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai const slice_ty = (try pt.ptrTypeSema(.{ .child = struct_field_ty.toIntern(), .flags = .{ - .size = .Slice, + .size = .slice, .is_const = true, }, })).toIntern(); @@ -18879,7 +18889,7 @@ fn typeInfoDecls( const slice_ty = (try pt.ptrTypeSema(.{ .child = declaration_ty.toIntern(), .flags = .{ - .size = .Slice, + .size = .slice, .is_const = true, }, })).toIntern(); @@ -20138,12 +20148,12 @@ fn zirPtrType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air } if (elem_ty.zigTypeTag(zcu) == .@"fn") { - if (inst_data.size != .One) { + if (inst_data.size != .one) { return sema.fail(block, elem_ty_src, "function pointers must be single pointers", .{}); } - } else if (inst_data.size == .Many and elem_ty.zigTypeTag(zcu) == .@"opaque") { + } else if (inst_data.size == .many and elem_ty.zigTypeTag(zcu) == .@"opaque") { return sema.fail(block, elem_ty_src, "unknown-length pointer to opaque not allowed", .{}); - } else if (inst_data.size == .C) { + } else if (inst_data.size == .c) { if (!try sema.validateExternType(elem_ty, .other)) { const msg = msg: { const msg = try sema.errMsg(elem_ty_src, "C pointers cannot point to non-C-ABI-compatible type '{}'", .{elem_ty.fmt(pt)}); @@ -21536,19 +21546,8 @@ fn zirReify( .@"anyframe" => return sema.failWithUseOfAsync(block, src), .enum_literal => return .enum_literal_type, .int => { - const struct_type = ip.loadStructType(ip.typeOf(union_val.val)); - const signedness_val = try Value.fromInterned(union_val.val).fieldValue( - pt, - struct_type.nameIndex(ip, try ip.getOrPutString(gpa, pt.tid, "signedness", .no_embedded_nulls)).?, - ); - const bits_val = try Value.fromInterned(union_val.val).fieldValue( - pt, - struct_type.nameIndex(ip, try ip.getOrPutString(gpa, pt.tid, "bits", .no_embedded_nulls)).?, - ); - - const signedness = zcu.toEnum(std.builtin.Signedness, signedness_val); - const bits: u16 = @intCast(try bits_val.toUnsignedIntSema(pt)); - const ty = try pt.intType(signedness, bits); + const int = try sema.interpretBuiltinType(block, operand_src, .fromInterned(union_val.val), std.builtin.Type.Int); + const ty = try pt.intType(int.signedness, int.bits); return Air.internedToRef(ty.toIntern()); }, .vector => { @@ -21574,20 +21573,15 @@ fn zirReify( return Air.internedToRef(ty.toIntern()); }, .float => { - const struct_type = ip.loadStructType(ip.typeOf(union_val.val)); - const bits_val = try Value.fromInterned(union_val.val).fieldValue(pt, struct_type.nameIndex( - ip, - try ip.getOrPutString(gpa, pt.tid, "bits", .no_embedded_nulls), - ).?); + const float = try sema.interpretBuiltinType(block, operand_src, .fromInterned(union_val.val), std.builtin.Type.Float); - const bits: u16 = @intCast(try bits_val.toUnsignedIntSema(pt)); - const ty = switch (bits) { + const ty = switch (float.bits) { 16 => Type.f16, 32 => Type.f32, 64 => Type.f64, 80 => Type.f80, 128 => Type.f128, - else => return sema.fail(block, src, "{}-bit float unsupported", .{bits}), + else => return sema.fail(block, src, "{}-bit float unsupported", .{float.bits}), }; return Air.internedToRef(ty.toIntern()); }, @@ -21623,7 +21617,7 @@ fn zirReify( ).?); const sentinel_val = try Value.fromInterned(union_val.val).fieldValue(pt, struct_type.nameIndex( ip, - try ip.getOrPutString(gpa, pt.tid, "sentinel", .no_embedded_nulls), + try ip.getOrPutString(gpa, pt.tid, "sentinel_ptr", .no_embedded_nulls), ).?); if (!try sema.intFitsInType(alignment_val, Type.u32, null)) { @@ -21641,11 +21635,11 @@ fn zirReify( try elem_ty.resolveLayout(pt); } - const ptr_size = zcu.toEnum(std.builtin.Type.Pointer.Size, size_val); + const ptr_size = try sema.interpretBuiltinType(block, operand_src, size_val, std.builtin.Type.Pointer.Size); const actual_sentinel: InternPool.Index = s: { if (!sentinel_val.isNull(zcu)) { - if (ptr_size == .One or ptr_size == .C) { + if (ptr_size == .one or ptr_size == .c) { return sema.fail(block, src, "sentinels are only allowed on slices and unknown-length pointers", .{}); } const sentinel_ptr_val = sentinel_val.optionalValue(zcu).?; @@ -21660,12 +21654,12 @@ fn zirReify( if (elem_ty.zigTypeTag(zcu) == .noreturn) { return sema.fail(block, src, "pointer to noreturn not allowed", .{}); } else if (elem_ty.zigTypeTag(zcu) == .@"fn") { - if (ptr_size != .One) { + if (ptr_size != .one) { return sema.fail(block, src, "function pointers must be single pointers", .{}); } - } else if (ptr_size == .Many and elem_ty.zigTypeTag(zcu) == .@"opaque") { + } else if (ptr_size == .many and elem_ty.zigTypeTag(zcu) == .@"opaque") { return sema.fail(block, src, "unknown-length pointer to opaque not allowed", .{}); - } else if (ptr_size == .C) { + } else if (ptr_size == .c) { if (!try sema.validateExternType(elem_ty, .other)) { const msg = msg: { const msg = try sema.errMsg(src, "C pointers cannot point to non-C-ABI-compatible type '{}'", .{elem_ty.fmt(pt)}); @@ -21691,7 +21685,7 @@ fn zirReify( .is_const = is_const_val.toBool(), .is_volatile = is_volatile_val.toBool(), .alignment = abi_align, - .address_space = zcu.toEnum(std.builtin.AddressSpace, address_space_val), + .address_space = try sema.interpretBuiltinType(block, operand_src, address_space_val, std.builtin.AddressSpace), .is_allowzero = is_allowzero_val.toBool(), }, }); @@ -21709,7 +21703,7 @@ fn zirReify( ).?); const sentinel_val = try Value.fromInterned(union_val.val).fieldValue(pt, struct_type.nameIndex( ip, - try ip.getOrPutString(gpa, pt.tid, "sentinel", .no_embedded_nulls), + try ip.getOrPutString(gpa, pt.tid, "sentinel_ptr", .no_embedded_nulls), ).?); const len = try len_val.toUnsignedIntSema(pt); @@ -21813,7 +21807,7 @@ fn zirReify( try ip.getOrPutString(gpa, pt.tid, "is_tuple", .no_embedded_nulls), ).?); - const layout = zcu.toEnum(std.builtin.Type.ContainerLayout, layout_val); + const layout = try sema.interpretBuiltinType(block, operand_src, layout_val, std.builtin.Type.ContainerLayout); // Decls if (try decls_val.sliceLen(pt) > 0) { @@ -21929,7 +21923,7 @@ fn zirReify( if (try decls_val.sliceLen(pt) > 0) { return sema.fail(block, src, "reified unions must have no decls", .{}); } - const layout = zcu.toEnum(std.builtin.Type.ContainerLayout, layout_val); + const layout = try sema.interpretBuiltinType(block, operand_src, layout_val, std.builtin.Type.ContainerLayout); const fields_arr = try sema.derefSliceAsArray(block, operand_src, fields_val, .{ .simple = .union_fields }); @@ -23321,21 +23315,21 @@ fn ptrCastFull( try Type.fromInterned(src_info.child).resolveLayout(pt); try Type.fromInterned(dest_info.child).resolveLayout(pt); - const src_slice_like = src_info.flags.size == .Slice or - (src_info.flags.size == .One and Type.fromInterned(src_info.child).zigTypeTag(zcu) == .array); + const src_slice_like = src_info.flags.size == .slice or + (src_info.flags.size == .one and Type.fromInterned(src_info.child).zigTypeTag(zcu) == .array); - const dest_slice_like = dest_info.flags.size == .Slice or - (dest_info.flags.size == .One and Type.fromInterned(dest_info.child).zigTypeTag(zcu) == .array); + const dest_slice_like = dest_info.flags.size == .slice or + (dest_info.flags.size == .one and Type.fromInterned(dest_info.child).zigTypeTag(zcu) == .array); - if (dest_info.flags.size == .Slice and !src_slice_like) { + if (dest_info.flags.size == .slice and !src_slice_like) { return sema.fail(block, src, "illegal pointer cast to slice", .{}); } - if (dest_info.flags.size == .Slice) { + if (dest_info.flags.size == .slice) { const src_elem_size = switch (src_info.flags.size) { - .Slice => Type.fromInterned(src_info.child).abiSize(zcu), + .slice => Type.fromInterned(src_info.child).abiSize(zcu), // pointer to array - .One => Type.fromInterned(src_info.child).childType(zcu).abiSize(zcu), + .one => Type.fromInterned(src_info.child).childType(zcu).abiSize(zcu), else => unreachable, }; const dest_elem_size = Type.fromInterned(dest_info.child).abiSize(zcu); @@ -23350,17 +23344,17 @@ fn ptrCastFull( check_size: { if (src_info.flags.size == dest_info.flags.size) break :check_size; if (src_slice_like and dest_slice_like) break :check_size; - if (src_info.flags.size == .C) break :check_size; - if (dest_info.flags.size == .C) break :check_size; + if (src_info.flags.size == .c) break :check_size; + if (dest_info.flags.size == .c) break :check_size; return sema.failWithOwnedErrorMsg(block, msg: { const msg = try sema.errMsg(src, "cannot implicitly convert {s} to {s}", .{ pointerSizeString(src_info.flags.size), pointerSizeString(dest_info.flags.size), }); errdefer msg.destroy(sema.gpa); - if (dest_info.flags.size == .Many and - (src_info.flags.size == .Slice or - (src_info.flags.size == .One and Type.fromInterned(src_info.child).zigTypeTag(zcu) == .array))) + if (dest_info.flags.size == .many and + (src_info.flags.size == .slice or + (src_info.flags.size == .one and Type.fromInterned(src_info.child).zigTypeTag(zcu) == .array))) { try sema.errNote(src, msg, "use 'ptr' field to convert slice to many pointer", .{}); } else { @@ -23371,7 +23365,7 @@ fn ptrCastFull( } check_child: { - const src_child = if (dest_info.flags.size == .Slice and src_info.flags.size == .One) blk: { + const src_child = if (dest_info.flags.size == .slice and src_info.flags.size == .one) blk: { // *[n]T -> []T break :blk Type.fromInterned(src_info.child).childType(zcu); } else Type.fromInterned(src_info.child); @@ -23402,12 +23396,12 @@ fn ptrCastFull( check_sent: { if (dest_info.sentinel == .none) break :check_sent; - if (src_info.flags.size == .C) break :check_sent; + if (src_info.flags.size == .c) break :check_sent; if (src_info.sentinel != .none) { const coerced_sent = try zcu.intern_pool.getCoerced(sema.gpa, pt.tid, src_info.sentinel, dest_info.child); if (dest_info.sentinel == coerced_sent) break :check_sent; } - if (src_slice_like and src_info.flags.size == .One and dest_info.flags.size == .Slice) { + if (src_slice_like and src_info.flags.size == .one and dest_info.flags.size == .slice) { // [*]nT -> []T const arr_ty = Type.fromInterned(src_info.child); if (arr_ty.sentinel(zcu)) |src_sentinel| { @@ -23555,7 +23549,7 @@ fn ptrCastFull( } } - const ptr = if (src_info.flags.size == .Slice and dest_info.flags.size != .Slice) ptr: { + const ptr = if (src_info.flags.size == .slice and dest_info.flags.size != .slice) ptr: { if (operand_ty.zigTypeTag(zcu) == .optional) { break :ptr try sema.analyzeOptionalSlicePtr(block, operand_src, operand, operand_ty); } else { @@ -23563,10 +23557,10 @@ fn ptrCastFull( } } else operand; - const dest_ptr_ty = if (dest_info.flags.size == .Slice and src_info.flags.size != .Slice) blk: { + const dest_ptr_ty = if (dest_info.flags.size == .slice and src_info.flags.size != .slice) blk: { // Only convert to a many-pointer at first var info = dest_info; - info.flags.size = .Many; + info.flags.size = .many; const ty = try pt.ptrTypeSema(info); if (dest_ty.zigTypeTag(zcu) == .optional) { break :blk try pt.optionalType(ty.toIntern()); @@ -23594,7 +23588,7 @@ fn ptrCastFull( } } } - if (dest_info.flags.size == .Slice and src_info.flags.size != .Slice) { + if (dest_info.flags.size == .slice and src_info.flags.size != .slice) { if (ptr_val.isUndef(zcu)) return pt.undefRef(dest_ty); const arr_len = try pt.intValue(Type.usize, Type.fromInterned(src_info.child).arrayLen(zcu)); const ptr_val_key = zcu.intern_pool.indexToKey(ptr_val.toIntern()).ptr; @@ -23622,7 +23616,7 @@ fn ptrCastFull( { const ptr_int = try block.addUnOp(.int_from_ptr, ptr); const is_non_zero = try block.addBinOp(.cmp_neq, ptr_int, .zero_usize); - const ok = if (src_info.flags.size == .Slice and dest_info.flags.size == .Slice) ok: { + const ok = if (src_info.flags.size == .slice and dest_info.flags.size == .slice) ok: { const len = try sema.analyzeSliceLen(block, operand_src, ptr); const len_zero = try block.addBinOp(.cmp_eq, len, .zero_usize); break :ok try block.addBinOp(.bool_or, len_zero, is_non_zero); @@ -23639,7 +23633,7 @@ fn ptrCastFull( const ptr_int = try block.addUnOp(.int_from_ptr, ptr); const remainder = try block.addBinOp(.bit_and, ptr_int, align_minus_1); const is_aligned = try block.addBinOp(.cmp_eq, remainder, .zero_usize); - const ok = if (src_info.flags.size == .Slice and dest_info.flags.size == .Slice) ok: { + const ok = if (src_info.flags.size == .slice and dest_info.flags.size == .slice) ok: { const len = try sema.analyzeSliceLen(block, operand_src, ptr); const len_zero = try block.addBinOp(.cmp_eq, len, .zero_usize); break :ok try block.addBinOp(.bool_or, len_zero, is_aligned); @@ -23672,7 +23666,7 @@ fn ptrCastFull( break :ptr try block.addBitCast(dest_ptr_ty, ptr); }; - if (dest_info.flags.size == .Slice and src_info.flags.size != .Slice) { + if (dest_info.flags.size == .slice and src_info.flags.size != .slice) { // We have to construct a slice using the operand's child's array length // Note that we know from the check at the start of the function that operand_ty is slice-like const arr_len = Air.internedToRef((try pt.intValue(Type.usize, Type.fromInterned(src_info.child).arrayLen(zcu))).toIntern()); @@ -24066,8 +24060,8 @@ fn checkInvalidPtrIntArithmetic( const zcu = pt.zcu; switch (try ty.zigTypeTagOrPoison(zcu)) { .pointer => switch (ty.ptrSize(zcu)) { - .One, .Slice => return, - .Many, .C => return sema.failWithInvalidPtrArithmetic(block, src, "pointer-integer", "addition and subtraction"), + .one, .slice => return, + .many, .c => return sema.failWithInvalidPtrArithmetic(block, src, "pointer-integer", "addition and subtraction"), }, else => return, } @@ -24456,7 +24450,7 @@ fn resolveExportOptions( const linkage_operand = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, pt.tid, "linkage", .no_embedded_nulls), linkage_src); const linkage_val = try sema.resolveConstDefinedValue(block, linkage_src, linkage_operand, .{ .simple = .export_options }); - const linkage = zcu.toEnum(std.builtin.GlobalLinkage, linkage_val); + const linkage = try sema.interpretBuiltinType(block, linkage_src, linkage_val, std.builtin.GlobalLinkage); const section_operand = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, pt.tid, "section", .no_embedded_nulls), section_src); const section_opt_val = try sema.resolveConstDefinedValue(block, section_src, section_operand, .{ .simple = .export_options }); @@ -24467,7 +24461,7 @@ fn resolveExportOptions( const visibility_operand = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, pt.tid, "visibility", .no_embedded_nulls), visibility_src); const visibility_val = try sema.resolveConstDefinedValue(block, visibility_src, visibility_operand, .{ .simple = .export_options }); - const visibility = zcu.toEnum(std.builtin.SymbolVisibility, visibility_val); + const visibility = try sema.interpretBuiltinType(block, visibility_src, visibility_val, std.builtin.SymbolVisibility); if (name.len < 1) { return sema.fail(block, name_src, "exported symbol name cannot be empty", .{}); @@ -24495,12 +24489,11 @@ fn resolveBuiltinEnum( comptime name: Zcu.BuiltinDecl, reason: ComptimeReason, ) CompileError!@field(std.builtin, @tagName(name)) { - const pt = sema.pt; const ty = try sema.getBuiltinType(src, name); const air_ref = try sema.resolveInst(zir_ref); const coerced = try sema.coerce(block, ty, air_ref, src); const val = try sema.resolveConstDefinedValue(block, src, coerced, reason); - return pt.zcu.toEnum(@field(std.builtin, @tagName(name)), val); + return sema.interpretBuiltinType(block, src, val, @field(std.builtin, @tagName(name))); } fn resolveAtomicOrder( @@ -25293,7 +25286,7 @@ fn zirBuiltinCall(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError const air_ref = try sema.resolveInst(extra.modifier); const modifier_ref = try sema.coerce(block, modifier_ty, air_ref, modifier_src); const modifier_val = try sema.resolveConstDefinedValue(block, modifier_src, modifier_ref, .{ .simple = .call_modifier }); - var modifier = zcu.toEnum(std.builtin.CallModifier, modifier_val); + var modifier = try sema.interpretBuiltinType(block, modifier_src, modifier_val, std.builtin.CallModifier); switch (modifier) { // These can be upgraded to comptime or nosuspend calls. .auto, .never_tail, .no_async => { @@ -25384,7 +25377,7 @@ fn zirFieldParentPtr(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.Ins const parent_ptr_ty = try sema.resolveDestType(block, inst_src, extra.parent_ptr_type, .remove_eu, "@fieldParentPtr"); try sema.checkPtrType(block, inst_src, parent_ptr_ty, true); const parent_ptr_info = parent_ptr_ty.ptrInfo(zcu); - if (parent_ptr_info.flags.size != .One) { + if (parent_ptr_info.flags.size != .one) { return sema.fail(block, inst_src, "expected single pointer type, found '{}'", .{parent_ptr_ty.fmt(pt)}); } const parent_ty = Type.fromInterned(parent_ptr_info.child); @@ -25862,7 +25855,7 @@ fn upgradeToArrayPtr(sema: *Sema, block: *Block, ptr: Air.Inst.Ref, len: u64) !A const zcu = pt.zcu; const ptr_ty = sema.typeOf(ptr); const info = ptr_ty.ptrInfo(zcu); - if (info.flags.size == .One) { + if (info.flags.size == .one) { // Already an array pointer. return ptr; } @@ -25880,7 +25873,7 @@ fn upgradeToArrayPtr(sema: *Sema, block: *Block, ptr: Air.Inst.Ref, len: u64) !A .address_space = info.flags.address_space, }, }); - const non_slice_ptr = if (info.flags.size == .Slice) + const non_slice_ptr = if (info.flags.size == .slice) try block.addTyOp(.slice_ptr, ptr_ty.slicePtrFieldType(zcu), ptr) else ptr; @@ -26069,22 +26062,22 @@ fn zirMemcpy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void const new_dest_ptr_ty = sema.typeOf(new_dest_ptr); const raw_dest_ptr = if (new_dest_ptr_ty.isSlice(zcu)) try sema.analyzeSlicePtr(block, dest_src, new_dest_ptr, new_dest_ptr_ty) - else if (new_dest_ptr_ty.ptrSize(zcu) == .One) ptr: { + else if (new_dest_ptr_ty.ptrSize(zcu) == .one) ptr: { var dest_manyptr_ty_key = zcu.intern_pool.indexToKey(new_dest_ptr_ty.toIntern()).ptr_type; - assert(dest_manyptr_ty_key.flags.size == .One); + assert(dest_manyptr_ty_key.flags.size == .one); dest_manyptr_ty_key.child = dest_elem_ty.toIntern(); - dest_manyptr_ty_key.flags.size = .Many; + dest_manyptr_ty_key.flags.size = .many; break :ptr try sema.coerceCompatiblePtrs(block, try pt.ptrTypeSema(dest_manyptr_ty_key), new_dest_ptr, dest_src); } else new_dest_ptr; const new_src_ptr_ty = sema.typeOf(new_src_ptr); const raw_src_ptr = if (new_src_ptr_ty.isSlice(zcu)) try sema.analyzeSlicePtr(block, src_src, new_src_ptr, new_src_ptr_ty) - else if (new_src_ptr_ty.ptrSize(zcu) == .One) ptr: { + else if (new_src_ptr_ty.ptrSize(zcu) == .one) ptr: { var src_manyptr_ty_key = zcu.intern_pool.indexToKey(new_src_ptr_ty.toIntern()).ptr_type; - assert(src_manyptr_ty_key.flags.size == .One); + assert(src_manyptr_ty_key.flags.size == .one); src_manyptr_ty_key.child = src_elem_ty.toIntern(); - src_manyptr_ty_key.flags.size = .Many; + src_manyptr_ty_key.flags.size = .many; break :ptr try sema.coerceCompatiblePtrs(block, try pt.ptrTypeSema(src_manyptr_ty_key), new_src_ptr, src_src); } else new_src_ptr; @@ -26129,13 +26122,13 @@ fn zirMemset(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void const dest_elem_ty: Type = dest_elem_ty: { const ptr_info = dest_ptr_ty.ptrInfo(zcu); switch (ptr_info.flags.size) { - .Slice => break :dest_elem_ty Type.fromInterned(ptr_info.child), - .One => { + .slice => break :dest_elem_ty Type.fromInterned(ptr_info.child), + .one => { if (Type.fromInterned(ptr_info.child).zigTypeTag(zcu) == .array) { break :dest_elem_ty Type.fromInterned(ptr_info.child).childType(zcu); } }, - .Many, .C => {}, + .many, .c => {}, } return sema.failWithOwnedErrorMsg(block, msg: { const msg = try sema.errMsg(src, "unknown @memset length", .{}); @@ -26172,7 +26165,7 @@ fn zirMemset(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void } })); const array_ptr_ty = ty: { var info = dest_ptr_ty.ptrInfo(zcu); - info.flags.size = .One; + info.flags.size = .one; info.child = array_ty.toIntern(); break :ty try pt.ptrType(info); }; @@ -26468,9 +26461,9 @@ fn resolvePrefetchOptions( const cache_val = try sema.resolveConstDefinedValue(block, cache_src, cache, .{ .simple = .prefetch_options }); return std.builtin.PrefetchOptions{ - .rw = zcu.toEnum(std.builtin.PrefetchOptions.Rw, rw_val), + .rw = try sema.interpretBuiltinType(block, rw_src, rw_val, std.builtin.PrefetchOptions.Rw), .locality = @intCast(try locality_val.toUnsignedIntSema(pt)), - .cache = zcu.toEnum(std.builtin.PrefetchOptions.Cache, cache_val), + .cache = try sema.interpretBuiltinType(block, cache_src, cache_val, std.builtin.PrefetchOptions.Cache), }; } @@ -26536,7 +26529,7 @@ fn resolveExternOptions( const linkage_ref = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, pt.tid, "linkage", .no_embedded_nulls), linkage_src); const linkage_val = try sema.resolveConstDefinedValue(block, linkage_src, linkage_ref, .{ .simple = .extern_options }); - const linkage = zcu.toEnum(std.builtin.GlobalLinkage, linkage_val); + const linkage = try sema.interpretBuiltinType(block, linkage_src, linkage_val, std.builtin.GlobalLinkage); const is_thread_local = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, pt.tid, "is_thread_local", .no_embedded_nulls), thread_local_src); const is_thread_local_val = try sema.resolveConstDefinedValue(block, thread_local_src, is_thread_local, .{ .simple = .extern_options }); @@ -26754,15 +26747,15 @@ fn zirInplaceArithResultTy(sema: *Sema, extended: Zir.Inst.Extended.InstData) Co .add_eq => ty: { const ptr_size = lhs_ty.ptrSizeOrNull(zcu) orelse break :ty lhs_ty; switch (ptr_size) { - .One, .Slice => break :ty lhs_ty, // invalid, let it error - .Many, .C => break :ty .usize, // `[*]T + usize` + .one, .slice => break :ty lhs_ty, // invalid, let it error + .many, .c => break :ty .usize, // `[*]T + usize` } }, .sub_eq => ty: { const ptr_size = lhs_ty.ptrSizeOrNull(zcu) orelse break :ty lhs_ty; switch (ptr_size) { - .One, .Slice => break :ty lhs_ty, // invalid, let it error - .Many, .C => break :ty .generic_poison, // could be `[*]T - [*]T` or `[*]T - usize` + .one, .slice => break :ty lhs_ty, // invalid, let it error + .many, .c => break :ty .generic_poison, // could be `[*]T - [*]T` or `[*]T - usize` } }, }; @@ -26770,9 +26763,6 @@ fn zirInplaceArithResultTy(sema: *Sema, extended: Zir.Inst.Extended.InstData) Co } fn zirBranchHint(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) CompileError!void { - const pt = sema.pt; - const zcu = pt.zcu; - const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data; const uncoerced_hint = try sema.resolveInst(extra.operand); const operand_src = block.builtinCallArgSrc(extra.node, 0); @@ -26784,7 +26774,7 @@ fn zirBranchHint(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstDat // We only apply the first hint in a branch. // This allows user-provided hints to override implicit cold hints. if (sema.branch_hint == null) { - sema.branch_hint = zcu.toEnum(std.builtin.BranchHint, hint_val); + sema.branch_hint = try sema.interpretBuiltinType(block, operand_src, hint_val, std.builtin.BranchHint); } } @@ -27556,7 +27546,7 @@ fn fieldVal( .child = Type.fromInterned(ptr_info.child).childType(zcu).toIntern(), .sentinel = if (inner_ty.sentinel(zcu)) |s| s.toIntern() else .none, .flags = .{ - .size = .Many, + .size = .many, .alignment = ptr_info.flags.alignment, .is_const = ptr_info.flags.is_const, .is_volatile = ptr_info.flags.is_volatile, @@ -27578,7 +27568,7 @@ fn fieldVal( }, .pointer => { const ptr_info = inner_ty.ptrInfo(zcu); - if (ptr_info.flags.size == .Slice) { + if (ptr_info.flags.size == .slice) { if (field_name.eqlSlice("ptr", ip)) { const slice = if (is_pointer_to) try sema.analyzeLoad(block, src, object, object_src) @@ -27740,7 +27730,7 @@ fn fieldPtr( .child = Type.fromInterned(ptr_info.child).childType(zcu).toIntern(), .sentinel = if (object_ty.sentinel(zcu)) |s| s.toIntern() else .none, .flags = .{ - .size = .Many, + .size = .many, .alignment = ptr_info.flags.alignment, .is_const = ptr_info.flags.is_const, .is_volatile = ptr_info.flags.is_volatile, @@ -27953,13 +27943,13 @@ fn fieldCallBind( const ip = &zcu.intern_pool; const raw_ptr_src = src; // TODO better source location const raw_ptr_ty = sema.typeOf(raw_ptr); - const inner_ty = if (raw_ptr_ty.zigTypeTag(zcu) == .pointer and (raw_ptr_ty.ptrSize(zcu) == .One or raw_ptr_ty.ptrSize(zcu) == .C)) + const inner_ty = if (raw_ptr_ty.zigTypeTag(zcu) == .pointer and (raw_ptr_ty.ptrSize(zcu) == .one or raw_ptr_ty.ptrSize(zcu) == .c)) raw_ptr_ty.childType(zcu) else return sema.fail(block, raw_ptr_src, "expected single pointer, found '{}'", .{raw_ptr_ty.fmt(pt)}); // Optionally dereference a second pointer to get the concrete type. - const is_double_ptr = inner_ty.zigTypeTag(zcu) == .pointer and inner_ty.ptrSize(zcu) == .One; + const is_double_ptr = inner_ty.zigTypeTag(zcu) == .pointer and inner_ty.ptrSize(zcu) == .one; const concrete_ty = if (is_double_ptr) inner_ty.childType(zcu) else inner_ty; const ptr_ty = if (is_double_ptr) inner_ty else raw_ptr_ty; const object_ptr = if (is_double_ptr) @@ -28025,8 +28015,8 @@ fn fieldCallBind( const first_param_type = Type.fromInterned(func_type.param_types.get(ip)[0]); if (first_param_type.isGenericPoison() or (first_param_type.zigTypeTag(zcu) == .pointer and - (first_param_type.ptrSize(zcu) == .One or - first_param_type.ptrSize(zcu) == .C) and + (first_param_type.ptrSize(zcu) == .one or + first_param_type.ptrSize(zcu) == .c) and first_param_type.childType(zcu).eql(concrete_ty, zcu))) { // Note that if the param type is generic poison, we know that it must @@ -28053,7 +28043,7 @@ fn fieldCallBind( .arg0_inst = deref, } }; } else if (child.zigTypeTag(zcu) == .pointer and - child.ptrSize(zcu) == .One and + child.ptrSize(zcu) == .one and child.childType(zcu).eql(concrete_ty, zcu)) { return .{ .method = .{ @@ -28673,8 +28663,8 @@ fn elemPtrOneLayerOnly( try checkIndexable(sema, block, src, indexable_ty); switch (indexable_ty.ptrSize(zcu)) { - .Slice => return sema.elemPtrSlice(block, src, indexable_src, indexable, elem_index_src, elem_index, oob_safety), - .Many, .C => { + .slice => return sema.elemPtrSlice(block, src, indexable_src, indexable, elem_index_src, elem_index, oob_safety), + .many, .c => { const maybe_ptr_val = try sema.resolveDefinedValue(block, indexable_src, indexable); const maybe_index_val = try sema.resolveDefinedValue(block, elem_index_src, elem_index); ct: { @@ -28688,7 +28678,7 @@ fn elemPtrOneLayerOnly( return block.addPtrElemPtr(indexable, elem_index, result_ty); }, - .One => { + .one => { const child_ty = indexable_ty.childType(zcu); const elem_ptr = switch (child_ty.zigTypeTag(zcu)) { .array, .vector => try sema.elemPtrArray(block, src, indexable_src, indexable, elem_index_src, elem_index, init, oob_safety), @@ -28728,8 +28718,8 @@ fn elemVal( switch (indexable_ty.zigTypeTag(zcu)) { .pointer => switch (indexable_ty.ptrSize(zcu)) { - .Slice => return sema.elemValSlice(block, src, indexable_src, indexable, elem_index_src, elem_index, oob_safety), - .Many, .C => { + .slice => return sema.elemValSlice(block, src, indexable_src, indexable, elem_index_src, elem_index, oob_safety), + .many, .c => { const maybe_indexable_val = try sema.resolveDefinedValue(block, indexable_src, indexable); const maybe_index_val = try sema.resolveDefinedValue(block, elem_index_src, elem_index); @@ -28748,7 +28738,7 @@ fn elemVal( return block.addBinOp(.ptr_elem_val, indexable, elem_index); }, - .One => { + .one => { arr_sent: { const inner_ty = indexable_ty.childType(zcu); if (inner_ty.zigTypeTag(zcu) != .array) break :arr_sent; @@ -29293,7 +29283,7 @@ fn coerceExtra( // *T to *[1]T single_item: { - if (dest_info.flags.size != .One) break :single_item; + if (dest_info.flags.size != .one) break :single_item; if (!inst_ty.isSinglePointer(zcu)) break :single_item; if (!sema.checkPtrAttributes(dest_ty, inst_ty, &in_memory_result)) break :pointer; const ptr_elem_ty = inst_ty.childType(zcu); @@ -29312,7 +29302,7 @@ fn coerceExtra( // Coercions where the source is a single pointer to an array. src_array_ptr: { if (!inst_ty.isSinglePointer(zcu)) break :src_array_ptr; - if (dest_info.flags.size == .One) break :src_array_ptr; // `*[n]T` -> `*T` isn't valid + if (dest_info.flags.size == .one) break :src_array_ptr; // `*[n]T` -> `*T` isn't valid if (!sema.checkPtrAttributes(dest_ty, inst_ty, &in_memory_result)) break :pointer; const array_ty = inst_ty.childType(zcu); if (array_ty.zigTypeTag(zcu) != .array) break :src_array_ptr; @@ -29356,25 +29346,25 @@ fn coerceExtra( } switch (dest_info.flags.size) { - .Slice => { + .slice => { // *[N]T to []T return sema.coerceArrayPtrToSlice(block, dest_ty, inst, inst_src); }, - .C => { + .c => { // *[N]T to [*c]T return sema.coerceCompatiblePtrs(block, dest_ty, inst, inst_src); }, - .Many => { + .many => { // *[N]T to [*]T return sema.coerceCompatiblePtrs(block, dest_ty, inst, inst_src); }, - .One => unreachable, // early exit at top of block + .one => unreachable, // early exit at top of block } } // coercion from C pointer if (inst_ty.isCPtr(zcu)) src_c_ptr: { - if (dest_info.flags.size == .Slice) break :src_c_ptr; + if (dest_info.flags.size == .slice) break :src_c_ptr; if (!sema.checkPtrAttributes(dest_ty, inst_ty, &in_memory_result)) break :src_c_ptr; // In this case we must add a safety check because the C pointer // could be null. @@ -29413,7 +29403,7 @@ fn coerceExtra( switch (dest_info.flags.size) { // coercion to C pointer - .C => switch (inst_ty.zigTypeTag(zcu)) { + .c => switch (inst_ty.zigTypeTag(zcu)) { .null => return Air.internedToRef(try pt.intern(.{ .ptr = .{ .ty = dest_ty.toIntern(), .base_addr = .int, @@ -29457,7 +29447,7 @@ fn coerceExtra( .ok => {}, else => break :p, } - if (inst_info.flags.size == .Slice) { + if (inst_info.flags.size == .slice) { assert(dest_info.sentinel == .none); if (inst_info.sentinel == .none or inst_info.sentinel != (try pt.intValue(Type.fromInterned(inst_info.child), 0)).toIntern()) @@ -29470,8 +29460,8 @@ fn coerceExtra( }, else => {}, }, - .One => {}, - .Slice => to_slice: { + .one => {}, + .slice => to_slice: { if (inst_ty.zigTypeTag(zcu) == .array) { return sema.fail( block, @@ -29512,7 +29502,7 @@ fn coerceExtra( } return sema.coerceTupleToSlicePtrs(block, dest_ty, dest_ty_src, inst, inst_src); }, - .Many => p: { + .many => p: { if (!inst_ty.isSlice(zcu)) break :p; if (!sema.checkPtrAttributes(dest_ty, inst_ty, &in_memory_result)) break :p; const inst_info = inst_ty.ptrInfo(zcu); @@ -30224,10 +30214,10 @@ const InMemoryCoercionResult = union(enum) { fn pointerSizeString(size: std.builtin.Type.Pointer.Size) []const u8 { return switch (size) { - .One => "single pointer", - .Many => "many pointer", - .C => "C pointer", - .Slice => "slice", + .one => "single pointer", + .many => "many pointer", + .c => "C pointer", + .slice => "slice", }; } @@ -30775,7 +30765,7 @@ fn coerceInMemoryAllowedPtrs( const src_info = src_ptr_ty.ptrInfo(zcu); const ok_ptr_size = src_info.flags.size == dest_info.flags.size or - src_info.flags.size == .C or dest_info.flags.size == .C; + src_info.flags.size == .c or dest_info.flags.size == .c; if (!ok_ptr_size) { return InMemoryCoercionResult{ .ptr_size = .{ .actual = src_info.flags.size, @@ -30874,7 +30864,7 @@ fn coerceInMemoryAllowedPtrs( if (ss != .none and ds != .none) { if (ds == try zcu.intern_pool.getCoerced(sema.gpa, pt.tid, ss, dest_info.child)) break :ok true; } - if (src_info.flags.size == .C) break :ok true; + if (src_info.flags.size == .c) break :ok true; if (!dest_is_mut and dest_info.sentinel == .none) break :ok true; break :ok false; }; @@ -31392,7 +31382,7 @@ fn checkPtrAttributes(sema: *Sema, dest_ty: Type, inst_ty: Type, in_memory_resul const dest_info = dest_ty.ptrInfo(zcu); const inst_info = inst_ty.ptrInfo(zcu); const len0 = (Type.fromInterned(inst_info.child).zigTypeTag(zcu) == .array and (Type.fromInterned(inst_info.child).arrayLenIncludingSentinel(zcu) == 0 or - (Type.fromInterned(inst_info.child).arrayLen(zcu) == 0 and dest_info.sentinel == .none and dest_info.flags.size != .C and dest_info.flags.size != .Many))) or + (Type.fromInterned(inst_info.child).arrayLen(zcu) == 0 and dest_info.sentinel == .none and dest_info.flags.size != .c and dest_info.flags.size != .many))) or (Type.fromInterned(inst_info.child).isTuple(zcu) and Type.fromInterned(inst_info.child).structFieldCount(zcu) == 0); const ok_const = (!inst_info.flags.is_const or dest_info.flags.is_const) or len0; @@ -32631,7 +32621,7 @@ fn analyzeSlice( elem_ty = ptr_ptr_child_ty.childType(zcu); }, .pointer => switch (ptr_ptr_child_ty.ptrSize(zcu)) { - .One => { + .one => { const double_child_ty = ptr_ptr_child_ty.childType(zcu); ptr_or_slice = try sema.analyzeLoad(block, src, ptr_ptr, ptr_src); if (double_child_ty.zigTypeTag(zcu) == .array) { @@ -32721,14 +32711,14 @@ fn analyzeSlice( elem_ty = double_child_ty; } }, - .Many, .C => { + .many, .c => { ptr_sentinel = ptr_ptr_child_ty.sentinel(zcu); ptr_or_slice = try sema.analyzeLoad(block, src, ptr_ptr, ptr_src); slice_ty = ptr_ptr_child_ty; array_ty = ptr_ptr_child_ty; elem_ty = ptr_ptr_child_ty.childType(zcu); - if (ptr_ptr_child_ty.ptrSize(zcu) == .C) { + if (ptr_ptr_child_ty.ptrSize(zcu) == .c) { if (try sema.resolveDefinedValue(block, ptr_src, ptr_or_slice)) |ptr_val| { if (ptr_val.isNull(zcu)) { return sema.fail(block, src, "slice of null pointer", .{}); @@ -32736,7 +32726,7 @@ fn analyzeSlice( } } }, - .Slice => { + .slice => { ptr_sentinel = ptr_ptr_child_ty.sentinel(zcu); ptr_or_slice = try sema.analyzeLoad(block, src, ptr_ptr, ptr_src); slice_ty = ptr_ptr_child_ty; @@ -32752,9 +32742,9 @@ fn analyzeSlice( else if (array_ty.zigTypeTag(zcu) == .array) ptr: { var manyptr_ty_key = zcu.intern_pool.indexToKey(slice_ty.toIntern()).ptr_type; assert(manyptr_ty_key.child == array_ty.toIntern()); - assert(manyptr_ty_key.flags.size == .One); + assert(manyptr_ty_key.flags.size == .one); manyptr_ty_key.child = elem_ty.toIntern(); - manyptr_ty_key.flags.size = .Many; + manyptr_ty_key.flags.size = .many; break :ptr try sema.coerceCompatiblePtrs(block, try pt.ptrTypeSema(manyptr_ty_key), ptr_or_slice, ptr_src); } else ptr_or_slice; @@ -32967,7 +32957,7 @@ fn analyzeSlice( const opt_new_len_val = try sema.resolveDefinedValue(block, src, new_len); const new_ptr_ty_info = new_ptr_ty.ptrInfo(zcu); - const new_allowzero = new_ptr_ty_info.flags.is_allowzero and sema.typeOf(ptr).ptrSize(zcu) != .C; + const new_allowzero = new_ptr_ty_info.flags.is_allowzero and sema.typeOf(ptr).ptrSize(zcu) != .c; if (opt_new_len_val) |new_len_val| { const new_len_int = try new_len_val.toUnsignedIntSema(pt); @@ -33038,7 +33028,7 @@ fn analyzeSlice( .child = elem_ty.toIntern(), .sentinel = if (sentinel) |s| s.toIntern() else .none, .flags = .{ - .size = .Slice, + .size = .slice, .alignment = new_ptr_ty_info.flags.alignment, .is_const = new_ptr_ty_info.flags.is_const, .is_volatile = new_ptr_ty_info.flags.is_volatile, @@ -33739,7 +33729,7 @@ const PeerResolveStrategy = enum { .int => .fixed_int, .comptime_float => .comptime_float, .float => .fixed_float, - .pointer => if (ty.ptrInfo(zcu).flags.size == .C) .c_ptr else .ptr, + .pointer => if (ty.ptrInfo(zcu).flags.size == .c) .c_ptr else .ptr, .array => .array, .vector => .vector, .optional => .optional, @@ -34235,7 +34225,7 @@ fn resolvePeerTypesInner( var ptr_info = opt_ptr_info orelse { opt_ptr_info = peer_info; - opt_ptr_info.?.flags.size = .C; + opt_ptr_info.?.flags.size = .c; first_idx = i; continue; }; @@ -34323,9 +34313,9 @@ fn resolvePeerTypesInner( }; switch (peer_info.flags.size) { - .One, .Many => {}, - .Slice => opt_slice_idx = i, - .C => return .{ .conflict = .{ + .one, .many => {}, + .slice => opt_slice_idx = i, + .c => return .{ .conflict = .{ .peer_idx_a = strat_reason, .peer_idx_b = i, } }, @@ -34370,21 +34360,21 @@ fn resolvePeerTypesInner( ptr_info.flags.is_allowzero = ptr_info.flags.is_allowzero or peer_info.flags.is_allowzero; const peer_sentinel: InternPool.Index = switch (peer_info.flags.size) { - .One => switch (ip.indexToKey(peer_info.child)) { + .one => switch (ip.indexToKey(peer_info.child)) { .array_type => |array_type| array_type.sentinel, else => .none, }, - .Many, .Slice => peer_info.sentinel, - .C => unreachable, + .many, .slice => peer_info.sentinel, + .c => unreachable, }; const cur_sentinel: InternPool.Index = switch (ptr_info.flags.size) { - .One => switch (ip.indexToKey(ptr_info.child)) { + .one => switch (ip.indexToKey(ptr_info.child)) { .array_type => |array_type| array_type.sentinel, else => .none, }, - .Many, .Slice => ptr_info.sentinel, - .C => unreachable, + .many, .slice => ptr_info.sentinel, + .c => unreachable, }; // We abstract array handling slightly so that tuple pointers can work like array pointers @@ -34395,8 +34385,8 @@ fn resolvePeerTypesInner( // single-pointer array sentinel). good: { switch (peer_info.flags.size) { - .One => switch (ptr_info.flags.size) { - .One => { + .one => switch (ptr_info.flags.size) { + .one => { if (try sema.resolvePairInMemoryCoercible(block, src, Type.fromInterned(ptr_info.child), Type.fromInterned(peer_info.child))) |pointee| { ptr_info.child = pointee.toIntern(); break :good; @@ -34415,28 +34405,28 @@ fn resolvePeerTypesInner( break :good; } // *[a]T + *[b]T = []T - ptr_info.flags.size = .Slice; + ptr_info.flags.size = .slice; ptr_info.child = elem_ty.toIntern(); break :good; } if (peer_arr.elem_ty.toIntern() == .noreturn_type) { // *struct{} + *[a]T = []T - ptr_info.flags.size = .Slice; + ptr_info.flags.size = .slice; ptr_info.child = cur_arr.elem_ty.toIntern(); break :good; } if (cur_arr.elem_ty.toIntern() == .noreturn_type) { // *[a]T + *struct{} = []T - ptr_info.flags.size = .Slice; + ptr_info.flags.size = .slice; ptr_info.child = peer_arr.elem_ty.toIntern(); break :good; } return generic_err; }, - .Many => { + .many => { // Only works for *[n]T + [*]T -> [*]T const arr = peer_pointee_array orelse return generic_err; if (try sema.resolvePairInMemoryCoercible(block, src, Type.fromInterned(ptr_info.child), arr.elem_ty)) |pointee| { @@ -34449,7 +34439,7 @@ fn resolvePeerTypesInner( } return generic_err; }, - .Slice => { + .slice => { // Only works for *[n]T + []T -> []T const arr = peer_pointee_array orelse return generic_err; if (try sema.resolvePairInMemoryCoercible(block, src, Type.fromInterned(ptr_info.child), arr.elem_ty)) |pointee| { @@ -34462,33 +34452,33 @@ fn resolvePeerTypesInner( } return generic_err; }, - .C => unreachable, + .c => unreachable, }, - .Many => switch (ptr_info.flags.size) { - .One => { + .many => switch (ptr_info.flags.size) { + .one => { // Only works for [*]T + *[n]T -> [*]T const arr = cur_pointee_array orelse return generic_err; if (try sema.resolvePairInMemoryCoercible(block, src, arr.elem_ty, Type.fromInterned(peer_info.child))) |pointee| { - ptr_info.flags.size = .Many; + ptr_info.flags.size = .many; ptr_info.child = pointee.toIntern(); break :good; } if (arr.elem_ty.toIntern() == .noreturn_type) { // [*]T + *struct{} -> [*]T - ptr_info.flags.size = .Many; + ptr_info.flags.size = .many; ptr_info.child = peer_info.child; break :good; } return generic_err; }, - .Many => { + .many => { if (try sema.resolvePairInMemoryCoercible(block, src, Type.fromInterned(ptr_info.child), Type.fromInterned(peer_info.child))) |pointee| { ptr_info.child = pointee.toIntern(); break :good; } return generic_err; }, - .Slice => { + .slice => { // Only works if no peers are actually slices if (opt_slice_idx) |slice_idx| { return .{ .conflict = .{ @@ -34498,54 +34488,54 @@ fn resolvePeerTypesInner( } // Okay, then works for [*]T + "[]T" -> [*]T if (try sema.resolvePairInMemoryCoercible(block, src, Type.fromInterned(ptr_info.child), Type.fromInterned(peer_info.child))) |pointee| { - ptr_info.flags.size = .Many; + ptr_info.flags.size = .many; ptr_info.child = pointee.toIntern(); break :good; } return generic_err; }, - .C => unreachable, + .c => unreachable, }, - .Slice => switch (ptr_info.flags.size) { - .One => { + .slice => switch (ptr_info.flags.size) { + .one => { // Only works for []T + *[n]T -> []T const arr = cur_pointee_array orelse return generic_err; if (try sema.resolvePairInMemoryCoercible(block, src, arr.elem_ty, Type.fromInterned(peer_info.child))) |pointee| { - ptr_info.flags.size = .Slice; + ptr_info.flags.size = .slice; ptr_info.child = pointee.toIntern(); break :good; } if (arr.elem_ty.toIntern() == .noreturn_type) { // []T + *struct{} -> []T - ptr_info.flags.size = .Slice; + ptr_info.flags.size = .slice; ptr_info.child = peer_info.child; break :good; } return generic_err; }, - .Many => { + .many => { // Impossible! (current peer is an actual slice) return generic_err; }, - .Slice => { + .slice => { if (try sema.resolvePairInMemoryCoercible(block, src, Type.fromInterned(ptr_info.child), Type.fromInterned(peer_info.child))) |pointee| { ptr_info.child = pointee.toIntern(); break :good; } return generic_err; }, - .C => unreachable, + .c => unreachable, }, - .C => unreachable, + .c => unreachable, } } const sentinel_ty = switch (ptr_info.flags.size) { - .One => switch (ip.indexToKey(ptr_info.child)) { + .one => switch (ip.indexToKey(ptr_info.child)) { .array_type => |array_type| array_type.child, else => ptr_info.child, }, - .Many, .Slice, .C => ptr_info.child, + .many, .slice, .c => ptr_info.child, }; sentinel: { @@ -34556,7 +34546,7 @@ fn resolvePeerTypesInner( const cur_sent_coerced = try ip.getCoerced(sema.gpa, pt.tid, cur_sentinel, sentinel_ty); if (peer_sent_coerced != cur_sent_coerced) break :no_sentinel; // Sentinels match - if (ptr_info.flags.size == .One) switch (ip.indexToKey(ptr_info.child)) { + if (ptr_info.flags.size == .one) switch (ip.indexToKey(ptr_info.child)) { .array_type => |array_type| ptr_info.child = (try pt.arrayType(.{ .len = array_type.len, .child = array_type.child, @@ -35416,8 +35406,8 @@ fn checkMemOperand(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type) !void const zcu = pt.zcu; if (ty.zigTypeTag(zcu) == .pointer) { switch (ty.ptrSize(zcu)) { - .Slice, .Many, .C => return, - .One => { + .slice, .many, .c => return, + .one => { const elem_ty = ty.childType(zcu); if (elem_ty.zigTypeTag(zcu) == .array) return; // TODO https://github.com/ziglang/zig/issues/15479 @@ -37136,11 +37126,10 @@ pub fn analyzeAsAddressSpace( ctx: AddressSpaceContext, ) !std.builtin.AddressSpace { const pt = sema.pt; - const zcu = pt.zcu; const addrspace_ty = try sema.getBuiltinType(src, .AddressSpace); const coerced = try sema.coerce(block, addrspace_ty, air_ref, src); const addrspace_val = try sema.resolveConstDefinedValue(block, src, coerced, .{ .simple = .@"addrspace" }); - const address_space = zcu.toEnum(std.builtin.AddressSpace, addrspace_val); + const address_space = try sema.interpretBuiltinType(block, src, addrspace_val, std.builtin.AddressSpace); const target = pt.zcu.getTarget(); const arch = target.cpu.arch; @@ -37248,13 +37237,13 @@ fn typePtrOrOptionalPtrTy(sema: *Sema, ty: Type) !?Type { const zcu = pt.zcu; return switch (zcu.intern_pool.indexToKey(ty.toIntern())) { .ptr_type => |ptr_type| switch (ptr_type.flags.size) { - .One, .Many, .C => ty, - .Slice => null, + .one, .many, .c => ty, + .slice => null, }, .opt_type => |opt_child| switch (zcu.intern_pool.indexToKey(opt_child)) { .ptr_type => |ptr_type| switch (ptr_type.flags.size) { - .Slice, .C => null, - .Many, .One => { + .slice, .c => null, + .many, .one => { if (ptr_type.flags.is_allowzero) return null; // optionals of zero sized types behave like bools, not pointers @@ -38260,7 +38249,7 @@ fn maybeDerefSliceAsArray( }); const ptr_ty = try pt.ptrTypeSema(p: { var p = Type.fromInterned(slice.ty).ptrInfo(zcu); - p.flags.size = .One; + p.flags.size = .one; p.child = array_ty.toIntern(); p.sentinel = .none; break :p p; diff --git a/src/Type.zig b/src/Type.zig index 023b763bf922..350e3f10ec2b 100644 --- a/src/Type.zig +++ b/src/Type.zig @@ -192,16 +192,16 @@ pub fn print(ty: Type, writer: anytype, pt: Zcu.PerThread) @TypeOf(writer).Error const info = ty.ptrInfo(zcu); if (info.sentinel != .none) switch (info.flags.size) { - .One, .C => unreachable, - .Many => try writer.print("[*:{}]", .{Value.fromInterned(info.sentinel).fmtValue(pt)}), - .Slice => try writer.print("[:{}]", .{Value.fromInterned(info.sentinel).fmtValue(pt)}), + .one, .c => unreachable, + .many => try writer.print("[*:{}]", .{Value.fromInterned(info.sentinel).fmtValue(pt)}), + .slice => try writer.print("[:{}]", .{Value.fromInterned(info.sentinel).fmtValue(pt)}), } else switch (info.flags.size) { - .One => try writer.writeAll("*"), - .Many => try writer.writeAll("[*]"), - .C => try writer.writeAll("[*c]"), - .Slice => try writer.writeAll("[]"), + .one => try writer.writeAll("*"), + .many => try writer.writeAll("[*]"), + .c => try writer.writeAll("[*c]"), + .slice => try writer.writeAll("[]"), } - if (info.flags.is_allowzero and info.flags.size != .C) try writer.writeAll("allowzero "); + if (info.flags.is_allowzero and info.flags.size != .c) try writer.writeAll("allowzero "); if (info.flags.alignment != .none or info.packed_offset.host_size != 0 or info.flags.vector_index != .none) @@ -686,7 +686,7 @@ pub fn hasWellDefinedLayout(ty: Type, zcu: *const Zcu) bool { .array_type => |array_type| Type.fromInterned(array_type.child).hasWellDefinedLayout(zcu), .opt_type => ty.isPtrLikeOptional(zcu), - .ptr_type => |ptr_type| ptr_type.flags.size != .Slice, + .ptr_type => |ptr_type| ptr_type.flags.size != .slice, .simple_type => |t| switch (t) { .f16, @@ -1303,7 +1303,7 @@ pub fn abiSizeInner( return .{ .scalar = intAbiSize(int_type.bits, target, use_llvm) }; }, .ptr_type => |ptr_type| switch (ptr_type.flags.size) { - .Slice => return .{ .scalar = @divExact(target.ptrBitWidth(), 8) * 2 }, + .slice => return .{ .scalar = @divExact(target.ptrBitWidth(), 8) * 2 }, else => return .{ .scalar = @divExact(target.ptrBitWidth(), 8) }, }, .anyframe_type => return .{ .scalar = @divExact(target.ptrBitWidth(), 8) }, @@ -1741,7 +1741,7 @@ pub fn bitSizeInner( switch (ip.indexToKey(ty.toIntern())) { .int_type => |int_type| return int_type.bits, .ptr_type => |ptr_type| switch (ptr_type.flags.size) { - .Slice => return target.ptrBitWidth() * 2, + .slice => return target.ptrBitWidth() * 2, else => return target.ptrBitWidth(), }, .anyframe_type => return target.ptrBitWidth(), @@ -1903,7 +1903,7 @@ pub fn layoutIsResolved(ty: Type, zcu: *const Zcu) bool { pub fn isSinglePointer(ty: Type, zcu: *const Zcu) bool { return switch (zcu.intern_pool.indexToKey(ty.toIntern())) { - .ptr_type => |ptr_info| ptr_info.flags.size == .One, + .ptr_type => |ptr_info| ptr_info.flags.size == .one, else => false, }; } @@ -1923,7 +1923,7 @@ pub fn ptrSizeOrNull(ty: Type, zcu: *const Zcu) ?std.builtin.Type.Pointer.Size { pub fn isSlice(ty: Type, zcu: *const Zcu) bool { return switch (zcu.intern_pool.indexToKey(ty.toIntern())) { - .ptr_type => |ptr_type| ptr_type.flags.size == .Slice, + .ptr_type => |ptr_type| ptr_type.flags.size == .slice, else => false, }; } @@ -1960,7 +1960,7 @@ pub fn isAllowzeroPtr(ty: Type, zcu: *const Zcu) bool { pub fn isCPtr(ty: Type, zcu: *const Zcu) bool { return switch (zcu.intern_pool.indexToKey(ty.toIntern())) { - .ptr_type => |ptr_type| ptr_type.flags.size == .C, + .ptr_type => |ptr_type| ptr_type.flags.size == .c, else => false, }; } @@ -1968,13 +1968,13 @@ pub fn isCPtr(ty: Type, zcu: *const Zcu) bool { pub fn isPtrAtRuntime(ty: Type, zcu: *const Zcu) bool { return switch (zcu.intern_pool.indexToKey(ty.toIntern())) { .ptr_type => |ptr_type| switch (ptr_type.flags.size) { - .Slice => false, - .One, .Many, .C => true, + .slice => false, + .one, .many, .c => true, }, .opt_type => |child| switch (zcu.intern_pool.indexToKey(child)) { .ptr_type => |p| switch (p.flags.size) { - .Slice, .C => false, - .Many, .One => !p.flags.is_allowzero, + .slice, .c => false, + .many, .one => !p.flags.is_allowzero, }, else => false, }, @@ -1995,11 +1995,11 @@ pub fn ptrAllowsZero(ty: Type, zcu: *const Zcu) bool { pub fn optionalReprIsPayload(ty: Type, zcu: *const Zcu) bool { return switch (zcu.intern_pool.indexToKey(ty.toIntern())) { .opt_type => |child_type| child_type == .anyerror_type or switch (zcu.intern_pool.indexToKey(child_type)) { - .ptr_type => |ptr_type| ptr_type.flags.size != .C and !ptr_type.flags.is_allowzero, + .ptr_type => |ptr_type| ptr_type.flags.size != .c and !ptr_type.flags.is_allowzero, .error_set_type, .inferred_error_set_type => true, else => false, }, - .ptr_type => |ptr_type| ptr_type.flags.size == .C, + .ptr_type => |ptr_type| ptr_type.flags.size == .c, else => false, }; } @@ -2009,11 +2009,11 @@ pub fn optionalReprIsPayload(ty: Type, zcu: *const Zcu) bool { /// This function must be kept in sync with `Sema.typePtrOrOptionalPtrTy`. pub fn isPtrLikeOptional(ty: Type, zcu: *const Zcu) bool { return switch (zcu.intern_pool.indexToKey(ty.toIntern())) { - .ptr_type => |ptr_type| ptr_type.flags.size == .C, + .ptr_type => |ptr_type| ptr_type.flags.size == .c, .opt_type => |child| switch (zcu.intern_pool.indexToKey(child)) { .ptr_type => |ptr_type| switch (ptr_type.flags.size) { - .Slice, .C => false, - .Many, .One => !ptr_type.flags.is_allowzero, + .slice, .c => false, + .many, .one => !ptr_type.flags.is_allowzero, }, else => false, }, @@ -2044,8 +2044,8 @@ pub fn childTypeIp(ty: Type, ip: *const InternPool) Type { pub fn elemType2(ty: Type, zcu: *const Zcu) Type { return switch (zcu.intern_pool.indexToKey(ty.toIntern())) { .ptr_type => |ptr_type| switch (ptr_type.flags.size) { - .One => Type.fromInterned(ptr_type.child).shallowElemType(zcu), - .Many, .C, .Slice => Type.fromInterned(ptr_type.child), + .one => Type.fromInterned(ptr_type.child).shallowElemType(zcu), + .many, .c, .slice => Type.fromInterned(ptr_type.child), }, .anyframe_type => |child| { assert(child != .none); @@ -2079,7 +2079,7 @@ pub fn optionalChild(ty: Type, zcu: *const Zcu) Type { return switch (zcu.intern_pool.indexToKey(ty.toIntern())) { .opt_type => |child| Type.fromInterned(child), .ptr_type => |ptr_type| b: { - assert(ptr_type.flags.size == .C); + assert(ptr_type.flags.size == .c); break :b ty; }, else => unreachable, @@ -2991,8 +2991,8 @@ pub fn isIndexable(ty: Type, zcu: *const Zcu) bool { return switch (ty.zigTypeTag(zcu)) { .array, .vector => true, .pointer => switch (ty.ptrSize(zcu)) { - .Slice, .Many, .C => true, - .One => switch (ty.childType(zcu).zigTypeTag(zcu)) { + .slice, .many, .c => true, + .one => switch (ty.childType(zcu).zigTypeTag(zcu)) { .array, .vector => true, .@"struct" => ty.childType(zcu).isTuple(zcu), else => false, @@ -3007,9 +3007,9 @@ pub fn indexableHasLen(ty: Type, zcu: *const Zcu) bool { return switch (ty.zigTypeTag(zcu)) { .array, .vector => true, .pointer => switch (ty.ptrSize(zcu)) { - .Many, .C => false, - .Slice => true, - .One => switch (ty.childType(zcu).zigTypeTag(zcu)) { + .many, .c => false, + .slice => true, + .one => switch (ty.childType(zcu).zigTypeTag(zcu)) { .array, .vector => true, .@"struct" => ty.childType(zcu).isTuple(zcu), else => false, @@ -4049,7 +4049,7 @@ pub fn elemPtrType(ptr_ty: Type, offset: ?usize, pt: Zcu.PerThread) !Type { host_size: u16 = 0, alignment: Alignment = .none, vector_index: VI = .none, - } = if (parent_ty.isVector(zcu) and ptr_info.flags.size == .One) blk: { + } = if (parent_ty.isVector(zcu) and ptr_info.flags.size == .one) blk: { const elem_bits = elem_ty.bitSize(zcu); if (elem_bits == 0) break :blk .{}; const is_packed = elem_bits < 8 or !std.math.isPowerOfTwo(elem_bits); diff --git a/src/Value.zig b/src/Value.zig index 3081a28b9b88..828ad051c828 100644 --- a/src/Value.zig +++ b/src/Value.zig @@ -1,5 +1,6 @@ const std = @import("std"); const builtin = @import("builtin"); +const build_options = @import("build_options"); const Type = @import("Type.zig"); const assert = std.debug.assert; const BigIntConst = std.math.big.int.Const; @@ -3724,7 +3725,7 @@ pub fn ptrOptPayload(parent_ptr: Value, pt: Zcu.PerThread) !Value { const parent_ptr_ty = parent_ptr.typeOf(zcu); const opt_ty = parent_ptr_ty.childType(zcu); - assert(parent_ptr_ty.ptrSize(zcu) == .One); + assert(parent_ptr_ty.ptrSize(zcu) == .one); assert(opt_ty.zigTypeTag(zcu) == .optional); const result_ty = try pt.ptrTypeSema(info: { @@ -3742,7 +3743,7 @@ pub fn ptrOptPayload(parent_ptr: Value, pt: Zcu.PerThread) !Value { return pt.getCoerced(parent_ptr, result_ty); } - const base_ptr = try parent_ptr.canonicalizeBasePtr(.One, opt_ty, pt); + const base_ptr = try parent_ptr.canonicalizeBasePtr(.one, opt_ty, pt); return Value.fromInterned(try pt.intern(.{ .ptr = .{ .ty = result_ty.toIntern(), .base_addr = .{ .opt_payload = base_ptr.toIntern() }, @@ -3758,7 +3759,7 @@ pub fn ptrEuPayload(parent_ptr: Value, pt: Zcu.PerThread) !Value { const parent_ptr_ty = parent_ptr.typeOf(zcu); const eu_ty = parent_ptr_ty.childType(zcu); - assert(parent_ptr_ty.ptrSize(zcu) == .One); + assert(parent_ptr_ty.ptrSize(zcu) == .one); assert(eu_ty.zigTypeTag(zcu) == .error_union); const result_ty = try pt.ptrTypeSema(info: { @@ -3771,7 +3772,7 @@ pub fn ptrEuPayload(parent_ptr: Value, pt: Zcu.PerThread) !Value { if (parent_ptr.isUndef(zcu)) return pt.undefValue(result_ty); - const base_ptr = try parent_ptr.canonicalizeBasePtr(.One, eu_ty, pt); + const base_ptr = try parent_ptr.canonicalizeBasePtr(.one, eu_ty, pt); return Value.fromInterned(try pt.intern(.{ .ptr = .{ .ty = result_ty.toIntern(), .base_addr = .{ .eu_payload = base_ptr.toIntern() }, @@ -3789,7 +3790,7 @@ pub fn ptrField(parent_ptr: Value, field_idx: u32, pt: Zcu.PerThread) !Value { const aggregate_ty = parent_ptr_ty.childType(zcu); const parent_ptr_info = parent_ptr_ty.ptrInfo(zcu); - assert(parent_ptr_info.flags.size == .One); + assert(parent_ptr_info.flags.size == .one); // Exiting this `switch` indicates that the `field` pointer representation should be used. // `field_align` may be `.none` to represent the natural alignment of `field_ty`, but is not necessarily. @@ -3920,7 +3921,7 @@ pub fn ptrField(parent_ptr: Value, field_idx: u32, pt: Zcu.PerThread) !Value { if (parent_ptr.isUndef(zcu)) return pt.undefValue(result_ty); - const base_ptr = try parent_ptr.canonicalizeBasePtr(.One, aggregate_ty, pt); + const base_ptr = try parent_ptr.canonicalizeBasePtr(.one, aggregate_ty, pt); return Value.fromInterned(try pt.intern(.{ .ptr = .{ .ty = result_ty.toIntern(), .base_addr = .{ .field = .{ @@ -3937,8 +3938,8 @@ pub fn ptrField(parent_ptr: Value, field_idx: u32, pt: Zcu.PerThread) !Value { pub fn ptrElem(orig_parent_ptr: Value, field_idx: u64, pt: Zcu.PerThread) !Value { const zcu = pt.zcu; const parent_ptr = switch (orig_parent_ptr.typeOf(zcu).ptrSize(zcu)) { - .One, .Many, .C => orig_parent_ptr, - .Slice => orig_parent_ptr.slicePtr(zcu), + .one, .many, .c => orig_parent_ptr, + .slice => orig_parent_ptr.slicePtr(zcu), }; const parent_ptr_ty = parent_ptr.typeOf(zcu); @@ -3959,7 +3960,7 @@ pub fn ptrElem(orig_parent_ptr: Value, field_idx: u64, pt: Zcu.PerThread) !Value }; const strat: PtrStrat = switch (parent_ptr_ty.ptrSize(zcu)) { - .One => switch (elem_ty.zigTypeTag(zcu)) { + .one => switch (elem_ty.zigTypeTag(zcu)) { .vector => .{ .offset = field_idx * @divExact(try elem_ty.childType(zcu).bitSizeSema(pt), 8) }, .array => strat: { const arr_elem_ty = elem_ty.childType(zcu); @@ -3971,12 +3972,12 @@ pub fn ptrElem(orig_parent_ptr: Value, field_idx: u64, pt: Zcu.PerThread) !Value else => unreachable, }, - .Many, .C => if (try elem_ty.comptimeOnlySema(pt)) + .many, .c => if (try elem_ty.comptimeOnlySema(pt)) .{ .elem_ptr = elem_ty } else .{ .offset = field_idx * (try elem_ty.abiSizeInner(.sema, zcu, pt.tid)).scalar }, - .Slice => unreachable, + .slice => unreachable, }; switch (strat) { @@ -4004,7 +4005,7 @@ pub fn ptrElem(orig_parent_ptr: Value, field_idx: u64, pt: Zcu.PerThread) !Value }, else => {}, } - const base_ptr = try parent_ptr.canonicalizeBasePtr(.Many, arr_base_ty, pt); + const base_ptr = try parent_ptr.canonicalizeBasePtr(.many, arr_base_ty, pt); return Value.fromInterned(try pt.intern(.{ .ptr = .{ .ty = result_ty.toIntern(), .base_addr = .{ .arr_elem = .{ @@ -4234,7 +4235,7 @@ pub fn pointerDerivationAdvanced(ptr_val: Value, arena: Allocator, pt: Zcu.PerTh .child = parent_ptr_info.child, .flags = flags: { var flags = parent_ptr_info.flags; - flags.size = .One; + flags.size = .one; break :flags flags; }, }); @@ -4304,8 +4305,8 @@ pub fn pointerDerivationAdvanced(ptr_val: Value, arena: Allocator, pt: Zcu.PerTh if (!cur_ty.isPtrLikeOptional(zcu)) break :ptr_opt; if (need_child.zigTypeTag(zcu) != .pointer) break :ptr_opt; switch (need_child.ptrSize(zcu)) { - .One, .Many => {}, - .Slice, .C => break :ptr_opt, + .one, .many => {}, + .slice, .c => break :ptr_opt, } const parent = try arena.create(PointerDeriveStep); parent.* = cur_derive; @@ -4323,7 +4324,7 @@ pub fn pointerDerivationAdvanced(ptr_val: Value, arena: Allocator, pt: Zcu.PerTh const elem_size = elem_ty.abiSize(zcu); const start_idx = cur_offset / elem_size; const end_idx = (cur_offset + need_bytes + elem_size - 1) / elem_size; - if (end_idx == start_idx + 1 and ptr_ty_info.flags.size == .One) { + if (end_idx == start_idx + 1 and ptr_ty_info.flags.size == .one) { const parent = try arena.create(PointerDeriveStep); parent.* = cur_derive; cur_derive = .{ .elem_ptr = .{ @@ -4531,6 +4532,20 @@ pub fn resolveLazy( } } +const InterpretMode = enum { + /// In this mode, types are assumed to match what the compiler was built with in terms of field + /// order, field types, etc. This improves compiler performance. However, it means that certain + /// modifications to `std.builtin` will result in compiler crashes. + direct, + /// In this mode, various details of the type are allowed to differ from what the compiler was built + /// with. Fields are matched by name rather than index; added struct fields are ignored, and removed + /// struct fields use their default value if one exists. This is slower than `.direct`, but permits + /// making certain changes to `std.builtin` (in particular reordering/adding/removing fields), so it + /// is useful when applying breaking changes. + by_name, +}; +const interpret_mode: InterpretMode = @field(InterpretMode, @tagName(build_options.value_interpret_mode)); + /// Given a `Value` representing a comptime-known value of type `T`, unwrap it into an actual `T` known to the compiler. /// This is useful for accessing `std.builtin` structures received from comptime logic. /// `val` must be fully resolved. @@ -4583,11 +4598,20 @@ pub fn interpret(val: Value, comptime T: type, pt: Zcu.PerThread) error{ OutOfMe else null, - .@"enum" => zcu.toEnum(T, val), + .@"enum" => switch (interpret_mode) { + .direct => { + const int = val.getUnsignedInt(zcu) orelse return error.TypeMismatch; + return std.meta.intToEnum(T, int) catch error.TypeMismatch; + }, + .by_name => { + const field_index = ty.enumTagFieldIndex(val, zcu) orelse return error.TypeMismatch; + const field_name = ty.enumFieldName(field_index, zcu); + return std.meta.stringToEnum(T, field_name.toSlice(ip)) orelse error.TypeMismatch; + }, + }, .@"union" => |@"union"| { - const union_obj = zcu.typeToUnion(ty) orelse return error.TypeMismatch; - if (union_obj.field_types.len != @"union".fields.len) return error.TypeMismatch; + // No need to handle `interpret_mode`, because the `.@"enum"` handling already deals with it. const tag_val = val.unionTag(zcu) orelse return error.TypeMismatch; const tag = try tag_val.interpret(@"union".tag_type.?, pt); return switch (tag) { @@ -4599,14 +4623,28 @@ pub fn interpret(val: Value, comptime T: type, pt: Zcu.PerThread) error{ OutOfMe }; }, - .@"struct" => |@"struct"| { - if (ty.structFieldCount(zcu) != @"struct".fields.len) return error.TypeMismatch; - var result: T = undefined; - inline for (@"struct".fields, 0..) |field, field_idx| { - const field_val = try val.fieldValue(pt, field_idx); - @field(result, field.name) = try field_val.interpret(field.type, pt); - } - return result; + .@"struct" => |@"struct"| switch (interpret_mode) { + .direct => { + if (ty.structFieldCount(zcu) != @"struct".fields.len) return error.TypeMismatch; + var result: T = undefined; + inline for (@"struct".fields, 0..) |field, field_idx| { + const field_val = try val.fieldValue(pt, field_idx); + @field(result, field.name) = try field_val.interpret(field.type, pt); + } + return result; + }, + .by_name => { + const struct_obj = zcu.typeToStruct(ty) orelse return error.TypeMismatch; + var result: T = undefined; + inline for (@"struct".fields) |field| { + const field_name_ip = try ip.getOrPutString(zcu.gpa, pt.tid, field.name, .no_embedded_nulls); + @field(result, field.name) = if (struct_obj.nameIndex(ip, field_name_ip)) |field_idx| f: { + const field_val = try val.fieldValue(pt, field_idx); + break :f try field_val.interpret(field.type, pt); + } else (field.defaultValue() orelse return error.TypeMismatch); + } + return result; + }, }, }; } @@ -4618,6 +4656,7 @@ pub fn uninterpret(val: anytype, ty: Type, pt: Zcu.PerThread) error{ OutOfMemory const T = @TypeOf(val); const zcu = pt.zcu; + const ip = &zcu.intern_pool; if (ty.zigTypeTag(zcu) != @typeInfo(T)) return error.TypeMismatch; return switch (@typeInfo(T)) { @@ -4657,9 +4696,17 @@ pub fn uninterpret(val: anytype, ty: Type, pt: Zcu.PerThread) error{ OutOfMemory else try pt.nullValue(ty), - .@"enum" => try pt.enumValue(ty, (try uninterpret(@intFromEnum(val), ty.intTagType(zcu), pt)).toIntern()), + .@"enum" => switch (interpret_mode) { + .direct => try pt.enumValue(ty, (try uninterpret(@intFromEnum(val), ty.intTagType(zcu), pt)).toIntern()), + .by_name => { + const field_name_ip = try ip.getOrPutString(zcu.gpa, pt.tid, @tagName(val), .no_embedded_nulls); + const field_idx = ty.enumFieldIndex(field_name_ip, zcu) orelse return error.TypeMismatch; + return pt.enumValueFieldIndex(ty, field_idx); + }, + }, .@"union" => |@"union"| { + // No need to handle `interpret_mode`, because the `.@"enum"` handling already deals with it. const tag: @"union".tag_type.? = val; const tag_val = try uninterpret(tag, ty.unionTagType(zcu).?, pt); const field_ty = ty.unionFieldType(tag_val, zcu) orelse return error.TypeMismatch; @@ -4672,17 +4719,44 @@ pub fn uninterpret(val: anytype, ty: Type, pt: Zcu.PerThread) error{ OutOfMemory }; }, - .@"struct" => |@"struct"| { - if (ty.structFieldCount(zcu) != @"struct".fields.len) return error.TypeMismatch; - var field_vals: [@"struct".fields.len]InternPool.Index = undefined; - inline for (&field_vals, @"struct".fields, 0..) |*field_val, field, field_idx| { - const field_ty = ty.fieldType(field_idx, zcu); - field_val.* = (try uninterpret(@field(val, field.name), field_ty, pt)).toIntern(); - } - return .fromInterned(try pt.intern(.{ .aggregate = .{ - .ty = ty.toIntern(), - .storage = .{ .elems = &field_vals }, - } })); + .@"struct" => |@"struct"| switch (interpret_mode) { + .direct => { + if (ty.structFieldCount(zcu) != @"struct".fields.len) return error.TypeMismatch; + var field_vals: [@"struct".fields.len]InternPool.Index = undefined; + inline for (&field_vals, @"struct".fields, 0..) |*field_val, field, field_idx| { + const field_ty = ty.fieldType(field_idx, zcu); + field_val.* = (try uninterpret(@field(val, field.name), field_ty, pt)).toIntern(); + } + return .fromInterned(try pt.intern(.{ .aggregate = .{ + .ty = ty.toIntern(), + .storage = .{ .elems = &field_vals }, + } })); + }, + .by_name => { + const struct_obj = zcu.typeToStruct(ty) orelse return error.TypeMismatch; + const want_fields_len = struct_obj.field_types.len; + const field_vals = try zcu.gpa.alloc(InternPool.Index, want_fields_len); + defer zcu.gpa.free(field_vals); + @memset(field_vals, .none); + inline for (@"struct".fields) |field| { + const field_name_ip = try ip.getOrPutString(zcu.gpa, pt.tid, field.name, .no_embedded_nulls); + if (struct_obj.nameIndex(ip, field_name_ip)) |field_idx| { + const field_ty = ty.fieldType(field_idx, zcu); + field_vals[field_idx] = (try uninterpret(@field(val, field.name), field_ty, pt)).toIntern(); + } + } + for (field_vals, 0..) |*field_val, field_idx| { + if (field_val.* == .none) { + const default_init = struct_obj.field_inits.get(ip)[field_idx]; + if (default_init == .none) return error.TypeMismatch; + field_val.* = default_init; + } + } + return .fromInterned(try pt.intern(.{ .aggregate = .{ + .ty = ty.toIntern(), + .storage = .{ .elems = field_vals }, + } })); + }, }, }; } diff --git a/src/Zcu.zig b/src/Zcu.zig index 1defb8c2d727..54f4349a6eaa 100644 --- a/src/Zcu.zig +++ b/src/Zcu.zig @@ -3486,10 +3486,6 @@ pub fn funcInfo(zcu: *const Zcu, func_index: InternPool.Index) InternPool.Key.Fu return zcu.intern_pool.toFunc(func_index); } -pub fn toEnum(zcu: *const Zcu, comptime E: type, val: Value) E { - return zcu.intern_pool.toEnum(E, val.toIntern()); -} - pub const UnionLayout = struct { abi_size: u64, abi_align: Alignment, diff --git a/src/Zcu/PerThread.zig b/src/Zcu/PerThread.zig index ab5f2b2994d0..85231fa1ceb1 100644 --- a/src/Zcu/PerThread.zig +++ b/src/Zcu/PerThread.zig @@ -3068,7 +3068,7 @@ pub fn populateTestFunctions( .child = test_fn_ty.toIntern(), .flags = .{ .is_const = true, - .size = .Slice, + .size = .slice, }, }); const new_init = try pt.intern(.{ .slice = .{ @@ -3303,7 +3303,7 @@ pub fn optionalType(pt: Zcu.PerThread, child_type: InternPool.Index) Allocator.E pub fn ptrType(pt: Zcu.PerThread, info: InternPool.Key.PtrType) Allocator.Error!Type { var canon_info = info; - if (info.flags.size == .C) canon_info.flags.is_allowzero = true; + if (info.flags.size == .c) canon_info.flags.is_allowzero = true; // Canonicalize non-zero alignment. If it matches the ABI alignment of the pointee // type, we change it to 0 here. If this causes an assertion trip because the @@ -3360,7 +3360,7 @@ pub fn manyConstPtrType(pt: Zcu.PerThread, child_type: Type) Allocator.Error!Typ return pt.ptrType(.{ .child = child_type.toIntern(), .flags = .{ - .size = .Many, + .size = .many, .is_const = true, }, }); diff --git a/src/arch/aarch64/CodeGen.zig b/src/arch/aarch64/CodeGen.zig index 33f691959219..c1657396ad33 100644 --- a/src/arch/aarch64/CodeGen.zig +++ b/src/arch/aarch64/CodeGen.zig @@ -2398,7 +2398,7 @@ fn ptrArithmetic( const ptr_ty = lhs_ty; const elem_ty = switch (ptr_ty.ptrSize(zcu)) { - .One => ptr_ty.childType(zcu).childType(zcu), // ptr to array, so get array element type + .one => ptr_ty.childType(zcu).childType(zcu), // ptr to array, so get array element type else => ptr_ty.childType(zcu), }; const elem_size = elem_ty.abiSize(zcu); diff --git a/src/arch/arm/CodeGen.zig b/src/arch/arm/CodeGen.zig index 65a202803dfe..10b0473ecfe3 100644 --- a/src/arch/arm/CodeGen.zig +++ b/src/arch/arm/CodeGen.zig @@ -3919,7 +3919,7 @@ fn ptrArithmetic( const ptr_ty = lhs_ty; const elem_ty = switch (ptr_ty.ptrSize(zcu)) { - .One => ptr_ty.childType(zcu).childType(zcu), // ptr to array, so get array element type + .one => ptr_ty.childType(zcu).childType(zcu), // ptr to array, so get array element type else => ptr_ty.childType(zcu), }; const elem_size: u32 = @intCast(elem_ty.abiSize(zcu)); diff --git a/src/arch/riscv64/CodeGen.zig b/src/arch/riscv64/CodeGen.zig index 820188e188df..c180b3aac922 100644 --- a/src/arch/riscv64/CodeGen.zig +++ b/src/arch/riscv64/CodeGen.zig @@ -7843,15 +7843,15 @@ fn airMemset(func: *Func, inst: Air.Inst.Index, safety: bool) !void { if (elem_abi_size == 1) { const ptr: MCValue = switch (dst_ptr_ty.ptrSize(zcu)) { // TODO: this only handles slices stored in the stack - .Slice => dst_ptr, - .One => dst_ptr, - .C, .Many => unreachable, + .slice => dst_ptr, + .one => dst_ptr, + .c, .many => unreachable, }; const len: MCValue = switch (dst_ptr_ty.ptrSize(zcu)) { // TODO: this only handles slices stored in the stack - .Slice => dst_ptr.address().offset(8).deref(), - .One => .{ .immediate = dst_ptr_ty.childType(zcu).arrayLen(zcu) }, - .C, .Many => unreachable, + .slice => dst_ptr.address().offset(8).deref(), + .one => .{ .immediate = dst_ptr_ty.childType(zcu).arrayLen(zcu) }, + .c, .many => unreachable, }; const len_lock: ?RegisterLock = switch (len) { .register => |reg| func.register_manager.lockRegAssumeUnused(reg), @@ -7867,8 +7867,8 @@ fn airMemset(func: *Func, inst: Air.Inst.Index, safety: bool) !void { // Length zero requires a runtime check - so we handle arrays specially // here to elide it. switch (dst_ptr_ty.ptrSize(zcu)) { - .Slice => return func.fail("TODO: airMemset Slices", .{}), - .One => { + .slice => return func.fail("TODO: airMemset Slices", .{}), + .one => { const elem_ptr_ty = try pt.singleMutPtrType(elem_ty); const len = dst_ptr_ty.childType(zcu).arrayLen(zcu); @@ -7889,7 +7889,7 @@ fn airMemset(func: *Func, inst: Air.Inst.Index, safety: bool) !void { const bytes_to_copy: MCValue = .{ .immediate = elem_abi_size * (len - 1) }; try func.genInlineMemcpy(second_elem_ptr_mcv, dst_ptr, bytes_to_copy); }, - .C, .Many => unreachable, + .c, .many => unreachable, } } return func.finishAir(inst, .unreach, .{ bin_op.lhs, bin_op.rhs, .none }); @@ -7906,7 +7906,7 @@ fn airMemcpy(func: *Func, inst: Air.Inst.Index) !void { const dst_ty = func.typeOf(bin_op.lhs); const len_mcv: MCValue = switch (dst_ty.ptrSize(zcu)) { - .Slice => len: { + .slice => len: { const len_reg, const len_lock = try func.allocReg(.int); defer func.register_manager.unlockReg(len_lock); @@ -7921,7 +7921,7 @@ fn airMemcpy(func: *Func, inst: Air.Inst.Index) !void { ); break :len .{ .register = len_reg }; }, - .One => len: { + .one => len: { const array_ty = dst_ty.childType(zcu); break :len .{ .immediate = array_ty.arrayLen(zcu) * array_ty.childType(zcu).abiSize(zcu) }; }, diff --git a/src/arch/riscv64/abi.zig b/src/arch/riscv64/abi.zig index 3ce63130834d..84788075895e 100644 --- a/src/arch/riscv64/abi.zig +++ b/src/arch/riscv64/abi.zig @@ -109,7 +109,7 @@ pub fn classifySystem(ty: Type, zcu: *Zcu) [8]SystemClass { return result; }, .pointer => switch (ty.ptrSize(zcu)) { - .Slice => { + .slice => { result[0] = .integer; result[1] = .integer; return result; diff --git a/src/arch/sparc64/CodeGen.zig b/src/arch/sparc64/CodeGen.zig index 32bca3bc9004..0957789325e8 100644 --- a/src/arch/sparc64/CodeGen.zig +++ b/src/arch/sparc64/CodeGen.zig @@ -2953,7 +2953,7 @@ fn binOp( .pointer => { const ptr_ty = lhs_ty; const elem_ty = switch (ptr_ty.ptrSize(zcu)) { - .One => ptr_ty.childType(zcu).childType(zcu), // ptr to array, so get array element type + .one => ptr_ty.childType(zcu).childType(zcu), // ptr to array, so get array element type else => ptr_ty.childType(zcu), }; const elem_size = elem_ty.abiSize(zcu); diff --git a/src/arch/wasm/CodeGen.zig b/src/arch/wasm/CodeGen.zig index eeaf9988cbd1..8b32fe1d7ab3 100644 --- a/src/arch/wasm/CodeGen.zig +++ b/src/arch/wasm/CodeGen.zig @@ -4726,7 +4726,7 @@ fn airPtrBinOp(cg: *CodeGen, inst: Air.Inst.Index, op: Op) InnerError!void { const offset = try cg.resolveInst(bin_op.rhs); const ptr_ty = cg.typeOf(bin_op.lhs); const pointee_ty = switch (ptr_ty.ptrSize(zcu)) { - .One => ptr_ty.childType(zcu).childType(zcu), // ptr to array, so get array element type + .one => ptr_ty.childType(zcu).childType(zcu), // ptr to array, so get array element type else => ptr_ty.childType(zcu), }; @@ -4756,12 +4756,12 @@ fn airMemset(cg: *CodeGen, inst: Air.Inst.Index, safety: bool) InnerError!void { const ptr_ty = cg.typeOf(bin_op.lhs); const value = try cg.resolveInst(bin_op.rhs); const len = switch (ptr_ty.ptrSize(zcu)) { - .Slice => try cg.sliceLen(ptr), - .One => @as(WValue, .{ .imm32 = @as(u32, @intCast(ptr_ty.childType(zcu).arrayLen(zcu))) }), - .C, .Many => unreachable, + .slice => try cg.sliceLen(ptr), + .one => @as(WValue, .{ .imm32 = @as(u32, @intCast(ptr_ty.childType(zcu).arrayLen(zcu))) }), + .c, .many => unreachable, }; - const elem_ty = if (ptr_ty.ptrSize(zcu) == .One) + const elem_ty = if (ptr_ty.ptrSize(zcu) == .one) ptr_ty.childType(zcu).childType(zcu) else ptr_ty.childType(zcu); @@ -5688,7 +5688,7 @@ fn airMemcpy(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void { const src = try cg.resolveInst(bin_op.rhs); const src_ty = cg.typeOf(bin_op.rhs); const len = switch (dst_ty.ptrSize(zcu)) { - .Slice => blk: { + .slice => blk: { const slice_len = try cg.sliceLen(dst); if (ptr_elem_ty.abiSize(zcu) != 1) { try cg.emitWValue(slice_len); @@ -5698,10 +5698,10 @@ fn airMemcpy(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void { } break :blk slice_len; }, - .One => @as(WValue, .{ + .one => @as(WValue, .{ .imm32 = @as(u32, @intCast(ptr_elem_ty.arrayLen(zcu) * ptr_elem_ty.childType(zcu).abiSize(zcu))), }), - .C, .Many => unreachable, + .c, .many => unreachable, }; const dst_ptr = try cg.sliceOrArrayPtr(dst, dst_ty); const src_ptr = try cg.sliceOrArrayPtr(src, src_ty); diff --git a/src/arch/x86_64/CodeGen.zig b/src/arch/x86_64/CodeGen.zig index 940cd001958d..dbb0179ebbb3 100644 --- a/src/arch/x86_64/CodeGen.zig +++ b/src/arch/x86_64/CodeGen.zig @@ -9607,13 +9607,13 @@ fn genMulDivBinOp( const manyptr_u32_ty = try pt.ptrType(.{ .child = .u32_type, .flags = .{ - .size = .Many, + .size = .many, }, }); const manyptr_const_u32_ty = try pt.ptrType(.{ .child = .u32_type, .flags = .{ - .size = .Many, + .size = .many, .is_const = true, }, }); @@ -16614,15 +16614,15 @@ fn airMemset(self: *Self, inst: Air.Inst.Index, safety: bool) !void { if (elem_abi_size == 1) { const ptr: MCValue = switch (dst_ptr_ty.ptrSize(zcu)) { // TODO: this only handles slices stored in the stack - .Slice => dst_ptr, - .One => dst_ptr, - .C, .Many => unreachable, + .slice => dst_ptr, + .one => dst_ptr, + .c, .many => unreachable, }; const len: MCValue = switch (dst_ptr_ty.ptrSize(zcu)) { // TODO: this only handles slices stored in the stack - .Slice => dst_ptr.address().offset(8).deref(), - .One => .{ .immediate = dst_ptr_ty.childType(zcu).arrayLen(zcu) }, - .C, .Many => unreachable, + .slice => dst_ptr.address().offset(8).deref(), + .one => .{ .immediate = dst_ptr_ty.childType(zcu).arrayLen(zcu) }, + .c, .many => unreachable, }; const len_lock: ?RegisterLock = switch (len) { .register => |reg| self.register_manager.lockRegAssumeUnused(reg), @@ -16638,7 +16638,7 @@ fn airMemset(self: *Self, inst: Air.Inst.Index, safety: bool) !void { // Length zero requires a runtime check - so we handle arrays specially // here to elide it. switch (dst_ptr_ty.ptrSize(zcu)) { - .Slice => { + .slice => { const slice_ptr_ty = dst_ptr_ty.slicePtrFieldType(zcu); // TODO: this only handles slices stored in the stack @@ -16681,7 +16681,7 @@ fn airMemset(self: *Self, inst: Air.Inst.Index, safety: bool) !void { self.performReloc(skip_reloc); }, - .One => { + .one => { const elem_ptr_ty = try pt.singleMutPtrType(elem_ty); const len = dst_ptr_ty.childType(zcu).arrayLen(zcu); @@ -16704,7 +16704,7 @@ fn airMemset(self: *Self, inst: Air.Inst.Index, safety: bool) !void { const bytes_to_copy: MCValue = .{ .immediate = elem_abi_size * (len - 1) }; try self.genInlineMemcpy(second_elem_ptr_mcv, dst_ptr, bytes_to_copy); }, - .C, .Many => unreachable, + .c, .many => unreachable, } } return self.finishAir(inst, .unreach, .{ bin_op.lhs, bin_op.rhs, .none }); @@ -16735,7 +16735,7 @@ fn airMemcpy(self: *Self, inst: Air.Inst.Index) !void { defer if (src_ptr_lock) |lock| self.register_manager.unlockReg(lock); const len: MCValue = switch (dst_ptr_ty.ptrSize(zcu)) { - .Slice => len: { + .slice => len: { const len_reg = try self.register_manager.allocReg(null, abi.RegisterClass.gp); const len_lock = self.register_manager.lockRegAssumeUnused(len_reg); defer self.register_manager.unlockReg(len_lock); @@ -16748,11 +16748,11 @@ fn airMemcpy(self: *Self, inst: Air.Inst.Index) !void { ); break :len .{ .register = len_reg }; }, - .One => len: { + .one => len: { const array_ty = dst_ptr_ty.childType(zcu); break :len .{ .immediate = array_ty.arrayLen(zcu) * array_ty.childType(zcu).abiSize(zcu) }; }, - .C, .Many => unreachable, + .c, .many => unreachable, }; const len_lock: ?RegisterLock = switch (len) { .register => |reg| self.register_manager.lockRegAssumeUnused(reg), diff --git a/src/arch/x86_64/abi.zig b/src/arch/x86_64/abi.zig index fac6b6ce6ddd..d825b70cf66a 100644 --- a/src/arch/x86_64/abi.zig +++ b/src/arch/x86_64/abi.zig @@ -108,7 +108,7 @@ pub fn classifySystemV(ty: Type, zcu: *Zcu, target: std.Target, ctx: Context) [8 var result = [1]Class{.none} ** 8; switch (ty.zigTypeTag(zcu)) { .pointer => switch (ty.ptrSize(zcu)) { - .Slice => { + .slice => { result[0] = .integer; result[1] = .integer; return result; diff --git a/src/clang.zig b/src/clang.zig index 8b909cd077a0..c12daca2bce5 100644 --- a/src/clang.zig +++ b/src/clang.zig @@ -177,7 +177,7 @@ pub const ASTUnit = opaque { extern fn ZigClangASTUnit_visitLocalTopLevelDecls( *ASTUnit, context: ?*anyopaque, - Fn: ?*const fn (?*anyopaque, *const Decl) callconv(.C) bool, + Fn: ?*const fn (?*anyopaque, *const Decl) callconv(.c) bool, ) bool; pub const getLocalPreprocessingEntities_begin = ZigClangASTUnit_getLocalPreprocessingEntities_begin; diff --git a/src/codegen.zig b/src/codegen.zig index acd7a4965d06..dd3b874bc0d9 100644 --- a/src/codegen.zig +++ b/src/codegen.zig @@ -945,7 +945,7 @@ pub fn genTypedValue( switch (ty.zigTypeTag(zcu)) { .void => return .{ .mcv = .none }, .pointer => switch (ty.ptrSize(zcu)) { - .Slice => {}, + .slice => {}, else => switch (val.toIntern()) { .null_value => { return .{ .mcv = .{ .immediate = 0 } }; diff --git a/src/codegen/c.zig b/src/codegen/c.zig index 6fee1beb89b6..bbb06ae06fb4 100644 --- a/src/codegen/c.zig +++ b/src/codegen/c.zig @@ -1589,14 +1589,14 @@ pub const DeclGen = struct { try dg.fmtIntLiteral(try pt.undefValue(ty), location), }), .ptr_type => |ptr_type| switch (ptr_type.flags.size) { - .One, .Many, .C => { + .one, .many, .c => { try writer.writeAll("(("); try dg.renderCType(writer, ctype); return writer.print("){x})", .{ try dg.fmtIntLiteral(try pt.undefValue(Type.usize), .Other), }); }, - .Slice => { + .slice => { if (!location.isInitializer()) { try writer.writeByte('('); try dg.renderCType(writer, ctype); @@ -3570,7 +3570,7 @@ fn airPtrElemPtr(f: *Function, inst: Air.Inst.Index) !CValue { try f.renderType(writer, inst_ty); try writer.writeByte(')'); if (elem_has_bits) try writer.writeByte('&'); - if (elem_has_bits and ptr_ty.ptrSize(zcu) == .One) { + if (elem_has_bits and ptr_ty.ptrSize(zcu) == .one) { // It's a pointer to an array, so we need to de-reference. try f.writeCValueDeref(writer, ptr); } else try f.writeCValue(writer, ptr, .Other); @@ -5798,8 +5798,8 @@ fn fieldLocation( } }, .ptr_type => |ptr_info| switch (ptr_info.flags.size) { - .One, .Many, .C => unreachable, - .Slice => switch (field_index) { + .one, .many, .c => unreachable, + .slice => switch (field_index) { 0 => return .{ .field = .{ .identifier = "ptr" } }, 1 => return .{ .field = .{ .identifier = "len" } }, else => unreachable, @@ -6902,7 +6902,7 @@ fn airMemset(f: *Function, inst: Air.Inst.Index, safety: bool) !CValue { try writer.writeAll("memset("); switch (dest_ty.ptrSize(zcu)) { - .Slice => { + .slice => { try f.writeCValueMember(writer, dest_slice, .{ .identifier = "ptr" }); try writer.writeAll(", 0xaa, "); try f.writeCValueMember(writer, dest_slice, .{ .identifier = "len" }); @@ -6912,14 +6912,14 @@ fn airMemset(f: *Function, inst: Air.Inst.Index, safety: bool) !CValue { try writer.writeAll(");\n"); } }, - .One => { + .one => { const array_ty = dest_ty.childType(zcu); const len = array_ty.arrayLen(zcu) * elem_abi_size; try f.writeCValue(writer, dest_slice, .FunctionArgument); try writer.print(", 0xaa, {d});\n", .{len}); }, - .Many, .C => unreachable, + .many, .c => unreachable, } try reap(f, inst, &.{ bin_op.lhs, bin_op.rhs }); return .none; @@ -6932,7 +6932,7 @@ fn airMemset(f: *Function, inst: Air.Inst.Index, safety: bool) !CValue { const elem_ptr_ty = try pt.ptrType(.{ .child = elem_ty.toIntern(), .flags = .{ - .size = .C, + .size = .c, }, }); @@ -6946,14 +6946,14 @@ fn airMemset(f: *Function, inst: Air.Inst.Index, safety: bool) !CValue { try f.writeCValue(writer, index, .Other); try writer.writeAll(" != "); switch (dest_ty.ptrSize(zcu)) { - .Slice => { + .slice => { try f.writeCValueMember(writer, dest_slice, .{ .identifier = "len" }); }, - .One => { + .one => { const array_ty = dest_ty.childType(zcu); try writer.print("{d}", .{array_ty.arrayLen(zcu)}); }, - .Many, .C => unreachable, + .many, .c => unreachable, } try writer.writeAll("; ++"); try f.writeCValue(writer, index, .Other); @@ -6981,7 +6981,7 @@ fn airMemset(f: *Function, inst: Air.Inst.Index, safety: bool) !CValue { try writer.writeAll("memset("); switch (dest_ty.ptrSize(zcu)) { - .Slice => { + .slice => { try f.writeCValueMember(writer, dest_slice, .{ .identifier = "ptr" }); try writer.writeAll(", "); try f.writeCValue(writer, bitcasted, .FunctionArgument); @@ -6989,7 +6989,7 @@ fn airMemset(f: *Function, inst: Air.Inst.Index, safety: bool) !CValue { try f.writeCValueMember(writer, dest_slice, .{ .identifier = "len" }); try writer.writeAll(");\n"); }, - .One => { + .one => { const array_ty = dest_ty.childType(zcu); const len = array_ty.arrayLen(zcu) * elem_abi_size; @@ -6998,7 +6998,7 @@ fn airMemset(f: *Function, inst: Air.Inst.Index, safety: bool) !CValue { try f.writeCValue(writer, bitcasted, .FunctionArgument); try writer.print(", {d});\n", .{len}); }, - .Many, .C => unreachable, + .many, .c => unreachable, } try f.freeCValue(inst, bitcasted); try reap(f, inst, &.{ bin_op.lhs, bin_op.rhs }); @@ -7015,7 +7015,7 @@ fn airMemcpy(f: *Function, inst: Air.Inst.Index) !CValue { const src_ty = f.typeOf(bin_op.rhs); const writer = f.object.writer(); - if (dest_ty.ptrSize(zcu) != .One) { + if (dest_ty.ptrSize(zcu) != .one) { try writer.writeAll("if ("); try writeArrayLen(f, writer, dest_ptr, dest_ty); try writer.writeAll(" != 0) "); @@ -7038,11 +7038,11 @@ fn writeArrayLen(f: *Function, writer: ArrayListWriter, dest_ptr: CValue, dest_t const pt = f.object.dg.pt; const zcu = pt.zcu; switch (dest_ty.ptrSize(zcu)) { - .One => try writer.print("{}", .{ + .one => try writer.print("{}", .{ try f.fmtIntLiteral(try pt.intValue(Type.usize, dest_ty.childType(zcu).arrayLen(zcu))), }), - .Many, .C => unreachable, - .Slice => try f.writeCValueMember(writer, dest_ptr, .{ .identifier = "len" }), + .many, .c => unreachable, + .slice => try f.writeCValueMember(writer, dest_ptr, .{ .identifier = "len" }), } } diff --git a/src/codegen/c/Type.zig b/src/codegen/c/Type.zig index 31daa75a1354..2c2db8b50668 100644 --- a/src/codegen/c/Type.zig +++ b/src/codegen/c/Type.zig @@ -1458,7 +1458,7 @@ pub const Pool = struct { _ => |ip_index| switch (ip.indexToKey(ip_index)) { .int_type => |int_info| return pool.fromIntInfo(allocator, int_info, mod, kind), .ptr_type => |ptr_info| switch (ptr_info.flags.size) { - .One, .Many, .C => { + .one, .many, .c => { const elem_ctype = elem_ctype: { if (ptr_info.packed_offset.host_size > 0 and ptr_info.flags.vector_index == .none) @@ -1505,7 +1505,7 @@ pub const Pool = struct { .@"volatile" = ptr_info.flags.is_volatile, }); }, - .Slice => { + .slice => { const target = &mod.resolved_target.result; var fields = [_]Info.Field{ .{ @@ -1598,7 +1598,7 @@ pub const Pool = struct { switch (payload_type) { .anyerror_type => return payload_ctype, else => switch (ip.indexToKey(payload_type)) { - .ptr_type => |payload_ptr_info| if (payload_ptr_info.flags.size != .C and + .ptr_type => |payload_ptr_info| if (payload_ptr_info.flags.size != .c and !payload_ptr_info.flags.is_allowzero) return payload_ctype, .error_set_type, .inferred_error_set_type => return payload_ctype, else => {}, diff --git a/src/codegen/llvm.zig b/src/codegen/llvm.zig index c23cc4354c69..99403db78cb2 100644 --- a/src/codegen/llvm.zig +++ b/src/codegen/llvm.zig @@ -2109,7 +2109,7 @@ pub const Object = struct { ptr_info.flags.is_allowzero or ptr_info.flags.is_const or ptr_info.flags.is_volatile or - ptr_info.flags.size == .Many or ptr_info.flags.size == .C or + ptr_info.flags.size == .many or ptr_info.flags.size == .c or !Type.fromInterned(ptr_info.child).hasRuntimeBitsIgnoreComptime(zcu)) { const bland_ptr_ty = try pt.ptrType(.{ @@ -2120,8 +2120,8 @@ pub const Object = struct { .flags = .{ .alignment = ptr_info.flags.alignment, .size = switch (ptr_info.flags.size) { - .Many, .C, .One => .One, - .Slice => .Slice, + .many, .c, .one => .one, + .slice => .slice, }, }, }); @@ -3382,8 +3382,8 @@ pub const Object = struct { toLlvmAddressSpace(ptr_type.flags.address_space, target), ); break :type switch (ptr_type.flags.size) { - .One, .Many, .C => ptr_ty, - .Slice => try o.builder.structType(.normal, &.{ + .one, .many, .c => ptr_ty, + .slice => try o.builder.structType(.normal, &.{ ptr_ty, try o.lowerType(Type.usize), }), @@ -6988,7 +6988,7 @@ pub const FuncGen = struct { const zcu = pt.zcu; const llvm_usize = try o.lowerType(Type.usize); switch (ty.ptrSize(zcu)) { - .Slice => { + .slice => { const len = try fg.wip.extractValue(ptr, &.{1}, ""); const elem_ty = ty.childType(zcu); const abi_size = elem_ty.abiSize(zcu); @@ -6996,13 +6996,13 @@ pub const FuncGen = struct { const abi_size_llvm_val = try o.builder.intValue(llvm_usize, abi_size); return fg.wip.bin(.@"mul nuw", len, abi_size_llvm_val, ""); }, - .One => { + .one => { const array_ty = ty.childType(zcu); const elem_ty = array_ty.childType(zcu); const abi_size = elem_ty.abiSize(zcu); return o.builder.intValue(llvm_usize, array_ty.arrayLen(zcu) * abi_size); }, - .Many, .C => unreachable, + .many, .c => unreachable, } } @@ -8670,11 +8670,11 @@ pub const FuncGen = struct { const llvm_elem_ty = try o.lowerPtrElemTy(ptr_ty.childType(zcu)); switch (ptr_ty.ptrSize(zcu)) { // It's a pointer to an array, so according to LLVM we need an extra GEP index. - .One => return self.wip.gep(.inbounds, llvm_elem_ty, ptr, &.{ + .one => return self.wip.gep(.inbounds, llvm_elem_ty, ptr, &.{ try o.builder.intValue(try o.lowerType(Type.usize), 0), offset, }, ""), - .C, .Many => return self.wip.gep(.inbounds, llvm_elem_ty, ptr, &.{offset}, ""), - .Slice => { + .c, .many => return self.wip.gep(.inbounds, llvm_elem_ty, ptr, &.{offset}, ""), + .slice => { const base = try self.wip.extractValue(ptr, &.{0}, ""); return self.wip.gep(.inbounds, llvm_elem_ty, base, &.{offset}, ""); }, @@ -8693,11 +8693,11 @@ pub const FuncGen = struct { const llvm_elem_ty = try o.lowerPtrElemTy(ptr_ty.childType(zcu)); switch (ptr_ty.ptrSize(zcu)) { // It's a pointer to an array, so according to LLVM we need an extra GEP index. - .One => return self.wip.gep(.inbounds, llvm_elem_ty, ptr, &.{ + .one => return self.wip.gep(.inbounds, llvm_elem_ty, ptr, &.{ try o.builder.intValue(try o.lowerType(Type.usize), 0), negative_offset, }, ""), - .C, .Many => return self.wip.gep(.inbounds, llvm_elem_ty, ptr, &.{negative_offset}, ""), - .Slice => { + .c, .many => return self.wip.gep(.inbounds, llvm_elem_ty, ptr, &.{negative_offset}, ""), + .slice => { const base = try self.wip.extractValue(ptr, &.{0}, ""); return self.wip.gep(.inbounds, llvm_elem_ty, base, &.{negative_offset}, ""); }, @@ -10034,9 +10034,9 @@ pub const FuncGen = struct { const llvm_usize_ty = try o.lowerType(Type.usize); const len = switch (ptr_ty.ptrSize(zcu)) { - .Slice => try self.wip.extractValue(dest_slice, &.{1}, ""), - .One => try o.builder.intValue(llvm_usize_ty, ptr_ty.childType(zcu).arrayLen(zcu)), - .Many, .C => unreachable, + .slice => try self.wip.extractValue(dest_slice, &.{1}, ""), + .one => try o.builder.intValue(llvm_usize_ty, ptr_ty.childType(zcu).arrayLen(zcu)), + .many, .c => unreachable, }; const elem_llvm_ty = try o.lowerType(elem_ty); const end_ptr = try self.wip.gep(.inbounds, elem_llvm_ty, dest_ptr, &.{len}, ""); diff --git a/src/codegen/llvm/Builder.zig b/src/codegen/llvm/Builder.zig index f5b05dfecd8e..b0869f3a8f35 100644 --- a/src/codegen/llvm/Builder.zig +++ b/src/codegen/llvm/Builder.zig @@ -8463,7 +8463,7 @@ pub const Metadata = enum(u32) { field.* = .{ .name = name, .type = []const u8, - .default_value = null, + .default_value_ptr = null, .is_comptime = false, .alignment = 0, }; @@ -8474,7 +8474,7 @@ pub const Metadata = enum(u32) { field.* = .{ .name = name, .type = std.fmt.Formatter(format), - .default_value = null, + .default_value_ptr = null, .is_comptime = false, .alignment = 0, }; diff --git a/src/codegen/spirv.zig b/src/codegen/spirv.zig index 91e2c4f7e7ca..ceb9c46b1ba3 100644 --- a/src/codegen/spirv.zig +++ b/src/codegen/spirv.zig @@ -1705,13 +1705,13 @@ const NavGen = struct { const storage_class = self.spvStorageClass(ptr_info.flags.address_space); const ptr_ty_id = try self.ptrType(child_ty, storage_class); - if (target.os.tag == .vulkan and ptr_info.flags.size == .Many) { + if (target.os.tag == .vulkan and ptr_info.flags.size == .many) { try self.spv.decorate(ptr_ty_id, .{ .ArrayStride = .{ .array_stride = @intCast(child_ty.abiSize(zcu)), } }); } - if (ptr_info.flags.size != .Slice) { + if (ptr_info.flags.size != .slice) { return ptr_ty_id; } @@ -4399,15 +4399,15 @@ const NavGen = struct { const result_ty_id = try self.resolveType(result_ty, .direct); switch (ptr_ty.ptrSize(zcu)) { - .One => { + .one => { // Pointer to array // TODO: Is this correct? return try self.accessChainId(result_ty_id, ptr_id, &.{offset_id}); }, - .C, .Many => { + .c, .many => { return try self.ptrAccessChain(result_ty_id, ptr_id, offset_id, &.{}); }, - .Slice => { + .slice => { // TODO: This is probably incorrect. A slice should be returned here, though this is what llvm does. const slice_ptr_id = try self.extractField(result_ty, ptr_id, 0); return try self.ptrAccessChain(result_ty_id, slice_ptr_id, offset_id, &.{}); @@ -4989,15 +4989,15 @@ const NavGen = struct { const pt = self.pt; const zcu = pt.zcu; switch (ty.ptrSize(zcu)) { - .Slice => return self.extractField(Type.usize, operand_id, 1), - .One => { + .slice => return self.extractField(Type.usize, operand_id, 1), + .one => { const array_ty = ty.childType(zcu); const elem_ty = array_ty.childType(zcu); const abi_size = elem_ty.abiSize(zcu); const size = array_ty.arrayLenIncludingSentinel(zcu) * abi_size; return try self.constInt(Type.usize, size, .direct); }, - .Many, .C => unreachable, + .many, .c => unreachable, } } diff --git a/src/codegen/spirv/Section.zig b/src/codegen/spirv/Section.zig index 1fdf884bdbed..4fe12f999f82 100644 --- a/src/codegen/spirv/Section.zig +++ b/src/codegen/spirv/Section.zig @@ -159,7 +159,7 @@ pub fn writeOperand(section: *Section, comptime Operand: type, operand: Operand) section.writeOperand(info.child, child); }, .pointer => |info| { - std.debug.assert(info.size == .Slice); // Should be no other pointer types in the spec. + std.debug.assert(info.size == .slice); // Should be no other pointer types in the spec. for (operand) |item| { section.writeOperand(info.child, item); } @@ -292,7 +292,7 @@ fn operandSize(comptime Operand: type, operand: Operand) usize { .@"enum" => 1, .optional => |info| if (operand) |child| operandSize(info.child, child) else 0, .pointer => |info| blk: { - std.debug.assert(info.size == .Slice); // Should be no other pointer types in the spec. + std.debug.assert(info.size == .slice); // Should be no other pointer types in the spec. var total: usize = 0; for (operand) |item| { total += operandSize(info.child, item); diff --git a/src/crash_report.zig b/src/crash_report.zig index 45410890a5fc..48a7fd5c39ec 100644 --- a/src/crash_report.zig +++ b/src/crash_report.zig @@ -190,7 +190,7 @@ pub fn attachSegfaultHandler() void { debug.updateSegfaultHandler(&act); } -fn handleSegfaultPosix(sig: i32, info: *const posix.siginfo_t, ctx_ptr: ?*anyopaque) callconv(.C) noreturn { +fn handleSegfaultPosix(sig: i32, info: *const posix.siginfo_t, ctx_ptr: ?*anyopaque) callconv(.c) noreturn { // TODO: use alarm() here to prevent infinite loops PanicSwitch.preDispatch(); diff --git a/src/link/Dwarf.zig b/src/link/Dwarf.zig index f76c4838539e..392d9dd181bf 100644 --- a/src/link/Dwarf.zig +++ b/src/link/Dwarf.zig @@ -3182,7 +3182,7 @@ fn updateLazyType( try uleb128(diw, ty.abiAlignment(zcu).toByteUnits().?); }, .ptr_type => |ptr_type| switch (ptr_type.flags.size) { - .One, .Many, .C => { + .one, .many, .c => { const ptr_child_type: Type = .fromInterned(ptr_type.child); try wip_nav.abbrevCode(if (ptr_type.sentinel == .none) .ptr_type else .ptr_sentinel_type); try wip_nav.strp(name); @@ -3210,7 +3210,7 @@ fn updateLazyType( try wip_nav.refType(ptr_child_type); } }, - .Slice => { + .slice => { try wip_nav.abbrevCode(.generated_struct_type); try wip_nav.strp(name); try uleb128(diw, ty.abiSize(zcu)); diff --git a/src/link/tapi/yaml.zig b/src/link/tapi/yaml.zig index 557ba8a91c23..dd392bc3b2a6 100644 --- a/src/link/tapi/yaml.zig +++ b/src/link/tapi/yaml.zig @@ -248,7 +248,7 @@ pub const Value = union(enum) { .array => return encode(arena, &input), .pointer => |info| switch (info.size) { - .One => switch (@typeInfo(info.child)) { + .one => switch (@typeInfo(info.child)) { .array => |child_info| { const Slice = []const child_info.child; return encode(arena, @as(Slice, input)); @@ -257,7 +257,7 @@ pub const Value = union(enum) { @compileError("Unhandled type: {s}" ++ @typeName(info.child)); }, }, - .Slice => { + .slice => { if (info.child == u8) { return Value{ .string = try arena.dupe(u8, input) }; } @@ -357,7 +357,7 @@ pub const Yaml = struct { }, .pointer => |info| { switch (info.size) { - .Slice => { + .slice => { var parsed = try self.arena.allocator().alloc(info.child, self.docs.items.len); for (self.docs.items, 0..) |doc, i| { parsed[i] = try self.parseValue(info.child, doc); @@ -446,7 +446,7 @@ pub const Yaml = struct { const arena = self.arena.allocator(); switch (ptr_info.size) { - .Slice => { + .slice => { if (ptr_info.child == u8) { return value.asString(); } diff --git a/src/mutable_value.zig b/src/mutable_value.zig index 9e63494d12ff..d894adfa331f 100644 --- a/src/mutable_value.zig +++ b/src/mutable_value.zig @@ -256,7 +256,7 @@ pub const MutableValue = union(enum) { }, .pointer => { const ptr_ty = ip.indexToKey(ty_ip).ptr_type; - if (ptr_ty.flags.size != .Slice) return; + if (ptr_ty.flags.size != .slice) return; const ptr = try arena.create(MutableValue); const len = try arena.create(MutableValue); ptr.* = .{ .interned = try pt.intern(.{ .undef = ip.slicePtrType(ty_ip) }) }; diff --git a/src/translate_c.zig b/src/translate_c.zig index c28d2c46b299..410791d3dc23 100644 --- a/src/translate_c.zig +++ b/src/translate_c.zig @@ -231,13 +231,13 @@ fn prepopulateGlobalNameTable(ast_unit: *clang.ASTUnit, c: *Context) !void { } } -fn declVisitorNamesOnlyC(context: ?*anyopaque, decl: *const clang.Decl) callconv(.C) bool { +fn declVisitorNamesOnlyC(context: ?*anyopaque, decl: *const clang.Decl) callconv(.c) bool { const c: *Context = @ptrCast(@alignCast(context)); declVisitorNamesOnly(c, decl) catch return false; return true; } -fn declVisitorC(context: ?*anyopaque, decl: *const clang.Decl) callconv(.C) bool { +fn declVisitorC(context: ?*anyopaque, decl: *const clang.Decl) callconv(.c) bool { const c: *Context = @ptrCast(@alignCast(context)); declVisitor(c, decl) catch return false; return true; diff --git a/stage1/config.zig.in b/stage1/config.zig.in index 500e089fa8e4..47d4b4e85feb 100644 --- a/stage1/config.zig.in +++ b/stage1/config.zig.in @@ -13,3 +13,4 @@ pub const value_tracing = false; pub const skip_non_native = false; pub const force_gpa = false; pub const dev = .core; +pub const value_interpret_mode = .direct; diff --git a/stage1/zig.h b/stage1/zig.h index 248bb8641cc7..e636785f1e0a 100644 --- a/stage1/zig.h +++ b/stage1/zig.h @@ -1,33 +1,143 @@ #undef linux -#ifndef __STDC_WANT_IEC_60559_TYPES_EXT__ -#define __STDC_WANT_IEC_60559_TYPES_EXT__ -#endif -#include -#include #include #include -#include - -#if _MSC_VER -#include -#elif defined(__i386__) || defined(__x86_64__) -#include -#endif -#if !defined(__cplusplus) && __STDC_VERSION__ <= 201710L -#if __STDC_VERSION__ >= 199901L -#include +#if defined(_MSC_VER) +#define zig_msvc +#elif defined(__clang__) +#define zig_clang +#define zig_gnuc +#elif defined(__GNUC__) +#define zig_gnuc +#elif defined(__IBMC__) +#define zig_xlc +#elif defined(__TINYC__) +#define zig_tinyc +#elif defined(__slimcc__) +#define zig_slimcc +#endif + +#if defined(__aarch64__) || (defined(zig_msvc) && defined(_M_ARM64)) +#define zig_aarch64 +#elif defined(__thumb__) || (defined(zig_msvc) && defined(_M_ARM)) +#define zig_thumb +#define zig_arm +#elif defined(__arm__) +#define zig_arm +#elif defined(__hexagon__) +#define zig_hexagon +#elif defined(__loongarch32) +#define zig_loongarch32 +#define zig_loongarch +#elif defined(__loongarch64) +#define zig_loongarch64 +#define zig_loongarch +#elif defined(__mips64) +#define zig_mips64 +#define zig_mips +#elif defined(__mips__) +#define zig_mips32 +#define zig_mips +#elif defined(__powerpc64__) +#define zig_powerpc64 +#define zig_powerpc +#elif defined(__powerpc__) +#define zig_powerpc32 +#define zig_powerpc +#elif defined(__riscv) && __riscv_xlen == 32 +#define zig_riscv32 +#define zig_riscv +#elif defined(__riscv) && __riscv_xlen == 64 +#define zig_riscv64 +#define zig_riscv +#elif defined(__s390x__) +#define zig_s390x +#elif defined(__sparc__) && defined(__arch64__) +#define zig_sparc64 +#define zig_sparc +#elif defined(__sparc__) +#define zig_sparc32 +#define zig_sparc +#elif defined(__wasm32__) +#define zig_wasm32 +#define zig_wasm +#elif defined(__wasm64__) +#define zig_wasm64 +#define zig_wasm +#elif defined(__i386__) || (defined(zig_msvc) && defined(_M_IX86)) +#define zig_x86_32 +#define zig_x86 +#elif defined (__x86_64__) || (defined(zig_msvc) && defined(_M_X64)) +#define zig_x86_64 +#define zig_x86 +#endif + +#if defined(zig_msvc) || __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ +#define zig_little_endian 1 +#define zig_big_endian 0 #else -typedef char bool; -#define false 0 -#define true 1 +#define zig_little_endian 0 +#define zig_big_endian 1 #endif + +#if defined(_AIX) +#define zig_aix +#elif defined(__MACH__) +#define zig_darwin +#elif defined(__DragonFly__) +#define zig_dragonfly +#define zig_bsd +#elif defined(__EMSCRIPTEN__) +#define zig_emscripten +#elif defined(__FreeBSD__) +#define zig_freebsd +#define zig_bsd +#elif defined(__Fuchsia__) +#define zig_fuchsia +#elif defined(__HAIKU__) +#define zig_haiku +#elif defined(__gnu_hurd__) +#define zig_hurd +#elif defined(__linux__) +#define zig_linux +#elif defined(__NetBSD__) +#define zig_netbsd +#define zig_bsd +#elif defined(__OpenBSD__) +#define zig_openbsd +#define zig_bsd +#elif defined(__SVR4) +#define zig_solaris +#elif defined(__wasi__) +#define zig_wasi +#elif defined(_WIN32) +#define zig_windows +#elif defined(__MVS__) +#define zig_zos +#endif + +#if defined(zig_windows) +#define zig_coff +#elif defined(__ELF__) +#define zig_elf +#elif defined(zig_zos) +#define zig_goff +#elif defined(zig_darwin) +#define zig_macho +#elif defined(zig_aix) +#define zig_xcoff #endif #define zig_concat(lhs, rhs) lhs##rhs #define zig_expand_concat(lhs, rhs) zig_concat(lhs, rhs) +#if defined(__has_include) +#define zig_has_include(include) __has_include(include) +#else +#define zig_has_include(include) 0 +#endif + #if defined(__has_builtin) #define zig_has_builtin(builtin) __has_builtin(__builtin_##builtin) #else @@ -41,37 +151,19 @@ typedef char bool; #define zig_has_attribute(attribute) 0 #endif -#if __LITTLE_ENDIAN__ || _MSC_VER -#define zig_little_endian 1 -#define zig_big_endian 0 -#else -#define zig_little_endian 0 -#define zig_big_endian 1 -#endif - -#if __STDC_VERSION__ >= 201112L +#if __STDC_VERSION__ >= 202311L +#define zig_threadlocal thread_local +#elif __STDC_VERSION__ >= 201112L #define zig_threadlocal _Thread_local -#elif defined(__GNUC__) +#elif defined(zig_gnuc) || defined(zig_slimcc) #define zig_threadlocal __thread -#elif _MSC_VER +#elif defined(zig_msvc) #define zig_threadlocal __declspec(thread) #else #define zig_threadlocal zig_threadlocal_unavailable #endif -#if defined(__clang__) -#define zig_clang -#elif defined(__GNUC__) -#define zig_gnuc -#endif - -#if defined(zig_gnuc) && (defined(__i386__) || defined(__x86_64__)) -#define zig_f128_has_miscompilations 1 -#else -#define zig_f128_has_miscompilations 0 -#endif - -#if _MSC_VER +#if defined(zig_msvc) #define zig_const_arr #define zig_callconv(c) __##c #else @@ -82,7 +174,7 @@ typedef char bool; #if zig_has_attribute(naked) || defined(zig_gnuc) #define zig_naked_decl __attribute__((naked)) #define zig_naked __attribute__((naked)) -#elif defined(_MSC_VER) +#elif defined(zig_msvc) #define zig_naked_decl #define zig_naked __declspec(naked) #else @@ -104,7 +196,7 @@ typedef char bool; #if zig_has_attribute(noinline) #define zig_never_inline __attribute__((noinline)) zig_maybe_flatten -#elif defined(_MSC_VER) +#elif defined(zig_msvc) #define zig_never_inline __declspec(noinline) zig_maybe_flatten #else #define zig_never_inline zig_never_inline_unavailable @@ -124,46 +216,48 @@ typedef char bool; #if __STDC_VERSION__ >= 199901L #define zig_restrict restrict -#elif defined(__GNUC__) +#elif defined(zig_gnuc) || defined(zig_tinyc) #define zig_restrict __restrict #else #define zig_restrict #endif -#if zig_has_attribute(aligned) +#if zig_has_attribute(aligned) || defined(zig_tinyc) #define zig_under_align(alignment) __attribute__((aligned(alignment))) -#elif _MSC_VER +#elif defined(zig_msvc) #define zig_under_align(alignment) __declspec(align(alignment)) #else #define zig_under_align zig_align_unavailable #endif -#if __STDC_VERSION__ >= 201112L +#if __STDC_VERSION__ >= 202311L +#define zig_align(alignment) alignas(alignment) +#elif __STDC_VERSION__ >= 201112L #define zig_align(alignment) _Alignas(alignment) #else #define zig_align(alignment) zig_under_align(alignment) #endif -#if zig_has_attribute(aligned) +#if zig_has_attribute(aligned) || defined(zig_tinyc) #define zig_align_fn(alignment) __attribute__((aligned(alignment))) -#elif _MSC_VER +#elif defined(zig_msvc) #define zig_align_fn(alignment) #else #define zig_align_fn zig_align_fn_unavailable #endif -#if zig_has_attribute(packed) +#if zig_has_attribute(packed) || defined(zig_tinyc) #define zig_packed(definition) __attribute__((packed)) definition -#elif _MSC_VER +#elif defined(zig_msvc) #define zig_packed(definition) __pragma(pack(1)) definition __pragma(pack()) #else #define zig_packed(definition) zig_packed_unavailable #endif -#if zig_has_attribute(section) +#if zig_has_attribute(section) || defined(zig_tinyc) #define zig_linksection(name) __attribute__((section(name))) #define zig_linksection_fn zig_linksection -#elif _MSC_VER +#elif defined(zig_msvc) #define zig_linksection(name) __pragma(section(name, read, write)) __declspec(allocate(name)) #define zig_linksection_fn(name) __pragma(section(name, read, execute)) __declspec(code_seg(name)) #else @@ -171,8 +265,10 @@ typedef char bool; #define zig_linksection_fn zig_linksection #endif -#if zig_has_builtin(unreachable) || defined(zig_gnuc) +#if zig_has_builtin(unreachable) || defined(zig_gnuc) || defined(zig_tinyc) #define zig_unreachable() __builtin_unreachable() +#elif defined(zig_msvc) +#define zig_unreachable() __assume(0) #else #define zig_unreachable() #endif @@ -183,23 +279,23 @@ typedef char bool; #define zig_extern extern #endif -#if _MSC_VER -#if _M_X64 +#if defined(zig_msvc) +#if defined(zig_x86_64) #define zig_mangle_c(symbol) symbol -#else /*_M_X64 */ +#else /* zig_x86_64 */ #define zig_mangle_c(symbol) "_" symbol -#endif /*_M_X64 */ -#else /* _MSC_VER */ -#if __APPLE__ +#endif /* zig_x86_64 */ +#else /* zig_msvc */ +#if defined(zig_macho) #define zig_mangle_c(symbol) "_" symbol -#else /* __APPLE__ */ +#else /* zig_macho */ #define zig_mangle_c(symbol) symbol -#endif /* __APPLE__ */ -#endif /* _MSC_VER */ +#endif /* zig_macho */ +#endif /* zig_msvc */ -#if zig_has_attribute(alias) && !__APPLE__ +#if (zig_has_attribute(alias) || defined(zig_tinyc)) && !defined(zig_macho) #define zig_export(symbol, name) __attribute__((alias(symbol))) -#elif _MSC_VER +#elif defined(zig_msvc) #define zig_export(symbol, name) ; \ __pragma(comment(linker, "/alternatename:" zig_mangle_c(name) "=" zig_mangle_c(symbol))) #else @@ -209,24 +305,24 @@ typedef char bool; #define zig_mangled_tentative zig_mangled #define zig_mangled_final zig_mangled -#if _MSC_VER +#if defined(zig_msvc) #define zig_mangled(mangled, unmangled) ; \ zig_export(#mangled, unmangled) #define zig_mangled_export(mangled, unmangled, symbol) \ zig_export(unmangled, #mangled) \ zig_export(symbol, unmangled) -#else /* _MSC_VER */ +#else /* zig_msvc */ #define zig_mangled(mangled, unmangled) __asm(zig_mangle_c(unmangled)) #define zig_mangled_export(mangled, unmangled, symbol) \ zig_mangled_final(mangled, unmangled) \ zig_export(symbol, unmangled) -#endif /* _MSC_VER */ +#endif /* zig_msvc */ -#if _MSC_VER +#if defined(zig_msvc) #define zig_import(Type, fn_name, libc_name, sig_args, call_args) zig_extern Type fn_name sig_args;\ __pragma(comment(linker, "/alternatename:" zig_mangle_c(#fn_name) "=" zig_mangle_c(#libc_name))); #define zig_import_builtin(Type, fn_name, libc_name, sig_args, call_args) zig_import(Type, fn_name, sig_args, call_args) -#else /* _MSC_VER */ +#else /* zig_msvc */ #define zig_import(Type, fn_name, libc_name, sig_args, call_args) zig_extern Type fn_name sig_args __asm(zig_mangle_c(#libc_name)); #define zig_import_builtin(Type, fn_name, libc_name, sig_args, call_args) zig_extern Type libc_name sig_args; \ static inline Type fn_name sig_args { return libc_name call_args; } @@ -235,10 +331,10 @@ typedef char bool; #define zig_expand_import_0(Type, fn_name, libc_name, sig_args, call_args) zig_import(Type, fn_name, libc_name, sig_args, call_args) #define zig_expand_import_1(Type, fn_name, libc_name, sig_args, call_args) zig_import_builtin(Type, fn_name, libc_name, sig_args, call_args) -#if zig_has_attribute(weak) || defined(zig_gnuc) +#if zig_has_attribute(weak) || defined(zig_gnuc) || defined(zig_tinyc) #define zig_weak_linkage __attribute__((weak)) #define zig_weak_linkage_fn __attribute__((weak)) -#elif _MSC_VER +#elif defined(zig_msvc) #define zig_weak_linkage __declspec(selectany) #define zig_weak_linkage_fn #else @@ -246,68 +342,94 @@ typedef char bool; #define zig_weak_linkage_fn zig_weak_linkage_unavailable #endif +#if defined(zig_gnuc) || defined(zig_tinyc) || defined(zig_slimcc) +#define zig_gnuc_asm +#endif + #if zig_has_builtin(trap) #define zig_trap() __builtin_trap() -#elif defined(_MSC_VER) && (defined(_M_IX86) || defined(_M_X64)) +#elif defined(zig_msvc) + +#if defined(zig_x86) #define zig_trap() __ud2() -#elif defined(_MSC_VER) +#else #define zig_trap() __fastfail(7) -#elif defined(__thumb__) +#endif + +#elif defined(zig_gnuc_asm) + +#if defined(zig_thumb) #define zig_trap() __asm__ volatile("udf #0xfe") -#elif defined(__arm__) || defined(__aarch64__) +#elif defined(zig_arm) || defined(zig_aarch64) #define zig_trap() __asm__ volatile("udf #0xfdee") -#elif defined(__loongarch__) || defined(__powerpc__) +#elif defined(zig_hexagon) +#define zig_trap() __asm__ volatile("r27:26 = memd(#0xbadc0fee)") +#elif defined(zig_loongarch) || defined(zig_powerpc) #define zig_trap() __asm__ volatile(".word 0x0") -#elif defined(__mips__) +#elif defined(zig_mips) #define zig_trap() __asm__ volatile(".word 0x3d") -#elif defined(__riscv) +#elif defined(zig_riscv) #define zig_trap() __asm__ volatile("unimp") -#elif defined(__s390__) +#elif defined(zig_s390x) #define zig_trap() __asm__ volatile("j 0x2") -#elif defined(__sparc__) +#elif defined(zig_sparc) #define zig_trap() __asm__ volatile("illtrap") -#elif defined(__i386__) || defined(__x86_64__) +#elif defined(zig_x86) #define zig_trap() __asm__ volatile("ud2") #else #define zig_trap() zig_trap_unavailable #endif +#else +#define zig_trap() zig_trap_unavailable +#endif + #if zig_has_builtin(debugtrap) #define zig_breakpoint() __builtin_debugtrap() -#elif defined(_MSC_VER) || defined(__MINGW32__) || defined(__MINGW64__) +#elif defined(zig_msvc) #define zig_breakpoint() __debugbreak() -#elif defined(__arm__) +#elif defined(zig_gnuc_asm) + +#if defined(zig_arm) #define zig_breakpoint() __asm__ volatile("bkpt #0x0") -#elif defined(__aarch64__) +#elif defined(zig_aarch64) #define zig_breakpoint() __asm__ volatile("brk #0xf000") -#elif defined(__loongarch__) +#elif defined(zig_hexagon) +#define zig_breakpoint() __asm__ volatile("brkpt") +#elif defined(zig_loongarch) #define zig_breakpoint() __asm__ volatile("break 0x0") -#elif defined(__mips__) +#elif defined(zig_mips) #define zig_breakpoint() __asm__ volatile("break") -#elif defined(__powerpc__) +#elif defined(zig_powerpc) #define zig_breakpoint() __asm__ volatile("trap") -#elif defined(__riscv) +#elif defined(zig_riscv) #define zig_breakpoint() __asm__ volatile("ebreak") -#elif defined(__s390__) +#elif defined(zig_s390x) #define zig_breakpoint() __asm__ volatile("j 0x6") -#elif defined(__sparc__) +#elif defined(zig_sparc) #define zig_breakpoint() __asm__ volatile("ta 0x1") -#elif defined(__i386__) || defined(__x86_64__) +#elif defined(zig_x86) #define zig_breakpoint() __asm__ volatile("int $0x3") #else #define zig_breakpoint() zig_breakpoint_unavailable #endif -#if zig_has_builtin(return_address) || defined(zig_gnuc) +#else +#define zig_breakpoint() zig_breakpoint_unavailable +#endif + +#if zig_has_builtin(return_address) || defined(zig_gnuc) || defined(zig_tinyc) #define zig_return_address() __builtin_extract_return_addr(__builtin_return_address(0)) -#elif defined(_MSC_VER) +#elif defined(zig_msvc) #define zig_return_address() _ReturnAddress() #else #define zig_return_address() 0 #endif -#if zig_has_builtin(frame_address) || defined(zig_gnuc) +#if zig_has_builtin(frame_address) || defined(zig_gnuc) || defined(zig_tinyc) #define zig_frame_address() __builtin_frame_address(0) +#elif defined(zig_msvc) +#define zig_frame_address() _AddressOfReturnAddress() #else #define zig_frame_address() 0 #endif @@ -326,18 +448,18 @@ typedef char bool; #define zig_wasm_memory_grow(index, delta) zig_unimplemented() #endif -#if __STDC_VERSION__ >= 201112L +#if __STDC_VERSION__ >= 202311L +#define zig_noreturn [[noreturn]] +#elif __STDC_VERSION__ >= 201112L #define zig_noreturn _Noreturn -#elif zig_has_attribute(noreturn) || defined(zig_gnuc) +#elif zig_has_attribute(noreturn) || defined(zig_gnuc) || defined(zig_tinyc) #define zig_noreturn __attribute__((noreturn)) -#elif _MSC_VER +#elif defined(zig_msvc) #define zig_noreturn __declspec(noreturn) #else #define zig_noreturn #endif -#define zig_bitSizeOf(T) (CHAR_BIT * sizeof(T)) - #define zig_compiler_rt_abbrev_uint32_t si #define zig_compiler_rt_abbrev_int32_t si #define zig_compiler_rt_abbrev_uint64_t di @@ -353,12 +475,25 @@ typedef char bool; zig_extern void *memcpy (void *zig_restrict, void const *zig_restrict, size_t); zig_extern void *memset (void *, int, size_t); -/* ===================== 8/16/32/64-bit Integer Support ===================== */ +/* ================ Bool and 8/16/32/64-bit Integer Support ================= */ -#if __STDC_VERSION__ >= 199901L || _MSC_VER -#include +#include + +#define zig_bitSizeOf(T) (CHAR_BIT * sizeof(T)) + +#if __STDC_VERSION__ >= 202311L +/* bool, true, and false are provided by the language. */ +#elif __STDC_VERSION__ >= 199901L || zig_has_include() +#include #else +typedef char bool; +#define false 0 +#define true 1 +#endif +#if __STDC_VERSION__ >= 199901L || defined(zig_msvc) || zig_has_include() +#include +#else #if SCHAR_MIN == ~0x7F && SCHAR_MAX == 0x7F && UCHAR_MAX == 0xFF typedef unsigned char uint8_t; typedef signed char int8_t; @@ -1132,7 +1267,7 @@ static inline int64_t zig_bit_reverse_i64(int64_t val, uint8_t bits) { static inline uint8_t zig_popcount_i##w(int##w##_t val, uint8_t bits) { \ return zig_popcount_u##w((uint##w##_t)val, bits); \ } -#if zig_has_builtin(popcount) || defined(zig_gnuc) +#if zig_has_builtin(popcount) || defined(zig_gnuc) || defined(zig_tinyc) #define zig_builtin_popcount(w) \ static inline uint8_t zig_popcount_u##w(uint##w##_t val, uint8_t bits) { \ (void)bits; \ @@ -1161,7 +1296,7 @@ zig_builtin_popcount(64) static inline uint8_t zig_ctz_i##w(int##w##_t val, uint8_t bits) { \ return zig_ctz_u##w((uint##w##_t)val, bits); \ } -#if zig_has_builtin(ctz) || defined(zig_gnuc) +#if zig_has_builtin(ctz) || defined(zig_gnuc) || defined(zig_tinyc) #define zig_builtin_ctz(w) \ static inline uint8_t zig_ctz_u##w(uint##w##_t val, uint8_t bits) { \ if (val == 0) return bits; \ @@ -1186,7 +1321,7 @@ zig_builtin_ctz(64) static inline uint8_t zig_clz_i##w(int##w##_t val, uint8_t bits) { \ return zig_clz_u##w((uint##w##_t)val, bits); \ } -#if zig_has_builtin(clz) || defined(zig_gnuc) +#if zig_has_builtin(clz) || defined(zig_gnuc) || defined(zig_tinyc) #define zig_builtin_clz(w) \ static inline uint8_t zig_clz_u##w(uint##w##_t val, uint8_t bits) { \ if (val == 0) return bits; \ @@ -1254,7 +1389,7 @@ typedef struct { zig_align(16) int64_t hi; uint64_t lo; } zig_i128; #define zig_make_u128(hi, lo) ((zig_u128){ .h##i = (hi), .l##o = (lo) }) #define zig_make_i128(hi, lo) ((zig_i128){ .h##i = (hi), .l##o = (lo) }) -#if _MSC_VER /* MSVC doesn't allow struct literals in constant expressions */ +#if defined(zig_msvc) /* MSVC doesn't allow struct literals in constant expressions */ #define zig_init_u128(hi, lo) { .h##i = (hi), .l##o = (lo) } #define zig_init_i128(hi, lo) { .h##i = (hi), .l##o = (lo) } #else /* But non-MSVC doesn't like the unprotected commas */ @@ -3016,7 +3151,13 @@ static inline uint16_t zig_popcount_big(const void *val, bool is_signed, uint16_ /* ========================= Floating Point Support ========================= */ -#if _MSC_VER +#ifndef __STDC_WANT_IEC_60559_TYPES_EXT__ +#define __STDC_WANT_IEC_60559_TYPES_EXT__ +#endif + +#include + +#if defined(zig_msvc) float __cdecl nanf(char const* input); double __cdecl nan(char const* input); long double __cdecl nanl(char const* input); @@ -3078,7 +3219,7 @@ typedef uint16_t zig_f16; #undef zig_init_special_f16 #define zig_init_special_f16(sign, name, arg, repr) repr #endif -#if __APPLE__ && (defined(__i386__) || defined(__x86_64__)) +#if defined(zig_darwin) && defined(zig_x86) typedef uint16_t zig_compiler_rt_f16; #else typedef zig_f16 zig_compiler_rt_f16; @@ -3086,7 +3227,7 @@ typedef zig_f16 zig_compiler_rt_f16; #define zig_has_f32 1 #define zig_libc_name_f32(name) name##f -#if _MSC_VER +#if defined(zig_msvc) #define zig_init_special_f32(sign, name, arg, repr) sign zig_make_f32(zig_msvc_flt_##name, ) #else #define zig_init_special_f32(sign, name, arg, repr) zig_make_special_f32(sign, name, arg, repr) @@ -3118,7 +3259,7 @@ typedef uint32_t zig_f32; #define zig_has_f64 1 #define zig_libc_name_f64(name) name -#if _MSC_VER +#if defined(zig_msvc) #define zig_init_special_f64(sign, name, arg, repr) sign zig_make_f64(zig_msvc_flt_##name, ) #else #define zig_init_special_f64(sign, name, arg, repr) zig_make_special_f64(sign, name, arg, repr) @@ -3183,6 +3324,12 @@ typedef zig_u128 zig_f80; #define zig_init_special_f80(sign, name, arg, repr) repr #endif +#if !defined(zig_clang) && defined(zig_gnuc) && defined(zig_x86) +#define zig_f128_has_miscompilations 1 +#else +#define zig_f128_has_miscompilations 0 +#endif + #define zig_has_f128 1 #define zig_libc_name_f128(name) name##q #define zig_init_special_f128(sign, name, arg, repr) zig_make_special_f128(sign, name, arg, repr) @@ -3211,7 +3358,7 @@ typedef __float128 zig_f128; #define zig_has_f128 0 #undef zig_make_special_f128 #undef zig_init_special_f128 -#if __APPLE__ || defined(__aarch64__) +#if defined(zig_darwin) || defined(zig_aarch64) typedef __attribute__((__vector_size__(2 * sizeof(uint64_t)))) uint64_t zig_v2u64; zig_basic_operator(zig_v2u64, xor_v2u64, ^) #define zig_repr_f128 v2u64 @@ -3230,10 +3377,10 @@ typedef zig_u128 zig_f128; #endif #endif -#if !_MSC_VER && defined(ZIG_TARGET_ABI_MSVC) +#if !defined(zig_msvc) && defined(ZIG_TARGET_ABI_MSVC) /* Emulate msvc abi on a gnu compiler */ typedef zig_f64 zig_c_longdouble; -#elif _MSC_VER && !defined(ZIG_TARGET_ABI_MSVC) +#elif defined(zig_msvc) && !defined(ZIG_TARGET_ABI_MSVC) /* Emulate gnu abi on an msvc compiler */ typedef zig_f128 zig_c_longdouble; #else @@ -3582,7 +3729,7 @@ zig_float_builtins(64) res = zig_atomicrmw_expected; \ } while (0) -#if __STDC_VERSION__ >= 201112L && !defined(__STDC_NO_ATOMICS__) +#if (__STDC_VERSION__ >= 201112L || (zig_has_include() && !defined(zig_msvc))) && !defined(__STDC_NO_ATOMICS__) #include typedef enum memory_order zig_memory_order; #define zig_memory_order_relaxed memory_order_relaxed @@ -3610,7 +3757,7 @@ typedef enum memory_order zig_memory_order; #define zig_atomicrmw_add_float zig_atomicrmw_add #undef zig_atomicrmw_sub_float #define zig_atomicrmw_sub_float zig_atomicrmw_sub -#elif defined(__GNUC__) +#elif defined(zig_gnuc) typedef int zig_memory_order; #define zig_memory_order_relaxed __ATOMIC_RELAXED #define zig_memory_order_acquire __ATOMIC_ACQUIRE @@ -3633,7 +3780,7 @@ typedef int zig_memory_order; #define zig_atomic_load(res, obj, order, Type, ReprType) __atomic_load (obj, &(res), order) #undef zig_atomicrmw_xchg_float #define zig_atomicrmw_xchg_float zig_atomicrmw_xchg -#elif _MSC_VER && (_M_IX86 || _M_X64) +#elif defined(zig_msvc) && defined(zig_x86) #define zig_memory_order_relaxed 0 #define zig_memory_order_acquire 2 #define zig_memory_order_release 3 @@ -3653,7 +3800,7 @@ typedef int zig_memory_order; #define zig_atomicrmw_max(res, obj, arg, order, Type, ReprType) res = zig_msvc_atomicrmw_max_ ##Type(obj, arg) #define zig_atomic_store( obj, arg, order, Type, ReprType) zig_msvc_atomic_store_ ##Type(obj, arg) #define zig_atomic_load(res, obj, order, Type, ReprType) res = zig_msvc_atomic_load_ ##order##_##Type(obj) -/* TODO: _MSC_VER && (_M_ARM || _M_ARM64) */ +/* TODO: zig_msvc && (zig_thumb || zig_aarch64) */ #else #define zig_memory_order_relaxed 0 #define zig_memory_order_acquire 2 @@ -3676,7 +3823,7 @@ typedef int zig_memory_order; #define zig_atomic_load(res, obj, order, Type, ReprType) zig_atomics_unavailable #endif -#if _MSC_VER && (_M_IX86 || _M_X64) +#if defined(zig_msvc) && defined(zig_x86) /* TODO: zig_msvc_atomic_load should load 32 bit without interlocked on x86, and load 64 bit without interlocked on x64 */ @@ -3773,7 +3920,7 @@ zig_msvc_atomics(i16, int16_t, short, 16, 16) zig_msvc_atomics(u32, uint32_t, long, , 32) zig_msvc_atomics(i32, int32_t, long, , 32) -#if _M_X64 +#if defined(zig_x86_64) zig_msvc_atomics(u64, uint64_t, __int64, 64, 64) zig_msvc_atomics(i64, int64_t, __int64, 64, 64) #endif @@ -3818,11 +3965,11 @@ zig_msvc_atomics(i64, int64_t, __int64, 64, 64) } zig_msvc_flt_atomics(f32, long, , 32) -#if _M_X64 +#if defined(zig_x86_64) zig_msvc_flt_atomics(f64, int64_t, 64, 64) #endif -#if _M_IX86 +#if defined(zig_x86_32) static inline void zig_msvc_atomic_barrier() { int32_t barrier; __asm { @@ -3859,7 +4006,7 @@ static inline bool zig_msvc_cmpxchg_p32(void volatile* obj, void* expected, void if (!success) *(void**)expected = initial; return success; } -#else /* _M_IX86 */ +#else /* zig_x86_32 */ static inline void* zig_msvc_atomicrmw_xchg_p64(void volatile* obj, void* arg) { return _InterlockedExchangePointer(obj, arg); } @@ -3920,55 +4067,59 @@ static inline void zig_msvc_atomic_store_i128(zig_i128 volatile* obj, zig_i128 a while (!zig_cmpxchg_weak(obj, expected, arg, zig_memory_order_seq_cst, zig_memory_order_seq_cst, i128, zig_i128)); } -#endif /* _M_IX86 */ +#endif /* zig_x86_32 */ -#endif /* _MSC_VER && (_M_IX86 || _M_X64) */ +#endif /* zig_msvc && zig_x86 */ /* ======================== Special Case Intrinsics ========================= */ -#if defined(_M_ARM) || defined(__thumb__) +#if defined(zig_msvc) +#include +#endif + +#if defined(zig_thumb) static inline void* zig_thumb_windows_teb(void) { void* teb = 0; -#if defined(_MSC_VER) +#if defined(zig_msvc) teb = (void*)_MoveFromCoprocessor(15, 0, 13, 0, 2); -#elif defined(__GNUC__) +#elif defined(zig_gnuc_asm) __asm__ ("mrc p15, 0, %[ptr], c13, c0, 2" : [ptr] "=r" (teb)); #endif return teb; } -#elif defined(_M_ARM64) || defined(__arch64__) +#elif defined(zig_aarch64) static inline void* zig_aarch64_windows_teb(void) { void* teb = 0; -#if defined(_MSC_VER) +#if defined(zig_msvc) teb = (void*)__readx18qword(0x0); -#elif defined(__GNUC__) +#elif defined(zig_gnuc_asm) __asm__ ("mov %[ptr], x18" : [ptr] "=r" (teb)); #endif return teb; } -#elif defined(_M_IX86) || defined(__i386__) +#elif defined(zig_x86_32) static inline void* zig_x86_windows_teb(void) { void* teb = 0; -#if defined(_MSC_VER) +#if defined(zig_msvc) teb = (void*)__readfsdword(0x18); -#elif defined(__GNUC__) +#elif defined(zig_gnuc_asm) __asm__ ("movl %%fs:0x18, %[ptr]" : [ptr] "=r" (teb)); #endif return teb; } -#elif defined(_M_X64) || defined(__x86_64__) +#elif defined(zig_x86_64) static inline void* zig_x86_64_windows_teb(void) { void* teb = 0; -#if defined(_MSC_VER) +#if defined(zig_msvc) teb = (void*)__readgsqword(0x30); -#elif defined(__GNUC__) +#elif defined(zig_gnuc_asm) __asm__ ("movq %%gs:0x30, %[ptr]" : [ptr] "=r" (teb)); #endif return teb; @@ -3976,29 +4127,39 @@ static inline void* zig_x86_64_windows_teb(void) { #endif -#if (_MSC_VER && (_M_IX86 || _M_X64)) || defined(__i386__) || defined(__x86_64__) +#if defined(zig_x86) static inline void zig_x86_cpuid(uint32_t leaf_id, uint32_t subid, uint32_t* eax, uint32_t* ebx, uint32_t* ecx, uint32_t* edx) { -#if _MSC_VER +#if defined(zig_msvc) int cpu_info[4]; __cpuidex(cpu_info, leaf_id, subid); *eax = (uint32_t)cpu_info[0]; *ebx = (uint32_t)cpu_info[1]; *ecx = (uint32_t)cpu_info[2]; *edx = (uint32_t)cpu_info[3]; +#elif defined(zig_gnuc_asm) + __asm__("cpuid" : "=a"(*eax), "=b"(*ebx), "=c"(*ecx), "=d"(*edx) : "a"(leaf_id), "c"(subid)); #else - __cpuid_count(leaf_id, subid, *eax, *ebx, *ecx, *edx); + *eax = 0; + *ebx = 0; + *ecx = 0; + *edx = 0; #endif } static inline uint32_t zig_x86_get_xcr0(void) { -#if _MSC_VER +#if defined(zig_msvc) return (uint32_t)_xgetbv(0); -#else +#elif defined(zig_gnuc_asm) uint32_t eax; uint32_t edx; __asm__("xgetbv" : "=a"(eax), "=d"(edx) : "c"(0)); return eax; +#else + *eax = 0; + *ebx = 0; + *ecx = 0; + *edx = 0; #endif } diff --git a/stage1/zig1.wasm b/stage1/zig1.wasm index 4ee7f618be72..7ea45015a55c 100644 Binary files a/stage1/zig1.wasm and b/stage1/zig1.wasm differ diff --git a/test/behavior/align.zig b/test/behavior/align.zig index 9974715e3b70..d360a99aa333 100644 --- a/test/behavior/align.zig +++ b/test/behavior/align.zig @@ -410,11 +410,11 @@ test "alignment of function with c calling convention" { var runtime_nothing = ¬hing; _ = &runtime_nothing; const casted1: *align(a) const u8 = @ptrCast(runtime_nothing); - const casted2: *const fn () callconv(.C) void = @ptrCast(casted1); + const casted2: *const fn () callconv(.c) void = @ptrCast(casted1); casted2(); } -fn nothing() callconv(.C) void {} +fn nothing() callconv(.c) void {} const DefaultAligned = struct { nevermind: u32, diff --git a/test/behavior/cast.zig b/test/behavior/cast.zig index 50e13a355b47..37db3ba941d0 100644 --- a/test/behavior/cast.zig +++ b/test/behavior/cast.zig @@ -1118,7 +1118,7 @@ test "compile time int to ptr of function" { // On some architectures function pointers must be aligned. const hardcoded_fn_addr = maxInt(usize) & ~@as(usize, 0xf); pub const FUNCTION_CONSTANT = @as(PFN_void, @ptrFromInt(hardcoded_fn_addr)); -pub const PFN_void = *const fn (*anyopaque) callconv(.C) void; +pub const PFN_void = *const fn (*anyopaque) callconv(.c) void; fn foobar(func: PFN_void) !void { try std.testing.expect(@intFromPtr(func) == hardcoded_fn_addr); @@ -1281,11 +1281,11 @@ test "implicit cast *[0]T to E![]const u8" { var global_array: [4]u8 = undefined; test "cast from array reference to fn: comptime fn ptr" { - const f = @as(*align(1) const fn () callconv(.C) void, @ptrCast(&global_array)); + const f = @as(*align(1) const fn () callconv(.c) void, @ptrCast(&global_array)); try expect(@intFromPtr(f) == @intFromPtr(&global_array)); } test "cast from array reference to fn: runtime fn ptr" { - var f = @as(*align(1) const fn () callconv(.C) void, @ptrCast(&global_array)); + var f = @as(*align(1) const fn () callconv(.c) void, @ptrCast(&global_array)); _ = &f; try expect(@intFromPtr(f) == @intFromPtr(&global_array)); } @@ -1309,12 +1309,12 @@ test "*const [N]null u8 to ?[]const u8" { test "cast between [*c]T and ?[*:0]T on fn parameter" { const S = struct { - const Handler = ?fn ([*c]const u8) callconv(.C) void; + const Handler = ?fn ([*c]const u8) callconv(.c) void; fn addCallback(comptime handler: Handler) void { _ = handler; } - fn myCallback(cstr: ?[*:0]const u8) callconv(.C) void { + fn myCallback(cstr: ?[*:0]const u8) callconv(.c) void { _ = cstr; } diff --git a/test/behavior/export_builtin.zig b/test/behavior/export_builtin.zig index bd53a1df9314..2b9a64b2abcb 100644 --- a/test/behavior/export_builtin.zig +++ b/test/behavior/export_builtin.zig @@ -26,7 +26,7 @@ test "exporting with internal linkage" { if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; const S = struct { - fn foo() callconv(.C) void {} + fn foo() callconv(.c) void {} comptime { @export(&foo, .{ .name = "exporting_with_internal_linkage_foo", .linkage = .internal }); } diff --git a/test/behavior/export_keyword.zig b/test/behavior/export_keyword.zig index 7e8638111714..2b49017be607 100644 --- a/test/behavior/export_keyword.zig +++ b/test/behavior/export_keyword.zig @@ -44,7 +44,7 @@ test "export function alias" { if (builtin.zig_backend == .stage2_x86_64 and builtin.target.ofmt != .elf and builtin.target.ofmt != .macho) return error.SkipZigTest; _ = struct { - fn foo_internal() callconv(.C) u32 { + fn foo_internal() callconv(.c) u32 { return 123; } export const foo_exported = foo_internal; diff --git a/test/behavior/extern.zig b/test/behavior/extern.zig index 0ef3e4935337..48b82fdf58c8 100644 --- a/test/behavior/extern.zig +++ b/test/behavior/extern.zig @@ -20,7 +20,7 @@ test "function extern symbol" { if (builtin.zig_backend == .stage2_x86_64 and builtin.target.ofmt != .elf and builtin.target.ofmt != .macho) return error.SkipZigTest; if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; - const a = @extern(*const fn () callconv(.C) i32, .{ .name = "a_mystery_function" }); + const a = @extern(*const fn () callconv(.c) i32, .{ .name = "a_mystery_function" }); try expect(a() == 4567); } @@ -35,7 +35,7 @@ test "function extern symbol matches extern decl" { const S = struct { extern fn another_mystery_function() u32; - const same_thing = @extern(*const fn () callconv(.C) u32, .{ .name = "another_mystery_function" }); + const same_thing = @extern(*const fn () callconv(.c) u32, .{ .name = "another_mystery_function" }); }; try expect(S.another_mystery_function() == 12345); try expect(S.same_thing() == 12345); @@ -55,5 +55,5 @@ test "coerce extern function types" { }; _ = S; - _ = @as(fn () callconv(.C) ?*u32, c_extern_function); + _ = @as(fn () callconv(.c) ?*u32, c_extern_function); } diff --git a/test/behavior/fn.zig b/test/behavior/fn.zig index b041be93d900..975b0e9baa3e 100644 --- a/test/behavior/fn.zig +++ b/test/behavior/fn.zig @@ -153,9 +153,9 @@ test "extern struct with stdcallcc fn pointer" { if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; const S = extern struct { - ptr: *const fn () callconv(if (builtin.target.cpu.arch == .x86) .Stdcall else .C) i32, + ptr: *const fn () callconv(if (builtin.target.cpu.arch == .x86) .Stdcall else .c) i32, - fn foo() callconv(if (builtin.target.cpu.arch == .x86) .Stdcall else .C) i32 { + fn foo() callconv(if (builtin.target.cpu.arch == .x86) .Stdcall else .c) i32 { return 1234; } }; @@ -169,7 +169,7 @@ const nComplexCallconv = 100; fn fComplexCallconvRet(x: u32) callconv(blk: { const s: struct { n: u32 } = .{ .n = nComplexCallconv }; break :blk switch (s.n) { - 0 => .C, + 0 => .c, 1 => .Inline, else => .Unspecified, }; @@ -435,13 +435,13 @@ test "implicit cast function to function ptr" { return 123; } }; - var fnPtr1: *const fn () callconv(.C) c_int = S1.someFunctionThatReturnsAValue; + var fnPtr1: *const fn () callconv(.c) c_int = S1.someFunctionThatReturnsAValue; _ = &fnPtr1; try expect(fnPtr1() == 123); const S2 = struct { extern fn someFunctionThatReturnsAValue() c_int; }; - var fnPtr2: *const fn () callconv(.C) c_int = S2.someFunctionThatReturnsAValue; + var fnPtr2: *const fn () callconv(.c) c_int = S2.someFunctionThatReturnsAValue; _ = &fnPtr2; try expect(fnPtr2() == 123); } diff --git a/test/behavior/generics.zig b/test/behavior/generics.zig index 70d07da5f4bd..4e86419258ab 100644 --- a/test/behavior/generics.zig +++ b/test/behavior/generics.zig @@ -324,7 +324,7 @@ test "generic function instantiation non-duplicates" { for (source, 0..) |s, i| dest[i] = s; } - fn foo() callconv(.C) void {} + fn foo() callconv(.c) void {} }; var buffer: [100]u8 = undefined; S.copy(u8, &buffer, "hello"); @@ -471,13 +471,13 @@ test "coerced function body has inequal value with its uncoerced body" { try expect(S.A.do() == 1234); } -test "generic function returns value from callconv(.C) function" { +test "generic function returns value from callconv(.c) function" { const S = struct { - fn getU8() callconv(.C) u8 { + fn getU8() callconv(.c) u8 { return 123; } - fn getGeneric(comptime T: type, supplier: fn () callconv(.C) T) T { + fn getGeneric(comptime T: type, supplier: fn () callconv(.c) T) T { return supplier(); } }; @@ -521,11 +521,11 @@ test "function argument tuple used as struct field" { try expect(c.t[0] == null); } -test "comptime callconv(.C) function ptr uses comptime type argument" { +test "comptime callconv(.c) function ptr uses comptime type argument" { const S = struct { fn A( comptime T: type, - comptime destroycb: ?*const fn (?*T) callconv(.C) void, + comptime destroycb: ?*const fn (?*T) callconv(.c) void, ) !void { try expect(destroycb == null); } diff --git a/test/behavior/import_c_keywords.zig b/test/behavior/import_c_keywords.zig index 9029dca31d49..b4a48e260fdc 100644 --- a/test/behavior/import_c_keywords.zig +++ b/test/behavior/import_c_keywords.zig @@ -80,7 +80,7 @@ test "import c keywords" { try std.testing.expect(ptr_id == &some_non_c_keyword_constant); if (builtin.target.ofmt != .coff and builtin.target.os.tag != .windows) { - var ptr_fn: *const fn () callconv(.C) Id = &double; + var ptr_fn: *const fn () callconv(.c) Id = &double; try std.testing.expect(ptr_fn == &float); ptr_fn = &an_alias_of_float; try std.testing.expect(ptr_fn == &float); diff --git a/test/behavior/packed-struct.zig b/test/behavior/packed-struct.zig index 112488096118..a122a19c58e1 100644 --- a/test/behavior/packed-struct.zig +++ b/test/behavior/packed-struct.zig @@ -891,7 +891,7 @@ test "runtime init of unnamed packed struct type" { }{ .x = z }).m(); } -test "packed struct passed to callconv(.C) function" { +test "packed struct passed to callconv(.c) function" { if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO @@ -906,7 +906,7 @@ test "packed struct passed to callconv(.C) function" { d: u46 = 0, }; - fn foo(p: Packed, a1: u64, a2: u64, a3: u64, a4: u64, a5: u64) callconv(.C) bool { + fn foo(p: Packed, a1: u64, a2: u64, a3: u64, a4: u64, a5: u64) callconv(.c) bool { return p.a == 12345 and p.b == true and p.c == true and p.d == 0 and a1 == 5 and a2 == 4 and a3 == 3 and a4 == 2 and a5 == 1; } }; @@ -1270,7 +1270,7 @@ test "2-byte packed struct argument in C calling convention" { x: u15 = 0, y: u1 = 0, - fn foo(s: @This()) callconv(.C) i32 { + fn foo(s: @This()) callconv(.c) i32 { return s.x; } fn bar(s: @This()) !void { diff --git a/test/behavior/struct.zig b/test/behavior/struct.zig index 1ba81695b8d6..74a77f3e21c0 100644 --- a/test/behavior/struct.zig +++ b/test/behavior/struct.zig @@ -803,7 +803,7 @@ test "fn with C calling convention returns struct by value" { handle: i32, }; - fn makeBar(t: i32) callconv(.C) ExternBar { + fn makeBar(t: i32) callconv(.c) ExternBar { return ExternBar{ .handle = t, }; diff --git a/test/behavior/tuple.zig b/test/behavior/tuple.zig index becfcce028d9..816b9e6d46d3 100644 --- a/test/behavior/tuple.zig +++ b/test/behavior/tuple.zig @@ -141,14 +141,14 @@ test "array-like initializer for tuple types" { .{ .name = "0", .type = i32, - .default_value = null, + .default_value_ptr = null, .is_comptime = false, .alignment = @alignOf(i32), }, .{ .name = "1", .type = u8, - .default_value = null, + .default_value_ptr = null, .is_comptime = false, .alignment = @alignOf(u8), }, @@ -330,7 +330,7 @@ test "zero sized struct in tuple handled correctly" { .fields = &.{.{ .name = "0", .type = struct {}, - .default_value = null, + .default_value_ptr = null, .is_comptime = false, .alignment = 0, }}, diff --git a/test/behavior/tuple_declarations.zig b/test/behavior/tuple_declarations.zig index 907b114aebab..f437f41dec4b 100644 --- a/test/behavior/tuple_declarations.zig +++ b/test/behavior/tuple_declarations.zig @@ -20,13 +20,13 @@ test "tuple declaration type info" { try expectEqualStrings(info.fields[0].name, "0"); try expect(info.fields[0].type == u32); - try expect(@as(*const u32, @ptrCast(@alignCast(info.fields[0].default_value))).* == 1); + try expect(info.fields[0].defaultValue() == 1); try expect(info.fields[0].is_comptime); try expect(info.fields[0].alignment == @alignOf(u32)); try expectEqualStrings(info.fields[1].name, "1"); try expect(info.fields[1].type == []const u8); - try expect(info.fields[1].default_value == null); + try expect(info.fields[1].defaultValue() == null); try expect(!info.fields[1].is_comptime); try expect(info.fields[1].alignment == @alignOf([]const u8)); } diff --git a/test/behavior/type.zig b/test/behavior/type.zig index 19feb2d5fff3..13e2873e280a 100644 --- a/test/behavior/type.zig +++ b/test/behavior/type.zig @@ -118,21 +118,21 @@ test "Type.Array" { .array = .{ .len = 123, .child = u8, - .sentinel = null, + .sentinel_ptr = null, }, })); try testing.expect([2]u32 == @Type(.{ .array = .{ .len = 2, .child = u32, - .sentinel = null, + .sentinel_ptr = null, }, })); try testing.expect([2:0]u32 == @Type(.{ .array = .{ .len = 2, .child = u32, - .sentinel = &@as(u32, 0), + .sentinel_ptr = &@as(u32, 0), }, })); try testTypes(&[_]type{ [1]u8, [30]usize, [7]bool }); @@ -141,14 +141,14 @@ test "Type.Array" { test "@Type create slice with null sentinel" { const Slice = @Type(.{ .pointer = .{ - .size = .Slice, + .size = .slice, .is_const = true, .is_volatile = false, .is_allowzero = false, .alignment = 8, .address_space = .generic, .child = *i32, - .sentinel = null, + .sentinel_ptr = null, }, }); try testing.expect(Slice == []align(8) const *i32); @@ -266,10 +266,10 @@ test "Type.Struct" { try testing.expectEqual(Type.ContainerLayout.auto, infoA.layout); try testing.expectEqualSlices(u8, "x", infoA.fields[0].name); try testing.expectEqual(u8, infoA.fields[0].type); - try testing.expectEqual(@as(?*const anyopaque, null), infoA.fields[0].default_value); + try testing.expectEqual(@as(?*const anyopaque, null), infoA.fields[0].default_value_ptr); try testing.expectEqualSlices(u8, "y", infoA.fields[1].name); try testing.expectEqual(u32, infoA.fields[1].type); - try testing.expectEqual(@as(?*const anyopaque, null), infoA.fields[1].default_value); + try testing.expectEqual(@as(?*const anyopaque, null), infoA.fields[1].default_value_ptr); try testing.expectEqualSlices(Type.Declaration, &.{}, infoA.decls); try testing.expectEqual(@as(bool, false), infoA.is_tuple); @@ -284,10 +284,10 @@ test "Type.Struct" { try testing.expectEqual(Type.ContainerLayout.@"extern", infoB.layout); try testing.expectEqualSlices(u8, "x", infoB.fields[0].name); try testing.expectEqual(u8, infoB.fields[0].type); - try testing.expectEqual(@as(?*const anyopaque, null), infoB.fields[0].default_value); + try testing.expectEqual(@as(?*const anyopaque, null), infoB.fields[0].default_value_ptr); try testing.expectEqualSlices(u8, "y", infoB.fields[1].name); try testing.expectEqual(u32, infoB.fields[1].type); - try testing.expectEqual(@as(u32, 5), @as(*align(1) const u32, @ptrCast(infoB.fields[1].default_value.?)).*); + try testing.expectEqual(@as(u32, 5), infoB.fields[1].defaultValue().?); try testing.expectEqual(@as(usize, 0), infoB.decls.len); try testing.expectEqual(@as(bool, false), infoB.is_tuple); @@ -296,10 +296,10 @@ test "Type.Struct" { try testing.expectEqual(Type.ContainerLayout.@"packed", infoC.layout); try testing.expectEqualSlices(u8, "x", infoC.fields[0].name); try testing.expectEqual(u8, infoC.fields[0].type); - try testing.expectEqual(@as(u8, 3), @as(*const u8, @ptrCast(infoC.fields[0].default_value.?)).*); + try testing.expectEqual(@as(u8, 3), infoC.fields[0].defaultValue().?); try testing.expectEqualSlices(u8, "y", infoC.fields[1].name); try testing.expectEqual(u32, infoC.fields[1].type); - try testing.expectEqual(@as(u32, 5), @as(*align(1) const u32, @ptrCast(infoC.fields[1].default_value.?)).*); + try testing.expectEqual(@as(u32, 5), infoC.fields[1].defaultValue().?); try testing.expectEqual(@as(usize, 0), infoC.decls.len); try testing.expectEqual(@as(bool, false), infoC.is_tuple); @@ -309,10 +309,10 @@ test "Type.Struct" { try testing.expectEqual(Type.ContainerLayout.auto, infoD.layout); try testing.expectEqualSlices(u8, "x", infoD.fields[0].name); try testing.expectEqual(comptime_int, infoD.fields[0].type); - try testing.expectEqual(@as(comptime_int, 3), @as(*const comptime_int, @ptrCast(infoD.fields[0].default_value.?)).*); + try testing.expectEqual(@as(comptime_int, 3), infoD.fields[0].defaultValue().?); try testing.expectEqualSlices(u8, "y", infoD.fields[1].name); try testing.expectEqual(comptime_int, infoD.fields[1].type); - try testing.expectEqual(@as(comptime_int, 5), @as(*const comptime_int, @ptrCast(infoD.fields[1].default_value.?)).*); + try testing.expectEqual(@as(comptime_int, 5), infoD.fields[1].defaultValue().?); try testing.expectEqual(@as(usize, 0), infoD.decls.len); try testing.expectEqual(@as(bool, false), infoD.is_tuple); @@ -322,10 +322,10 @@ test "Type.Struct" { try testing.expectEqual(Type.ContainerLayout.auto, infoE.layout); try testing.expectEqualSlices(u8, "0", infoE.fields[0].name); try testing.expectEqual(comptime_int, infoE.fields[0].type); - try testing.expectEqual(@as(comptime_int, 1), @as(*const comptime_int, @ptrCast(infoE.fields[0].default_value.?)).*); + try testing.expectEqual(@as(comptime_int, 1), infoE.fields[0].defaultValue().?); try testing.expectEqualSlices(u8, "1", infoE.fields[1].name); try testing.expectEqual(comptime_int, infoE.fields[1].type); - try testing.expectEqual(@as(comptime_int, 2), @as(*const comptime_int, @ptrCast(infoE.fields[1].default_value.?)).*); + try testing.expectEqual(@as(comptime_int, 2), infoE.fields[1].defaultValue().?); try testing.expectEqual(@as(usize, 0), infoE.decls.len); try testing.expectEqual(@as(bool, true), infoE.is_tuple); @@ -548,11 +548,11 @@ test "Type.Fn" { const some_opaque = opaque {}; const some_ptr = *some_opaque; - const T = fn (c_int, some_ptr) callconv(.C) void; + const T = fn (c_int, some_ptr) callconv(.c) void; { const fn_info = std.builtin.Type{ .@"fn" = .{ - .calling_convention = .C, + .calling_convention = .c, .is_generic = false, .is_var_args = false, .return_type = void, @@ -582,7 +582,7 @@ test "reified struct field name from optional payload" { .fields = &.{.{ .name = name, .type = u8, - .default_value = null, + .default_value_ptr = null, .is_comptime = false, .alignment = 1, }}, @@ -628,7 +628,7 @@ test "reified struct uses @alignOf" { .{ .name = "globals", .type = modules.mach.globals, - .default_value = null, + .default_value_ptr = null, .is_comptime = false, .alignment = @alignOf(modules.mach.globals), }, @@ -688,7 +688,7 @@ test "empty struct assigned to reified struct field" { .fields = &.{.{ .name = "components", .type = @TypeOf(modules.components), - .default_value = null, + .default_value_ptr = null, .is_comptime = false, .alignment = @alignOf(@TypeOf(modules.components)), }}, @@ -738,7 +738,7 @@ test "struct field names sliced at comptime from larger string" { .alignment = 0, .name = name ++ "", .type = usize, - .default_value = null, + .default_value_ptr = null, .is_comptime = false, }}; } diff --git a/test/behavior/type_info.zig b/test/behavior/type_info.zig index 051aba15c36c..2b7a66c763f2 100644 --- a/test/behavior/type_info.zig +++ b/test/behavior/type_info.zig @@ -44,7 +44,7 @@ test "type info: C pointer type info" { fn testCPtr() !void { const ptr_info = @typeInfo([*c]align(4) const i8); try expect(ptr_info == .pointer); - try expect(ptr_info.pointer.size == .C); + try expect(ptr_info.pointer.size == .c); try expect(ptr_info.pointer.is_const); try expect(!ptr_info.pointer.is_volatile); try expect(ptr_info.pointer.alignment == 4); @@ -54,8 +54,8 @@ fn testCPtr() !void { test "type info: value is correctly copied" { comptime { var ptrInfo = @typeInfo([]u32); - ptrInfo.pointer.size = .One; - try expect(@typeInfo([]u32).pointer.size == .Slice); + ptrInfo.pointer.size = .one; + try expect(@typeInfo([]u32).pointer.size == .slice); } } @@ -79,12 +79,12 @@ test "type info: pointer type info" { fn testPointer() !void { const u32_ptr_info = @typeInfo(*u32); try expect(u32_ptr_info == .pointer); - try expect(u32_ptr_info.pointer.size == .One); + try expect(u32_ptr_info.pointer.size == .one); try expect(u32_ptr_info.pointer.is_const == false); try expect(u32_ptr_info.pointer.is_volatile == false); try expect(u32_ptr_info.pointer.alignment == @alignOf(u32)); try expect(u32_ptr_info.pointer.child == u32); - try expect(u32_ptr_info.pointer.sentinel == null); + try expect(u32_ptr_info.pointer.sentinel() == null); } test "type info: unknown length pointer type info" { @@ -95,10 +95,10 @@ test "type info: unknown length pointer type info" { fn testUnknownLenPtr() !void { const u32_ptr_info = @typeInfo([*]const volatile f64); try expect(u32_ptr_info == .pointer); - try expect(u32_ptr_info.pointer.size == .Many); + try expect(u32_ptr_info.pointer.size == .many); try expect(u32_ptr_info.pointer.is_const == true); try expect(u32_ptr_info.pointer.is_volatile == true); - try expect(u32_ptr_info.pointer.sentinel == null); + try expect(u32_ptr_info.pointer.sentinel() == null); try expect(u32_ptr_info.pointer.alignment == @alignOf(f64)); try expect(u32_ptr_info.pointer.child == f64); } @@ -111,12 +111,12 @@ test "type info: null terminated pointer type info" { fn testNullTerminatedPtr() !void { const ptr_info = @typeInfo([*:0]u8); try expect(ptr_info == .pointer); - try expect(ptr_info.pointer.size == .Many); + try expect(ptr_info.pointer.size == .many); try expect(ptr_info.pointer.is_const == false); try expect(ptr_info.pointer.is_volatile == false); - try expect(@as(*const u8, @ptrCast(ptr_info.pointer.sentinel.?)).* == 0); + try expect(ptr_info.pointer.sentinel().? == 0); - try expect(@typeInfo([:0]u8).pointer.sentinel != null); + try expect(@typeInfo([:0]u8).pointer.sentinel() != null); } test "type info: slice type info" { @@ -127,7 +127,7 @@ test "type info: slice type info" { fn testSlice() !void { const u32_slice_info = @typeInfo([]u32); try expect(u32_slice_info == .pointer); - try expect(u32_slice_info.pointer.size == .Slice); + try expect(u32_slice_info.pointer.size == .slice); try expect(u32_slice_info.pointer.is_const == false); try expect(u32_slice_info.pointer.is_volatile == false); try expect(u32_slice_info.pointer.alignment == 4); @@ -145,14 +145,14 @@ fn testArray() !void { try expect(info == .array); try expect(info.array.len == 42); try expect(info.array.child == u8); - try expect(info.array.sentinel == null); + try expect(info.array.sentinel() == null); } { const info = @typeInfo([10:0]u8); try expect(info.array.len == 10); try expect(info.array.child == u8); - try expect(@as(*const u8, @ptrCast(info.array.sentinel.?)).* == @as(u8, 0)); + try expect(info.array.sentinel().? == @as(u8, 0)); try expect(@sizeOf([10:0]u8) == info.array.len + 1); } } @@ -292,8 +292,8 @@ fn testStruct() !void { try expect(unpacked_struct_info.@"struct".is_tuple == false); try expect(unpacked_struct_info.@"struct".backing_integer == null); try expect(unpacked_struct_info.@"struct".fields[0].alignment == @alignOf(u32)); - try expect(@as(*align(1) const u32, @ptrCast(unpacked_struct_info.@"struct".fields[0].default_value.?)).* == 4); - try expect(mem.eql(u8, "foobar", @as(*align(1) const *const [6:0]u8, @ptrCast(unpacked_struct_info.@"struct".fields[1].default_value.?)).*)); + try expect(unpacked_struct_info.@"struct".fields[0].defaultValue().? == 4); + try expect(mem.eql(u8, "foobar", unpacked_struct_info.@"struct".fields[1].defaultValue().?)); } const TestStruct = struct { @@ -315,8 +315,8 @@ fn testPackedStruct() !void { try expect(struct_info.@"struct".fields.len == 4); try expect(struct_info.@"struct".fields[0].alignment == 0); try expect(struct_info.@"struct".fields[2].type == f32); - try expect(struct_info.@"struct".fields[2].default_value == null); - try expect(@as(*align(1) const u32, @ptrCast(struct_info.@"struct".fields[3].default_value.?)).* == 4); + try expect(struct_info.@"struct".fields[2].defaultValue() == null); + try expect(struct_info.@"struct".fields[3].defaultValue().? == 4); try expect(struct_info.@"struct".fields[3].alignment == 0); try expect(struct_info.@"struct".decls.len == 1); } @@ -374,13 +374,13 @@ fn testFunction() !void { try expect(foo_fn_info.@"fn".is_var_args); try expect(foo_fn_info.@"fn".return_type.? == usize); const foo_ptr_fn_info = @typeInfo(@TypeOf(&typeInfoFoo)); - try expect(foo_ptr_fn_info.pointer.size == .One); + try expect(foo_ptr_fn_info.pointer.size == .one); try expect(foo_ptr_fn_info.pointer.is_const); try expect(!foo_ptr_fn_info.pointer.is_volatile); try expect(foo_ptr_fn_info.pointer.address_space == .generic); try expect(foo_ptr_fn_info.pointer.child == foo_fn_type); try expect(!foo_ptr_fn_info.pointer.is_allowzero); - try expect(foo_ptr_fn_info.pointer.sentinel == null); + try expect(foo_ptr_fn_info.pointer.sentinel() == null); // Avoid looking at `typeInfoFooAligned` on targets which don't support function alignment. switch (builtin.target.cpu.arch) { @@ -401,14 +401,14 @@ fn testFunction() !void { try expect(aligned_foo_fn_info.@"fn".is_var_args); try expect(aligned_foo_fn_info.@"fn".return_type.? == usize); const aligned_foo_ptr_fn_info = @typeInfo(@TypeOf(&typeInfoFooAligned)); - try expect(aligned_foo_ptr_fn_info.pointer.size == .One); + try expect(aligned_foo_ptr_fn_info.pointer.size == .one); try expect(aligned_foo_ptr_fn_info.pointer.is_const); try expect(!aligned_foo_ptr_fn_info.pointer.is_volatile); try expect(aligned_foo_ptr_fn_info.pointer.alignment == 4); try expect(aligned_foo_ptr_fn_info.pointer.address_space == .generic); try expect(aligned_foo_ptr_fn_info.pointer.child == aligned_foo_fn_type); try expect(!aligned_foo_ptr_fn_info.pointer.is_allowzero); - try expect(aligned_foo_ptr_fn_info.pointer.sentinel == null); + try expect(aligned_foo_ptr_fn_info.pointer.sentinel() == null); } extern fn typeInfoFoo(a: usize, b: bool, ...) callconv(.c) usize; @@ -517,7 +517,7 @@ test "type info: TypeId -> Type impl cast" { test "sentinel of opaque pointer type" { const c_void_info = @typeInfo(*anyopaque); - try expect(c_void_info.pointer.sentinel == null); + try expect(c_void_info.pointer.sentinel_ptr == null); } test "@typeInfo does not force declarations into existence" { @@ -601,9 +601,9 @@ test "typeInfo resolves usingnamespace declarations" { try expectEqualStrings(decls[1].name, "f1"); } -test "value from struct @typeInfo default_value can be loaded at comptime" { +test "value from struct @typeInfo default_value_ptr can be loaded at comptime" { comptime { - const a = @typeInfo(@TypeOf(.{ .foo = @as(u8, 1) })).@"struct".fields[0].default_value; + const a = @typeInfo(@TypeOf(.{ .foo = @as(u8, 1) })).@"struct".fields[0].default_value_ptr; try expect(@as(*const u8, @ptrCast(a)).* == 1); } } @@ -646,7 +646,7 @@ test "@typeInfo decls ignore dependency loops" { test "type info of tuple of string literal default value" { const struct_field = @typeInfo(@TypeOf(.{"hi"})).@"struct".fields[0]; - const value = @as(*align(1) const *const [2:0]u8, @ptrCast(struct_field.default_value.?)).*; + const value = struct_field.defaultValue().?; comptime std.debug.assert(value[0] == 'h'); } diff --git a/test/behavior/union.zig b/test/behavior/union.zig index a3ce6169a565..6e8c895b1a1e 100644 --- a/test/behavior/union.zig +++ b/test/behavior/union.zig @@ -1229,7 +1229,7 @@ test "return an extern union from C calling convention" { s: S, }; - fn bar(arg_u: U) callconv(.C) U { + fn bar(arg_u: U) callconv(.c) U { var u = arg_u; _ = &u; return u; diff --git a/test/behavior/var_args.zig b/test/behavior/var_args.zig index 350379bdfeb2..b5370b781361 100644 --- a/test/behavior/var_args.zig +++ b/test/behavior/var_args.zig @@ -108,19 +108,19 @@ test "simple variadic function" { if (builtin.cpu.arch == .s390x and builtin.zig_backend == .stage2_llvm) return error.SkipZigTest; // https://github.com/ziglang/zig/issues/21350 const S = struct { - fn simple(...) callconv(.C) c_int { + fn simple(...) callconv(.c) c_int { var ap = @cVaStart(); defer @cVaEnd(&ap); return @cVaArg(&ap, c_int); } - fn compatible(_: c_int, ...) callconv(.C) c_int { + fn compatible(_: c_int, ...) callconv(.c) c_int { var ap = @cVaStart(); defer @cVaEnd(&ap); return @cVaArg(&ap, c_int); } - fn add(count: c_int, ...) callconv(.C) c_int { + fn add(count: c_int, ...) callconv(.c) c_int { var ap = @cVaStart(); defer @cVaEnd(&ap); var i: usize = 0; @@ -169,7 +169,7 @@ test "coerce reference to var arg" { if (builtin.cpu.arch == .s390x and builtin.zig_backend == .stage2_llvm) return error.SkipZigTest; // https://github.com/ziglang/zig/issues/21350 const S = struct { - fn addPtr(count: c_int, ...) callconv(.C) c_int { + fn addPtr(count: c_int, ...) callconv(.c) c_int { var ap = @cVaStart(); defer @cVaEnd(&ap); var i: usize = 0; @@ -202,7 +202,7 @@ test "variadic functions" { if (builtin.cpu.arch == .s390x and builtin.zig_backend == .stage2_llvm) return error.SkipZigTest; // https://github.com/ziglang/zig/issues/21350 const S = struct { - fn printf(list_ptr: *std.ArrayList(u8), format: [*:0]const u8, ...) callconv(.C) void { + fn printf(list_ptr: *std.ArrayList(u8), format: [*:0]const u8, ...) callconv(.c) void { var ap = @cVaStart(); defer @cVaEnd(&ap); vprintf(list_ptr, format, &ap); @@ -212,7 +212,7 @@ test "variadic functions" { list: *std.ArrayList(u8), format: [*:0]const u8, ap: *std.builtin.VaList, - ) callconv(.C) void { + ) callconv(.c) void { for (std.mem.span(format)) |c| switch (c) { 's' => { const arg = @cVaArg(ap, [*:0]const u8); @@ -247,7 +247,7 @@ test "copy VaList" { if (builtin.cpu.arch == .s390x and builtin.zig_backend == .stage2_llvm) return error.SkipZigTest; // https://github.com/ziglang/zig/issues/21350 const S = struct { - fn add(count: c_int, ...) callconv(.C) c_int { + fn add(count: c_int, ...) callconv(.c) c_int { var ap = @cVaStart(); defer @cVaEnd(&ap); var copy = @cVaCopy(&ap); @@ -284,7 +284,7 @@ test "unused VaList arg" { if (builtin.cpu.arch == .s390x and builtin.zig_backend == .stage2_llvm) return error.SkipZigTest; // https://github.com/ziglang/zig/issues/21350 const S = struct { - fn thirdArg(dummy: c_int, ...) callconv(.C) c_int { + fn thirdArg(dummy: c_int, ...) callconv(.c) c_int { _ = dummy; var ap = @cVaStart(); diff --git a/test/cases/compile_errors/generic_instantiation_failure_in_generic_function_return_type.zig b/test/cases/compile_errors/generic_instantiation_failure_in_generic_function_return_type.zig index 1be4360317b6..ee1dd783433e 100644 --- a/test/cases/compile_errors/generic_instantiation_failure_in_generic_function_return_type.zig +++ b/test/cases/compile_errors/generic_instantiation_failure_in_generic_function_return_type.zig @@ -21,7 +21,7 @@ pub fn isPtrTo(comptime id: std.builtin.TypeId) TraitFn { pub fn isSingleItemPtr(comptime T: type) bool { if (comptime is(.pointer)(T)) { - return @typeInfo(T).pointer.size == .One; + return @typeInfo(T).pointer.size == .one; } return false; } diff --git a/test/cases/compile_errors/invalid_pointer_with_reify_type.zig b/test/cases/compile_errors/invalid_pointer_with_reify_type.zig index 16b96d5327b2..c1f622c1a57d 100644 --- a/test/cases/compile_errors/invalid_pointer_with_reify_type.zig +++ b/test/cases/compile_errors/invalid_pointer_with_reify_type.zig @@ -1,18 +1,16 @@ export fn entry() void { _ = @Type(.{ .pointer = .{ - .size = .One, + .size = .one, .is_const = false, .is_volatile = false, .alignment = 1, .address_space = .generic, .child = u8, .is_allowzero = false, - .sentinel = &@as(u8, 0), + .sentinel_ptr = &@as(u8, 0), } }); } // error -// backend=stage2 -// target=native // // :2:9: error: sentinels are only allowed on slices and unknown-length pointers diff --git a/test/cases/compile_errors/non_scalar_sentinel.zig b/test/cases/compile_errors/non_scalar_sentinel.zig index 3684ac50b2b2..c2d8bced8d7b 100644 --- a/test/cases/compile_errors/non_scalar_sentinel.zig +++ b/test/cases/compile_errors/non_scalar_sentinel.zig @@ -12,30 +12,30 @@ comptime { } comptime { - _ = @Type(.{ .array = .{ .child = S, .len = 0, .sentinel = &sentinel } }); + _ = @Type(.{ .array = .{ .child = S, .len = 0, .sentinel_ptr = &sentinel } }); } comptime { _ = @Type(.{ .pointer = .{ - .size = .Many, + .size = .slice, .is_const = false, .is_volatile = false, .alignment = @alignOf(S), .address_space = .generic, .child = S, .is_allowzero = false, - .sentinel = &sentinel, + .sentinel_ptr = &sentinel, } }); } comptime { _ = @Type(.{ .pointer = .{ - .size = .Many, + .size = .many, .is_const = false, .is_volatile = false, .alignment = @alignOf(S), .address_space = .generic, .child = S, .is_allowzero = false, - .sentinel = &sentinel, + .sentinel_ptr = &sentinel, } }); } diff --git a/test/cases/compile_errors/packed_struct_field_alignment_unavailable_for_reify_type.zig b/test/cases/compile_errors/packed_struct_field_alignment_unavailable_for_reify_type.zig index 0251c018fac8..20fb548d838f 100644 --- a/test/cases/compile_errors/packed_struct_field_alignment_unavailable_for_reify_type.zig +++ b/test/cases/compile_errors/packed_struct_field_alignment_unavailable_for_reify_type.zig @@ -1,11 +1,9 @@ export fn entry() void { _ = @Type(.{ .@"struct" = .{ .layout = .@"packed", .fields = &.{ - .{ .name = "one", .type = u4, .default_value = null, .is_comptime = false, .alignment = 2 }, + .{ .name = "one", .type = u4, .default_value_ptr = null, .is_comptime = false, .alignment = 2 }, }, .decls = &.{}, .is_tuple = false } }); } // error -// backend=stage2 -// target=native // // :2:9: error: alignment in a packed struct field must be set to 0 diff --git a/test/cases/compile_errors/reify_struct.zig b/test/cases/compile_errors/reify_struct.zig index fcea61b46f4c..12d445082cd3 100644 --- a/test/cases/compile_errors/reify_struct.zig +++ b/test/cases/compile_errors/reify_struct.zig @@ -4,7 +4,7 @@ comptime { .fields = &.{.{ .name = "foo", .type = u32, - .default_value = null, + .default_value_ptr = null, .is_comptime = false, .alignment = 4, }}, @@ -18,7 +18,7 @@ comptime { .fields = &.{.{ .name = "3", .type = u32, - .default_value = null, + .default_value_ptr = null, .is_comptime = false, .alignment = 4, }}, @@ -32,7 +32,7 @@ comptime { .fields = &.{.{ .name = "0", .type = u32, - .default_value = null, + .default_value_ptr = null, .is_comptime = true, .alignment = 4, }}, @@ -46,7 +46,7 @@ comptime { .fields = &.{.{ .name = "0", .type = u32, - .default_value = null, + .default_value_ptr = null, .is_comptime = true, .alignment = 4, }}, @@ -60,7 +60,7 @@ comptime { .fields = &.{.{ .name = "0", .type = u32, - .default_value = null, + .default_value_ptr = null, .is_comptime = true, .alignment = 4, }}, @@ -70,8 +70,6 @@ comptime { } // error -// backend=stage2 -// target=native // // :2:5: error: tuple cannot have non-numeric field 'foo' // :16:5: error: tuple field name '3' does not match field index 0 diff --git a/test/cases/compile_errors/reify_type_with_invalid_field_alignment.zig b/test/cases/compile_errors/reify_type_with_invalid_field_alignment.zig index 3dfb2ae1ff5d..0fcb4ba7fc73 100644 --- a/test/cases/compile_errors/reify_type_with_invalid_field_alignment.zig +++ b/test/cases/compile_errors/reify_type_with_invalid_field_alignment.zig @@ -17,7 +17,7 @@ comptime { .fields = &.{.{ .name = "0", .type = u32, - .default_value = null, + .default_value_ptr = null, .is_comptime = true, .alignment = 5, }}, @@ -29,21 +29,19 @@ comptime { comptime { _ = @Type(.{ .pointer = .{ - .size = .Many, + .size = .many, .is_const = true, .is_volatile = false, .alignment = 7, .address_space = .generic, .child = u8, .is_allowzero = false, - .sentinel = null, + .sentinel_ptr = null, }, }); } // error -// backend=stage2 -// target=native // // :2:9: error: alignment value '3' is not a power of two or zero // :14:9: error: alignment value '5' is not a power of two or zero diff --git a/test/cases/compile_errors/reify_type_with_undefined.zig b/test/cases/compile_errors/reify_type_with_undefined.zig index 1c34a2a84ef4..bfdeec6a811b 100644 --- a/test/cases/compile_errors/reify_type_with_undefined.zig +++ b/test/cases/compile_errors/reify_type_with_undefined.zig @@ -1,5 +1,5 @@ comptime { - _ = @Type(.{ .array = .{ .len = 0, .child = u8, .sentinel = undefined } }); + _ = @Type(.{ .array = .{ .len = 0, .child = u8, .sentinel_ptr = undefined } }); } comptime { _ = @Type(.{