From bc797a97b1f7476b620567ff32b7a396ebdb4c9c Mon Sep 17 00:00:00 2001 From: mlugg Date: Tue, 8 Oct 2024 21:16:35 +0100 Subject: [PATCH] std: update for new `CallingConvention` The old `CallingConvention` type is replaced with the new `NewCallingConvention`. References to `NewCallingConvention` in the compiler are updated accordingly. In addition, a few parts of the standard library are updated to use the new type correctly. --- lib/std/Target.zig | 4 +- lib/std/builtin.zig | 107 ++++++++++----------------------- lib/std/crypto/25519/field.zig | 6 +- lib/std/os/windows.zig | 5 +- lib/std/start.zig | 11 ++-- src/InternPool.zig | 40 ++++++------ src/Sema.zig | 42 ++++++------- src/Type.zig | 2 +- src/Zcu.zig | 2 +- src/arch/riscv64/Lower.zig | 2 +- src/arch/wasm/CodeGen.zig | 6 +- src/arch/x86_64/CodeGen.zig | 4 +- src/arch/x86_64/Lower.zig | 2 +- src/arch/x86_64/abi.zig | 16 ++--- src/codegen/c.zig | 2 +- src/codegen/llvm.zig | 10 +-- src/link/Coff.zig | 4 +- src/link/Dwarf.zig | 2 +- src/target.zig | 2 +- 19 files changed, 109 insertions(+), 160 deletions(-) diff --git a/lib/std/Target.zig b/lib/std/Target.zig index d17e31e6573b..ca00403142ae 100644 --- a/lib/std/Target.zig +++ b/lib/std/Target.zig @@ -1612,7 +1612,7 @@ pub const Cpu = struct { /// Returns the array of `Arch` to which a specific `std.builtin.CallingConvention` applies. /// Asserts that `cc` is not `.auto`, `.@"async"`, `.naked`, or `.@"inline"`. - pub fn fromCallconv(cc: std.builtin.NewCallingConvention) []const Arch { + pub fn fromCallconv(cc: std.builtin.CallingConvention) []const Arch { return switch (cc) { .auto, .@"async", @@ -3032,7 +3032,7 @@ pub fn cTypePreferredAlignment(target: Target, c_type: CType) u16 { ); } -pub fn defaultCCallingConvention(target: Target) ?std.builtin.NewCallingConvention { +pub fn defaultCCallingConvention(target: Target) ?std.builtin.CallingConvention { return switch (target.cpu.arch) { .x86_64 => switch (target.os.tag) { .windows, .uefi => .{ .x86_64_win = .{} }, diff --git a/lib/std/builtin.zig b/lib/std/builtin.zig index afbc0e1f736e..0753417f5875 100644 --- a/lib/std/builtin.zig +++ b/lib/std/builtin.zig @@ -160,72 +160,20 @@ pub const OptimizeMode = enum { /// Deprecated; use OptimizeMode. pub const Mode = OptimizeMode; -/// This data structure is used by the Zig language code generation and -/// therefore must be kept in sync with the compiler implementation. -pub const CallingConvention = enum(u8) { - /// This is the default Zig calling convention used when not using `export` on `fn` - /// and no other calling convention is specified. - Unspecified, - /// Matches the C ABI for the target. - /// This is the default calling convention when using `export` on `fn` - /// and no other calling convention is specified. - C, - /// This makes a function not have any function prologue or epilogue, - /// making the function itself uncallable in regular Zig code. - /// This can be useful when integrating with assembly. - Naked, - /// Functions with this calling convention are called asynchronously, - /// as if called as `async function()`. - Async, - /// Functions with this calling convention are inlined at all call sites. - Inline, - /// x86-only. - Interrupt, - Signal, - /// x86-only. - Stdcall, - /// x86-only. - Fastcall, - /// x86-only. - Vectorcall, - /// x86-only. - Thiscall, - /// ARM Procedure Call Standard (obsolete) - /// ARM-only. - APCS, - /// ARM Architecture Procedure Call Standard (current standard) - /// ARM-only. - AAPCS, - /// ARM Architecture Procedure Call Standard Vector Floating-Point - /// ARM-only. - AAPCSVFP, - /// x86-64-only. - SysV, - /// x86-64-only. - Win64, - /// AMD GPU, NVPTX, or SPIR-V kernel - Kernel, - // Vulkan-only - Fragment, - Vertex, -}; - /// The calling convention of a function defines how arguments and return values are passed, as well /// as any other requirements which callers and callees must respect, such as register preservation /// and stack alignment. /// /// This data structure is used by the Zig language code generation and /// therefore must be kept in sync with the compiler implementation. -/// -/// TODO: this will be renamed `CallingConvention` after an initial zig1.wasm update. -pub const NewCallingConvention = union(enum(u8)) { - pub const Tag = @typeInfo(NewCallingConvention).@"union".tag_type.?; +pub const CallingConvention = union(enum(u8)) { + pub const Tag = @typeInfo(CallingConvention).@"union".tag_type.?; /// This is an alias for the default C calling convention for this target. /// Functions marked as `extern` or `export` are given this calling convention by default. pub const c = builtin.target.defaultCCallingConvention().?; - pub const winapi: NewCallingConvention = switch (builtin.target.arch) { + pub const winapi: CallingConvention = switch (builtin.target.arch) { .x86_64 => .{ .x86_64_win = .{} }, .x86 => .{ .x86_stdcall = .{} }, .aarch64, .aarch64_be => .{ .aarch64_aapcs_win = .{} }, @@ -233,7 +181,7 @@ pub const NewCallingConvention = union(enum(u8)) { else => unreachable, }; - pub const kernel: NewCallingConvention = switch (builtin.target.cpu.arch) { + pub const kernel: CallingConvention = switch (builtin.target.cpu.arch) { .amdgcn => .amdgcn_kernel, .nvptx, .nvptx64 => .nvptx_kernel, .spirv, .spirv32, .spirv64 => .spirv_kernel, @@ -241,53 +189,53 @@ pub const NewCallingConvention = union(enum(u8)) { }; /// Deprecated; use `.auto`. - pub const Unspecified: NewCallingConvention = .auto; + pub const Unspecified: CallingConvention = .auto; /// Deprecated; use `.c`. - pub const C: NewCallingConvention = .c; + pub const C: CallingConvention = .c; /// Deprecated; use `.naked`. - pub const Naked: NewCallingConvention = .naked; + pub const Naked: CallingConvention = .naked; /// Deprecated; use `.@"async"`. - pub const Async: NewCallingConvention = .@"async"; + pub const Async: CallingConvention = .@"async"; /// Deprecated; use `.@"inline"`. - pub const Inline: NewCallingConvention = .@"inline"; + pub const Inline: CallingConvention = .@"inline"; /// Deprecated; use `.x86_64_interrupt`, `.x86_interrupt`, or `.avr_interrupt`. - pub const Interrupt: NewCallingConvention = switch (builtin.target.cpu.arch) { + pub const Interrupt: CallingConvention = switch (builtin.target.cpu.arch) { .x86_64 => .{ .x86_64_interrupt = .{} }, .x86 => .{ .x86_interrupt = .{} }, .avr => .avr_interrupt, else => unreachable, }; /// Deprecated; use `.avr_signal`. - pub const Signal: NewCallingConvention = .avr_signal; + pub const Signal: CallingConvention = .avr_signal; /// Deprecated; use `.x86_stdcall`. - pub const Stdcall: NewCallingConvention = .{ .x86_stdcall = .{} }; + pub const Stdcall: CallingConvention = .{ .x86_stdcall = .{} }; /// Deprecated; use `.x86_fastcall`. - pub const Fastcall: NewCallingConvention = .{ .x86_fastcall = .{} }; + pub const Fastcall: CallingConvention = .{ .x86_fastcall = .{} }; /// Deprecated; use `.x86_64_vectorcall`, `.x86_vectorcall`, or `aarch64_vfabi`. - pub const Vectorcall: NewCallingConvention = switch (builtin.target.cpu.arch) { + pub const Vectorcall: CallingConvention = switch (builtin.target.cpu.arch) { .x86_64 => .{ .x86_64_vectorcall = .{} }, .x86 => .{ .x86_vectorcall = .{} }, .aarch64, .aarch64_be => .{ .aarch64_vfabi = .{} }, else => unreachable, }; /// Deprecated; use `.x86_thiscall`. - pub const Thiscall: NewCallingConvention = .{ .x86_thiscall = .{} }; + pub const Thiscall: CallingConvention = .{ .x86_thiscall = .{} }; /// Deprecated; use `.arm_apcs`. - pub const APCS: NewCallingConvention = .{ .arm_apcs = .{} }; + pub const APCS: CallingConvention = .{ .arm_apcs = .{} }; /// Deprecated; use `.arm_aapcs`. - pub const AAPCS: NewCallingConvention = .{ .arm_aapcs = .{} }; + pub const AAPCS: CallingConvention = .{ .arm_aapcs = .{} }; /// Deprecated; use `.arm_aapcs_vfp`. - pub const AAPCSVFP: NewCallingConvention = .{ .arm_aapcs_vfp = .{} }; + pub const AAPCSVFP: CallingConvention = .{ .arm_aapcs_vfp = .{} }; /// Deprecated; use `.x86_64_sysv`. - pub const SysV: NewCallingConvention = .{ .x86_64_sysv = .{} }; + pub const SysV: CallingConvention = .{ .x86_64_sysv = .{} }; /// Deprecated; use `.x86_64_win`. - pub const Win64: NewCallingConvention = .{ .x86_64_win = .{} }; + pub const Win64: CallingConvention = .{ .x86_64_win = .{} }; /// Deprecated; use `.kernel`. - pub const Kernel: NewCallingConvention = .kernel; + pub const Kernel: CallingConvention = .kernel; /// Deprecated; use `.spirv_fragment`. - pub const Fragment: NewCallingConvention = .spirv_fragment; + pub const Fragment: CallingConvention = .spirv_fragment; /// Deprecated; use `.spirv_vertex`. - pub const Vertex: NewCallingConvention = .spirv_vertex; + pub const Vertex: CallingConvention = .spirv_vertex; /// The default Zig calling convention when neither `export` nor `inline` is specified. /// This calling convention makes no guarantees about stack alignment, registers, etc. @@ -535,9 +483,16 @@ pub const NewCallingConvention = union(enum(u8)) { /// Asserts that `cc` is not `.auto`, `.@"async"`, `.naked`, or `.@"inline"`. pub const archs = std.Target.Cpu.Arch.fromCallconv; - pub fn eql(a: NewCallingConvention, b: NewCallingConvention) bool { + pub fn eql(a: CallingConvention, b: CallingConvention) bool { return std.meta.eql(a, b); } + + pub fn withStackAlign(cc: CallingConvention, incoming_stack_alignment: u64) CallingConvention { + const tag: CallingConvention.Tag = cc; + var result = cc; + @field(result, tag).incoming_stack_alignment = incoming_stack_alignment; + return result; + } }; /// This data structure is used by the Zig language code generation and diff --git a/lib/std/crypto/25519/field.zig b/lib/std/crypto/25519/field.zig index e18093f4c2f5..c2fc8408bd19 100644 --- a/lib/std/crypto/25519/field.zig +++ b/lib/std/crypto/25519/field.zig @@ -6,9 +6,9 @@ const NonCanonicalError = crypto.errors.NonCanonicalError; const NotSquareError = crypto.errors.NotSquareError; // Inline conditionally, when it can result in large code generation. -const bloaty_inline = switch (builtin.mode) { - .ReleaseSafe, .ReleaseFast => .Inline, - .Debug, .ReleaseSmall => .Unspecified, +const bloaty_inline: std.builtin.CallingConvention = switch (builtin.mode) { + .ReleaseSafe, .ReleaseFast => .@"inline", + .Debug, .ReleaseSmall => .auto, }; pub const Fe = struct { diff --git a/lib/std/os/windows.zig b/lib/std/os/windows.zig index 7f4d3290dc2c..7a460d5a9e7a 100644 --- a/lib/std/os/windows.zig +++ b/lib/std/os/windows.zig @@ -2824,10 +2824,7 @@ pub const STD_OUTPUT_HANDLE = maxInt(DWORD) - 11 + 1; /// The standard error device. Initially, this is the active console screen buffer, CONOUT$. pub const STD_ERROR_HANDLE = maxInt(DWORD) - 12 + 1; -pub const WINAPI: std.builtin.CallingConvention = if (native_arch == .x86) - .Stdcall -else - .C; +pub const WINAPI: std.builtin.CallingConvention = .winapi; pub const BOOL = c_int; pub const BOOLEAN = BYTE; diff --git a/lib/std/start.zig b/lib/std/start.zig index 01a33522d033..a70d9e609ef0 100644 --- a/lib/std/start.zig +++ b/lib/std/start.zig @@ -55,7 +55,7 @@ comptime { if (builtin.link_libc and @hasDecl(root, "main")) { if (native_arch.isWasm()) { @export(&mainWithoutEnv, .{ .name = "main" }); - } else if (@typeInfo(@TypeOf(root.main)).@"fn".calling_convention != .C) { + } else if (!@typeInfo(@TypeOf(root.main)).@"fn".calling_convention.eql(.c)) { @export(&main, .{ .name = "main" }); } } else if (native_os == .windows) { @@ -102,12 +102,11 @@ fn main2() callconv(.C) c_int { return 0; } -fn _start2() callconv(.C) noreturn { +fn _start2() callconv(.withStackAlign(.c, 1)) noreturn { callMain2(); } fn callMain2() noreturn { - @setAlignStack(16); root.main(); exit2(0); } @@ -428,8 +427,7 @@ fn _start() callconv(.Naked) noreturn { ); } -fn WinStartup() callconv(std.os.windows.WINAPI) noreturn { - @setAlignStack(16); +fn WinStartup() callconv(.withStackAlign(.winapi, 1)) noreturn { if (!builtin.single_threaded and !builtin.link_libc) { _ = @import("os/windows/tls.zig"); } @@ -439,8 +437,7 @@ fn WinStartup() callconv(std.os.windows.WINAPI) noreturn { std.os.windows.ntdll.RtlExitUserProcess(callMain()); } -fn wWinMainCRTStartup() callconv(std.os.windows.WINAPI) noreturn { - @setAlignStack(16); +fn wWinMainCRTStartup() callconv(.withStackAlign(.winapi, 1)) noreturn { if (!builtin.single_threaded and !builtin.link_libc) { _ = @import("os/windows/tls.zig"); } diff --git a/src/InternPool.zig b/src/InternPool.zig index 11fee424ecd3..c81dbd3c8c10 100644 --- a/src/InternPool.zig +++ b/src/InternPool.zig @@ -1988,7 +1988,7 @@ pub const Key = union(enum) { /// Tells whether a parameter is noalias. See `paramIsNoalias` helper /// method for accessing this. noalias_bits: u32, - cc: std.builtin.NewCallingConvention, + cc: std.builtin.CallingConvention, is_var_args: bool, is_generic: bool, is_noinline: bool, @@ -8526,7 +8526,7 @@ pub const GetFuncTypeKey = struct { comptime_bits: u32 = 0, noalias_bits: u32 = 0, /// `null` means generic. - cc: ?std.builtin.NewCallingConvention = .auto, + cc: ?std.builtin.CallingConvention = .auto, is_var_args: bool = false, is_generic: bool = false, is_noinline: bool = false, @@ -8668,7 +8668,7 @@ pub const GetFuncDeclKey = struct { rbrace_line: u32, lbrace_column: u32, rbrace_column: u32, - cc: ?std.builtin.NewCallingConvention, + cc: ?std.builtin.CallingConvention, is_noinline: bool, }; @@ -8733,7 +8733,7 @@ pub const GetFuncDeclIesKey = struct { comptime_bits: u32, bare_return_type: Index, /// null means generic. - cc: ?std.builtin.NewCallingConvention, + cc: ?std.builtin.CallingConvention, /// null means generic. alignment: ?Alignment, section_is_generic: bool, @@ -8948,7 +8948,7 @@ pub const GetFuncInstanceKey = struct { comptime_args: []const Index, noalias_bits: u32, bare_return_type: Index, - cc: std.builtin.NewCallingConvention, + cc: std.builtin.CallingConvention, alignment: Alignment, section: OptionalNullTerminatedString, is_noinline: bool, @@ -12226,13 +12226,13 @@ pub fn getErrorValueIfExists(ip: *const InternPool, name: NullTerminatedString) } const PackedCallingConvention = packed struct(u18) { - tag: std.builtin.NewCallingConvention.Tag, + tag: std.builtin.CallingConvention.Tag, /// May be ignored depending on `tag`. incoming_stack_alignment: Alignment, /// Interpretation depends on `tag`. extra: u4, - fn pack(cc: std.builtin.NewCallingConvention) PackedCallingConvention { + fn pack(cc: std.builtin.CallingConvention) PackedCallingConvention { return switch (cc) { inline else => |pl, tag| switch (@TypeOf(pl)) { void => .{ @@ -12240,27 +12240,27 @@ const PackedCallingConvention = packed struct(u18) { .incoming_stack_alignment = .none, // unused .extra = 0, // unused }, - std.builtin.NewCallingConvention.CommonOptions => .{ + std.builtin.CallingConvention.CommonOptions => .{ .tag = tag, .incoming_stack_alignment = .fromByteUnits(pl.incoming_stack_alignment orelse 0), .extra = 0, // unused }, - std.builtin.NewCallingConvention.X86RegparmOptions => .{ + std.builtin.CallingConvention.X86RegparmOptions => .{ .tag = tag, .incoming_stack_alignment = .fromByteUnits(pl.incoming_stack_alignment orelse 0), .extra = pl.register_params, }, - std.builtin.NewCallingConvention.ArmInterruptOptions => .{ + std.builtin.CallingConvention.ArmInterruptOptions => .{ .tag = tag, .incoming_stack_alignment = .fromByteUnits(pl.incoming_stack_alignment orelse 0), .extra = @intFromEnum(pl.type), }, - std.builtin.NewCallingConvention.MipsInterruptOptions => .{ + std.builtin.CallingConvention.MipsInterruptOptions => .{ .tag = tag, .incoming_stack_alignment = .fromByteUnits(pl.incoming_stack_alignment orelse 0), .extra = @intFromEnum(pl.mode), }, - std.builtin.NewCallingConvention.RiscvInterruptOptions => .{ + std.builtin.CallingConvention.RiscvInterruptOptions => .{ .tag = tag, .incoming_stack_alignment = .fromByteUnits(pl.incoming_stack_alignment orelse 0), .extra = @intFromEnum(pl.level), @@ -12270,30 +12270,30 @@ const PackedCallingConvention = packed struct(u18) { }; } - fn unpack(cc: PackedCallingConvention) std.builtin.NewCallingConvention { + fn unpack(cc: PackedCallingConvention) std.builtin.CallingConvention { @setEvalBranchQuota(400_000); return switch (cc.tag) { inline else => |tag| @unionInit( - std.builtin.NewCallingConvention, + std.builtin.CallingConvention, @tagName(tag), - switch (std.meta.FieldType(std.builtin.NewCallingConvention, tag)) { + switch (std.meta.FieldType(std.builtin.CallingConvention, tag)) { void => {}, - std.builtin.NewCallingConvention.CommonOptions => .{ + std.builtin.CallingConvention.CommonOptions => .{ .incoming_stack_alignment = cc.incoming_stack_alignment.toByteUnits(), }, - std.builtin.NewCallingConvention.X86RegparmOptions => .{ + std.builtin.CallingConvention.X86RegparmOptions => .{ .incoming_stack_alignment = cc.incoming_stack_alignment.toByteUnits(), .register_params = @intCast(cc.extra), }, - std.builtin.NewCallingConvention.ArmInterruptOptions => .{ + std.builtin.CallingConvention.ArmInterruptOptions => .{ .incoming_stack_alignment = cc.incoming_stack_alignment.toByteUnits(), .type = @enumFromInt(cc.extra), }, - std.builtin.NewCallingConvention.MipsInterruptOptions => .{ + std.builtin.CallingConvention.MipsInterruptOptions => .{ .incoming_stack_alignment = cc.incoming_stack_alignment.toByteUnits(), .mode = @enumFromInt(cc.extra), }, - std.builtin.NewCallingConvention.RiscvInterruptOptions => .{ + std.builtin.CallingConvention.RiscvInterruptOptions => .{ .incoming_stack_alignment = cc.incoming_stack_alignment.toByteUnits(), .level = @enumFromInt(cc.extra), }, diff --git a/src/Sema.zig b/src/Sema.zig index 24455ecb084f..ac1a79a2b389 100644 --- a/src/Sema.zig +++ b/src/Sema.zig @@ -2703,9 +2703,9 @@ fn analyzeValueAsCallconv( block: *Block, src: LazySrcLoc, unresolved_val: Value, -) !std.builtin.NewCallingConvention { +) !std.builtin.CallingConvention { const resolved_val = try sema.resolveLazyValue(unresolved_val); - return resolved_val.interpret(std.builtin.NewCallingConvention, sema.pt) catch |err| switch (err) { + return resolved_val.interpret(std.builtin.CallingConvention, 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"), @@ -9520,7 +9520,7 @@ fn zirFunc( // If this instruction has a body, then it's a function declaration, and we decide // the callconv based on whether it is exported. Otherwise, the callconv defaults // to `.auto`. - const cc: std.builtin.NewCallingConvention = if (has_body) cc: { + const cc: std.builtin.CallingConvention = if (has_body) cc: { const func_decl_cau = if (sema.generic_owner != .none) cau: { const generic_owner_fn = zcu.funcInfo(sema.generic_owner); // The generic owner definitely has a `Cau` for the corresponding function declaration. @@ -9686,7 +9686,7 @@ fn handleExternLibName( /// These are calling conventions that are confirmed to work with variadic functions. /// Any calling conventions not included here are either not yet verified to work with variadic /// functions or there are no more other calling conventions that support variadic functions. -const calling_conventions_supporting_var_args = [_]std.builtin.NewCallingConvention.Tag{ +const calling_conventions_supporting_var_args = [_]std.builtin.CallingConvention.Tag{ .x86_64_sysv, .x86_64_win, .x86_sysv, @@ -9738,12 +9738,12 @@ const calling_conventions_supporting_var_args = [_]std.builtin.NewCallingConvent .xtensa_call0, .xtensa_windowed, }; -fn callConvSupportsVarArgs(cc: std.builtin.NewCallingConvention.Tag) bool { +fn callConvSupportsVarArgs(cc: std.builtin.CallingConvention.Tag) bool { return for (calling_conventions_supporting_var_args) |supported_cc| { if (cc == supported_cc) return true; } else false; } -fn checkCallConvSupportsVarArgs(sema: *Sema, block: *Block, src: LazySrcLoc, cc: std.builtin.NewCallingConvention.Tag) CompileError!void { +fn checkCallConvSupportsVarArgs(sema: *Sema, block: *Block, src: LazySrcLoc, cc: std.builtin.CallingConvention.Tag) CompileError!void { const CallingConventionsSupportingVarArgsList = struct { pub fn format(_: @This(), comptime fmt: []const u8, options: std.fmt.FormatOptions, writer: anytype) !void { _ = fmt; @@ -9784,7 +9784,7 @@ fn funcCommon( address_space: ?std.builtin.AddressSpace, section: Section, /// null means generic poison - cc: ?std.builtin.NewCallingConvention, + cc: ?std.builtin.CallingConvention, /// this might be Type.generic_poison bare_return_type: Type, var_args: bool, @@ -10141,7 +10141,7 @@ fn finishFunc( ret_poison: bool, bare_return_type: Type, ret_ty_src: LazySrcLoc, - cc_resolved: std.builtin.NewCallingConvention, + cc_resolved: std.builtin.CallingConvention, is_source_decl: bool, ret_ty_requires_comptime: bool, func_inst: Zir.Inst.Index, @@ -26744,7 +26744,7 @@ fn zirFuncFancy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A break :blk .{ .explicit = section_name }; } else .default; - const cc: ?std.builtin.NewCallingConvention = if (extra.data.bits.has_cc_body) blk: { + const cc: ?std.builtin.CallingConvention = if (extra.data.bits.has_cc_body) blk: { const body_len = sema.code.extra[extra_index]; extra_index += 1; const body = sema.code.bodySlice(extra_index, body_len); @@ -27253,14 +27253,14 @@ fn zirBuiltinValue(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstD ) orelse @panic("std.builtin is corrupt"); }, .calling_convention_inline => { - comptime assert(@typeInfo(std.builtin.NewCallingConvention.Tag).@"enum".tag_type == u8); + comptime assert(@typeInfo(std.builtin.CallingConvention.Tag).@"enum".tag_type == u8); const callconv_ty = try sema.getBuiltinType("CallingConvention"); const callconv_tag_ty = callconv_ty.unionTagType(zcu) orelse @panic("std.builtin is corrupt"); const inline_tag_val = try pt.enumValue( callconv_tag_ty, (try pt.intValue( Type.u8, - @intFromEnum(std.builtin.NewCallingConvention.@"inline"), + @intFromEnum(std.builtin.CallingConvention.@"inline"), )).toIntern(), ); return sema.coerce(block, callconv_ty, Air.internedToRef(inline_tag_val.toIntern()), src); @@ -30621,8 +30621,8 @@ const InMemoryCoercionResult = union(enum) { }; const CC = struct { - actual: std.builtin.NewCallingConvention, - wanted: std.builtin.NewCallingConvention, + actual: std.builtin.CallingConvention, + wanted: std.builtin.CallingConvention, }; const BitRange = struct { @@ -31348,10 +31348,10 @@ fn coerceInMemoryAllowedFns( fn callconvCoerceAllowed( target: std.Target, - src_cc: std.builtin.NewCallingConvention, - dest_cc: std.builtin.NewCallingConvention, + src_cc: std.builtin.CallingConvention, + dest_cc: std.builtin.CallingConvention, ) bool { - const Tag = std.builtin.NewCallingConvention.Tag; + const Tag = std.builtin.CallingConvention.Tag; if (@as(Tag, src_cc) != @as(Tag, dest_cc)) return false; switch (src_cc) { @@ -31364,17 +31364,17 @@ fn callconvCoerceAllowed( if (dest_stack_align < src_stack_align) return false; } switch (@TypeOf(src_data)) { - void, std.builtin.NewCallingConvention.CommonOptions => {}, - std.builtin.NewCallingConvention.X86RegparmOptions => { + void, std.builtin.CallingConvention.CommonOptions => {}, + std.builtin.CallingConvention.X86RegparmOptions => { if (src_data.register_params != dest_data.register_params) return false; }, - std.builtin.NewCallingConvention.ArmInterruptOptions => { + std.builtin.CallingConvention.ArmInterruptOptions => { if (src_data.type != dest_data.type) return false; }, - std.builtin.NewCallingConvention.MipsInterruptOptions => { + std.builtin.CallingConvention.MipsInterruptOptions => { if (src_data.mode != dest_data.mode) return false; }, - std.builtin.NewCallingConvention.RiscvInterruptOptions => { + std.builtin.CallingConvention.RiscvInterruptOptions => { if (src_data.level != dest_data.level) return false; }, else => comptime unreachable, diff --git a/src/Type.zig b/src/Type.zig index 1a3f530e13c1..9c44e696579c 100644 --- a/src/Type.zig +++ b/src/Type.zig @@ -2493,7 +2493,7 @@ pub fn fnReturnType(ty: Type, zcu: *const Zcu) Type { } /// Asserts the type is a function. -pub fn fnCallingConvention(ty: Type, zcu: *const Zcu) std.builtin.NewCallingConvention { +pub fn fnCallingConvention(ty: Type, zcu: *const Zcu) std.builtin.CallingConvention { return zcu.intern_pool.indexToKey(ty.toIntern()).func_type.cc; } diff --git a/src/Zcu.zig b/src/Zcu.zig index 378d06b5c27a..778d2b68ad7d 100644 --- a/src/Zcu.zig +++ b/src/Zcu.zig @@ -3540,7 +3540,7 @@ pub fn maybeUnresolveIes(zcu: *Zcu, func_index: InternPool.Index) !void { } } -pub fn callconvSupported(zcu: *Zcu, cc: std.builtin.NewCallingConvention) union(enum) { +pub fn callconvSupported(zcu: *Zcu, cc: std.builtin.CallingConvention) union(enum) { ok, bad_arch: []const std.Target.Cpu.Arch, // value is allowed archs for cc bad_backend: std.builtin.CompilerBackend, // value is current backend diff --git a/src/arch/riscv64/Lower.zig b/src/arch/riscv64/Lower.zig index 34757a8ed289..a9ae9df898d6 100644 --- a/src/arch/riscv64/Lower.zig +++ b/src/arch/riscv64/Lower.zig @@ -6,7 +6,7 @@ link_mode: std.builtin.LinkMode, pic: bool, allocator: Allocator, mir: Mir, -cc: std.builtin.NewCallingConvention, +cc: std.builtin.CallingConvention, err_msg: ?*ErrorMsg = null, src_loc: Zcu.LazySrcLoc, result_insts_len: u8 = undefined, diff --git a/src/arch/wasm/CodeGen.zig b/src/arch/wasm/CodeGen.zig index 26365b9b0215..a04a8528dc85 100644 --- a/src/arch/wasm/CodeGen.zig +++ b/src/arch/wasm/CodeGen.zig @@ -1145,7 +1145,7 @@ fn ensureAllocLocal(func: *CodeGen, ty: Type) InnerError!WValue { /// Memory is owned by the caller. fn genFunctype( gpa: Allocator, - cc: std.builtin.NewCallingConvention, + cc: std.builtin.CallingConvention, params: []const InternPool.Index, return_type: Type, pt: Zcu.PerThread, @@ -1408,7 +1408,7 @@ fn resolveCallingConventionValues(func: *CodeGen, fn_ty: Type) InnerError!CallWV return result; } -fn firstParamSRet(cc: std.builtin.NewCallingConvention, return_type: Type, pt: Zcu.PerThread, target: std.Target) bool { +fn firstParamSRet(cc: std.builtin.CallingConvention, return_type: Type, pt: Zcu.PerThread, target: std.Target) bool { switch (cc) { .@"inline" => unreachable, .auto => return isByRef(return_type, pt, target), @@ -1424,7 +1424,7 @@ fn firstParamSRet(cc: std.builtin.NewCallingConvention, return_type: Type, pt: Z /// Lowers a Zig type and its value based on a given calling convention to ensure /// it matches the ABI. -fn lowerArg(func: *CodeGen, cc: std.builtin.NewCallingConvention, ty: Type, value: WValue) !void { +fn lowerArg(func: *CodeGen, cc: std.builtin.CallingConvention, ty: Type, value: WValue) !void { if (cc != .wasm_watc) { return func.lowerToStack(value); } diff --git a/src/arch/x86_64/CodeGen.zig b/src/arch/x86_64/CodeGen.zig index 6c34679c7439..f6ab8d3e8775 100644 --- a/src/arch/x86_64/CodeGen.zig +++ b/src/arch/x86_64/CodeGen.zig @@ -2694,7 +2694,7 @@ fn setFrameLoc( offset.* += self.frame_allocs.items(.abi_size)[frame_i]; } -fn computeFrameLayout(self: *Self, cc: std.builtin.NewCallingConvention) !FrameLayout { +fn computeFrameLayout(self: *Self, cc: std.builtin.CallingConvention) !FrameLayout { const frame_allocs_len = self.frame_allocs.len; try self.frame_locs.resize(self.gpa, frame_allocs_len); const stack_frame_order = try self.gpa.alloc(FrameIndex, frame_allocs_len - FrameIndex.named_count); @@ -3006,7 +3006,7 @@ pub fn spillEflagsIfOccupied(self: *Self) !void { } } -pub fn spillCallerPreservedRegs(self: *Self, cc: std.builtin.NewCallingConvention) !void { +pub fn spillCallerPreservedRegs(self: *Self, cc: std.builtin.CallingConvention) !void { switch (cc) { .x86_64_sysv => try self.spillRegisters(abi.getCallerPreservedRegs(.{ .x86_64_sysv = .{} })), .x86_64_win => try self.spillRegisters(abi.getCallerPreservedRegs(.{ .x86_64_win = .{} })), diff --git a/src/arch/x86_64/Lower.zig b/src/arch/x86_64/Lower.zig index a49819476bea..058201c2d7f0 100644 --- a/src/arch/x86_64/Lower.zig +++ b/src/arch/x86_64/Lower.zig @@ -6,7 +6,7 @@ link_mode: std.builtin.LinkMode, pic: bool, allocator: std.mem.Allocator, mir: Mir, -cc: std.builtin.NewCallingConvention, +cc: std.builtin.CallingConvention, err_msg: ?*Zcu.ErrorMsg = null, src_loc: Zcu.LazySrcLoc, result_insts_len: u8 = undefined, diff --git a/src/arch/x86_64/abi.zig b/src/arch/x86_64/abi.zig index 094d5fc3787a..fac6b6ce6ddd 100644 --- a/src/arch/x86_64/abi.zig +++ b/src/arch/x86_64/abi.zig @@ -436,9 +436,9 @@ pub const Win64 = struct { }; pub fn resolveCallingConvention( - cc: std.builtin.NewCallingConvention, + cc: std.builtin.CallingConvention, target: std.Target, -) std.builtin.NewCallingConvention { +) std.builtin.CallingConvention { return switch (cc) { .auto => switch (target.os.tag) { else => .{ .x86_64_sysv = .{} }, @@ -448,7 +448,7 @@ pub fn resolveCallingConvention( }; } -pub fn getCalleePreservedRegs(cc: std.builtin.NewCallingConvention) []const Register { +pub fn getCalleePreservedRegs(cc: std.builtin.CallingConvention) []const Register { return switch (cc) { .x86_64_sysv => &SysV.callee_preserved_regs, .x86_64_win => &Win64.callee_preserved_regs, @@ -456,7 +456,7 @@ pub fn getCalleePreservedRegs(cc: std.builtin.NewCallingConvention) []const Regi }; } -pub fn getCallerPreservedRegs(cc: std.builtin.NewCallingConvention) []const Register { +pub fn getCallerPreservedRegs(cc: std.builtin.CallingConvention) []const Register { return switch (cc) { .x86_64_sysv => &SysV.caller_preserved_regs, .x86_64_win => &Win64.caller_preserved_regs, @@ -464,7 +464,7 @@ pub fn getCallerPreservedRegs(cc: std.builtin.NewCallingConvention) []const Regi }; } -pub fn getCAbiIntParamRegs(cc: std.builtin.NewCallingConvention) []const Register { +pub fn getCAbiIntParamRegs(cc: std.builtin.CallingConvention) []const Register { return switch (cc) { .x86_64_sysv => &SysV.c_abi_int_param_regs, .x86_64_win => &Win64.c_abi_int_param_regs, @@ -472,7 +472,7 @@ pub fn getCAbiIntParamRegs(cc: std.builtin.NewCallingConvention) []const Registe }; } -pub fn getCAbiSseParamRegs(cc: std.builtin.NewCallingConvention) []const Register { +pub fn getCAbiSseParamRegs(cc: std.builtin.CallingConvention) []const Register { return switch (cc) { .x86_64_sysv => &SysV.c_abi_sse_param_regs, .x86_64_win => &Win64.c_abi_sse_param_regs, @@ -480,7 +480,7 @@ pub fn getCAbiSseParamRegs(cc: std.builtin.NewCallingConvention) []const Registe }; } -pub fn getCAbiIntReturnRegs(cc: std.builtin.NewCallingConvention) []const Register { +pub fn getCAbiIntReturnRegs(cc: std.builtin.CallingConvention) []const Register { return switch (cc) { .x86_64_sysv => &SysV.c_abi_int_return_regs, .x86_64_win => &Win64.c_abi_int_return_regs, @@ -488,7 +488,7 @@ pub fn getCAbiIntReturnRegs(cc: std.builtin.NewCallingConvention) []const Regist }; } -pub fn getCAbiSseReturnRegs(cc: std.builtin.NewCallingConvention) []const Register { +pub fn getCAbiSseReturnRegs(cc: std.builtin.CallingConvention) []const Register { return switch (cc) { .x86_64_sysv => &SysV.c_abi_sse_return_regs, .x86_64_win => &Win64.c_abi_sse_return_regs, diff --git a/src/codegen/c.zig b/src/codegen/c.zig index 816913d4bda0..c33aa9d31a39 100644 --- a/src/codegen/c.zig +++ b/src/codegen/c.zig @@ -7604,7 +7604,7 @@ fn writeMemoryOrder(w: anytype, order: std.builtin.AtomicOrder) !void { return w.writeAll(toMemoryOrder(order)); } -fn toCallingConvention(cc: std.builtin.NewCallingConvention, zcu: *Zcu) ?[]const u8 { +fn toCallingConvention(cc: std.builtin.CallingConvention, zcu: *Zcu) ?[]const u8 { return switch (cc) { .auto, .naked => null, .x86_stdcall => "stdcall", diff --git a/src/codegen/llvm.zig b/src/codegen/llvm.zig index 84f7266d705d..7bf43cef54e9 100644 --- a/src/codegen/llvm.zig +++ b/src/codegen/llvm.zig @@ -11595,13 +11595,13 @@ const CallingConventionInfo = struct { inreg_param_count: u2 = 0, }; -pub fn toLlvmCallConv(cc: std.builtin.NewCallingConvention, target: std.Target) ?CallingConventionInfo { +pub fn toLlvmCallConv(cc: std.builtin.CallingConvention, target: std.Target) ?CallingConventionInfo { const llvm_cc = toLlvmCallConvTag(cc, target) orelse return null; const incoming_stack_alignment: ?u64, const register_params: u2 = switch (cc) { inline else => |pl| switch (@TypeOf(pl)) { void => .{ null, 0 }, - std.builtin.NewCallingConvention.CommonOptions => .{ pl.incoming_stack_alignment, 0 }, - std.builtin.NewCallingConvention.X86RegparmOptions => .{ pl.incoming_stack_alignment, pl.register_params }, + std.builtin.CallingConvention.CommonOptions => .{ pl.incoming_stack_alignment, 0 }, + std.builtin.CallingConvention.X86RegparmOptions => .{ pl.incoming_stack_alignment, pl.register_params }, else => unreachable, }, }; @@ -11615,7 +11615,7 @@ pub fn toLlvmCallConv(cc: std.builtin.NewCallingConvention, target: std.Target) .inreg_param_count = register_params, }; } -fn toLlvmCallConvTag(cc_tag: std.builtin.NewCallingConvention.Tag, target: std.Target) ?Builder.CallConv { +fn toLlvmCallConvTag(cc_tag: std.builtin.CallingConvention.Tag, target: std.Target) ?Builder.CallConv { if (target.defaultCCallingConvention()) |default_c| { if (cc_tag == default_c) { return .ccc; @@ -12371,7 +12371,7 @@ fn iterateParamTypes(object: *Object, fn_info: InternPool.Key.FuncType) ParamTyp } fn ccAbiPromoteInt( - cc: std.builtin.NewCallingConvention, + cc: std.builtin.CallingConvention, zcu: *Zcu, ty: Type, ) ?std.builtin.Signedness { diff --git a/src/link/Coff.zig b/src/link/Coff.zig index d99057cc2442..5a35bb70c34f 100644 --- a/src/link/Coff.zig +++ b/src/link/Coff.zig @@ -1485,12 +1485,12 @@ pub fn updateExports( const exported_ty = exported_nav.typeOf(ip); if (!ip.isFunctionType(exported_ty)) continue; const c_cc = target.defaultCCallingConvention().?; - const winapi_cc: std.builtin.NewCallingConvention = switch (target.cpu.arch) { + const winapi_cc: std.builtin.CallingConvention = switch (target.cpu.arch) { .x86 => .{ .x86_stdcall = .{} }, else => c_cc, }; const exported_cc = Type.fromInterned(exported_ty).fnCallingConvention(zcu); - const CcTag = std.builtin.NewCallingConvention.Tag; + const CcTag = std.builtin.CallingConvention.Tag; if (@as(CcTag, exported_cc) == @as(CcTag, c_cc) and exp.opts.name.eqlSlice("main", ip) and comp.config.link_libc) { zcu.stage1_flags.have_c_main = true; } else if (@as(CcTag, exported_cc) == @as(CcTag, winapi_cc) and target.os.tag == .windows) { diff --git a/src/link/Dwarf.zig b/src/link/Dwarf.zig index 3fa3fe4953e5..019e8e03f2da 100644 --- a/src/link/Dwarf.zig +++ b/src/link/Dwarf.zig @@ -3400,7 +3400,7 @@ fn updateType( try wip_nav.strp(name); const cc: DW.CC = cc: { if (zcu.getTarget().defaultCCallingConvention()) |cc| { - if (@as(std.builtin.NewCallingConvention.Tag, cc) == func_type.cc) { + if (@as(std.builtin.CallingConvention.Tag, cc) == func_type.cc) { break :cc .normal; } } diff --git a/src/target.zig b/src/target.zig index e93c18282869..7d30781f4380 100644 --- a/src/target.zig +++ b/src/target.zig @@ -544,7 +544,7 @@ pub fn compilerRtIntAbbrev(bits: u16) []const u8 { }; } -pub fn fnCallConvAllowsZigTypes(cc: std.builtin.NewCallingConvention) bool { +pub fn fnCallConvAllowsZigTypes(cc: std.builtin.CallingConvention) bool { return switch (cc) { .auto, .@"async", .@"inline" => true, // For now we want to authorize PTX kernel to use zig objects, even if