Commit f777b29832
Changed files (16)
src/arch/x86_64/CodeGen.zig
@@ -12105,7 +12105,7 @@ fn genLocalDebugInfo(
self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op.operand,
),
};
- const frame_index = try self.allocFrameIndex(FrameAlloc.initSpill(ty, self.pt));
+ const frame_index = try self.allocFrameIndex(FrameAlloc.initSpill(ty, self.pt.zcu));
try self.genSetMem(.{ .frame = frame_index }, 0, ty, mcv, .{});
try self.asmAirMemory(.dbg_local, inst, .{
.base = .{ .frame = frame_index },
src/arch/x86_64/Emit.zig
@@ -357,7 +357,7 @@ pub fn emitMir(emit: *Emit) Error!void {
} } };
},
};
- const ip = &emit.lower.bin_file.comp.module.?.intern_pool;
+ const ip = &emit.lower.bin_file.comp.zcu.?.intern_pool;
const air_inst = emit.air.instructions.get(@intFromEnum(air_inst_index));
const name: Air.NullTerminatedString = switch (air_inst.tag) {
else => unreachable,
src/link/Elf/ZigObject.zig
@@ -157,7 +157,7 @@ pub fn flushModule(self: *ZigObject, elf_file: *Elf, tid: Zcu.PerThread.Id) !voi
}
if (build_options.enable_logging) {
- const pt: Zcu.PerThread = .{ .zcu = elf_file.base.comp.module.?, .tid = tid };
+ const pt: Zcu.PerThread = .{ .zcu = elf_file.base.comp.zcu.?, .tid = tid };
for (self.navs.keys(), self.navs.values()) |nav_index, meta| {
checkNavAllocated(pt, nav_index, meta);
}
@@ -167,7 +167,7 @@ pub fn flushModule(self: *ZigObject, elf_file: *Elf, tid: Zcu.PerThread.Id) !voi
}
if (self.dwarf) |*dwarf| {
- const pt: Zcu.PerThread = .{ .zcu = elf_file.base.comp.module.?, .tid = tid };
+ const pt: Zcu.PerThread = .{ .zcu = elf_file.base.comp.zcu.?, .tid = tid };
try dwarf.flushModule(pt);
const gpa = elf_file.base.comp.gpa;
@@ -1306,7 +1306,7 @@ pub fn updateNav(
else => nav.status.resolved.val,
};
- if (nav_init != .none and Value.fromInterned(nav_init).typeOf(zcu).hasRuntimeBits(pt)) {
+ if (nav_init != .none and Value.fromInterned(nav_init).typeOf(zcu).hasRuntimeBits(zcu)) {
const sym_index = try self.getOrCreateMetadataForNav(elf_file, nav_index);
self.symbol(sym_index).atom(elf_file).?.freeRelocs(self);
src/link/MachO/ZigObject.zig
@@ -595,7 +595,7 @@ pub fn flushModule(self: *ZigObject, macho_file: *MachO, tid: Zcu.PerThread.Id)
}
if (self.dwarf) |*dwarf| {
- const pt: Zcu.PerThread = .{ .zcu = macho_file.base.comp.module.?, .tid = tid };
+ const pt: Zcu.PerThread = .{ .zcu = macho_file.base.comp.zcu.?, .tid = tid };
try dwarf.flushModule(pt);
self.debug_abbrev_dirty = false;
@@ -887,7 +887,7 @@ pub fn updateNav(
else => nav.status.resolved.val,
};
- if (nav_init != .none and Value.fromInterned(nav_init).typeOf(zcu).hasRuntimeBits(pt)) {
+ if (nav_init != .none and Value.fromInterned(nav_init).typeOf(zcu).hasRuntimeBits(zcu)) {
const sym_index = try self.getOrCreateMetadataForNav(macho_file, nav_index);
self.symbols.items[sym_index].getAtom(macho_file).?.freeRelocs(macho_file);
src/link/Wasm/ZigObject.zig
@@ -259,7 +259,7 @@ pub fn updateNav(
else => .{ false, .none, nav_val },
};
- if (nav_init.typeOf(zcu).hasRuntimeBits(pt)) {
+ if (nav_init.typeOf(zcu).hasRuntimeBits(zcu)) {
const gpa = wasm_file.base.comp.gpa;
const atom_index = try zig_object.getOrCreateAtomForNav(wasm_file, pt, nav_index);
const atom = wasm_file.getAtomPtr(atom_index);
src/link/C.zig
@@ -327,7 +327,7 @@ pub fn updateNav(self: *C, pt: Zcu.PerThread, nav_index: InternPool.Nav.Index) !
.variable => |variable| variable.init,
else => nav.status.resolved.val,
};
- if (nav_init != .none and !Value.fromInterned(nav_init).typeOf(zcu).hasRuntimeBits(pt)) return;
+ if (nav_init != .none and !Value.fromInterned(nav_init).typeOf(zcu).hasRuntimeBits(zcu)) return;
const gop = try self.navs.getOrPut(gpa, nav_index);
errdefer _ = self.navs.pop();
src/link/Coff.zig
@@ -1221,7 +1221,7 @@ pub fn updateNav(
else => nav_val,
};
- if (nav_init.typeOf(zcu).hasRuntimeBits(pt)) {
+ if (nav_init.typeOf(zcu).hasRuntimeBits(zcu)) {
const atom_index = try self.getOrCreateAtomForNav(nav_index);
Atom.freeRelocations(self, atom_index);
const atom = self.getAtom(atom_index);
src/link/Dwarf.zig
@@ -780,7 +780,7 @@ const Entry = struct {
else
"?", 0),
});
- const zcu = dwarf.bin_file.comp.module.?;
+ const zcu = dwarf.bin_file.comp.zcu.?;
const ip = &zcu.intern_pool;
for (dwarf.types.keys(), dwarf.types.values()) |ty, other_entry| {
const ty_unit: Unit.Index = if (Type.fromInterned(ty).typeDeclInst(zcu)) |inst_index|
@@ -1429,7 +1429,7 @@ pub const WipNav = struct {
}
} else {
try wip_nav.abbrevCode(abbrev_code.block);
- const bytes = Type.fromInterned(loaded_enum.tag_ty).abiSize(wip_nav.pt);
+ const bytes = Type.fromInterned(loaded_enum.tag_ty).abiSize(wip_nav.pt.zcu);
try uleb128(diw, bytes);
big_int.writeTwosComplement(try wip_nav.debug_info.addManyAsSlice(wip_nav.dwarf.gpa, @intCast(bytes)), wip_nav.dwarf.endian);
}
@@ -1770,7 +1770,7 @@ pub fn initWipNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool.Nav.In
const ty_reloc_index = try wip_nav.refForward();
try wip_nav.exprloc(.{ .addr = .{ .sym = sym_index } });
try uleb128(diw, nav.status.resolved.alignment.toByteUnits() orelse
- ty.abiAlignment(pt).toByteUnits().?);
+ ty.abiAlignment(zcu).toByteUnits().?);
try diw.writeByte(@intFromBool(false));
wip_nav.finishForward(ty_reloc_index);
try wip_nav.abbrevCode(.is_const);
@@ -1821,7 +1821,7 @@ pub fn initWipNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool.Nav.In
const addr: Loc = .{ .addr = .{ .sym = sym_index } };
try wip_nav.exprloc(if (variable.is_threadlocal) .{ .form_tls_address = &addr } else addr);
try uleb128(diw, nav.status.resolved.alignment.toByteUnits() orelse
- ty.abiAlignment(pt).toByteUnits().?);
+ ty.abiAlignment(zcu).toByteUnits().?);
try diw.writeByte(@intFromBool(false));
},
.func => |func| {
@@ -2158,8 +2158,8 @@ pub fn updateComptimeNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool
try diw.writeByte(accessibility);
try wip_nav.strp(nav.name.toSlice(ip));
if (loaded_struct.field_types.len == 0) try diw.writeByte(@intFromBool(false)) else {
- try uleb128(diw, nav_val.toType().abiSize(pt));
- try uleb128(diw, nav_val.toType().abiAlignment(pt).toByteUnits().?);
+ try uleb128(diw, nav_val.toType().abiSize(zcu));
+ try uleb128(diw, nav_val.toType().abiAlignment(zcu).toByteUnits().?);
for (0..loaded_struct.field_types.len) |field_index| {
const is_comptime = loaded_struct.fieldIsComptime(ip, field_index);
try wip_nav.abbrevCode(if (is_comptime) .struct_field_comptime else .struct_field);
@@ -2173,7 +2173,7 @@ pub fn updateComptimeNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool
if (!is_comptime) {
try uleb128(diw, loaded_struct.offsets.get(ip)[field_index]);
try uleb128(diw, loaded_struct.fieldAlign(ip, field_index).toByteUnits() orelse
- field_type.abiAlignment(pt).toByteUnits().?);
+ field_type.abiAlignment(zcu).toByteUnits().?);
}
}
try uleb128(diw, @intFromEnum(AbbrevCode.null));
@@ -2195,7 +2195,7 @@ pub fn updateComptimeNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool
const field_type = Type.fromInterned(loaded_struct.field_types.get(ip)[field_index]);
try wip_nav.refType(field_type);
try uleb128(diw, field_bit_offset);
- field_bit_offset += @intCast(field_type.bitSize(pt));
+ field_bit_offset += @intCast(field_type.bitSize(zcu));
}
try uleb128(diw, @intFromEnum(AbbrevCode.null));
},
@@ -2360,7 +2360,7 @@ pub fn updateComptimeNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool
try uleb128(diw, loc.column + 1);
try diw.writeByte(accessibility);
try wip_nav.strp(nav.name.toSlice(ip));
- const union_layout = pt.getUnionLayout(loaded_union);
+ const union_layout = Type.getUnionLayout(loaded_union, zcu);
try uleb128(diw, union_layout.abi_size);
try uleb128(diw, union_layout.abi_align.toByteUnits().?);
const loaded_tag = loaded_union.loadTagType(ip);
@@ -2391,7 +2391,7 @@ pub fn updateComptimeNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool
try wip_nav.refType(field_type);
try uleb128(diw, union_layout.payloadOffset());
try uleb128(diw, loaded_union.fieldAlign(ip, field_index).toByteUnits() orelse
- if (field_type.isNoReturn(zcu)) 1 else field_type.abiAlignment(pt).toByteUnits().?);
+ if (field_type.isNoReturn(zcu)) 1 else field_type.abiAlignment(zcu).toByteUnits().?);
}
try uleb128(diw, @intFromEnum(AbbrevCode.null));
}
@@ -2406,7 +2406,7 @@ pub fn updateComptimeNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool
const field_type = Type.fromInterned(loaded_union.field_types.get(ip)[field_index]);
try wip_nav.refType(field_type);
try uleb128(diw, loaded_union.fieldAlign(ip, field_index).toByteUnits() orelse
- field_type.abiAlignment(pt).toByteUnits().?);
+ field_type.abiAlignment(zcu).toByteUnits().?);
}
try uleb128(diw, @intFromEnum(AbbrevCode.null));
break :done;
@@ -2560,8 +2560,8 @@ fn updateType(
inline .signed, .unsigned => |signedness| @field(DW.ATE, @tagName(signedness)),
});
try uleb128(diw, int_type.bits);
- try uleb128(diw, ty.abiSize(pt));
- try uleb128(diw, ty.abiAlignment(pt).toByteUnits().?);
+ try uleb128(diw, ty.abiSize(zcu));
+ try uleb128(diw, ty.abiAlignment(zcu).toByteUnits().?);
},
.ptr_type => |ptr_type| switch (ptr_type.flags.size) {
.One, .Many, .C => {
@@ -2569,7 +2569,7 @@ fn updateType(
try wip_nav.abbrevCode(.ptr_type);
try wip_nav.strp(name);
try uleb128(diw, ptr_type.flags.alignment.toByteUnits() orelse
- ptr_child_type.abiAlignment(pt).toByteUnits().?);
+ ptr_child_type.abiAlignment(zcu).toByteUnits().?);
try diw.writeByte(@intFromEnum(ptr_type.flags.address_space));
if (ptr_type.flags.is_const or ptr_type.flags.is_volatile) try wip_nav.infoSectionOffset(
.debug_info,
@@ -2594,8 +2594,8 @@ fn updateType(
.Slice => {
try wip_nav.abbrevCode(.struct_type);
try wip_nav.strp(name);
- try uleb128(diw, ty.abiSize(pt));
- try uleb128(diw, ty.abiAlignment(pt).toByteUnits().?);
+ try uleb128(diw, ty.abiSize(zcu));
+ try uleb128(diw, ty.abiAlignment(zcu).toByteUnits().?);
try wip_nav.abbrevCode(.generated_field);
try wip_nav.strp("ptr");
const ptr_field_type = ty.slicePtrFieldType(zcu);
@@ -2605,7 +2605,7 @@ fn updateType(
try wip_nav.strp("len");
const len_field_type = Type.usize;
try wip_nav.refType(len_field_type);
- try uleb128(diw, len_field_type.abiAlignment(pt).forward(ptr_field_type.abiSize(pt)));
+ try uleb128(diw, len_field_type.abiAlignment(zcu).forward(ptr_field_type.abiSize(zcu)));
try uleb128(diw, @intFromEnum(AbbrevCode.null));
},
},
@@ -2623,8 +2623,8 @@ fn updateType(
const opt_child_type = Type.fromInterned(opt_child_type_index);
try wip_nav.abbrevCode(.union_type);
try wip_nav.strp(name);
- try uleb128(diw, ty.abiSize(pt));
- try uleb128(diw, ty.abiAlignment(pt).toByteUnits().?);
+ try uleb128(diw, ty.abiSize(zcu));
+ try uleb128(diw, ty.abiAlignment(zcu).toByteUnits().?);
if (opt_child_type.isNoReturn(zcu)) {
try wip_nav.abbrevCode(.generated_field);
try wip_nav.strp("null");
@@ -2652,8 +2652,8 @@ fn updateType(
switch (repr) {
.unpacked => {
try wip_nav.refType(Type.bool);
- try uleb128(diw, if (opt_child_type.hasRuntimeBits(pt))
- opt_child_type.abiSize(pt)
+ try uleb128(diw, if (opt_child_type.hasRuntimeBits(zcu))
+ opt_child_type.abiSize(zcu)
else
0);
},
@@ -2700,8 +2700,8 @@ fn updateType(
const error_union_error_set_offset, const error_union_payload_offset = switch (error_union_type.payload_type) {
.generic_poison_type => .{ 0, 0 },
else => .{
- codegen.errUnionErrorOffset(error_union_payload_type, pt),
- codegen.errUnionPayloadOffset(error_union_payload_type, pt),
+ codegen.errUnionErrorOffset(error_union_payload_type, zcu),
+ codegen.errUnionPayloadOffset(error_union_payload_type, zcu),
},
};
@@ -2710,8 +2710,8 @@ fn updateType(
if (error_union_type.error_set_type != .generic_poison_type and
error_union_type.payload_type != .generic_poison_type)
{
- try uleb128(diw, ty.abiSize(pt));
- try uleb128(diw, ty.abiAlignment(pt).toByteUnits().?);
+ try uleb128(diw, ty.abiSize(zcu));
+ try uleb128(diw, ty.abiAlignment(zcu).toByteUnits().?);
} else {
try uleb128(diw, 0);
try uleb128(diw, 1);
@@ -2788,9 +2788,9 @@ fn updateType(
DW.ATE.unsigned
else
unreachable);
- try uleb128(diw, ty.bitSize(pt));
- try uleb128(diw, ty.abiSize(pt));
- try uleb128(diw, ty.abiAlignment(pt).toByteUnits().?);
+ try uleb128(diw, ty.bitSize(zcu));
+ try uleb128(diw, ty.abiSize(zcu));
+ try uleb128(diw, ty.abiAlignment(zcu).toByteUnits().?);
},
.anyopaque,
.void,
@@ -2820,8 +2820,8 @@ fn updateType(
} else {
try wip_nav.abbrevCode(.struct_type);
try wip_nav.strp(name);
- try uleb128(diw, ty.abiSize(pt));
- try uleb128(diw, ty.abiAlignment(pt).toByteUnits().?);
+ try uleb128(diw, ty.abiSize(zcu));
+ try uleb128(diw, ty.abiAlignment(zcu).toByteUnits().?);
var field_byte_offset: u64 = 0;
for (0..anon_struct_type.types.len) |field_index| {
const comptime_value = anon_struct_type.values.get(ip)[field_index];
@@ -2834,11 +2834,11 @@ fn updateType(
const field_type = Type.fromInterned(anon_struct_type.types.get(ip)[field_index]);
try wip_nav.refType(field_type);
if (comptime_value == .none) {
- const field_align = field_type.abiAlignment(pt);
+ const field_align = field_type.abiAlignment(zcu);
field_byte_offset = field_align.forward(field_byte_offset);
try uleb128(diw, field_byte_offset);
- try uleb128(diw, field_type.abiAlignment(pt).toByteUnits().?);
- field_byte_offset += field_type.abiSize(pt);
+ try uleb128(diw, field_type.abiAlignment(zcu).toByteUnits().?);
+ field_byte_offset += field_type.abiSize(zcu);
}
}
try uleb128(diw, @intFromEnum(AbbrevCode.null));
@@ -2976,8 +2976,8 @@ pub fn updateContainerType(dwarf: *Dwarf, pt: Zcu.PerThread, type_index: InternP
try uleb128(diw, file_gop.index);
try wip_nav.strp(loaded_struct.name.toSlice(ip));
if (loaded_struct.field_types.len > 0) {
- try uleb128(diw, ty.abiSize(pt));
- try uleb128(diw, ty.abiAlignment(pt).toByteUnits().?);
+ try uleb128(diw, ty.abiSize(zcu));
+ try uleb128(diw, ty.abiAlignment(zcu).toByteUnits().?);
for (0..loaded_struct.field_types.len) |field_index| {
const is_comptime = loaded_struct.fieldIsComptime(ip, field_index);
try wip_nav.abbrevCode(if (is_comptime) .struct_field_comptime else .struct_field);
@@ -2991,7 +2991,7 @@ pub fn updateContainerType(dwarf: *Dwarf, pt: Zcu.PerThread, type_index: InternP
if (!is_comptime) {
try uleb128(diw, loaded_struct.offsets.get(ip)[field_index]);
try uleb128(diw, loaded_struct.fieldAlign(ip, field_index).toByteUnits() orelse
- field_type.abiAlignment(pt).toByteUnits().?);
+ field_type.abiAlignment(zcu).toByteUnits().?);
}
}
try uleb128(diw, @intFromEnum(AbbrevCode.null));
@@ -3042,8 +3042,8 @@ pub fn updateContainerType(dwarf: *Dwarf, pt: Zcu.PerThread, type_index: InternP
try wip_nav.abbrevCode(if (loaded_struct.field_types.len == 0) .namespace_struct_type else .struct_type);
try wip_nav.strp(name);
if (loaded_struct.field_types.len == 0) try diw.writeByte(@intFromBool(false)) else {
- try uleb128(diw, ty.abiSize(pt));
- try uleb128(diw, ty.abiAlignment(pt).toByteUnits().?);
+ try uleb128(diw, ty.abiSize(zcu));
+ try uleb128(diw, ty.abiAlignment(zcu).toByteUnits().?);
for (0..loaded_struct.field_types.len) |field_index| {
const is_comptime = loaded_struct.fieldIsComptime(ip, field_index);
try wip_nav.abbrevCode(if (is_comptime) .struct_field_comptime else .struct_field);
@@ -3057,7 +3057,7 @@ pub fn updateContainerType(dwarf: *Dwarf, pt: Zcu.PerThread, type_index: InternP
if (!is_comptime) {
try uleb128(diw, loaded_struct.offsets.get(ip)[field_index]);
try uleb128(diw, loaded_struct.fieldAlign(ip, field_index).toByteUnits() orelse
- field_type.abiAlignment(pt).toByteUnits().?);
+ field_type.abiAlignment(zcu).toByteUnits().?);
}
}
try uleb128(diw, @intFromEnum(AbbrevCode.null));
@@ -3074,7 +3074,7 @@ pub fn updateContainerType(dwarf: *Dwarf, pt: Zcu.PerThread, type_index: InternP
const field_type = Type.fromInterned(loaded_struct.field_types.get(ip)[field_index]);
try wip_nav.refType(field_type);
try uleb128(diw, field_bit_offset);
- field_bit_offset += @intCast(field_type.bitSize(pt));
+ field_bit_offset += @intCast(field_type.bitSize(zcu));
}
if (loaded_struct.field_types.len > 0) try uleb128(diw, @intFromEnum(AbbrevCode.null));
},
@@ -3099,7 +3099,7 @@ pub fn updateContainerType(dwarf: *Dwarf, pt: Zcu.PerThread, type_index: InternP
const loaded_union = ip.loadUnionType(type_index);
try wip_nav.abbrevCode(if (loaded_union.field_types.len > 0) .union_type else .empty_union_type);
try wip_nav.strp(name);
- const union_layout = pt.getUnionLayout(loaded_union);
+ const union_layout = Type.getUnionLayout(loaded_union, zcu);
try uleb128(diw, union_layout.abi_size);
try uleb128(diw, union_layout.abi_align.toByteUnits().?);
const loaded_tag = loaded_union.loadTagType(ip);
@@ -3130,7 +3130,7 @@ pub fn updateContainerType(dwarf: *Dwarf, pt: Zcu.PerThread, type_index: InternP
try wip_nav.refType(field_type);
try uleb128(diw, union_layout.payloadOffset());
try uleb128(diw, loaded_union.fieldAlign(ip, field_index).toByteUnits() orelse
- if (field_type.isNoReturn(zcu)) 1 else field_type.abiAlignment(pt).toByteUnits().?);
+ if (field_type.isNoReturn(zcu)) 1 else field_type.abiAlignment(zcu).toByteUnits().?);
}
try uleb128(diw, @intFromEnum(AbbrevCode.null));
}
@@ -3145,7 +3145,7 @@ pub fn updateContainerType(dwarf: *Dwarf, pt: Zcu.PerThread, type_index: InternP
const field_type = Type.fromInterned(loaded_union.field_types.get(ip)[field_index]);
try wip_nav.refType(field_type);
try uleb128(diw, loaded_union.fieldAlign(ip, field_index).toByteUnits() orelse
- field_type.abiAlignment(pt).toByteUnits().?);
+ field_type.abiAlignment(zcu).toByteUnits().?);
}
if (loaded_union.field_types.len > 0) try uleb128(diw, @intFromEnum(AbbrevCode.null));
},
src/link/Plan9.zig
@@ -457,7 +457,7 @@ pub fn updateNav(self: *Plan9, pt: Zcu.PerThread, nav_index: InternPool.Nav.Inde
else => nav_val,
};
- if (nav_init.typeOf(zcu).hasRuntimeBits(pt)) {
+ if (nav_init.typeOf(zcu).hasRuntimeBits(zcu)) {
const atom_idx = try self.seeNav(pt, nav_index);
var code_buffer = std.ArrayList(u8).init(gpa);
src/Zcu/PerThread.zig
@@ -1326,7 +1326,7 @@ fn semaCau(pt: Zcu.PerThread, cau_index: InternPool.Cau.Index) !SemaCauResult {
try decl_ty.resolveFully(pt);
}
- if (!resolve_type or !decl_ty.hasRuntimeBits(pt)) {
+ if (!resolve_type or !decl_ty.hasRuntimeBits(zcu)) {
if (zcu.comp.config.use_llvm) break :queue_codegen;
if (file.mod.strip) break :queue_codegen;
}
src/codegen.zig
@@ -878,12 +878,12 @@ fn genNavRef(
// TODO this feels clunky. Perhaps we should check for it in `genTypedValue`?
if (ty.castPtrToFn(zcu)) |fn_ty| {
if (zcu.typeToFunc(fn_ty).?.is_generic) {
- return .{ .mcv = .{ .immediate = fn_ty.abiAlignment(pt).toByteUnits().? } };
+ return .{ .mcv = .{ .immediate = fn_ty.abiAlignment(zcu).toByteUnits().? } };
}
} else if (ty.zigTypeTag(zcu) == .Pointer) {
const elem_ty = ty.elemType2(zcu);
- if (!elem_ty.hasRuntimeBits(pt)) {
- return .{ .mcv = .{ .immediate = elem_ty.abiAlignment(pt).toByteUnits().? } };
+ if (!elem_ty.hasRuntimeBits(zcu)) {
+ return .{ .mcv = .{ .immediate = elem_ty.abiAlignment(zcu).toByteUnits().? } };
}
}
@@ -964,15 +964,15 @@ pub fn genTypedValue(
},
else => switch (ip.indexToKey(val.toIntern())) {
.int => {
- return .{ .mcv = .{ .immediate = val.toUnsignedInt(pt) } };
+ return .{ .mcv = .{ .immediate = val.toUnsignedInt(zcu) } };
},
.ptr => |ptr| if (ptr.byte_offset == 0) switch (ptr.base_addr) {
.nav => |nav| return genNavRef(lf, pt, src_loc, val, nav, target),
- .uav => |uav| if (Value.fromInterned(uav.val).typeOf(zcu).hasRuntimeBits(pt))
+ .uav => |uav| if (Value.fromInterned(uav.val).typeOf(zcu).hasRuntimeBits(zcu))
return switch (try lf.lowerUav(
pt,
uav.val,
- Type.fromInterned(uav.orig_ty).ptrAlignment(pt),
+ Type.fromInterned(uav.orig_ty).ptrAlignment(zcu),
src_loc,
)) {
.mcv => |mcv| return .{ .mcv = switch (mcv) {
@@ -983,7 +983,7 @@ pub fn genTypedValue(
.fail => |em| return .{ .fail = em },
}
else
- return .{ .mcv = .{ .immediate = Type.fromInterned(uav.orig_ty).ptrAlignment(pt)
+ return .{ .mcv = .{ .immediate = Type.fromInterned(uav.orig_ty).ptrAlignment(zcu)
.forward(@intCast((@as(u66, 1) << @intCast(target.ptrBitWidth() | 1)) / 3)) } },
else => {},
},
src/Compilation.zig
@@ -3091,7 +3091,7 @@ pub fn getAllErrorsAlloc(comp: *Compilation) !ErrorBundle {
var all_references: ?std.AutoHashMapUnmanaged(InternPool.AnalUnit, ?Zcu.ResolvedReference) = null;
defer if (all_references) |*a| a.deinit(gpa);
- if (comp.module) |zcu| {
+ if (comp.zcu) |zcu| {
const ip = &zcu.intern_pool;
for (zcu.failed_files.keys(), zcu.failed_files.values()) |file, error_msg| {
@@ -3268,7 +3268,7 @@ pub fn getAllErrorsAlloc(comp: *Compilation) !ErrorBundle {
}
}
- if (comp.module) |zcu| {
+ if (comp.zcu) |zcu| {
if (comp.incremental and bundle.root_list.items.len == 0) {
const should_have_error = for (zcu.transitive_failed_analysis.keys()) |failed_unit| {
if (all_references == null) {
@@ -3976,7 +3976,7 @@ fn processOneCodegenJob(tid: usize, comp: *Compilation, codegen_job: CodegenJob)
const named_frame = tracy.namedFrame("codegen_type");
defer named_frame.end();
- const pt: Zcu.PerThread = .{ .zcu = comp.module.?, .tid = @enumFromInt(tid) };
+ const pt: Zcu.PerThread = .{ .zcu = comp.zcu.?, .tid = @enumFromInt(tid) };
try pt.linkerUpdateContainerType(ty);
},
}
@@ -4258,7 +4258,7 @@ fn workerAstGenFile(
const child_prog_node = prog_node.start(file.sub_file_path, 0);
defer child_prog_node.end();
- const pt: Zcu.PerThread = .{ .zcu = comp.module.?, .tid = @enumFromInt(tid) };
+ const pt: Zcu.PerThread = .{ .zcu = comp.zcu.?, .tid = @enumFromInt(tid) };
pt.astGenFile(file, path_digest) catch |err| switch (err) {
error.AnalysisFail => return,
else => {
src/Sema.zig
@@ -3544,7 +3544,7 @@ fn zirAllocExtended(
}
const target = pt.zcu.getTarget();
try var_ty.resolveLayout(pt);
- if (sema.func_is_naked and try sema.typeHasRuntimeBits(var_ty)) {
+ if (sema.func_is_naked and try var_ty.hasRuntimeBitsSema(pt)) {
const var_src = block.src(.{ .node_offset_store_ptr = extra.data.src_node });
return sema.fail(block, var_src, "local variable in naked function", .{});
}
@@ -3988,7 +3988,7 @@ fn zirAlloc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.I
if (block.is_comptime) {
return sema.analyzeComptimeAlloc(block, var_ty, .none);
}
- if (sema.func_is_naked and try sema.typeHasRuntimeBits(var_ty)) {
+ if (sema.func_is_naked and try var_ty.hasRuntimeBitsSema(pt)) {
const mut_src = block.src(.{ .node_offset_store_ptr = inst_data.src_node });
return sema.fail(block, mut_src, "local variable in naked function", .{});
}
@@ -4016,7 +4016,7 @@ fn zirAllocMut(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
if (block.is_comptime) {
return sema.analyzeComptimeAlloc(block, var_ty, .none);
}
- if (sema.func_is_naked and try sema.typeHasRuntimeBits(var_ty)) {
+ if (sema.func_is_naked and try var_ty.hasRuntimeBitsSema(pt)) {
const var_src = block.src(.{ .node_offset_store_ptr = inst_data.src_node });
return sema.fail(block, var_src, "local variable in naked function", .{});
}
@@ -4153,7 +4153,7 @@ fn zirResolveInferredAlloc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Com
// TODO: source location of runtime control flow
return sema.fail(block, src, "value with comptime-only type '{}' depends on runtime control flow", .{final_elem_ty.fmt(pt)});
}
- if (sema.func_is_naked and try sema.typeHasRuntimeBits(final_elem_ty)) {
+ if (sema.func_is_naked and try final_elem_ty.hasRuntimeBitsSema(pt)) {
const mut_src = block.src(.{ .node_offset_store_ptr = inst_data.src_node });
return sema.fail(block, mut_src, "local variable in naked function", .{});
}
@@ -17534,7 +17534,7 @@ fn zirSizeOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
.AnyFrame,
=> {},
}
- const val = try ty.lazyAbiSize(pt);
+ const val = try ty.abiSizeLazy(pt);
return Air.internedToRef(val.toIntern());
}
@@ -35313,7 +35313,7 @@ pub fn resolveStructLayout(sema: *Sema, ty: Type) SemaError!void {
if (struct_type.haveLayout(ip))
return;
- try sema.resolveTypeFieldsStruct(ty.toIntern(), struct_type);
+ try sema.resolveStructFieldTypes(ty.toIntern(), struct_type);
if (struct_type.layout == .@"packed") {
sema.backingIntType(struct_type) catch |err| switch (err) {
@@ -38454,7 +38454,7 @@ pub fn resolveDeclaredEnum(
wip_ty.setTagTy(ip, int_tag_ty.toIntern());
if (small.nonexhaustive and int_tag_ty.toIntern() != .comptime_int_type) {
- if (fields_len > 1 and std.math.log2_int(u64, fields_len) == int_tag_ty.bitSize(pt)) {
+ if (fields_len > 1 and std.math.log2_int(u64, fields_len) == int_tag_ty.bitSize(zcu)) {
return sema.fail(&block, src, "non-exhaustive enum specifies every value", .{});
}
}
src/Type.zig
@@ -1259,7 +1259,7 @@ pub fn abiSize(ty: Type, zcu: *Zcu) u64 {
}
/// May capture a reference to `ty`.
-pub fn lazyAbiSize(ty: Type, pt: Zcu.PerThread) !Value {
+pub fn abiSizeLazy(ty: Type, pt: Zcu.PerThread) !Value {
switch (try ty.abiSizeInner(.lazy, pt.zcu, pt.tid)) {
.val => |val| return val,
.scalar => |x| return pt.intValue(Type.comptime_int, x),
@@ -3446,7 +3446,7 @@ pub fn structFieldOffset(
const union_type = ip.loadUnionType(ty.toIntern());
if (!union_type.hasTag(ip))
return 0;
- const layout = union_type.getUnionLayout(zcu);
+ const layout = Type.getUnionLayout(union_type, zcu);
if (layout.tag_align.compare(.gte, layout.payload_align)) {
// {Tag, Payload}
return layout.payload_align.forward(layout.tag_size);
@@ -4000,6 +4000,65 @@ fn resolveUnionInner(
};
}
+pub fn getUnionLayout(loaded_union: InternPool.LoadedUnionType, zcu: *Zcu) Zcu.UnionLayout {
+ const ip = &zcu.intern_pool;
+ assert(loaded_union.haveLayout(ip));
+ var most_aligned_field: u32 = undefined;
+ var most_aligned_field_size: u64 = undefined;
+ var biggest_field: u32 = undefined;
+ var payload_size: u64 = 0;
+ var payload_align: InternPool.Alignment = .@"1";
+ for (loaded_union.field_types.get(ip), 0..) |field_ty, field_index| {
+ if (!Type.fromInterned(field_ty).hasRuntimeBitsIgnoreComptime(zcu)) continue;
+
+ const explicit_align = loaded_union.fieldAlign(ip, field_index);
+ const field_align = if (explicit_align != .none)
+ explicit_align
+ else
+ Type.fromInterned(field_ty).abiAlignment(zcu);
+ const field_size = Type.fromInterned(field_ty).abiSize(zcu);
+ if (field_size > payload_size) {
+ payload_size = field_size;
+ biggest_field = @intCast(field_index);
+ }
+ if (field_align.compare(.gte, payload_align)) {
+ payload_align = field_align;
+ most_aligned_field = @intCast(field_index);
+ most_aligned_field_size = field_size;
+ }
+ }
+ const have_tag = loaded_union.flagsUnordered(ip).runtime_tag.hasTag();
+ if (!have_tag or !Type.fromInterned(loaded_union.enum_tag_ty).hasRuntimeBits(zcu)) {
+ return .{
+ .abi_size = payload_align.forward(payload_size),
+ .abi_align = payload_align,
+ .most_aligned_field = most_aligned_field,
+ .most_aligned_field_size = most_aligned_field_size,
+ .biggest_field = biggest_field,
+ .payload_size = payload_size,
+ .payload_align = payload_align,
+ .tag_align = .none,
+ .tag_size = 0,
+ .padding = 0,
+ };
+ }
+
+ const tag_size = Type.fromInterned(loaded_union.enum_tag_ty).abiSize(zcu);
+ const tag_align = Type.fromInterned(loaded_union.enum_tag_ty).abiAlignment(zcu).max(.@"1");
+ return .{
+ .abi_size = loaded_union.sizeUnordered(ip),
+ .abi_align = tag_align.max(payload_align),
+ .most_aligned_field = most_aligned_field,
+ .most_aligned_field_size = most_aligned_field_size,
+ .biggest_field = biggest_field,
+ .payload_size = payload_size,
+ .payload_align = payload_align,
+ .tag_align = tag_align,
+ .tag_size = tag_size,
+ .padding = loaded_union.paddingUnordered(ip),
+ };
+}
+
/// Returns the type of a pointer to an element.
/// Asserts that the type is a pointer, and that the element type is indexable.
/// If the element index is comptime-known, it must be passed in `offset`.
src/Value.zig
@@ -4196,14 +4196,14 @@ pub fn pointerDerivationAdvanced(ptr_val: Value, arena: Allocator, pt: Zcu.PerTh
const base_ptr_ty = base_ptr.typeOf(zcu);
const agg_ty = base_ptr_ty.childType(zcu);
const field_ty, const field_align = switch (agg_ty.zigTypeTag(zcu)) {
- .Struct => .{ agg_ty.fieldType(field.index, zcu), try agg_ty.fieldAlignmentInner(
- field.index,
+ .Struct => .{ agg_ty.fieldType(@intCast(field.index), zcu), try agg_ty.fieldAlignmentInner(
+ @intCast(field.index),
if (have_sema) .sema else .normal,
pt.zcu,
if (have_sema) pt.tid else {},
) },
- .Union => .{ agg_ty.unionFieldTypeByIndex(field.index, zcu), try agg_ty.fieldAlignmentInner(
- field.index,
+ .Union => .{ agg_ty.unionFieldTypeByIndex(@intCast(field.index), zcu), try agg_ty.fieldAlignmentInner(
+ @intCast(field.index),
if (have_sema) .sema else .normal,
pt.zcu,
if (have_sema) pt.tid else {},
src/Zcu.zig
@@ -2840,9 +2840,9 @@ pub fn addTypeReference(zcu: *Zcu, src_unit: AnalUnit, referenced_type: InternPo
gop.value_ptr.* = @intCast(ref_idx);
}
-pub fn errorSetBits(mod: *Zcu) u16 {
- if (mod.error_limit == 0) return 0;
- return @as(u16, std.math.log2_int(ErrorInt, mod.error_limit)) + 1;
+pub fn errorSetBits(zcu: *const Zcu) u16 {
+ if (zcu.error_limit == 0) return 0;
+ return @as(u16, std.math.log2_int(ErrorInt, zcu.error_limit)) + 1;
}
pub fn errNote(