aboutsummaryrefslogtreecommitdiff
path: root/src/InternPool.zig
diff options
context:
space:
mode:
authormlugg <mlugg@mlugg.co.uk>2024-12-18 04:01:38 +0000
committermlugg <mlugg@mlugg.co.uk>2024-12-18 23:06:35 +0000
commit7408679234ae84afaf0130fb21c49b031ef52e3c (patch)
treef23e7a95f68a764a6eabbb46ea53108db4c788c9 /src/InternPool.zig
parent242bb4469547c322081ad15a84019486aedbc74d (diff)
downloadzig-7408679234ae84afaf0130fb21c49b031ef52e3c.tar.gz
zig-7408679234ae84afaf0130fb21c49b031ef52e3c.zip
compiler: disallow `callconv` etc from depending on function parameters
Resolves: #22261
Diffstat (limited to 'src/InternPool.zig')
-rw-r--r--src/InternPool.zig47
1 files changed, 9 insertions, 38 deletions
diff --git a/src/InternPool.zig b/src/InternPool.zig
index 1d8fe45ade..a2c98d73c4 100644
--- a/src/InternPool.zig
+++ b/src/InternPool.zig
@@ -1961,9 +1961,6 @@ pub const Key = union(enum) {
is_var_args: bool,
is_generic: bool,
is_noinline: bool,
- cc_is_generic: bool,
- section_is_generic: bool,
- addrspace_is_generic: bool,
pub fn paramIsComptime(self: @This(), i: u5) bool {
assert(i < self.param_types.len);
@@ -5456,10 +5453,7 @@ pub const Tag = enum(u8) {
has_comptime_bits: bool,
has_noalias_bits: bool,
is_noinline: bool,
- cc_is_generic: bool,
- section_is_generic: bool,
- addrspace_is_generic: bool,
- _: u6 = 0,
+ _: u9 = 0,
};
};
@@ -6885,9 +6879,6 @@ fn extraFuncType(tid: Zcu.PerThread.Id, extra: Local.Extra, extra_index: u32) Ke
.cc = type_function.data.flags.cc.unpack(),
.is_var_args = type_function.data.flags.is_var_args,
.is_noinline = type_function.data.flags.is_noinline,
- .cc_is_generic = type_function.data.flags.cc_is_generic,
- .section_is_generic = type_function.data.flags.section_is_generic,
- .addrspace_is_generic = type_function.data.flags.addrspace_is_generic,
.is_generic = type_function.data.flags.is_generic,
};
}
@@ -8529,9 +8520,6 @@ pub fn getFuncType(
.has_noalias_bits = key.noalias_bits != 0,
.is_generic = key.is_generic,
.is_noinline = key.is_noinline,
- .cc_is_generic = key.cc == null,
- .section_is_generic = key.section_is_generic,
- .addrspace_is_generic = key.addrspace_is_generic,
},
});
@@ -8703,10 +8691,6 @@ pub const GetFuncDeclIesKey = struct {
bare_return_type: Index,
/// null means generic.
cc: ?std.builtin.CallingConvention,
- /// null means generic.
- alignment: ?Alignment,
- section_is_generic: bool,
- addrspace_is_generic: bool,
is_var_args: bool,
is_generic: bool,
is_noinline: bool,
@@ -8792,9 +8776,6 @@ pub fn getFuncDeclIes(
.has_noalias_bits = key.noalias_bits != 0,
.is_generic = key.is_generic,
.is_noinline = key.is_noinline,
- .cc_is_generic = key.cc == null,
- .section_is_generic = key.section_is_generic,
- .addrspace_is_generic = key.addrspace_is_generic,
},
});
if (key.comptime_bits != 0) extra.appendAssumeCapacity(.{key.comptime_bits});
@@ -8926,9 +8907,6 @@ pub const GetFuncInstanceKey = struct {
comptime_args: []const Index,
noalias_bits: u32,
bare_return_type: Index,
- cc: std.builtin.CallingConvention,
- alignment: Alignment,
- section: OptionalNullTerminatedString,
is_noinline: bool,
generic_owner: Index,
inferred_error_set: bool,
@@ -8943,11 +8921,14 @@ pub fn getFuncInstance(
if (arg.inferred_error_set)
return getFuncInstanceIes(ip, gpa, tid, arg);
+ const generic_owner = unwrapCoercedFunc(ip, arg.generic_owner);
+ const generic_owner_ty = ip.indexToKey(ip.funcDeclInfo(generic_owner).ty).func_type;
+
const func_ty = try ip.getFuncType(gpa, tid, .{
.param_types = arg.param_types,
.return_type = arg.bare_return_type,
.noalias_bits = arg.noalias_bits,
- .cc = arg.cc,
+ .cc = generic_owner_ty.cc,
.is_noinline = arg.is_noinline,
});
@@ -8957,8 +8938,6 @@ pub fn getFuncInstance(
try extra.ensureUnusedCapacity(@typeInfo(Tag.FuncInstance).@"struct".fields.len +
arg.comptime_args.len);
- const generic_owner = unwrapCoercedFunc(ip, arg.generic_owner);
-
assert(arg.comptime_args.len == ip.funcTypeParamsLen(ip.typeOf(generic_owner)));
const prev_extra_len = extra.mutate.len;
@@ -9005,8 +8984,6 @@ pub fn getFuncInstance(
generic_owner,
func_index,
func_extra_index,
- arg.alignment,
- arg.section,
);
return gop.put();
}
@@ -9031,6 +9008,7 @@ pub fn getFuncInstanceIes(
try items.ensureUnusedCapacity(4);
const generic_owner = unwrapCoercedFunc(ip, arg.generic_owner);
+ const generic_owner_ty = ip.indexToKey(ip.funcDeclInfo(arg.generic_owner).ty).func_type;
// The strategy here is to add the function decl unconditionally, then to
// ask if it already exists, and if so, revert the lengths of the mutated
@@ -9086,15 +9064,12 @@ pub fn getFuncInstanceIes(
.params_len = params_len,
.return_type = error_union_type,
.flags = .{
- .cc = .pack(arg.cc),
+ .cc = .pack(generic_owner_ty.cc),
.is_var_args = false,
.has_comptime_bits = false,
.has_noalias_bits = arg.noalias_bits != 0,
.is_generic = false,
.is_noinline = arg.is_noinline,
- .cc_is_generic = false,
- .section_is_generic = false,
- .addrspace_is_generic = false,
},
});
// no comptime_bits because has_comptime_bits is false
@@ -9158,8 +9133,6 @@ pub fn getFuncInstanceIes(
generic_owner,
func_index,
func_extra_index,
- arg.alignment,
- arg.section,
);
func_gop.putFinal(func_index);
@@ -9177,8 +9150,6 @@ fn finishFuncInstance(
generic_owner: Index,
func_index: Index,
func_extra_index: u32,
- alignment: Alignment,
- section: OptionalNullTerminatedString,
) Allocator.Error!void {
const fn_owner_nav = ip.getNav(ip.funcDeclInfo(generic_owner).owner_nav);
const fn_namespace = ip.getCau(fn_owner_nav.analysis_owner.unwrap().?).namespace;
@@ -9191,8 +9162,8 @@ fn finishFuncInstance(
.name = nav_name,
.fqn = try ip.namespacePtr(fn_namespace).internFullyQualifiedName(ip, gpa, tid, nav_name),
.val = func_index,
- .alignment = alignment,
- .@"linksection" = section,
+ .alignment = fn_owner_nav.status.resolved.alignment,
+ .@"linksection" = fn_owner_nav.status.resolved.@"linksection",
.@"addrspace" = fn_owner_nav.status.resolved.@"addrspace",
});