aboutsummaryrefslogtreecommitdiff
path: root/src/Type.zig
diff options
context:
space:
mode:
authormlugg <mlugg@mlugg.co.uk>2024-09-28 02:10:25 +0100
committermlugg <mlugg@mlugg.co.uk>2024-10-19 19:08:59 +0100
commit51706af908e0c6acb822ef36760b7fe31faf62a6 (patch)
treed814bcfcfd83ebc5fd50da11f18a9a6427a54859 /src/Type.zig
parent8573836892ba1b7cd34d377b46258930161256c3 (diff)
downloadzig-51706af908e0c6acb822ef36760b7fe31faf62a6.tar.gz
zig-51706af908e0c6acb822ef36760b7fe31faf62a6.zip
compiler: introduce new `CallingConvention`
This commit begins implementing accepted proposal #21209 by making `std.builtin.CallingConvention` a tagged union. The stage1 dance here is a little convoluted. This commit introduces the new type as `NewCallingConvention`, keeping the old `CallingConvention` around. The compiler uses `std.builtin.NewCallingConvention` exclusively, but when fetching the type from `std` when running the compiler (e.g. with `getBuiltinType`), the name `CallingConvention` is used. This allows a prior build of Zig to be used to build this commit. The next commit will update `zig1.wasm`, and then the compiler and standard library can be updated to completely replace `CallingConvention` with `NewCallingConvention`. The second half of #21209 is to remove `@setAlignStack`, which will be implemented in another commit after updating `zig1.wasm`.
Diffstat (limited to 'src/Type.zig')
-rw-r--r--src/Type.zig16
1 files changed, 10 insertions, 6 deletions
diff --git a/src/Type.zig b/src/Type.zig
index c6feb9ddd4..1a3f530e13 100644
--- a/src/Type.zig
+++ b/src/Type.zig
@@ -390,10 +390,14 @@ pub fn print(ty: Type, writer: anytype, pt: Zcu.PerThread) @TypeOf(writer).Error
try writer.writeAll("...");
}
try writer.writeAll(") ");
- if (fn_info.cc != .Unspecified) {
- try writer.writeAll("callconv(.");
- try writer.writeAll(@tagName(fn_info.cc));
- try writer.writeAll(") ");
+ if (fn_info.cc != .auto) print_cc: {
+ if (zcu.getTarget().defaultCCallingConvention()) |ccc| {
+ if (fn_info.cc.eql(ccc)) {
+ try writer.writeAll("callconv(.c) ");
+ break :print_cc;
+ }
+ }
+ try writer.print("callconv({any}) ", .{fn_info.cc});
}
if (fn_info.return_type == .generic_poison_type) {
try writer.writeAll("anytype");
@@ -791,7 +795,7 @@ pub fn fnHasRuntimeBitsInner(
const fn_info = zcu.typeToFunc(ty).?;
if (fn_info.is_generic) return false;
if (fn_info.is_var_args) return true;
- if (fn_info.cc == .Inline) return false;
+ if (fn_info.cc == .@"inline") return false;
return !try Type.fromInterned(fn_info.return_type).comptimeOnlyInner(strat, zcu, tid);
}
@@ -2489,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.CallingConvention {
+pub fn fnCallingConvention(ty: Type, zcu: *const Zcu) std.builtin.NewCallingConvention {
return zcu.intern_pool.indexToKey(ty.toIntern()).func_type.cc;
}