authorgravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2026-02-27 14:40:01+00:00
committergravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2026-03-10 10:26:13+00:00
logd462794e20127f396753c7d6064a9d2b4e0304d9
tree6631378a8f76604a2ba177ef8ce528a6ef1523b9
parentbb78871aa44594a1b4782792942664e532491d5a
signaturelock-open Commit is signed but in an unrecognized format.

get the compiler building

The change in codegen/x86_64/CodeGen.zig was not strictly necessary (the Sema change I did solves the error I was getting there), I just think it's better style anyway.

6 files changed, 57 insertions(+), 29 deletions(-)

lib/std/os/windows.zig+5-5
......@@ -4160,7 +4160,7 @@ pub const RUNTIME_FUNCTION = switch (native_arch) {
41604160 BeginAddress: DWORD,
41614161 DUMMYUNIONNAME: extern union {
41624162 UnwindData: DWORD,
4163 DUMMYSTRUCTNAME: packed struct {
4163 DUMMYSTRUCTNAME: packed struct(u32) {
41644164 Flag: u2,
41654165 FunctionLength: u11,
41664166 Ret: u2,
......@@ -4177,7 +4177,7 @@ pub const RUNTIME_FUNCTION = switch (native_arch) {
41774177 BeginAddress: DWORD,
41784178 DUMMYUNIONNAME: extern union {
41794179 UnwindData: DWORD,
4180 DUMMYSTRUCTNAME: packed struct {
4180 DUMMYSTRUCTNAME: packed struct(u32) {
41814181 Flag: u2,
41824182 FunctionLength: u11,
41834183 RegF: u3,
......@@ -5013,7 +5013,7 @@ pub const KUSER_SHARED_DATA = extern struct {
50135013 KdDebuggerEnabled: BOOLEAN,
50145014 DummyUnion1: extern union {
50155015 MitigationPolicies: UCHAR,
5016 Alt: packed struct {
5016 Alt: packed struct(u8) {
50175017 NXSupportPolicy: u2,
50185018 SEHValidationPolicy: u2,
50195019 CurDirDevicesSkippedForDlls: u2,
......@@ -5029,7 +5029,7 @@ pub const KUSER_SHARED_DATA = extern struct {
50295029 SafeBootMode: BOOLEAN,
50305030 DummyUnion2: extern union {
50315031 VirtualizationFlags: UCHAR,
5032 Alt: packed struct {
5032 Alt: packed struct(u8) {
50335033 ArchStartedInEl2: u1,
50345034 QcSlIsSupported: u1,
50355035 SpareBits: u6,
......@@ -5038,7 +5038,7 @@ pub const KUSER_SHARED_DATA = extern struct {
50385038 Reserved12: [2]UCHAR,
50395039 DummyUnion3: extern union {
50405040 SharedDataFlags: ULONG,
5041 Alt: packed struct {
5041 Alt: packed struct(u32) {
50425042 DbgErrorPortPresent: u1,
50435043 DbgElevationEnabled: u1,
50445044 DbgVirtEnabled: u1,
src/Sema.zig+28-20
......@@ -3081,7 +3081,7 @@ fn zirRef(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins
30813081
30823082 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_tok;
30833083 const operand = sema.resolveInst(inst_data.operand);
3084 return sema.analyzeRef(block, block.tokenOffset(inst_data.src_tok), operand);
3084 return sema.analyzeRef(block, block.tokenOffset(inst_data.src_tok), operand, .none);
30853085}
30863086
30873087fn zirEnsureResultUsed(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void {
......@@ -18690,7 +18690,7 @@ fn zirStructInit(
1869018690 const union_val = try sema.bitCast(block, resolved_ty, init_inst, src, field_src);
1869118691 const result_val = try sema.coerce(block, result_ty, union_val, src);
1869218692 if (is_ref) {
18693 return sema.analyzeRef(block, src, result_val);
18693 return sema.analyzeRef(block, src, result_val, .none);
1869418694 } else {
1869518695 return result_val;
1869618696 }
......@@ -24192,7 +24192,7 @@ fn zirMemcpy(
2419224192 }
2419324193 } else if (dest_len == .none and len_val == null) {
2419424194 // Change the dest to a slice, since its type must have the length.
24195 const dest_ptr_ptr = try sema.analyzeRef(block, dest_src, new_dest_ptr);
24195 const dest_ptr_ptr = try sema.analyzeRef(block, dest_src, new_dest_ptr, .none);
2419624196 new_dest_ptr = try sema.analyzeSlice(block, dest_src, dest_ptr_ptr, .zero, src_len, .none, LazySrcLoc.unneeded, dest_src, dest_src, dest_src, false);
2419724197 const new_src_ptr_ty = sema.typeOf(new_src_ptr);
2419824198 if (new_src_ptr_ty.isSlice(zcu)) {
......@@ -26301,7 +26301,7 @@ fn structFieldPtr(
2630126301 const field_index: u32 = if (struct_ty.isTuple(zcu)) field_index: {
2630226302 if (field_name.eqlSlice("len", ip)) {
2630326303 const len_inst = try pt.intRef(.usize, struct_ty.structFieldCount(zcu));
26304 return sema.analyzeRef(block, src, len_inst);
26304 return sema.analyzeRef(block, src, len_inst, .none);
2630526305 }
2630626306 break :field_index try sema.tupleFieldIndex(block, struct_ty, field_name, field_name_src);
2630726307 } else field_index: {
......@@ -29787,10 +29787,7 @@ fn coerceTupleToSlicePtrs(
2978729787 .child = slice_info.child,
2978829788 });
2978929789 const array_inst = try sema.coerceTupleToArray(block, array_ty, slice_ty_src, tuple, tuple_src);
29790 if (slice_info.flags.alignment != .none) {
29791 return sema.fail(block, slice_ty_src, "TODO: override the alignment of the array decl we create here", .{});
29792 }
29793 const ptr_array = try sema.analyzeRef(block, slice_ty_src, array_inst);
29790 const ptr_array = try sema.analyzeRef(block, slice_ty_src, array_inst, slice_info.flags.alignment);
2979429791 return sema.coerceArrayPtrToSlice(block, slice_ty, ptr_array, slice_ty_src);
2979529792}
2979629793
......@@ -29809,10 +29806,7 @@ fn coerceTupleToArrayPtrs(
2980929806 const ptr_info = ptr_array_ty.ptrInfo(zcu);
2981029807 const array_ty: Type = .fromInterned(ptr_info.child);
2981129808 const array_inst = try sema.coerceTupleToArray(block, array_ty, array_ty_src, tuple, tuple_src);
29812 if (ptr_info.flags.alignment != .none) {
29813 return sema.fail(block, array_ty_src, "TODO: override the alignment of the array decl we create here", .{});
29814 }
29815 const ptr_array = try sema.analyzeRef(block, array_ty_src, array_inst);
29809 const ptr_array = try sema.analyzeRef(block, array_ty_src, array_inst, ptr_info.flags.alignment);
2981629810 return ptr_array;
2981729811}
2981829812
......@@ -30137,34 +30131,48 @@ fn analyzeRef(
3013730131 block: *Block,
3013830132 src: LazySrcLoc,
3013930133 operand: Air.Inst.Ref,
30134 alignment: Alignment,
3014030135) CompileError!Air.Inst.Ref {
3014130136 const pt = sema.pt;
3014230137 const zcu = pt.zcu;
3014330138 const operand_ty = sema.typeOf(operand);
3014430139
30140 const address_space = target_util.defaultAddressSpace(zcu.getTarget(), .local);
30141 const ptr_type = try pt.ptrType(.{
30142 .child = operand_ty.toIntern(),
30143 .flags = .{
30144 .alignment = alignment,
30145 .is_const = true,
30146 .address_space = address_space,
30147 },
30148 });
30149
3014530150 if (sema.resolveValue(operand)) |val| {
3014630151 switch (zcu.intern_pool.indexToKey(val.toIntern())) {
3014730152 .@"extern" => |e| return sema.analyzeNavRef(block, src, e.owner_nav),
3014830153 .func => |f| return sema.analyzeNavRef(block, src, f.owner_nav),
30149 else => return uavRef(sema, val),
30154 else => return .fromIntern(try pt.intern(.{ .ptr = .{
30155 .ty = ptr_type.toIntern(),
30156 .base_addr = .{ .uav = .{
30157 .val = val.toIntern(),
30158 .orig_ty = ptr_type.toIntern(),
30159 } },
30160 .byte_offset = 0,
30161 } })),
3015030162 }
3015130163 }
3015230164
3015330165 // No `requireRuntimeBlock`; it's okay to `ref` to a runtime value in a comptime context,
3015430166 // it's just that we can only use the *type* of the result, since the value is runtime-known.
3015530167
30156 const address_space = target_util.defaultAddressSpace(zcu.getTarget(), .local);
30157 const ptr_type = try pt.ptrType(.{
30168 const mut_ptr_type = try pt.ptrType(.{
3015830169 .child = operand_ty.toIntern(),
3015930170 .flags = .{
30160 .is_const = true,
30171 .alignment = alignment,
30172 .is_const = false,
3016130173 .address_space = address_space,
3016230174 },
3016330175 });
30164 const mut_ptr_type = try pt.ptrType(.{
30165 .child = operand_ty.toIntern(),
30166 .flags = .{ .address_space = address_space },
30167 });
3016830176 const alloc = try block.addTy(.alloc, mut_ptr_type);
3016930177
3017030178 // In a comptime context, the store would fail, since the operand is runtime-known. But that's
src/Sema/type_resolution.zig+1-1
......@@ -147,7 +147,7 @@ pub fn ensureStructDefaultsResolved(sema: *Sema, ty: Type, src: LazySrcLoc) Sema
147147 const ip = &zcu.intern_pool;
148148
149149 assert(ip.indexToKey(ty.toIntern()) == .struct_type);
150 if (zcu.comp.config.incremental) assert(sema.dependencies.contains(.{ .type_layout = ty.toIntern() }));
150 ty.assertHasLayout(zcu);
151151
152152 try sema.declareDependency(.{ .struct_defaults = ty.toIntern() });
153153 try sema.addReferenceEntry(null, src, .wrap(.{ .struct_defaults = ty.toIntern() }));
src/Zcu/PerThread.zig+21-1
......@@ -4112,7 +4112,27 @@ pub fn enumValueFieldIndex(pt: Zcu.PerThread, ty: Type, field_index: u32) Alloca
41124112
41134113pub fn undefValue(pt: Zcu.PerThread, ty: Type) Allocator.Error!Value {
41144114 if (std.debug.runtime_safety) {
4115 assert(ty.classify(pt.zcu) != .one_possible_value);
4115 // TODO: values of type `struct { comptime x: u8 = undefined }` are currently represented as
4116 // undef. This is wrong: they should really be represented as empty aggregates instead,
4117 // because `comptime` fields shouldn't factor into that decision! This is implemented
4118 // through logic in `aggregateValue` and requires this weird workaround in what ought to be
4119 // a straightforward assertion:
4120 //assert(ty.classify(pt.zcu) != .one_possible_value);
4121 if (ty.classify(pt.zcu) == .one_possible_value) {
4122 const ip = &pt.zcu.intern_pool;
4123 switch (ip.indexToKey(ty.toIntern())) {
4124 else => unreachable, // assertion failure
4125 .struct_type => {
4126 const comptime_bits = ip.loadStructType(ty.toIntern()).field_is_comptime_bits.getAll(ip);
4127 for (comptime_bits) |bag| {
4128 if (@popCount(bag) > 0) break;
4129 } else unreachable; // assertion failure
4130 },
4131 .tuple_type => |tuple| for (tuple.values.get(ip)) |val| {
4132 if (val != .none) break;
4133 } else unreachable, // assertion failure
4134 }
4135 }
41164136 }
41174137 return .fromInterned(try pt.intern(.{ .undef = ty.toIntern() }));
41184138}
src/codegen/spirv/CodeGen.zig+1-1
......@@ -689,7 +689,7 @@ fn constInt(cg: *CodeGen, ty: Type, value: anytype) !Id {
689689 .comptime_int => if (value < 0) .signed else .unsigned,
690690 else => unreachable,
691691 };
692 if (@sizeOf(@TypeOf(value)) >= 4 and big_int) {
692 if (@TypeOf(value) != comptime_int and @sizeOf(@TypeOf(value)) >= 4 and big_int) {
693693 const value64: u64 = switch (signedness) {
694694 .signed => @bitCast(@as(i64, @intCast(value))),
695695 .unsigned => @as(u64, @intCast(value)),
src/codegen/x86_64/CodeGen.zig+1-1
......@@ -181111,7 +181111,7 @@ fn resolveCallingConventionValues(
181111181111 var ret_sse = abi.getCAbiSseReturnRegs(cc);
181112181112 var ret_x87 = abi.getCAbiX87ReturnRegs(cc);
181113181113
181114 const classes = switch (cc) {
181114 const classes: []const abi.Class = switch (cc) {
181115181115 .x86_64_sysv => std.mem.sliceTo(&abi.classifySystemV(ret_ty, zcu, cg.target, .ret), .none),
181116181116 .x86_64_win => &.{abi.classifyWindows(ret_ty, zcu, cg.target, .ret)},
181117181117 else => unreachable,