authorgravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2024-10-08 21:16:35+01:00
committergravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2024-10-19 19:15:23+01:00
logbc797a97b1f7476b620567ff32b7a396ebdb4c9c
tree368d8fbb1d1dd5fb0b84b8499392ec4f69ea2693
parent36405b9b43237960733a86d0b1eeac1bc047311c
signaturelock-open Commit is signed but in an unrecognized format.

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.

19 files changed, 109 insertions(+), 160 deletions(-)

lib/std/Target.zig+2-2
......@@ -1612,7 +1612,7 @@ pub const Cpu = struct {
16121612
16131613 /// Returns the array of `Arch` to which a specific `std.builtin.CallingConvention` applies.
16141614 /// Asserts that `cc` is not `.auto`, `.@"async"`, `.naked`, or `.@"inline"`.
1615 pub fn fromCallconv(cc: std.builtin.NewCallingConvention) []const Arch {
1615 pub fn fromCallconv(cc: std.builtin.CallingConvention) []const Arch {
16161616 return switch (cc) {
16171617 .auto,
16181618 .@"async",
......@@ -3032,7 +3032,7 @@ pub fn cTypePreferredAlignment(target: Target, c_type: CType) u16 {
30323032 );
30333033}
30343034
3035pub fn defaultCCallingConvention(target: Target) ?std.builtin.NewCallingConvention {
3035pub fn defaultCCallingConvention(target: Target) ?std.builtin.CallingConvention {
30363036 return switch (target.cpu.arch) {
30373037 .x86_64 => switch (target.os.tag) {
30383038 .windows, .uefi => .{ .x86_64_win = .{} },
lib/std/builtin.zig+31-76
......@@ -160,72 +160,20 @@ pub const OptimizeMode = enum {
160160/// Deprecated; use OptimizeMode.
161161pub const Mode = OptimizeMode;
162162
163/// This data structure is used by the Zig language code generation and
164/// therefore must be kept in sync with the compiler implementation.
165pub const CallingConvention = enum(u8) {
166 /// This is the default Zig calling convention used when not using `export` on `fn`
167 /// and no other calling convention is specified.
168 Unspecified,
169 /// Matches the C ABI for the target.
170 /// This is the default calling convention when using `export` on `fn`
171 /// and no other calling convention is specified.
172 C,
173 /// This makes a function not have any function prologue or epilogue,
174 /// making the function itself uncallable in regular Zig code.
175 /// This can be useful when integrating with assembly.
176 Naked,
177 /// Functions with this calling convention are called asynchronously,
178 /// as if called as `async function()`.
179 Async,
180 /// Functions with this calling convention are inlined at all call sites.
181 Inline,
182 /// x86-only.
183 Interrupt,
184 Signal,
185 /// x86-only.
186 Stdcall,
187 /// x86-only.
188 Fastcall,
189 /// x86-only.
190 Vectorcall,
191 /// x86-only.
192 Thiscall,
193 /// ARM Procedure Call Standard (obsolete)
194 /// ARM-only.
195 APCS,
196 /// ARM Architecture Procedure Call Standard (current standard)
197 /// ARM-only.
198 AAPCS,
199 /// ARM Architecture Procedure Call Standard Vector Floating-Point
200 /// ARM-only.
201 AAPCSVFP,
202 /// x86-64-only.
203 SysV,
204 /// x86-64-only.
205 Win64,
206 /// AMD GPU, NVPTX, or SPIR-V kernel
207 Kernel,
208 // Vulkan-only
209 Fragment,
210 Vertex,
211};
212
213163/// The calling convention of a function defines how arguments and return values are passed, as well
214164/// as any other requirements which callers and callees must respect, such as register preservation
215165/// and stack alignment.
216166///
217167/// This data structure is used by the Zig language code generation and
218168/// therefore must be kept in sync with the compiler implementation.
219///
220/// TODO: this will be renamed `CallingConvention` after an initial zig1.wasm update.
221pub const NewCallingConvention = union(enum(u8)) {
222 pub const Tag = @typeInfo(NewCallingConvention).@"union".tag_type.?;
169pub const CallingConvention = union(enum(u8)) {
170 pub const Tag = @typeInfo(CallingConvention).@"union".tag_type.?;
223171
224172 /// This is an alias for the default C calling convention for this target.
225173 /// Functions marked as `extern` or `export` are given this calling convention by default.
226174 pub const c = builtin.target.defaultCCallingConvention().?;
227175
228 pub const winapi: NewCallingConvention = switch (builtin.target.arch) {
176 pub const winapi: CallingConvention = switch (builtin.target.arch) {
229177 .x86_64 => .{ .x86_64_win = .{} },
230178 .x86 => .{ .x86_stdcall = .{} },
231179 .aarch64, .aarch64_be => .{ .aarch64_aapcs_win = .{} },
......@@ -233,7 +181,7 @@ pub const NewCallingConvention = union(enum(u8)) {
233181 else => unreachable,
234182 };
235183
236 pub const kernel: NewCallingConvention = switch (builtin.target.cpu.arch) {
184 pub const kernel: CallingConvention = switch (builtin.target.cpu.arch) {
237185 .amdgcn => .amdgcn_kernel,
238186 .nvptx, .nvptx64 => .nvptx_kernel,
239187 .spirv, .spirv32, .spirv64 => .spirv_kernel,
......@@ -241,53 +189,53 @@ pub const NewCallingConvention = union(enum(u8)) {
241189 };
242190
243191 /// Deprecated; use `.auto`.
244 pub const Unspecified: NewCallingConvention = .auto;
192 pub const Unspecified: CallingConvention = .auto;
245193 /// Deprecated; use `.c`.
246 pub const C: NewCallingConvention = .c;
194 pub const C: CallingConvention = .c;
247195 /// Deprecated; use `.naked`.
248 pub const Naked: NewCallingConvention = .naked;
196 pub const Naked: CallingConvention = .naked;
249197 /// Deprecated; use `.@"async"`.
250 pub const Async: NewCallingConvention = .@"async";
198 pub const Async: CallingConvention = .@"async";
251199 /// Deprecated; use `.@"inline"`.
252 pub const Inline: NewCallingConvention = .@"inline";
200 pub const Inline: CallingConvention = .@"inline";
253201 /// Deprecated; use `.x86_64_interrupt`, `.x86_interrupt`, or `.avr_interrupt`.
254 pub const Interrupt: NewCallingConvention = switch (builtin.target.cpu.arch) {
202 pub const Interrupt: CallingConvention = switch (builtin.target.cpu.arch) {
255203 .x86_64 => .{ .x86_64_interrupt = .{} },
256204 .x86 => .{ .x86_interrupt = .{} },
257205 .avr => .avr_interrupt,
258206 else => unreachable,
259207 };
260208 /// Deprecated; use `.avr_signal`.
261 pub const Signal: NewCallingConvention = .avr_signal;
209 pub const Signal: CallingConvention = .avr_signal;
262210 /// Deprecated; use `.x86_stdcall`.
263 pub const Stdcall: NewCallingConvention = .{ .x86_stdcall = .{} };
211 pub const Stdcall: CallingConvention = .{ .x86_stdcall = .{} };
264212 /// Deprecated; use `.x86_fastcall`.
265 pub const Fastcall: NewCallingConvention = .{ .x86_fastcall = .{} };
213 pub const Fastcall: CallingConvention = .{ .x86_fastcall = .{} };
266214 /// Deprecated; use `.x86_64_vectorcall`, `.x86_vectorcall`, or `aarch64_vfabi`.
267 pub const Vectorcall: NewCallingConvention = switch (builtin.target.cpu.arch) {
215 pub const Vectorcall: CallingConvention = switch (builtin.target.cpu.arch) {
268216 .x86_64 => .{ .x86_64_vectorcall = .{} },
269217 .x86 => .{ .x86_vectorcall = .{} },
270218 .aarch64, .aarch64_be => .{ .aarch64_vfabi = .{} },
271219 else => unreachable,
272220 };
273221 /// Deprecated; use `.x86_thiscall`.
274 pub const Thiscall: NewCallingConvention = .{ .x86_thiscall = .{} };
222 pub const Thiscall: CallingConvention = .{ .x86_thiscall = .{} };
275223 /// Deprecated; use `.arm_apcs`.
276 pub const APCS: NewCallingConvention = .{ .arm_apcs = .{} };
224 pub const APCS: CallingConvention = .{ .arm_apcs = .{} };
277225 /// Deprecated; use `.arm_aapcs`.
278 pub const AAPCS: NewCallingConvention = .{ .arm_aapcs = .{} };
226 pub const AAPCS: CallingConvention = .{ .arm_aapcs = .{} };
279227 /// Deprecated; use `.arm_aapcs_vfp`.
280 pub const AAPCSVFP: NewCallingConvention = .{ .arm_aapcs_vfp = .{} };
228 pub const AAPCSVFP: CallingConvention = .{ .arm_aapcs_vfp = .{} };
281229 /// Deprecated; use `.x86_64_sysv`.
282 pub const SysV: NewCallingConvention = .{ .x86_64_sysv = .{} };
230 pub const SysV: CallingConvention = .{ .x86_64_sysv = .{} };
283231 /// Deprecated; use `.x86_64_win`.
284 pub const Win64: NewCallingConvention = .{ .x86_64_win = .{} };
232 pub const Win64: CallingConvention = .{ .x86_64_win = .{} };
285233 /// Deprecated; use `.kernel`.
286 pub const Kernel: NewCallingConvention = .kernel;
234 pub const Kernel: CallingConvention = .kernel;
287235 /// Deprecated; use `.spirv_fragment`.
288 pub const Fragment: NewCallingConvention = .spirv_fragment;
236 pub const Fragment: CallingConvention = .spirv_fragment;
289237 /// Deprecated; use `.spirv_vertex`.
290 pub const Vertex: NewCallingConvention = .spirv_vertex;
238 pub const Vertex: CallingConvention = .spirv_vertex;
291239
292240 /// The default Zig calling convention when neither `export` nor `inline` is specified.
293241 /// This calling convention makes no guarantees about stack alignment, registers, etc.
......@@ -535,9 +483,16 @@ pub const NewCallingConvention = union(enum(u8)) {
535483 /// Asserts that `cc` is not `.auto`, `.@"async"`, `.naked`, or `.@"inline"`.
536484 pub const archs = std.Target.Cpu.Arch.fromCallconv;
537485
538 pub fn eql(a: NewCallingConvention, b: NewCallingConvention) bool {
486 pub fn eql(a: CallingConvention, b: CallingConvention) bool {
539487 return std.meta.eql(a, b);
540488 }
489
490 pub fn withStackAlign(cc: CallingConvention, incoming_stack_alignment: u64) CallingConvention {
491 const tag: CallingConvention.Tag = cc;
492 var result = cc;
493 @field(result, tag).incoming_stack_alignment = incoming_stack_alignment;
494 return result;
495 }
541496};
542497
543498/// This data structure is used by the Zig language code generation and
lib/std/crypto/25519/field.zig+3-3
......@@ -6,9 +6,9 @@ const NonCanonicalError = crypto.errors.NonCanonicalError;
66const NotSquareError = crypto.errors.NotSquareError;
77
88// Inline conditionally, when it can result in large code generation.
9const bloaty_inline = switch (builtin.mode) {
10 .ReleaseSafe, .ReleaseFast => .Inline,
11 .Debug, .ReleaseSmall => .Unspecified,
9const bloaty_inline: std.builtin.CallingConvention = switch (builtin.mode) {
10 .ReleaseSafe, .ReleaseFast => .@"inline",
11 .Debug, .ReleaseSmall => .auto,
1212};
1313
1414pub const Fe = struct {
lib/std/os/windows.zig+1-4
......@@ -2824,10 +2824,7 @@ pub const STD_OUTPUT_HANDLE = maxInt(DWORD) - 11 + 1;
28242824/// The standard error device. Initially, this is the active console screen buffer, CONOUT$.
28252825pub const STD_ERROR_HANDLE = maxInt(DWORD) - 12 + 1;
28262826
2827pub const WINAPI: std.builtin.CallingConvention = if (native_arch == .x86)
2828 .Stdcall
2829else
2830 .C;
2827pub const WINAPI: std.builtin.CallingConvention = .winapi;
28312828
28322829pub const BOOL = c_int;
28332830pub const BOOLEAN = BYTE;
lib/std/start.zig+4-7
......@@ -55,7 +55,7 @@ comptime {
5555 if (builtin.link_libc and @hasDecl(root, "main")) {
5656 if (native_arch.isWasm()) {
5757 @export(&mainWithoutEnv, .{ .name = "main" });
58 } else if (@typeInfo(@TypeOf(root.main)).@"fn".calling_convention != .C) {
58 } else if (!@typeInfo(@TypeOf(root.main)).@"fn".calling_convention.eql(.c)) {
5959 @export(&main, .{ .name = "main" });
6060 }
6161 } else if (native_os == .windows) {
......@@ -102,12 +102,11 @@ fn main2() callconv(.C) c_int {
102102 return 0;
103103}
104104
105fn _start2() callconv(.C) noreturn {
105fn _start2() callconv(.withStackAlign(.c, 1)) noreturn {
106106 callMain2();
107107}
108108
109109fn callMain2() noreturn {
110 @setAlignStack(16);
111110 root.main();
112111 exit2(0);
113112}
......@@ -428,8 +427,7 @@ fn _start() callconv(.Naked) noreturn {
428427 );
429428}
430429
431fn WinStartup() callconv(std.os.windows.WINAPI) noreturn {
432 @setAlignStack(16);
430fn WinStartup() callconv(.withStackAlign(.winapi, 1)) noreturn {
433431 if (!builtin.single_threaded and !builtin.link_libc) {
434432 _ = @import("os/windows/tls.zig");
435433 }
......@@ -439,8 +437,7 @@ fn WinStartup() callconv(std.os.windows.WINAPI) noreturn {
439437 std.os.windows.ntdll.RtlExitUserProcess(callMain());
440438}
441439
442fn wWinMainCRTStartup() callconv(std.os.windows.WINAPI) noreturn {
443 @setAlignStack(16);
440fn wWinMainCRTStartup() callconv(.withStackAlign(.winapi, 1)) noreturn {
444441 if (!builtin.single_threaded and !builtin.link_libc) {
445442 _ = @import("os/windows/tls.zig");
446443 }
src/InternPool.zig+20-20
......@@ -1988,7 +1988,7 @@ pub const Key = union(enum) {
19881988 /// Tells whether a parameter is noalias. See `paramIsNoalias` helper
19891989 /// method for accessing this.
19901990 noalias_bits: u32,
1991 cc: std.builtin.NewCallingConvention,
1991 cc: std.builtin.CallingConvention,
19921992 is_var_args: bool,
19931993 is_generic: bool,
19941994 is_noinline: bool,
......@@ -8526,7 +8526,7 @@ pub const GetFuncTypeKey = struct {
85268526 comptime_bits: u32 = 0,
85278527 noalias_bits: u32 = 0,
85288528 /// `null` means generic.
8529 cc: ?std.builtin.NewCallingConvention = .auto,
8529 cc: ?std.builtin.CallingConvention = .auto,
85308530 is_var_args: bool = false,
85318531 is_generic: bool = false,
85328532 is_noinline: bool = false,
......@@ -8668,7 +8668,7 @@ pub const GetFuncDeclKey = struct {
86688668 rbrace_line: u32,
86698669 lbrace_column: u32,
86708670 rbrace_column: u32,
8671 cc: ?std.builtin.NewCallingConvention,
8671 cc: ?std.builtin.CallingConvention,
86728672 is_noinline: bool,
86738673};
86748674
......@@ -8733,7 +8733,7 @@ pub const GetFuncDeclIesKey = struct {
87338733 comptime_bits: u32,
87348734 bare_return_type: Index,
87358735 /// null means generic.
8736 cc: ?std.builtin.NewCallingConvention,
8736 cc: ?std.builtin.CallingConvention,
87378737 /// null means generic.
87388738 alignment: ?Alignment,
87398739 section_is_generic: bool,
......@@ -8948,7 +8948,7 @@ pub const GetFuncInstanceKey = struct {
89488948 comptime_args: []const Index,
89498949 noalias_bits: u32,
89508950 bare_return_type: Index,
8951 cc: std.builtin.NewCallingConvention,
8951 cc: std.builtin.CallingConvention,
89528952 alignment: Alignment,
89538953 section: OptionalNullTerminatedString,
89548954 is_noinline: bool,
......@@ -12226,13 +12226,13 @@ pub fn getErrorValueIfExists(ip: *const InternPool, name: NullTerminatedString)
1222612226}
1222712227
1222812228const PackedCallingConvention = packed struct(u18) {
12229 tag: std.builtin.NewCallingConvention.Tag,
12229 tag: std.builtin.CallingConvention.Tag,
1223012230 /// May be ignored depending on `tag`.
1223112231 incoming_stack_alignment: Alignment,
1223212232 /// Interpretation depends on `tag`.
1223312233 extra: u4,
1223412234
12235 fn pack(cc: std.builtin.NewCallingConvention) PackedCallingConvention {
12235 fn pack(cc: std.builtin.CallingConvention) PackedCallingConvention {
1223612236 return switch (cc) {
1223712237 inline else => |pl, tag| switch (@TypeOf(pl)) {
1223812238 void => .{
......@@ -12240,27 +12240,27 @@ const PackedCallingConvention = packed struct(u18) {
1224012240 .incoming_stack_alignment = .none, // unused
1224112241 .extra = 0, // unused
1224212242 },
12243 std.builtin.NewCallingConvention.CommonOptions => .{
12243 std.builtin.CallingConvention.CommonOptions => .{
1224412244 .tag = tag,
1224512245 .incoming_stack_alignment = .fromByteUnits(pl.incoming_stack_alignment orelse 0),
1224612246 .extra = 0, // unused
1224712247 },
12248 std.builtin.NewCallingConvention.X86RegparmOptions => .{
12248 std.builtin.CallingConvention.X86RegparmOptions => .{
1224912249 .tag = tag,
1225012250 .incoming_stack_alignment = .fromByteUnits(pl.incoming_stack_alignment orelse 0),
1225112251 .extra = pl.register_params,
1225212252 },
12253 std.builtin.NewCallingConvention.ArmInterruptOptions => .{
12253 std.builtin.CallingConvention.ArmInterruptOptions => .{
1225412254 .tag = tag,
1225512255 .incoming_stack_alignment = .fromByteUnits(pl.incoming_stack_alignment orelse 0),
1225612256 .extra = @intFromEnum(pl.type),
1225712257 },
12258 std.builtin.NewCallingConvention.MipsInterruptOptions => .{
12258 std.builtin.CallingConvention.MipsInterruptOptions => .{
1225912259 .tag = tag,
1226012260 .incoming_stack_alignment = .fromByteUnits(pl.incoming_stack_alignment orelse 0),
1226112261 .extra = @intFromEnum(pl.mode),
1226212262 },
12263 std.builtin.NewCallingConvention.RiscvInterruptOptions => .{
12263 std.builtin.CallingConvention.RiscvInterruptOptions => .{
1226412264 .tag = tag,
1226512265 .incoming_stack_alignment = .fromByteUnits(pl.incoming_stack_alignment orelse 0),
1226612266 .extra = @intFromEnum(pl.level),
......@@ -12270,30 +12270,30 @@ const PackedCallingConvention = packed struct(u18) {
1227012270 };
1227112271 }
1227212272
12273 fn unpack(cc: PackedCallingConvention) std.builtin.NewCallingConvention {
12273 fn unpack(cc: PackedCallingConvention) std.builtin.CallingConvention {
1227412274 @setEvalBranchQuota(400_000);
1227512275 return switch (cc.tag) {
1227612276 inline else => |tag| @unionInit(
12277 std.builtin.NewCallingConvention,
12277 std.builtin.CallingConvention,
1227812278 @tagName(tag),
12279 switch (std.meta.FieldType(std.builtin.NewCallingConvention, tag)) {
12279 switch (std.meta.FieldType(std.builtin.CallingConvention, tag)) {
1228012280 void => {},
12281 std.builtin.NewCallingConvention.CommonOptions => .{
12281 std.builtin.CallingConvention.CommonOptions => .{
1228212282 .incoming_stack_alignment = cc.incoming_stack_alignment.toByteUnits(),
1228312283 },
12284 std.builtin.NewCallingConvention.X86RegparmOptions => .{
12284 std.builtin.CallingConvention.X86RegparmOptions => .{
1228512285 .incoming_stack_alignment = cc.incoming_stack_alignment.toByteUnits(),
1228612286 .register_params = @intCast(cc.extra),
1228712287 },
12288 std.builtin.NewCallingConvention.ArmInterruptOptions => .{
12288 std.builtin.CallingConvention.ArmInterruptOptions => .{
1228912289 .incoming_stack_alignment = cc.incoming_stack_alignment.toByteUnits(),
1229012290 .type = @enumFromInt(cc.extra),
1229112291 },
12292 std.builtin.NewCallingConvention.MipsInterruptOptions => .{
12292 std.builtin.CallingConvention.MipsInterruptOptions => .{
1229312293 .incoming_stack_alignment = cc.incoming_stack_alignment.toByteUnits(),
1229412294 .mode = @enumFromInt(cc.extra),
1229512295 },
12296 std.builtin.NewCallingConvention.RiscvInterruptOptions => .{
12296 std.builtin.CallingConvention.RiscvInterruptOptions => .{
1229712297 .incoming_stack_alignment = cc.incoming_stack_alignment.toByteUnits(),
1229812298 .level = @enumFromInt(cc.extra),
1229912299 },
src/Sema.zig+21-21
......@@ -2703,9 +2703,9 @@ fn analyzeValueAsCallconv(
27032703 block: *Block,
27042704 src: LazySrcLoc,
27052705 unresolved_val: Value,
2706) !std.builtin.NewCallingConvention {
2706) !std.builtin.CallingConvention {
27072707 const resolved_val = try sema.resolveLazyValue(unresolved_val);
2708 return resolved_val.interpret(std.builtin.NewCallingConvention, sema.pt) catch |err| switch (err) {
2708 return resolved_val.interpret(std.builtin.CallingConvention, sema.pt) catch |err| switch (err) {
27092709 error.OutOfMemory => |e| return e,
27102710 error.UndefinedValue => return sema.failWithUseOfUndef(block, src),
27112711 error.TypeMismatch => @panic("std.builtin is corrupt"),
......@@ -9520,7 +9520,7 @@ fn zirFunc(
95209520 // If this instruction has a body, then it's a function declaration, and we decide
95219521 // the callconv based on whether it is exported. Otherwise, the callconv defaults
95229522 // to `.auto`.
9523 const cc: std.builtin.NewCallingConvention = if (has_body) cc: {
9523 const cc: std.builtin.CallingConvention = if (has_body) cc: {
95249524 const func_decl_cau = if (sema.generic_owner != .none) cau: {
95259525 const generic_owner_fn = zcu.funcInfo(sema.generic_owner);
95269526 // The generic owner definitely has a `Cau` for the corresponding function declaration.
......@@ -9686,7 +9686,7 @@ fn handleExternLibName(
96869686/// These are calling conventions that are confirmed to work with variadic functions.
96879687/// Any calling conventions not included here are either not yet verified to work with variadic
96889688/// functions or there are no more other calling conventions that support variadic functions.
9689const calling_conventions_supporting_var_args = [_]std.builtin.NewCallingConvention.Tag{
9689const calling_conventions_supporting_var_args = [_]std.builtin.CallingConvention.Tag{
96909690 .x86_64_sysv,
96919691 .x86_64_win,
96929692 .x86_sysv,
......@@ -9738,12 +9738,12 @@ const calling_conventions_supporting_var_args = [_]std.builtin.NewCallingConvent
97389738 .xtensa_call0,
97399739 .xtensa_windowed,
97409740};
9741fn callConvSupportsVarArgs(cc: std.builtin.NewCallingConvention.Tag) bool {
9741fn callConvSupportsVarArgs(cc: std.builtin.CallingConvention.Tag) bool {
97429742 return for (calling_conventions_supporting_var_args) |supported_cc| {
97439743 if (cc == supported_cc) return true;
97449744 } else false;
97459745}
9746fn checkCallConvSupportsVarArgs(sema: *Sema, block: *Block, src: LazySrcLoc, cc: std.builtin.NewCallingConvention.Tag) CompileError!void {
9746fn checkCallConvSupportsVarArgs(sema: *Sema, block: *Block, src: LazySrcLoc, cc: std.builtin.CallingConvention.Tag) CompileError!void {
97479747 const CallingConventionsSupportingVarArgsList = struct {
97489748 pub fn format(_: @This(), comptime fmt: []const u8, options: std.fmt.FormatOptions, writer: anytype) !void {
97499749 _ = fmt;
......@@ -9784,7 +9784,7 @@ fn funcCommon(
97849784 address_space: ?std.builtin.AddressSpace,
97859785 section: Section,
97869786 /// null means generic poison
9787 cc: ?std.builtin.NewCallingConvention,
9787 cc: ?std.builtin.CallingConvention,
97889788 /// this might be Type.generic_poison
97899789 bare_return_type: Type,
97909790 var_args: bool,
......@@ -10141,7 +10141,7 @@ fn finishFunc(
1014110141 ret_poison: bool,
1014210142 bare_return_type: Type,
1014310143 ret_ty_src: LazySrcLoc,
10144 cc_resolved: std.builtin.NewCallingConvention,
10144 cc_resolved: std.builtin.CallingConvention,
1014510145 is_source_decl: bool,
1014610146 ret_ty_requires_comptime: bool,
1014710147 func_inst: Zir.Inst.Index,
......@@ -26744,7 +26744,7 @@ fn zirFuncFancy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
2674426744 break :blk .{ .explicit = section_name };
2674526745 } else .default;
2674626746
26747 const cc: ?std.builtin.NewCallingConvention = if (extra.data.bits.has_cc_body) blk: {
26747 const cc: ?std.builtin.CallingConvention = if (extra.data.bits.has_cc_body) blk: {
2674826748 const body_len = sema.code.extra[extra_index];
2674926749 extra_index += 1;
2675026750 const body = sema.code.bodySlice(extra_index, body_len);
......@@ -27253,14 +27253,14 @@ fn zirBuiltinValue(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstD
2725327253 ) orelse @panic("std.builtin is corrupt");
2725427254 },
2725527255 .calling_convention_inline => {
27256 comptime assert(@typeInfo(std.builtin.NewCallingConvention.Tag).@"enum".tag_type == u8);
27256 comptime assert(@typeInfo(std.builtin.CallingConvention.Tag).@"enum".tag_type == u8);
2725727257 const callconv_ty = try sema.getBuiltinType("CallingConvention");
2725827258 const callconv_tag_ty = callconv_ty.unionTagType(zcu) orelse @panic("std.builtin is corrupt");
2725927259 const inline_tag_val = try pt.enumValue(
2726027260 callconv_tag_ty,
2726127261 (try pt.intValue(
2726227262 Type.u8,
27263 @intFromEnum(std.builtin.NewCallingConvention.@"inline"),
27263 @intFromEnum(std.builtin.CallingConvention.@"inline"),
2726427264 )).toIntern(),
2726527265 );
2726627266 return sema.coerce(block, callconv_ty, Air.internedToRef(inline_tag_val.toIntern()), src);
......@@ -30621,8 +30621,8 @@ const InMemoryCoercionResult = union(enum) {
3062130621 };
3062230622
3062330623 const CC = struct {
30624 actual: std.builtin.NewCallingConvention,
30625 wanted: std.builtin.NewCallingConvention,
30624 actual: std.builtin.CallingConvention,
30625 wanted: std.builtin.CallingConvention,
3062630626 };
3062730627
3062830628 const BitRange = struct {
......@@ -31348,10 +31348,10 @@ fn coerceInMemoryAllowedFns(
3134831348
3134931349fn callconvCoerceAllowed(
3135031350 target: std.Target,
31351 src_cc: std.builtin.NewCallingConvention,
31352 dest_cc: std.builtin.NewCallingConvention,
31351 src_cc: std.builtin.CallingConvention,
31352 dest_cc: std.builtin.CallingConvention,
3135331353) bool {
31354 const Tag = std.builtin.NewCallingConvention.Tag;
31354 const Tag = std.builtin.CallingConvention.Tag;
3135531355 if (@as(Tag, src_cc) != @as(Tag, dest_cc)) return false;
3135631356
3135731357 switch (src_cc) {
......@@ -31364,17 +31364,17 @@ fn callconvCoerceAllowed(
3136431364 if (dest_stack_align < src_stack_align) return false;
3136531365 }
3136631366 switch (@TypeOf(src_data)) {
31367 void, std.builtin.NewCallingConvention.CommonOptions => {},
31368 std.builtin.NewCallingConvention.X86RegparmOptions => {
31367 void, std.builtin.CallingConvention.CommonOptions => {},
31368 std.builtin.CallingConvention.X86RegparmOptions => {
3136931369 if (src_data.register_params != dest_data.register_params) return false;
3137031370 },
31371 std.builtin.NewCallingConvention.ArmInterruptOptions => {
31371 std.builtin.CallingConvention.ArmInterruptOptions => {
3137231372 if (src_data.type != dest_data.type) return false;
3137331373 },
31374 std.builtin.NewCallingConvention.MipsInterruptOptions => {
31374 std.builtin.CallingConvention.MipsInterruptOptions => {
3137531375 if (src_data.mode != dest_data.mode) return false;
3137631376 },
31377 std.builtin.NewCallingConvention.RiscvInterruptOptions => {
31377 std.builtin.CallingConvention.RiscvInterruptOptions => {
3137831378 if (src_data.level != dest_data.level) return false;
3137931379 },
3138031380 else => comptime unreachable,
src/Type.zig+1-1
......@@ -2493,7 +2493,7 @@ pub fn fnReturnType(ty: Type, zcu: *const Zcu) Type {
24932493}
24942494
24952495/// Asserts the type is a function.
2496pub fn fnCallingConvention(ty: Type, zcu: *const Zcu) std.builtin.NewCallingConvention {
2496pub fn fnCallingConvention(ty: Type, zcu: *const Zcu) std.builtin.CallingConvention {
24972497 return zcu.intern_pool.indexToKey(ty.toIntern()).func_type.cc;
24982498}
24992499
src/Zcu.zig+1-1
......@@ -3540,7 +3540,7 @@ pub fn maybeUnresolveIes(zcu: *Zcu, func_index: InternPool.Index) !void {
35403540 }
35413541}
35423542
3543pub fn callconvSupported(zcu: *Zcu, cc: std.builtin.NewCallingConvention) union(enum) {
3543pub fn callconvSupported(zcu: *Zcu, cc: std.builtin.CallingConvention) union(enum) {
35443544 ok,
35453545 bad_arch: []const std.Target.Cpu.Arch, // value is allowed archs for cc
35463546 bad_backend: std.builtin.CompilerBackend, // value is current backend
src/arch/riscv64/Lower.zig+1-1
......@@ -6,7 +6,7 @@ link_mode: std.builtin.LinkMode,
66pic: bool,
77allocator: Allocator,
88mir: Mir,
9cc: std.builtin.NewCallingConvention,
9cc: std.builtin.CallingConvention,
1010err_msg: ?*ErrorMsg = null,
1111src_loc: Zcu.LazySrcLoc,
1212result_insts_len: u8 = undefined,
src/arch/wasm/CodeGen.zig+3-3
......@@ -1145,7 +1145,7 @@ fn ensureAllocLocal(func: *CodeGen, ty: Type) InnerError!WValue {
11451145/// Memory is owned by the caller.
11461146fn genFunctype(
11471147 gpa: Allocator,
1148 cc: std.builtin.NewCallingConvention,
1148 cc: std.builtin.CallingConvention,
11491149 params: []const InternPool.Index,
11501150 return_type: Type,
11511151 pt: Zcu.PerThread,
......@@ -1408,7 +1408,7 @@ fn resolveCallingConventionValues(func: *CodeGen, fn_ty: Type) InnerError!CallWV
14081408 return result;
14091409}
14101410
1411fn firstParamSRet(cc: std.builtin.NewCallingConvention, return_type: Type, pt: Zcu.PerThread, target: std.Target) bool {
1411fn firstParamSRet(cc: std.builtin.CallingConvention, return_type: Type, pt: Zcu.PerThread, target: std.Target) bool {
14121412 switch (cc) {
14131413 .@"inline" => unreachable,
14141414 .auto => return isByRef(return_type, pt, target),
......@@ -1424,7 +1424,7 @@ fn firstParamSRet(cc: std.builtin.NewCallingConvention, return_type: Type, pt: Z
14241424
14251425/// Lowers a Zig type and its value based on a given calling convention to ensure
14261426/// it matches the ABI.
1427fn lowerArg(func: *CodeGen, cc: std.builtin.NewCallingConvention, ty: Type, value: WValue) !void {
1427fn lowerArg(func: *CodeGen, cc: std.builtin.CallingConvention, ty: Type, value: WValue) !void {
14281428 if (cc != .wasm_watc) {
14291429 return func.lowerToStack(value);
14301430 }
src/arch/x86_64/CodeGen.zig+2-2
......@@ -2694,7 +2694,7 @@ fn setFrameLoc(
26942694 offset.* += self.frame_allocs.items(.abi_size)[frame_i];
26952695}
26962696
2697fn computeFrameLayout(self: *Self, cc: std.builtin.NewCallingConvention) !FrameLayout {
2697fn computeFrameLayout(self: *Self, cc: std.builtin.CallingConvention) !FrameLayout {
26982698 const frame_allocs_len = self.frame_allocs.len;
26992699 try self.frame_locs.resize(self.gpa, frame_allocs_len);
27002700 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 {
30063006 }
30073007}
30083008
3009pub fn spillCallerPreservedRegs(self: *Self, cc: std.builtin.NewCallingConvention) !void {
3009pub fn spillCallerPreservedRegs(self: *Self, cc: std.builtin.CallingConvention) !void {
30103010 switch (cc) {
30113011 .x86_64_sysv => try self.spillRegisters(abi.getCallerPreservedRegs(.{ .x86_64_sysv = .{} })),
30123012 .x86_64_win => try self.spillRegisters(abi.getCallerPreservedRegs(.{ .x86_64_win = .{} })),
src/arch/x86_64/Lower.zig+1-1
......@@ -6,7 +6,7 @@ link_mode: std.builtin.LinkMode,
66pic: bool,
77allocator: std.mem.Allocator,
88mir: Mir,
9cc: std.builtin.NewCallingConvention,
9cc: std.builtin.CallingConvention,
1010err_msg: ?*Zcu.ErrorMsg = null,
1111src_loc: Zcu.LazySrcLoc,
1212result_insts_len: u8 = undefined,
src/arch/x86_64/abi.zig+8-8
......@@ -436,9 +436,9 @@ pub const Win64 = struct {
436436};
437437
438438pub fn resolveCallingConvention(
439 cc: std.builtin.NewCallingConvention,
439 cc: std.builtin.CallingConvention,
440440 target: std.Target,
441) std.builtin.NewCallingConvention {
441) std.builtin.CallingConvention {
442442 return switch (cc) {
443443 .auto => switch (target.os.tag) {
444444 else => .{ .x86_64_sysv = .{} },
......@@ -448,7 +448,7 @@ pub fn resolveCallingConvention(
448448 };
449449}
450450
451pub fn getCalleePreservedRegs(cc: std.builtin.NewCallingConvention) []const Register {
451pub fn getCalleePreservedRegs(cc: std.builtin.CallingConvention) []const Register {
452452 return switch (cc) {
453453 .x86_64_sysv => &SysV.callee_preserved_regs,
454454 .x86_64_win => &Win64.callee_preserved_regs,
......@@ -456,7 +456,7 @@ pub fn getCalleePreservedRegs(cc: std.builtin.NewCallingConvention) []const Regi
456456 };
457457}
458458
459pub fn getCallerPreservedRegs(cc: std.builtin.NewCallingConvention) []const Register {
459pub fn getCallerPreservedRegs(cc: std.builtin.CallingConvention) []const Register {
460460 return switch (cc) {
461461 .x86_64_sysv => &SysV.caller_preserved_regs,
462462 .x86_64_win => &Win64.caller_preserved_regs,
......@@ -464,7 +464,7 @@ pub fn getCallerPreservedRegs(cc: std.builtin.NewCallingConvention) []const Regi
464464 };
465465}
466466
467pub fn getCAbiIntParamRegs(cc: std.builtin.NewCallingConvention) []const Register {
467pub fn getCAbiIntParamRegs(cc: std.builtin.CallingConvention) []const Register {
468468 return switch (cc) {
469469 .x86_64_sysv => &SysV.c_abi_int_param_regs,
470470 .x86_64_win => &Win64.c_abi_int_param_regs,
......@@ -472,7 +472,7 @@ pub fn getCAbiIntParamRegs(cc: std.builtin.NewCallingConvention) []const Registe
472472 };
473473}
474474
475pub fn getCAbiSseParamRegs(cc: std.builtin.NewCallingConvention) []const Register {
475pub fn getCAbiSseParamRegs(cc: std.builtin.CallingConvention) []const Register {
476476 return switch (cc) {
477477 .x86_64_sysv => &SysV.c_abi_sse_param_regs,
478478 .x86_64_win => &Win64.c_abi_sse_param_regs,
......@@ -480,7 +480,7 @@ pub fn getCAbiSseParamRegs(cc: std.builtin.NewCallingConvention) []const Registe
480480 };
481481}
482482
483pub fn getCAbiIntReturnRegs(cc: std.builtin.NewCallingConvention) []const Register {
483pub fn getCAbiIntReturnRegs(cc: std.builtin.CallingConvention) []const Register {
484484 return switch (cc) {
485485 .x86_64_sysv => &SysV.c_abi_int_return_regs,
486486 .x86_64_win => &Win64.c_abi_int_return_regs,
......@@ -488,7 +488,7 @@ pub fn getCAbiIntReturnRegs(cc: std.builtin.NewCallingConvention) []const Regist
488488 };
489489}
490490
491pub fn getCAbiSseReturnRegs(cc: std.builtin.NewCallingConvention) []const Register {
491pub fn getCAbiSseReturnRegs(cc: std.builtin.CallingConvention) []const Register {
492492 return switch (cc) {
493493 .x86_64_sysv => &SysV.c_abi_sse_return_regs,
494494 .x86_64_win => &Win64.c_abi_sse_return_regs,
src/codegen/c.zig+1-1
......@@ -7604,7 +7604,7 @@ fn writeMemoryOrder(w: anytype, order: std.builtin.AtomicOrder) !void {
76047604 return w.writeAll(toMemoryOrder(order));
76057605}
76067606
7607fn toCallingConvention(cc: std.builtin.NewCallingConvention, zcu: *Zcu) ?[]const u8 {
7607fn toCallingConvention(cc: std.builtin.CallingConvention, zcu: *Zcu) ?[]const u8 {
76087608 return switch (cc) {
76097609 .auto, .naked => null,
76107610 .x86_stdcall => "stdcall",
src/codegen/llvm.zig+5-5
......@@ -11595,13 +11595,13 @@ const CallingConventionInfo = struct {
1159511595 inreg_param_count: u2 = 0,
1159611596};
1159711597
11598pub fn toLlvmCallConv(cc: std.builtin.NewCallingConvention, target: std.Target) ?CallingConventionInfo {
11598pub fn toLlvmCallConv(cc: std.builtin.CallingConvention, target: std.Target) ?CallingConventionInfo {
1159911599 const llvm_cc = toLlvmCallConvTag(cc, target) orelse return null;
1160011600 const incoming_stack_alignment: ?u64, const register_params: u2 = switch (cc) {
1160111601 inline else => |pl| switch (@TypeOf(pl)) {
1160211602 void => .{ null, 0 },
11603 std.builtin.NewCallingConvention.CommonOptions => .{ pl.incoming_stack_alignment, 0 },
11604 std.builtin.NewCallingConvention.X86RegparmOptions => .{ pl.incoming_stack_alignment, pl.register_params },
11603 std.builtin.CallingConvention.CommonOptions => .{ pl.incoming_stack_alignment, 0 },
11604 std.builtin.CallingConvention.X86RegparmOptions => .{ pl.incoming_stack_alignment, pl.register_params },
1160511605 else => unreachable,
1160611606 },
1160711607 };
......@@ -11615,7 +11615,7 @@ pub fn toLlvmCallConv(cc: std.builtin.NewCallingConvention, target: std.Target)
1161511615 .inreg_param_count = register_params,
1161611616 };
1161711617}
11618fn toLlvmCallConvTag(cc_tag: std.builtin.NewCallingConvention.Tag, target: std.Target) ?Builder.CallConv {
11618fn toLlvmCallConvTag(cc_tag: std.builtin.CallingConvention.Tag, target: std.Target) ?Builder.CallConv {
1161911619 if (target.defaultCCallingConvention()) |default_c| {
1162011620 if (cc_tag == default_c) {
1162111621 return .ccc;
......@@ -12371,7 +12371,7 @@ fn iterateParamTypes(object: *Object, fn_info: InternPool.Key.FuncType) ParamTyp
1237112371}
1237212372
1237312373fn ccAbiPromoteInt(
12374 cc: std.builtin.NewCallingConvention,
12374 cc: std.builtin.CallingConvention,
1237512375 zcu: *Zcu,
1237612376 ty: Type,
1237712377) ?std.builtin.Signedness {
src/link/Coff.zig+2-2
......@@ -1485,12 +1485,12 @@ pub fn updateExports(
14851485 const exported_ty = exported_nav.typeOf(ip);
14861486 if (!ip.isFunctionType(exported_ty)) continue;
14871487 const c_cc = target.defaultCCallingConvention().?;
1488 const winapi_cc: std.builtin.NewCallingConvention = switch (target.cpu.arch) {
1488 const winapi_cc: std.builtin.CallingConvention = switch (target.cpu.arch) {
14891489 .x86 => .{ .x86_stdcall = .{} },
14901490 else => c_cc,
14911491 };
14921492 const exported_cc = Type.fromInterned(exported_ty).fnCallingConvention(zcu);
1493 const CcTag = std.builtin.NewCallingConvention.Tag;
1493 const CcTag = std.builtin.CallingConvention.Tag;
14941494 if (@as(CcTag, exported_cc) == @as(CcTag, c_cc) and exp.opts.name.eqlSlice("main", ip) and comp.config.link_libc) {
14951495 zcu.stage1_flags.have_c_main = true;
14961496 } else if (@as(CcTag, exported_cc) == @as(CcTag, winapi_cc) and target.os.tag == .windows) {
src/link/Dwarf.zig+1-1
......@@ -3400,7 +3400,7 @@ fn updateType(
34003400 try wip_nav.strp(name);
34013401 const cc: DW.CC = cc: {
34023402 if (zcu.getTarget().defaultCCallingConvention()) |cc| {
3403 if (@as(std.builtin.NewCallingConvention.Tag, cc) == func_type.cc) {
3403 if (@as(std.builtin.CallingConvention.Tag, cc) == func_type.cc) {
34043404 break :cc .normal;
34053405 }
34063406 }
src/target.zig+1-1
......@@ -544,7 +544,7 @@ pub fn compilerRtIntAbbrev(bits: u16) []const u8 {
544544 };
545545}
546546
547pub fn fnCallConvAllowsZigTypes(cc: std.builtin.NewCallingConvention) bool {
547pub fn fnCallConvAllowsZigTypes(cc: std.builtin.CallingConvention) bool {
548548 return switch (cc) {
549549 .auto, .@"async", .@"inline" => true,
550550 // For now we want to authorize PTX kernel to use zig objects, even if