aboutsummaryrefslogtreecommitdiff
path: root/src/type.zig
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2021-08-01 22:04:18 -0700
committerAndrew Kelley <andrew@ziglang.org>2021-08-01 22:04:18 -0700
commitdae4c18aa7999a866b6b145ed3c88cb6c06852be (patch)
tree6aa41102b19c8e0af04bf1dd8af5158c4cc8b3a5 /src/type.zig
parentd5f173d28f2991e05dad399ed4d688297e0a5ca7 (diff)
downloadzig-dae4c18aa7999a866b6b145ed3c88cb6c06852be.tar.gz
zig-dae4c18aa7999a866b6b145ed3c88cb6c06852be.zip
stage2: ZIR encodes comptime parameters
`func_extended` ZIR instructions now have a one of the unused flags used as a `has_comptime_bits` boolean. When set, it means 1 or more parameters are `comptime`. In this case, there is a u32 per every 32 parameters (usually just 1 u32) with each bit indicating whether the corresponding parameter is `comptime`. Sema uses this information to correctly mark generic functions as generic. There is now a TODO compile error in place in case a generic function call happens. A future commit will do the generic function call implementation.
Diffstat (limited to 'src/type.zig')
-rw-r--r--src/type.zig15
1 files changed, 15 insertions, 0 deletions
diff --git a/src/type.zig b/src/type.zig
index 82c28ef398..a8c3d77bbb 100644
--- a/src/type.zig
+++ b/src/type.zig
@@ -764,6 +764,7 @@ pub const Type = extern union {
.param_types = param_types,
.cc = payload.cc,
.is_var_args = payload.is_var_args,
+ .is_generic = payload.is_generic,
});
},
.pointer => {
@@ -2407,6 +2408,19 @@ pub const Type = extern union {
};
}
+ /// Asserts the type is a function.
+ pub fn fnIsGeneric(self: Type) bool {
+ return switch (self.tag()) {
+ .fn_noreturn_no_args => false,
+ .fn_void_no_args => false,
+ .fn_naked_noreturn_no_args => false,
+ .fn_ccc_void_no_args => false,
+ .function => self.castTag(.function).?.data.is_generic,
+
+ else => unreachable,
+ };
+ }
+
pub fn isNumeric(self: Type) bool {
return switch (self.tag()) {
.f16,
@@ -3214,6 +3228,7 @@ pub const Type = extern union {
return_type: Type,
cc: std.builtin.CallingConvention,
is_var_args: bool,
+ is_generic: bool,
},
};