aboutsummaryrefslogtreecommitdiff
path: root/src/codegen
diff options
context:
space:
mode:
Diffstat (limited to 'src/codegen')
-rw-r--r--src/codegen/c.zig2
-rw-r--r--src/codegen/llvm.zig291
-rw-r--r--src/codegen/spirv.zig19
3 files changed, 161 insertions, 151 deletions
diff --git a/src/codegen/c.zig b/src/codegen/c.zig
index 92e9edb433..2fd3d2b164 100644
--- a/src/codegen/c.zig
+++ b/src/codegen/c.zig
@@ -2581,7 +2581,7 @@ pub fn genTypeDecl(
_ = try renderTypePrefix(.flush, global_ctype_pool, zcu, writer, global_ctype, .suffix, .{});
try writer.writeByte(';');
const owner_decl = zcu.declPtr(owner_decl_index);
- const owner_mod = zcu.namespacePtr(owner_decl.src_namespace).file_scope.mod;
+ const owner_mod = zcu.namespacePtr(owner_decl.src_namespace).fileScope(zcu).mod;
if (!owner_mod.strip) {
try writer.writeAll(" /* ");
try owner_decl.renderFullyQualifiedName(zcu, writer);
diff --git a/src/codegen/llvm.zig b/src/codegen/llvm.zig
index 02933929c8..6efef20f22 100644
--- a/src/codegen/llvm.zig
+++ b/src/codegen/llvm.zig
@@ -1362,7 +1362,8 @@ pub const Object = struct {
const decl_index = func.owner_decl;
const decl = zcu.declPtr(decl_index);
const namespace = zcu.namespacePtr(decl.src_namespace);
- const owner_mod = namespace.file_scope.mod;
+ const file_scope = namespace.fileScope(zcu);
+ const owner_mod = file_scope.mod;
const fn_info = zcu.typeToFunc(decl.typeOf(zcu)).?;
const target = owner_mod.resolved_target.result;
const ip = &zcu.intern_pool;
@@ -1633,7 +1634,7 @@ pub const Object = struct {
function_index.setAttributes(try attributes.finish(&o.builder), &o.builder);
const file, const subprogram = if (!wip.strip) debug_info: {
- const file = try o.getDebugFile(namespace.file_scope);
+ const file = try o.getDebugFile(file_scope);
const line_number = decl.navSrcLine(zcu) + 1;
const is_internal_linkage = decl.val.getExternFunc(zcu) == null;
@@ -1720,23 +1721,23 @@ pub const Object = struct {
pub fn updateExports(
self: *Object,
- mod: *Module,
+ zcu: *Zcu,
exported: Module.Exported,
export_indices: []const u32,
) link.File.UpdateExportsError!void {
const decl_index = switch (exported) {
.decl_index => |i| i,
- .value => |val| return updateExportedValue(self, mod, val, export_indices),
+ .value => |val| return updateExportedValue(self, zcu, val, export_indices),
};
- const ip = &mod.intern_pool;
+ const ip = &zcu.intern_pool;
const global_index = self.decl_map.get(decl_index).?;
- const decl = mod.declPtr(decl_index);
- const comp = mod.comp;
+ const decl = zcu.declPtr(decl_index);
+ const comp = zcu.comp;
if (export_indices.len != 0) {
- return updateExportedGlobal(self, mod, global_index, export_indices);
+ return updateExportedGlobal(self, zcu, global_index, export_indices);
} else {
- const fqn = try self.builder.strtabString((try decl.fullyQualifiedName(mod)).toSlice(ip));
+ const fqn = try self.builder.strtabString((try decl.fullyQualifiedName(zcu)).toSlice(ip));
try global_index.rename(fqn, &self.builder);
global_index.setLinkage(.internal, &self.builder);
if (comp.config.dll_export_fns)
@@ -1908,12 +1909,12 @@ pub const Object = struct {
const gpa = o.gpa;
const target = o.target;
- const mod = o.module;
- const ip = &mod.intern_pool;
+ const zcu = o.module;
+ const ip = &zcu.intern_pool;
if (o.debug_type_map.get(ty)) |debug_type| return debug_type;
- switch (ty.zigTypeTag(mod)) {
+ switch (ty.zigTypeTag(zcu)) {
.Void,
.NoReturn,
=> {
@@ -1925,12 +1926,12 @@ pub const Object = struct {
return debug_void_type;
},
.Int => {
- const info = ty.intInfo(mod);
+ const info = ty.intInfo(zcu);
assert(info.bits != 0);
const name = try o.allocTypeName(ty);
defer gpa.free(name);
const builder_name = try o.builder.metadataString(name);
- const debug_bits = ty.abiSize(mod) * 8; // lldb cannot handle non-byte sized types
+ const debug_bits = ty.abiSize(zcu) * 8; // lldb cannot handle non-byte sized types
const debug_int_type = switch (info.signedness) {
.signed => try o.builder.debugSignedType(builder_name, debug_bits),
.unsigned => try o.builder.debugUnsignedType(builder_name, debug_bits),
@@ -1939,10 +1940,10 @@ pub const Object = struct {
return debug_int_type;
},
.Enum => {
- const owner_decl_index = ty.getOwnerDecl(mod);
+ const owner_decl_index = ty.getOwnerDecl(zcu);
const owner_decl = o.module.declPtr(owner_decl_index);
- if (!ty.hasRuntimeBitsIgnoreComptime(mod)) {
+ if (!ty.hasRuntimeBitsIgnoreComptime(zcu)) {
const debug_enum_type = try o.makeEmptyNamespaceDebugType(owner_decl_index);
try o.debug_type_map.put(gpa, ty, debug_enum_type);
return debug_enum_type;
@@ -1954,13 +1955,13 @@ pub const Object = struct {
defer gpa.free(enumerators);
const int_ty = Type.fromInterned(enum_type.tag_ty);
- const int_info = ty.intInfo(mod);
+ const int_info = ty.intInfo(zcu);
assert(int_info.bits != 0);
for (enum_type.names.get(ip), 0..) |field_name_ip, i| {
var bigint_space: Value.BigIntSpace = undefined;
const bigint = if (enum_type.values.len != 0)
- Value.fromInterned(enum_type.values.get(ip)[i]).toBigInt(&bigint_space, mod)
+ Value.fromInterned(enum_type.values.get(ip)[i]).toBigInt(&bigint_space, zcu)
else
std.math.big.int.Mutable.init(&bigint_space.limbs, i).toConst();
@@ -1972,7 +1973,8 @@ pub const Object = struct {
);
}
- const file = try o.getDebugFile(mod.namespacePtr(owner_decl.src_namespace).file_scope);
+ const file_scope = zcu.namespacePtr(owner_decl.src_namespace).fileScope(zcu);
+ const file = try o.getDebugFile(file_scope);
const scope = try o.namespaceToDebugScope(owner_decl.src_namespace);
const name = try o.allocTypeName(ty);
@@ -1982,10 +1984,10 @@ pub const Object = struct {
try o.builder.metadataString(name),
file,
scope,
- owner_decl.typeSrcLine(mod) + 1, // Line
+ owner_decl.typeSrcLine(zcu) + 1, // Line
try o.lowerDebugType(int_ty),
- ty.abiSize(mod) * 8,
- (ty.abiAlignment(mod).toByteUnits() orelse 0) * 8,
+ ty.abiSize(zcu) * 8,
+ (ty.abiAlignment(zcu).toByteUnits() orelse 0) * 8,
try o.builder.debugTuple(enumerators),
);
@@ -2014,7 +2016,7 @@ pub const Object = struct {
},
.Pointer => {
// Normalize everything that the debug info does not represent.
- const ptr_info = ty.ptrInfo(mod);
+ const ptr_info = ty.ptrInfo(zcu);
if (ptr_info.sentinel != .none or
ptr_info.flags.address_space != .generic or
@@ -2025,10 +2027,10 @@ pub const Object = struct {
ptr_info.flags.is_const or
ptr_info.flags.is_volatile or
ptr_info.flags.size == .Many or ptr_info.flags.size == .C or
- !Type.fromInterned(ptr_info.child).hasRuntimeBitsIgnoreComptime(mod))
+ !Type.fromInterned(ptr_info.child).hasRuntimeBitsIgnoreComptime(zcu))
{
- const bland_ptr_ty = try mod.ptrType(.{
- .child = if (!Type.fromInterned(ptr_info.child).hasRuntimeBitsIgnoreComptime(mod))
+ const bland_ptr_ty = try zcu.ptrType(.{
+ .child = if (!Type.fromInterned(ptr_info.child).hasRuntimeBitsIgnoreComptime(zcu))
.anyopaque_type
else
ptr_info.child,
@@ -2050,18 +2052,18 @@ pub const Object = struct {
// Set as forward reference while the type is lowered in case it references itself
try o.debug_type_map.put(gpa, ty, debug_fwd_ref);
- if (ty.isSlice(mod)) {
- const ptr_ty = ty.slicePtrFieldType(mod);
+ if (ty.isSlice(zcu)) {
+ const ptr_ty = ty.slicePtrFieldType(zcu);
const len_ty = Type.usize;
const name = try o.allocTypeName(ty);
defer gpa.free(name);
const line = 0;
- const ptr_size = ptr_ty.abiSize(mod);
- const ptr_align = ptr_ty.abiAlignment(mod);
- const len_size = len_ty.abiSize(mod);
- const len_align = len_ty.abiAlignment(mod);
+ const ptr_size = ptr_ty.abiSize(zcu);
+ const ptr_align = ptr_ty.abiAlignment(zcu);
+ const len_size = len_ty.abiSize(zcu);
+ const len_align = len_ty.abiAlignment(zcu);
const len_offset = len_align.forward(ptr_size);
@@ -2093,8 +2095,8 @@ pub const Object = struct {
o.debug_compile_unit, // Scope
line,
.none, // Underlying type
- ty.abiSize(mod) * 8,
- (ty.abiAlignment(mod).toByteUnits() orelse 0) * 8,
+ ty.abiSize(zcu) * 8,
+ (ty.abiAlignment(zcu).toByteUnits() orelse 0) * 8,
try o.builder.debugTuple(&.{
debug_ptr_type,
debug_len_type,
@@ -2122,7 +2124,7 @@ pub const Object = struct {
0, // Line
debug_elem_ty,
target.ptrBitWidth(),
- (ty.ptrAlignment(mod).toByteUnits() orelse 0) * 8,
+ (ty.ptrAlignment(zcu).toByteUnits() orelse 0) * 8,
0, // Offset
);
@@ -2146,13 +2148,14 @@ pub const Object = struct {
const name = try o.allocTypeName(ty);
defer gpa.free(name);
- const owner_decl_index = ty.getOwnerDecl(mod);
+ const owner_decl_index = ty.getOwnerDecl(zcu);
const owner_decl = o.module.declPtr(owner_decl_index);
+ const file_scope = zcu.namespacePtr(owner_decl.src_namespace).fileScope(zcu);
const debug_opaque_type = try o.builder.debugStructType(
try o.builder.metadataString(name),
- try o.getDebugFile(mod.namespacePtr(owner_decl.src_namespace).file_scope),
+ try o.getDebugFile(file_scope),
try o.namespaceToDebugScope(owner_decl.src_namespace),
- owner_decl.typeSrcLine(mod) + 1, // Line
+ owner_decl.typeSrcLine(zcu) + 1, // Line
.none, // Underlying type
0, // Size
0, // Align
@@ -2167,13 +2170,13 @@ pub const Object = struct {
.none, // File
.none, // Scope
0, // Line
- try o.lowerDebugType(ty.childType(mod)),
- ty.abiSize(mod) * 8,
- (ty.abiAlignment(mod).toByteUnits() orelse 0) * 8,
+ try o.lowerDebugType(ty.childType(zcu)),
+ ty.abiSize(zcu) * 8,
+ (ty.abiAlignment(zcu).toByteUnits() orelse 0) * 8,
try o.builder.debugTuple(&.{
try o.builder.debugSubrange(
try o.builder.debugConstant(try o.builder.intConst(.i64, 0)),
- try o.builder.debugConstant(try o.builder.intConst(.i64, ty.arrayLen(mod))),
+ try o.builder.debugConstant(try o.builder.intConst(.i64, ty.arrayLen(zcu))),
),
}),
);
@@ -2181,14 +2184,14 @@ pub const Object = struct {
return debug_array_type;
},
.Vector => {
- const elem_ty = ty.elemType2(mod);
+ const elem_ty = ty.elemType2(zcu);
// Vector elements cannot be padded since that would make
// @bitSizOf(elem) * len > @bitSizOf(vec).
// Neither gdb nor lldb seem to be able to display non-byte sized
// vectors properly.
- const debug_elem_type = switch (elem_ty.zigTypeTag(mod)) {
+ const debug_elem_type = switch (elem_ty.zigTypeTag(zcu)) {
.Int => blk: {
- const info = elem_ty.intInfo(mod);
+ const info = elem_ty.intInfo(zcu);
assert(info.bits != 0);
const name = try o.allocTypeName(ty);
defer gpa.free(name);
@@ -2202,7 +2205,7 @@ pub const Object = struct {
try o.builder.metadataString("bool"),
1,
),
- else => try o.lowerDebugType(ty.childType(mod)),
+ else => try o.lowerDebugType(ty.childType(zcu)),
};
const debug_vector_type = try o.builder.debugVectorType(
@@ -2211,12 +2214,12 @@ pub const Object = struct {
.none, // Scope
0, // Line
debug_elem_type,
- ty.abiSize(mod) * 8,
- (ty.abiAlignment(mod).toByteUnits() orelse 0) * 8,
+ ty.abiSize(zcu) * 8,
+ (ty.abiAlignment(zcu).toByteUnits() orelse 0) * 8,
try o.builder.debugTuple(&.{
try o.builder.debugSubrange(
try o.builder.debugConstant(try o.builder.intConst(.i64, 0)),
- try o.builder.debugConstant(try o.builder.intConst(.i64, ty.vectorLen(mod))),
+ try o.builder.debugConstant(try o.builder.intConst(.i64, ty.vectorLen(zcu))),
),
}),
);
@@ -2227,8 +2230,8 @@ pub const Object = struct {
.Optional => {
const name = try o.allocTypeName(ty);
defer gpa.free(name);
- const child_ty = ty.optionalChild(mod);
- if (!child_ty.hasRuntimeBitsIgnoreComptime(mod)) {
+ const child_ty = ty.optionalChild(zcu);
+ if (!child_ty.hasRuntimeBitsIgnoreComptime(zcu)) {
const debug_bool_type = try o.builder.debugBoolType(
try o.builder.metadataString(name),
8,
@@ -2242,7 +2245,7 @@ pub const Object = struct {
// Set as forward reference while the type is lowered in case it references itself
try o.debug_type_map.put(gpa, ty, debug_fwd_ref);
- if (ty.optionalReprIsPayload(mod)) {
+ if (ty.optionalReprIsPayload(zcu)) {
const debug_optional_type = try o.lowerDebugType(child_ty);
o.builder.debugForwardReferenceSetType(debug_fwd_ref, debug_optional_type);
@@ -2255,10 +2258,10 @@ pub const Object = struct {
}
const non_null_ty = Type.u8;
- const payload_size = child_ty.abiSize(mod);
- const payload_align = child_ty.abiAlignment(mod);
- const non_null_size = non_null_ty.abiSize(mod);
- const non_null_align = non_null_ty.abiAlignment(mod);
+ const payload_size = child_ty.abiSize(zcu);
+ const payload_align = child_ty.abiAlignment(zcu);
+ const non_null_size = non_null_ty.abiSize(zcu);
+ const non_null_align = non_null_ty.abiAlignment(zcu);
const non_null_offset = non_null_align.forward(payload_size);
const debug_data_type = try o.builder.debugMemberType(
@@ -2289,8 +2292,8 @@ pub const Object = struct {
o.debug_compile_unit, // Scope
0, // Line
.none, // Underlying type
- ty.abiSize(mod) * 8,
- (ty.abiAlignment(mod).toByteUnits() orelse 0) * 8,
+ ty.abiSize(zcu) * 8,
+ (ty.abiAlignment(zcu).toByteUnits() orelse 0) * 8,
try o.builder.debugTuple(&.{
debug_data_type,
debug_some_type,
@@ -2306,8 +2309,8 @@ pub const Object = struct {
return debug_optional_type;
},
.ErrorUnion => {
- const payload_ty = ty.errorUnionPayload(mod);
- if (!payload_ty.hasRuntimeBitsIgnoreComptime(mod)) {
+ const payload_ty = ty.errorUnionPayload(zcu);
+ if (!payload_ty.hasRuntimeBitsIgnoreComptime(zcu)) {
// TODO: Maybe remove?
const debug_error_union_type = try o.lowerDebugType(Type.anyerror);
try o.debug_type_map.put(gpa, ty, debug_error_union_type);
@@ -2317,10 +2320,10 @@ pub const Object = struct {
const name = try o.allocTypeName(ty);
defer gpa.free(name);
- const error_size = Type.anyerror.abiSize(mod);
- const error_align = Type.anyerror.abiAlignment(mod);
- const payload_size = payload_ty.abiSize(mod);
- const payload_align = payload_ty.abiAlignment(mod);
+ const error_size = Type.anyerror.abiSize(zcu);
+ const error_align = Type.anyerror.abiAlignment(zcu);
+ const payload_size = payload_ty.abiSize(zcu);
+ const payload_align = payload_ty.abiAlignment(zcu);
var error_index: u32 = undefined;
var payload_index: u32 = undefined;
@@ -2368,8 +2371,8 @@ pub const Object = struct {
o.debug_compile_unit, // Sope
0, // Line
.none, // Underlying type
- ty.abiSize(mod) * 8,
- (ty.abiAlignment(mod).toByteUnits() orelse 0) * 8,
+ ty.abiSize(zcu) * 8,
+ (ty.abiAlignment(zcu).toByteUnits() orelse 0) * 8,
try o.builder.debugTuple(&fields),
);
@@ -2390,14 +2393,14 @@ pub const Object = struct {
const name = try o.allocTypeName(ty);
defer gpa.free(name);
- if (mod.typeToPackedStruct(ty)) |struct_type| {
+ if (zcu.typeToPackedStruct(ty)) |struct_type| {
const backing_int_ty = struct_type.backingIntType(ip).*;
if (backing_int_ty != .none) {
- const info = Type.fromInterned(backing_int_ty).intInfo(mod);
+ const info = Type.fromInterned(backing_int_ty).intInfo(zcu);
const builder_name = try o.builder.metadataString(name);
const debug_int_type = switch (info.signedness) {
- .signed => try o.builder.debugSignedType(builder_name, ty.abiSize(mod) * 8),
- .unsigned => try o.builder.debugUnsignedType(builder_name, ty.abiSize(mod) * 8),
+ .signed => try o.builder.debugSignedType(builder_name, ty.abiSize(zcu) * 8),
+ .unsigned => try o.builder.debugUnsignedType(builder_name, ty.abiSize(zcu) * 8),
};
try o.debug_type_map.put(gpa, ty, debug_int_type);
return debug_int_type;
@@ -2417,10 +2420,10 @@ pub const Object = struct {
const debug_fwd_ref = try o.builder.debugForwardReference();
for (tuple.types.get(ip), tuple.values.get(ip), 0..) |field_ty, field_val, i| {
- if (field_val != .none or !Type.fromInterned(field_ty).hasRuntimeBits(mod)) continue;
+ if (field_val != .none or !Type.fromInterned(field_ty).hasRuntimeBits(zcu)) continue;
- const field_size = Type.fromInterned(field_ty).abiSize(mod);
- const field_align = Type.fromInterned(field_ty).abiAlignment(mod);
+ const field_size = Type.fromInterned(field_ty).abiSize(zcu);
+ const field_align = Type.fromInterned(field_ty).abiAlignment(zcu);
const field_offset = field_align.forward(offset);
offset = field_offset + field_size;
@@ -2448,8 +2451,8 @@ pub const Object = struct {
o.debug_compile_unit, // Scope
0, // Line
.none, // Underlying type
- ty.abiSize(mod) * 8,
- (ty.abiAlignment(mod).toByteUnits() orelse 0) * 8,
+ ty.abiSize(zcu) * 8,
+ (ty.abiAlignment(zcu).toByteUnits() orelse 0) * 8,
try o.builder.debugTuple(fields.items),
);
@@ -2467,7 +2470,7 @@ pub const Object = struct {
// into. Therefore we can satisfy this by making an empty namespace,
// rather than changing the frontend to unnecessarily resolve the
// struct field types.
- const owner_decl_index = ty.getOwnerDecl(mod);
+ const owner_decl_index = ty.getOwnerDecl(zcu);
const debug_struct_type = try o.makeEmptyNamespaceDebugType(owner_decl_index);
try o.debug_type_map.put(gpa, ty, debug_struct_type);
return debug_struct_type;
@@ -2476,14 +2479,14 @@ pub const Object = struct {
else => {},
}
- if (!ty.hasRuntimeBitsIgnoreComptime(mod)) {
- const owner_decl_index = ty.getOwnerDecl(mod);
+ if (!ty.hasRuntimeBitsIgnoreComptime(zcu)) {
+ const owner_decl_index = ty.getOwnerDecl(zcu);
const debug_struct_type = try o.makeEmptyNamespaceDebugType(owner_decl_index);
try o.debug_type_map.put(gpa, ty, debug_struct_type);
return debug_struct_type;
}
- const struct_type = mod.typeToStruct(ty).?;
+ const struct_type = zcu.typeToStruct(ty).?;
var fields: std.ArrayListUnmanaged(Builder.Metadata) = .{};
defer fields.deinit(gpa);
@@ -2499,14 +2502,14 @@ pub const Object = struct {
var it = struct_type.iterateRuntimeOrder(ip);
while (it.next()) |field_index| {
const field_ty = Type.fromInterned(struct_type.field_types.get(ip)[field_index]);
- if (!field_ty.hasRuntimeBitsIgnoreComptime(mod)) continue;
- const field_size = field_ty.abiSize(mod);
- const field_align = mod.structFieldAlignment(
+ if (!field_ty.hasRuntimeBitsIgnoreComptime(zcu)) continue;
+ const field_size = field_ty.abiSize(zcu);
+ const field_align = zcu.structFieldAlignment(
struct_type.fieldAlign(ip, field_index),
field_ty,
struct_type.layout,
);
- const field_offset = ty.structFieldOffset(field_index, mod);
+ const field_offset = ty.structFieldOffset(field_index, zcu);
const field_name = struct_type.fieldName(ip, field_index).unwrap() orelse
try ip.getOrPutStringFmt(gpa, "{d}", .{field_index}, .no_embedded_nulls);
@@ -2529,8 +2532,8 @@ pub const Object = struct {
o.debug_compile_unit, // Scope
0, // Line
.none, // Underlying type
- ty.abiSize(mod) * 8,
- (ty.abiAlignment(mod).toByteUnits() orelse 0) * 8,
+ ty.abiSize(zcu) * 8,
+ (ty.abiAlignment(zcu).toByteUnits() orelse 0) * 8,
try o.builder.debugTuple(fields.items),
);
@@ -2543,14 +2546,14 @@ pub const Object = struct {
return debug_struct_type;
},
.Union => {
- const owner_decl_index = ty.getOwnerDecl(mod);
+ const owner_decl_index = ty.getOwnerDecl(zcu);
const name = try o.allocTypeName(ty);
defer gpa.free(name);
const union_type = ip.loadUnionType(ty.toIntern());
if (!union_type.haveFieldTypes(ip) or
- !ty.hasRuntimeBitsIgnoreComptime(mod) or
+ !ty.hasRuntimeBitsIgnoreComptime(zcu) or
!union_type.haveLayout(ip))
{
const debug_union_type = try o.makeEmptyNamespaceDebugType(owner_decl_index);
@@ -2558,7 +2561,7 @@ pub const Object = struct {
return debug_union_type;
}
- const layout = mod.getUnionLayout(union_type);
+ const layout = zcu.getUnionLayout(union_type);
const debug_fwd_ref = try o.builder.debugForwardReference();
@@ -2572,8 +2575,8 @@ pub const Object = struct {
o.debug_compile_unit, // Scope
0, // Line
.none, // Underlying type
- ty.abiSize(mod) * 8,
- (ty.abiAlignment(mod).toByteUnits() orelse 0) * 8,
+ ty.abiSize(zcu) * 8,
+ (ty.abiAlignment(zcu).toByteUnits() orelse 0) * 8,
try o.builder.debugTuple(
&.{try o.lowerDebugType(Type.fromInterned(union_type.enum_tag_ty))},
),
@@ -2600,12 +2603,12 @@ pub const Object = struct {
for (0..tag_type.names.len) |field_index| {
const field_ty = union_type.field_types.get(ip)[field_index];
- if (!Type.fromInterned(field_ty).hasRuntimeBitsIgnoreComptime(mod)) continue;
+ if (!Type.fromInterned(field_ty).hasRuntimeBitsIgnoreComptime(zcu)) continue;
- const field_size = Type.fromInterned(field_ty).abiSize(mod);
+ const field_size = Type.fromInterned(field_ty).abiSize(zcu);
const field_align: InternPool.Alignment = switch (union_type.flagsPtr(ip).layout) {
.@"packed" => .none,
- .auto, .@"extern" => mod.unionFieldNormalAlignment(union_type, @intCast(field_index)),
+ .auto, .@"extern" => zcu.unionFieldNormalAlignment(union_type, @intCast(field_index)),
};
const field_name = tag_type.names.get(ip)[field_index];
@@ -2634,8 +2637,8 @@ pub const Object = struct {
o.debug_compile_unit, // Scope
0, // Line
.none, // Underlying type
- ty.abiSize(mod) * 8,
- (ty.abiAlignment(mod).toByteUnits() orelse 0) * 8,
+ ty.abiSize(zcu) * 8,
+ (ty.abiAlignment(zcu).toByteUnits() orelse 0) * 8,
try o.builder.debugTuple(fields.items),
);
@@ -2693,8 +2696,8 @@ pub const Object = struct {
o.debug_compile_unit, // Scope
0, // Line
.none, // Underlying type
- ty.abiSize(mod) * 8,
- (ty.abiAlignment(mod).toByteUnits() orelse 0) * 8,
+ ty.abiSize(zcu) * 8,
+ (ty.abiAlignment(zcu).toByteUnits() orelse 0) * 8,
try o.builder.debugTuple(&full_fields),
);
@@ -2707,7 +2710,7 @@ pub const Object = struct {
return debug_tagged_union_type;
},
.Fn => {
- const fn_info = mod.typeToFunc(ty).?;
+ const fn_info = zcu.typeToFunc(ty).?;
var debug_param_types = std.ArrayList(Builder.Metadata).init(gpa);
defer debug_param_types.deinit();
@@ -2715,32 +2718,32 @@ pub const Object = struct {
try debug_param_types.ensureUnusedCapacity(3 + fn_info.param_types.len);
// Return type goes first.
- if (Type.fromInterned(fn_info.return_type).hasRuntimeBitsIgnoreComptime(mod)) {
- const sret = firstParamSRet(fn_info, mod, target);
+ if (Type.fromInterned(fn_info.return_type).hasRuntimeBitsIgnoreComptime(zcu)) {
+ const sret = firstParamSRet(fn_info, zcu, target);
const ret_ty = if (sret) Type.void else Type.fromInterned(fn_info.return_type);
debug_param_types.appendAssumeCapacity(try o.lowerDebugType(ret_ty));
if (sret) {
- const ptr_ty = try mod.singleMutPtrType(Type.fromInterned(fn_info.return_type));
+ const ptr_ty = try zcu.singleMutPtrType(Type.fromInterned(fn_info.return_type));
debug_param_types.appendAssumeCapacity(try o.lowerDebugType(ptr_ty));
}
} else {
debug_param_types.appendAssumeCapacity(try o.lowerDebugType(Type.void));
}
- if (Type.fromInterned(fn_info.return_type).isError(mod) and
+ if (Type.fromInterned(fn_info.return_type).isError(zcu) and
o.module.comp.config.any_error_tracing)
{
- const ptr_ty = try mod.singleMutPtrType(try o.getStackTraceType());
+ const ptr_ty = try zcu.singleMutPtrType(try o.getStackTraceType());
debug_param_types.appendAssumeCapacity(try o.lowerDebugType(ptr_ty));
}
for (0..fn_info.param_types.len) |i| {
const param_ty = Type.fromInterned(fn_info.param_types.get(ip)[i]);
- if (!param_ty.hasRuntimeBitsIgnoreComptime(mod)) continue;
+ if (!param_ty.hasRuntimeBitsIgnoreComptime(zcu)) continue;
- if (isByRef(param_ty, mod)) {
- const ptr_ty = try mod.singleMutPtrType(param_ty);
+ if (isByRef(param_ty, zcu)) {
+ const ptr_ty = try zcu.singleMutPtrType(param_ty);
debug_param_types.appendAssumeCapacity(try o.lowerDebugType(ptr_ty));
} else {
debug_param_types.appendAssumeCapacity(try o.lowerDebugType(param_ty));
@@ -2767,9 +2770,10 @@ pub const Object = struct {
}
fn namespaceToDebugScope(o: *Object, namespace_index: InternPool.NamespaceIndex) !Builder.Metadata {
- const mod = o.module;
- const namespace = mod.namespacePtr(namespace_index);
- if (namespace.parent == .none) return try o.getDebugFile(namespace.file_scope);
+ const zcu = o.module;
+ const namespace = zcu.namespacePtr(namespace_index);
+ const file_scope = namespace.fileScope(zcu);
+ if (namespace.parent == .none) return try o.getDebugFile(file_scope);
const gop = try o.debug_unresolved_namespace_scopes.getOrPut(o.gpa, namespace_index);
@@ -2779,13 +2783,14 @@ pub const Object = struct {
}
fn makeEmptyNamespaceDebugType(o: *Object, decl_index: InternPool.DeclIndex) !Builder.Metadata {
- const mod = o.module;
- const decl = mod.declPtr(decl_index);
+ const zcu = o.module;
+ const decl = zcu.declPtr(decl_index);
+ const file_scope = zcu.namespacePtr(decl.src_namespace).fileScope(zcu);
return o.builder.debugStructType(
- try o.builder.metadataString(decl.name.toSlice(&mod.intern_pool)), // TODO use fully qualified name
- try o.getDebugFile(mod.namespacePtr(decl.src_namespace).file_scope),
+ try o.builder.metadataString(decl.name.toSlice(&zcu.intern_pool)), // TODO use fully qualified name
+ try o.getDebugFile(file_scope),
try o.namespaceToDebugScope(decl.src_namespace),
- decl.typeSrcLine(mod) + 1,
+ decl.typeSrcLine(zcu) + 1,
.none,
0,
0,
@@ -2794,21 +2799,22 @@ pub const Object = struct {
}
fn getStackTraceType(o: *Object) Allocator.Error!Type {
- const mod = o.module;
+ const zcu = o.module;
- const std_mod = mod.std_mod;
- const std_file = (mod.importPkg(std_mod) catch unreachable).file;
+ const std_mod = zcu.std_mod;
+ const std_file_imported = zcu.importPkg(std_mod) catch unreachable;
- const builtin_str = try mod.intern_pool.getOrPutString(mod.gpa, "builtin", .no_embedded_nulls);
- const std_namespace = mod.namespacePtr(mod.declPtr(std_file.root_decl.unwrap().?).src_namespace);
- const builtin_decl = std_namespace.decls.getKeyAdapted(builtin_str, Module.DeclAdapter{ .zcu = mod }).?;
+ const builtin_str = try zcu.intern_pool.getOrPutString(zcu.gpa, "builtin", .no_embedded_nulls);
+ const std_file_root_decl = zcu.fileRootDecl(std_file_imported.file_index);
+ const std_namespace = zcu.namespacePtr(zcu.declPtr(std_file_root_decl.unwrap().?).src_namespace);
+ const builtin_decl = std_namespace.decls.getKeyAdapted(builtin_str, Module.DeclAdapter{ .zcu = zcu }).?;
- const stack_trace_str = try mod.intern_pool.getOrPutString(mod.gpa, "StackTrace", .no_embedded_nulls);
+ const stack_trace_str = try zcu.intern_pool.getOrPutString(zcu.gpa, "StackTrace", .no_embedded_nulls);
// buffer is only used for int_type, `builtin` is a struct.
- const builtin_ty = mod.declPtr(builtin_decl).val.toType();
- const builtin_namespace = mod.namespacePtrUnwrap(builtin_ty.getNamespaceIndex(mod)).?;
- const stack_trace_decl_index = builtin_namespace.decls.getKeyAdapted(stack_trace_str, Module.DeclAdapter{ .zcu = mod }).?;
- const stack_trace_decl = mod.declPtr(stack_trace_decl_index);
+ const builtin_ty = zcu.declPtr(builtin_decl).val.toType();
+ const builtin_namespace = zcu.namespacePtrUnwrap(builtin_ty.getNamespaceIndex(zcu)).?;
+ const stack_trace_decl_index = builtin_namespace.decls.getKeyAdapted(stack_trace_str, Module.DeclAdapter{ .zcu = zcu }).?;
+ const stack_trace_decl = zcu.declPtr(stack_trace_decl_index);
// Sema should have ensured that StackTrace was analyzed.
assert(stack_trace_decl.has_tv);
@@ -2834,7 +2840,7 @@ pub const Object = struct {
const gpa = o.gpa;
const decl = zcu.declPtr(decl_index);
const namespace = zcu.namespacePtr(decl.src_namespace);
- const owner_mod = namespace.file_scope.mod;
+ const owner_mod = namespace.fileScope(zcu).mod;
const zig_fn_type = decl.typeOf(zcu);
const gop = try o.decl_map.getOrPut(gpa, decl_index);
if (gop.found_existing) return gop.value_ptr.ptr(&o.builder).kind.function;
@@ -3059,17 +3065,17 @@ pub const Object = struct {
if (gop.found_existing) return gop.value_ptr.ptr(&o.builder).kind.variable;
errdefer assert(o.decl_map.remove(decl_index));
- const mod = o.module;
- const decl = mod.declPtr(decl_index);
- const is_extern = decl.isExtern(mod);
+ const zcu = o.module;
+ const decl = zcu.declPtr(decl_index);
+ const is_extern = decl.isExtern(zcu);
const variable_index = try o.builder.addVariable(
try o.builder.strtabString((if (is_extern)
decl.name
else
- try decl.fullyQualifiedName(mod)).toSlice(&mod.intern_pool)),
- try o.lowerType(decl.typeOf(mod)),
- toLlvmGlobalAddressSpace(decl.@"addrspace", mod.getTarget()),
+ try decl.fullyQualifiedName(zcu)).toSlice(&zcu.intern_pool)),
+ try o.lowerType(decl.typeOf(zcu)),
+ toLlvmGlobalAddressSpace(decl.@"addrspace", zcu.getTarget()),
);
gop.value_ptr.* = variable_index.ptrConst(&o.builder).global;
@@ -3077,9 +3083,9 @@ pub const Object = struct {
if (is_extern) {
variable_index.setLinkage(.external, &o.builder);
variable_index.setUnnamedAddr(.default, &o.builder);
- if (decl.val.getVariable(mod)) |decl_var| {
- const decl_namespace = mod.namespacePtr(decl.src_namespace);
- const single_threaded = decl_namespace.file_scope.mod.single_threaded;
+ if (decl.val.getVariable(zcu)) |decl_var| {
+ const decl_namespace = zcu.namespacePtr(decl.src_namespace);
+ const single_threaded = decl_namespace.fileScope(zcu).mod.single_threaded;
variable_index.setThreadLocal(
if (decl_var.is_threadlocal and !single_threaded) .generaldynamic else .default,
&o.builder,
@@ -4638,7 +4644,8 @@ pub const DeclGen = struct {
const o = dg.object;
const zcu = o.module;
const namespace = zcu.namespacePtr(dg.decl.src_namespace);
- return namespace.file_scope.mod;
+ const file_scope = namespace.fileScope(zcu);
+ return file_scope.mod;
}
fn todo(dg: *DeclGen, comptime format: []const u8, args: anytype) Error {
@@ -4682,7 +4689,7 @@ pub const DeclGen = struct {
if (decl.val.getVariable(zcu)) |decl_var| {
const decl_namespace = zcu.namespacePtr(decl.src_namespace);
- const single_threaded = decl_namespace.file_scope.mod.single_threaded;
+ const single_threaded = decl_namespace.fileScope(zcu).mod.single_threaded;
variable_index.setThreadLocal(
if (decl_var.is_threadlocal and !single_threaded) .generaldynamic else .default,
&o.builder,
@@ -4692,10 +4699,11 @@ pub const DeclGen = struct {
const line_number = decl.navSrcLine(zcu) + 1;
const namespace = zcu.namespacePtr(decl.src_namespace);
- const owner_mod = namespace.file_scope.mod;
+ const file_scope = namespace.fileScope(zcu);
+ const owner_mod = file_scope.mod;
if (!owner_mod.strip) {
- const debug_file = try o.getDebugFile(namespace.file_scope);
+ const debug_file = try o.getDebugFile(file_scope);
const debug_global_var = try o.builder.debugGlobalVar(
try o.builder.metadataString(decl.name.toSlice(ip)), // Name
@@ -5143,9 +5151,10 @@ pub const FuncGen = struct {
const decl_index = func.owner_decl;
const decl = zcu.declPtr(decl_index);
const namespace = zcu.namespacePtr(decl.src_namespace);
- const owner_mod = namespace.file_scope.mod;
+ const file_scope = namespace.fileScope(zcu);
+ const owner_mod = file_scope.mod;
- self.file = try o.getDebugFile(namespace.file_scope);
+ self.file = try o.getDebugFile(file_scope);
const line_number = decl.navSrcLine(zcu) + 1;
self.inlined = self.wip.debug_location;
diff --git a/src/codegen/spirv.zig b/src/codegen/spirv.zig
index c56a5a799e..2fbe9097d6 100644
--- a/src/codegen/spirv.zig
+++ b/src/codegen/spirv.zig
@@ -188,19 +188,20 @@ pub const Object = struct {
fn genDecl(
self: *Object,
- mod: *Module,
+ zcu: *Zcu,
decl_index: InternPool.DeclIndex,
air: Air,
liveness: Liveness,
) !void {
- const decl = mod.declPtr(decl_index);
- const namespace = mod.namespacePtr(decl.src_namespace);
- const structured_cfg = namespace.file_scope.mod.structured_cfg;
+ const gpa = self.gpa;
+ const decl = zcu.declPtr(decl_index);
+ const namespace = zcu.namespacePtr(decl.src_namespace);
+ const structured_cfg = namespace.fileScope(zcu).mod.structured_cfg;
var decl_gen = DeclGen{
- .gpa = self.gpa,
+ .gpa = gpa,
.object = self,
- .module = mod,
+ .module = zcu,
.spv = &self.spv,
.decl_index = decl_index,
.air = air,
@@ -212,19 +213,19 @@ pub const Object = struct {
false => .{ .unstructured = .{} },
},
.current_block_label = undefined,
- .base_line = decl.navSrcLine(mod),
+ .base_line = decl.navSrcLine(zcu),
};
defer decl_gen.deinit();
decl_gen.genDecl() catch |err| switch (err) {
error.CodegenFail => {
- try mod.failed_analysis.put(mod.gpa, InternPool.AnalUnit.wrap(.{ .decl = decl_index }), decl_gen.error_msg.?);
+ try zcu.failed_analysis.put(gpa, InternPool.AnalUnit.wrap(.{ .decl = decl_index }), decl_gen.error_msg.?);
},
else => |other| {
// There might be an error that happened *after* self.error_msg
// was already allocated, so be sure to free it.
if (decl_gen.error_msg) |error_msg| {
- error_msg.deinit(mod.gpa);
+ error_msg.deinit(gpa);
}
return other;