aboutsummaryrefslogtreecommitdiff
path: root/src/Module.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/Module.zig')
-rw-r--r--src/Module.zig64
1 files changed, 24 insertions, 40 deletions
diff --git a/src/Module.zig b/src/Module.zig
index ab394af0ad..995fdda7ea 100644
--- a/src/Module.zig
+++ b/src/Module.zig
@@ -84,7 +84,6 @@ string_literal_bytes: std.ArrayListUnmanaged(u8) = .{},
/// The set of all the generic function instantiations. This is used so that when a generic
/// function is called twice with the same comptime parameter arguments, both calls dispatch
/// to the same function.
-/// TODO: remove functions from this set when they are destroyed.
monomorphed_funcs: MonomorphedFuncsSet = .{},
/// The set of all comptime function calls that have been cached so that future calls
/// with the same parameters will get the same return value.
@@ -92,7 +91,6 @@ memoized_calls: MemoizedCallSet = .{},
/// Contains the values from `@setAlignStack`. A sparse table is used here
/// instead of a field of `Fn` because usage of `@setAlignStack` is rare, while
/// functions are many.
-/// TODO: remove functions from this set when they are destroyed.
align_stack_fns: std.AutoHashMapUnmanaged(*const Fn, SetAlignStack) = .{},
/// We optimize memory usage for a compilation with no compile errors by storing the
@@ -560,6 +558,8 @@ pub const Decl = struct {
gpa.destroy(extern_fn);
}
if (decl.getFunction()) |func| {
+ _ = mod.align_stack_fns.remove(func);
+ _ = mod.monomorphed_funcs.remove(func);
func.deinit(gpa);
gpa.destroy(func);
}
@@ -853,8 +853,6 @@ pub const EmitH = struct {
pub const ErrorSet = struct {
/// The Decl that corresponds to the error set itself.
owner_decl: Decl.Index,
- /// Offset from Decl node index, points to the error set AST node.
- node_offset: i32,
/// The string bytes are stored in the owner Decl arena.
/// These must be in sorted order. See sortNames.
names: NameMap,
@@ -866,7 +864,7 @@ pub const ErrorSet = struct {
return .{
.file_scope = owner_decl.getFileScope(),
.parent_decl_node = owner_decl.src_node,
- .lazy = LazySrcLoc.nodeOffset(self.node_offset),
+ .lazy = LazySrcLoc.nodeOffset(0),
};
}
@@ -893,12 +891,15 @@ pub const Struct = struct {
namespace: Namespace,
/// The Decl that corresponds to the struct itself.
owner_decl: Decl.Index,
- /// Offset from `owner_decl`, points to the struct AST node.
- node_offset: i32,
/// Index of the struct_decl ZIR instruction.
zir_index: Zir.Inst.Index,
layout: std.builtin.Type.ContainerLayout,
+ /// If the layout is not packed, this is the noreturn type.
+ /// If the layout is packed, this is the backing integer type of the packed struct.
+ /// Whether zig chooses this type or the user specifies it, it is stored here.
+ /// This will be set to the noreturn type until status is `have_layout`.
+ backing_int_ty: Type = Type.initTag(.noreturn),
status: enum {
none,
field_types_wip,
@@ -953,7 +954,7 @@ pub const Struct = struct {
return .{
.file_scope = owner_decl.getFileScope(),
.parent_decl_node = owner_decl.src_node,
- .lazy = LazySrcLoc.nodeOffset(s.node_offset),
+ .lazy = LazySrcLoc.nodeOffset(0),
};
}
@@ -968,7 +969,7 @@ pub const Struct = struct {
});
return s.srcLoc(mod);
};
- const node = owner_decl.relativeToNodeIndex(s.node_offset);
+ const node = owner_decl.relativeToNodeIndex(0);
const node_tags = tree.nodes.items(.tag);
switch (node_tags[node]) {
.container_decl,
@@ -1029,7 +1030,7 @@ pub const Struct = struct {
pub fn packedFieldBitOffset(s: Struct, target: Target, index: usize) u16 {
assert(s.layout == .Packed);
- assert(s.haveFieldTypes());
+ assert(s.haveLayout());
var bit_sum: u64 = 0;
for (s.fields.values()) |field, i| {
if (i == index) {
@@ -1037,19 +1038,7 @@ pub const Struct = struct {
}
bit_sum += field.ty.bitSize(target);
}
- return @intCast(u16, bit_sum);
- }
-
- pub fn packedIntegerBits(s: Struct, target: Target) u16 {
- return s.packedFieldBitOffset(target, s.fields.count());
- }
-
- pub fn packedIntegerType(s: Struct, target: Target, buf: *Type.Payload.Bits) Type {
- buf.* = .{
- .base = .{ .tag = .int_unsigned },
- .data = s.packedIntegerBits(target),
- };
- return Type.initPayload(&buf.base);
+ unreachable; // index out of bounds
}
};
@@ -1060,8 +1049,6 @@ pub const Struct = struct {
pub const EnumSimple = struct {
/// The Decl that corresponds to the enum itself.
owner_decl: Decl.Index,
- /// Offset from `owner_decl`, points to the enum decl AST node.
- node_offset: i32,
/// Set of field names in declaration order.
fields: NameMap,
@@ -1072,7 +1059,7 @@ pub const EnumSimple = struct {
return .{
.file_scope = owner_decl.getFileScope(),
.parent_decl_node = owner_decl.src_node,
- .lazy = LazySrcLoc.nodeOffset(self.node_offset),
+ .lazy = LazySrcLoc.nodeOffset(0),
};
}
};
@@ -1083,8 +1070,6 @@ pub const EnumSimple = struct {
pub const EnumNumbered = struct {
/// The Decl that corresponds to the enum itself.
owner_decl: Decl.Index,
- /// Offset from `owner_decl`, points to the enum decl AST node.
- node_offset: i32,
/// An integer type which is used for the numerical value of the enum.
/// Whether zig chooses this type or the user specifies it, it is stored here.
tag_ty: Type,
@@ -1103,7 +1088,7 @@ pub const EnumNumbered = struct {
return .{
.file_scope = owner_decl.getFileScope(),
.parent_decl_node = owner_decl.src_node,
- .lazy = LazySrcLoc.nodeOffset(self.node_offset),
+ .lazy = LazySrcLoc.nodeOffset(0),
};
}
};
@@ -1113,8 +1098,6 @@ pub const EnumNumbered = struct {
pub const EnumFull = struct {
/// The Decl that corresponds to the enum itself.
owner_decl: Decl.Index,
- /// Offset from `owner_decl`, points to the enum decl AST node.
- node_offset: i32,
/// An integer type which is used for the numerical value of the enum.
/// Whether zig chooses this type or the user specifies it, it is stored here.
tag_ty: Type,
@@ -1137,7 +1120,7 @@ pub const EnumFull = struct {
return .{
.file_scope = owner_decl.getFileScope(),
.parent_decl_node = owner_decl.src_node,
- .lazy = LazySrcLoc.nodeOffset(self.node_offset),
+ .lazy = LazySrcLoc.nodeOffset(0),
};
}
};
@@ -1155,8 +1138,6 @@ pub const Union = struct {
namespace: Namespace,
/// The Decl that corresponds to the union itself.
owner_decl: Decl.Index,
- /// Offset from `owner_decl`, points to the union decl AST node.
- node_offset: i32,
/// Index of the union_decl ZIR instruction.
zir_index: Zir.Inst.Index,
@@ -1203,7 +1184,7 @@ pub const Union = struct {
return .{
.file_scope = owner_decl.getFileScope(),
.parent_decl_node = owner_decl.src_node,
- .lazy = LazySrcLoc.nodeOffset(self.node_offset),
+ .lazy = LazySrcLoc.nodeOffset(0),
};
}
@@ -1218,7 +1199,7 @@ pub const Union = struct {
});
return u.srcLoc(mod);
};
- const node = owner_decl.relativeToNodeIndex(u.node_offset);
+ const node = owner_decl.relativeToNodeIndex(0);
const node_tags = tree.nodes.items(.tag);
var buf: [2]Ast.Node.Index = undefined;
switch (node_tags[node]) {
@@ -1410,8 +1391,6 @@ pub const Union = struct {
pub const Opaque = struct {
/// The Decl that corresponds to the opaque itself.
owner_decl: Decl.Index,
- /// Offset from `owner_decl`, points to the opaque decl AST node.
- node_offset: i32,
/// Represents the declarations inside this opaque.
namespace: Namespace,
@@ -1420,7 +1399,7 @@ pub const Opaque = struct {
return .{
.file_scope = owner_decl.getFileScope(),
.parent_decl_node = owner_decl.src_node,
- .lazy = LazySrcLoc.nodeOffset(self.node_offset),
+ .lazy = LazySrcLoc.nodeOffset(0),
};
}
@@ -4115,6 +4094,12 @@ pub fn ensureDeclAnalyzed(mod: *Module, decl_index: Decl.Index) SemaError!void {
// The exports this Decl performs will be re-discovered, so we remove them here
// prior to re-analysis.
mod.deleteDeclExports(decl_index);
+
+ // Similarly, `@setAlignStack` invocations will be re-discovered.
+ if (decl.getFunction()) |func| {
+ _ = mod.align_stack_fns.remove(func);
+ }
+
// Dependencies will be re-discovered, so we remove them here prior to re-analysis.
for (decl.dependencies.keys()) |dep_index| {
const dep = mod.declPtr(dep_index);
@@ -4337,7 +4322,6 @@ pub fn semaFile(mod: *Module, file: *File) SemaError!void {
struct_obj.* = .{
.owner_decl = undefined, // set below
.fields = .{},
- .node_offset = 0, // it's the struct for the root file
.zir_index = undefined, // set below
.layout = .Auto,
.status = .none,