aboutsummaryrefslogtreecommitdiff
path: root/src/InternPool.zig
diff options
context:
space:
mode:
authorMatthew Lugg <mlugg@mlugg.co.uk>2024-12-19 07:57:16 +0000
committerGitHub <noreply@github.com>2024-12-19 07:57:16 +0000
commite2e3633612be656177512873a9de6524082d04dd (patch)
treec71b592a592e21b108fccc0be3f99a45b6a13c6e /src/InternPool.zig
parentf857bf72e2239718bbbe4cba08d6961ad77fc69a (diff)
parent58b8b1ac2af642e886f3a561bf6dfd971bb80a96 (diff)
downloadzig-e2e3633612be656177512873a9de6524082d04dd.tar.gz
zig-e2e3633612be656177512873a9de6524082d04dd.zip
Merge pull request #22264 from mlugg/no-generic-callconv
compiler: disallow `callconv` etc from depending on function parameters Also, disallow `align`/`linksection`/`addrspace` annotations on container-level declarations with comptime-only types.
Diffstat (limited to 'src/InternPool.zig')
-rw-r--r--src/InternPool.zig59
1 files changed, 9 insertions, 50 deletions
diff --git a/src/InternPool.zig b/src/InternPool.zig
index 56fb7e1474..a2c98d73c4 100644
--- a/src/InternPool.zig
+++ b/src/InternPool.zig
@@ -1462,16 +1462,6 @@ pub const MapIndex = enum(u32) {
}
};
-pub const RuntimeIndex = enum(u32) {
- zero = 0,
- comptime_field_ptr = std.math.maxInt(u32),
- _,
-
- pub fn increment(ri: *RuntimeIndex) void {
- ri.* = @enumFromInt(@intFromEnum(ri.*) + 1);
- }
-};
-
pub const ComptimeAllocIndex = enum(u32) { _ };
pub const NamespaceIndex = enum(u32) {
@@ -1971,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);
@@ -5466,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,
};
};
@@ -6895,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,
};
}
@@ -8539,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,
},
});
@@ -8713,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,
@@ -8802,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});
@@ -8936,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,
@@ -8953,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,
});
@@ -8967,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;
@@ -9015,8 +8984,6 @@ pub fn getFuncInstance(
generic_owner,
func_index,
func_extra_index,
- arg.alignment,
- arg.section,
);
return gop.put();
}
@@ -9041,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
@@ -9096,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
@@ -9168,8 +9133,6 @@ pub fn getFuncInstanceIes(
generic_owner,
func_index,
func_extra_index,
- arg.alignment,
- arg.section,
);
func_gop.putFinal(func_index);
@@ -9187,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;
@@ -9201,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",
});
@@ -9788,7 +9749,6 @@ fn addExtraAssumeCapacity(extra: Local.Extra.Mutable, item: anytype) u32 {
OptionalNamespaceIndex,
MapIndex,
OptionalMapIndex,
- RuntimeIndex,
String,
NullTerminatedString,
OptionalNullTerminatedString,
@@ -9852,7 +9812,6 @@ fn extraDataTrail(extra: Local.Extra, comptime T: type, index: u32) struct { dat
OptionalNamespaceIndex,
MapIndex,
OptionalMapIndex,
- RuntimeIndex,
String,
NullTerminatedString,
OptionalNullTerminatedString,