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) {...@@ -4160,7 +4160,7 @@ pub const RUNTIME_FUNCTION = switch (native_arch) {
4160 BeginAddress: DWORD,4160 BeginAddress: DWORD,
4161 DUMMYUNIONNAME: extern union {4161 DUMMYUNIONNAME: extern union {
4162 UnwindData: DWORD,4162 UnwindData: DWORD,
4163 DUMMYSTRUCTNAME: packed struct {4163 DUMMYSTRUCTNAME: packed struct(u32) {
4164 Flag: u2,4164 Flag: u2,
4165 FunctionLength: u11,4165 FunctionLength: u11,
4166 Ret: u2,4166 Ret: u2,
...@@ -4177,7 +4177,7 @@ pub const RUNTIME_FUNCTION = switch (native_arch) {...@@ -4177,7 +4177,7 @@ pub const RUNTIME_FUNCTION = switch (native_arch) {
4177 BeginAddress: DWORD,4177 BeginAddress: DWORD,
4178 DUMMYUNIONNAME: extern union {4178 DUMMYUNIONNAME: extern union {
4179 UnwindData: DWORD,4179 UnwindData: DWORD,
4180 DUMMYSTRUCTNAME: packed struct {4180 DUMMYSTRUCTNAME: packed struct(u32) {
4181 Flag: u2,4181 Flag: u2,
4182 FunctionLength: u11,4182 FunctionLength: u11,
4183 RegF: u3,4183 RegF: u3,
...@@ -5013,7 +5013,7 @@ pub const KUSER_SHARED_DATA = extern struct {...@@ -5013,7 +5013,7 @@ pub const KUSER_SHARED_DATA = extern struct {
5013 KdDebuggerEnabled: BOOLEAN,5013 KdDebuggerEnabled: BOOLEAN,
5014 DummyUnion1: extern union {5014 DummyUnion1: extern union {
5015 MitigationPolicies: UCHAR,5015 MitigationPolicies: UCHAR,
5016 Alt: packed struct {5016 Alt: packed struct(u8) {
5017 NXSupportPolicy: u2,5017 NXSupportPolicy: u2,
5018 SEHValidationPolicy: u2,5018 SEHValidationPolicy: u2,
5019 CurDirDevicesSkippedForDlls: u2,5019 CurDirDevicesSkippedForDlls: u2,
...@@ -5029,7 +5029,7 @@ pub const KUSER_SHARED_DATA = extern struct {...@@ -5029,7 +5029,7 @@ pub const KUSER_SHARED_DATA = extern struct {
5029 SafeBootMode: BOOLEAN,5029 SafeBootMode: BOOLEAN,
5030 DummyUnion2: extern union {5030 DummyUnion2: extern union {
5031 VirtualizationFlags: UCHAR,5031 VirtualizationFlags: UCHAR,
5032 Alt: packed struct {5032 Alt: packed struct(u8) {
5033 ArchStartedInEl2: u1,5033 ArchStartedInEl2: u1,
5034 QcSlIsSupported: u1,5034 QcSlIsSupported: u1,
5035 SpareBits: u6,5035 SpareBits: u6,
...@@ -5038,7 +5038,7 @@ pub const KUSER_SHARED_DATA = extern struct {...@@ -5038,7 +5038,7 @@ pub const KUSER_SHARED_DATA = extern struct {
5038 Reserved12: [2]UCHAR,5038 Reserved12: [2]UCHAR,
5039 DummyUnion3: extern union {5039 DummyUnion3: extern union {
5040 SharedDataFlags: ULONG,5040 SharedDataFlags: ULONG,
5041 Alt: packed struct {5041 Alt: packed struct(u32) {
5042 DbgErrorPortPresent: u1,5042 DbgErrorPortPresent: u1,
5043 DbgElevationEnabled: u1,5043 DbgElevationEnabled: u1,
5044 DbgVirtEnabled: u1,5044 DbgVirtEnabled: u1,
src/Sema.zig+28-20
...@@ -3081,7 +3081,7 @@ fn zirRef(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins...@@ -3081,7 +3081,7 @@ fn zirRef(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins
30813081
3082 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_tok;3082 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_tok;
3083 const operand = sema.resolveInst(inst_data.operand);3083 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);
3085}3085}
30863086
3087fn zirEnsureResultUsed(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void {3087fn zirEnsureResultUsed(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void {
...@@ -18690,7 +18690,7 @@ fn zirStructInit(...@@ -18690,7 +18690,7 @@ fn zirStructInit(
18690 const union_val = try sema.bitCast(block, resolved_ty, init_inst, src, field_src);18690 const union_val = try sema.bitCast(block, resolved_ty, init_inst, src, field_src);
18691 const result_val = try sema.coerce(block, result_ty, union_val, src);18691 const result_val = try sema.coerce(block, result_ty, union_val, src);
18692 if (is_ref) {18692 if (is_ref) {
18693 return sema.analyzeRef(block, src, result_val);18693 return sema.analyzeRef(block, src, result_val, .none);
18694 } else {18694 } else {
18695 return result_val;18695 return result_val;
18696 }18696 }
...@@ -24192,7 +24192,7 @@ fn zirMemcpy(...@@ -24192,7 +24192,7 @@ fn zirMemcpy(
24192 }24192 }
24193 } else if (dest_len == .none and len_val == null) {24193 } else if (dest_len == .none and len_val == null) {
24194 // Change the dest to a slice, since its type must have the length.24194 // 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);
24196 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);24196 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);
24197 const new_src_ptr_ty = sema.typeOf(new_src_ptr);24197 const new_src_ptr_ty = sema.typeOf(new_src_ptr);
24198 if (new_src_ptr_ty.isSlice(zcu)) {24198 if (new_src_ptr_ty.isSlice(zcu)) {
...@@ -26301,7 +26301,7 @@ fn structFieldPtr(...@@ -26301,7 +26301,7 @@ fn structFieldPtr(
26301 const field_index: u32 = if (struct_ty.isTuple(zcu)) field_index: {26301 const field_index: u32 = if (struct_ty.isTuple(zcu)) field_index: {
26302 if (field_name.eqlSlice("len", ip)) {26302 if (field_name.eqlSlice("len", ip)) {
26303 const len_inst = try pt.intRef(.usize, struct_ty.structFieldCount(zcu));26303 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);
26305 }26305 }
26306 break :field_index try sema.tupleFieldIndex(block, struct_ty, field_name, field_name_src);26306 break :field_index try sema.tupleFieldIndex(block, struct_ty, field_name, field_name_src);
26307 } else field_index: {26307 } else field_index: {
...@@ -29787,10 +29787,7 @@ fn coerceTupleToSlicePtrs(...@@ -29787,10 +29787,7 @@ fn coerceTupleToSlicePtrs(
29787 .child = slice_info.child,29787 .child = slice_info.child,
29788 });29788 });
29789 const array_inst = try sema.coerceTupleToArray(block, array_ty, slice_ty_src, tuple, tuple_src);29789 const array_inst = try sema.coerceTupleToArray(block, array_ty, slice_ty_src, tuple, tuple_src);
29790 if (slice_info.flags.alignment != .none) {29790 const ptr_array = try sema.analyzeRef(block, slice_ty_src, array_inst, slice_info.flags.alignment);
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);
29794 return sema.coerceArrayPtrToSlice(block, slice_ty, ptr_array, slice_ty_src);29791 return sema.coerceArrayPtrToSlice(block, slice_ty, ptr_array, slice_ty_src);
29795}29792}
2979629793
...@@ -29809,10 +29806,7 @@ fn coerceTupleToArrayPtrs(...@@ -29809,10 +29806,7 @@ fn coerceTupleToArrayPtrs(
29809 const ptr_info = ptr_array_ty.ptrInfo(zcu);29806 const ptr_info = ptr_array_ty.ptrInfo(zcu);
29810 const array_ty: Type = .fromInterned(ptr_info.child);29807 const array_ty: Type = .fromInterned(ptr_info.child);
29811 const array_inst = try sema.coerceTupleToArray(block, array_ty, array_ty_src, tuple, tuple_src);29808 const array_inst = try sema.coerceTupleToArray(block, array_ty, array_ty_src, tuple, tuple_src);
29812 if (ptr_info.flags.alignment != .none) {29809 const ptr_array = try sema.analyzeRef(block, array_ty_src, array_inst, ptr_info.flags.alignment);
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);
29816 return ptr_array;29810 return ptr_array;
29817}29811}
2981829812
...@@ -30137,34 +30131,48 @@ fn analyzeRef(...@@ -30137,34 +30131,48 @@ fn analyzeRef(
30137 block: *Block,30131 block: *Block,
30138 src: LazySrcLoc,30132 src: LazySrcLoc,
30139 operand: Air.Inst.Ref,30133 operand: Air.Inst.Ref,
30134 alignment: Alignment,
30140) CompileError!Air.Inst.Ref {30135) CompileError!Air.Inst.Ref {
30141 const pt = sema.pt;30136 const pt = sema.pt;
30142 const zcu = pt.zcu;30137 const zcu = pt.zcu;
30143 const operand_ty = sema.typeOf(operand);30138 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
30145 if (sema.resolveValue(operand)) |val| {30150 if (sema.resolveValue(operand)) |val| {
30146 switch (zcu.intern_pool.indexToKey(val.toIntern())) {30151 switch (zcu.intern_pool.indexToKey(val.toIntern())) {
30147 .@"extern" => |e| return sema.analyzeNavRef(block, src, e.owner_nav),30152 .@"extern" => |e| return sema.analyzeNavRef(block, src, e.owner_nav),
30148 .func => |f| return sema.analyzeNavRef(block, src, f.owner_nav),30153 .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 } })),
30150 }30162 }
30151 }30163 }
3015230164
30153 // No `requireRuntimeBlock`; it's okay to `ref` to a runtime value in a comptime context,30165 // No `requireRuntimeBlock`; it's okay to `ref` to a runtime value in a comptime context,
30154 // it's just that we can only use the *type* of the result, since the value is runtime-known.30166 // 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);30168 const mut_ptr_type = try pt.ptrType(.{
30157 const ptr_type = try pt.ptrType(.{
30158 .child = operand_ty.toIntern(),30169 .child = operand_ty.toIntern(),
30159 .flags = .{30170 .flags = .{
30160 .is_const = true,30171 .alignment = alignment,
30172 .is_const = false,
30161 .address_space = address_space,30173 .address_space = address_space,
30162 },30174 },
30163 });30175 });
30164 const mut_ptr_type = try pt.ptrType(.{
30165 .child = operand_ty.toIntern(),
30166 .flags = .{ .address_space = address_space },
30167 });
30168 const alloc = try block.addTy(.alloc, mut_ptr_type);30176 const alloc = try block.addTy(.alloc, mut_ptr_type);
3016930177
30170 // In a comptime context, the store would fail, since the operand is runtime-known. But that's30178 // 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...@@ -147,7 +147,7 @@ pub fn ensureStructDefaultsResolved(sema: *Sema, ty: Type, src: LazySrcLoc) Sema
147 const ip = &zcu.intern_pool;147 const ip = &zcu.intern_pool;
148148
149 assert(ip.indexToKey(ty.toIntern()) == .struct_type);149 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
152 try sema.declareDependency(.{ .struct_defaults = ty.toIntern() });152 try sema.declareDependency(.{ .struct_defaults = ty.toIntern() });
153 try sema.addReferenceEntry(null, src, .wrap(.{ .struct_defaults = ty.toIntern() }));153 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...@@ -4112,7 +4112,27 @@ pub fn enumValueFieldIndex(pt: Zcu.PerThread, ty: Type, field_index: u32) Alloca
41124112
4113pub fn undefValue(pt: Zcu.PerThread, ty: Type) Allocator.Error!Value {4113pub fn undefValue(pt: Zcu.PerThread, ty: Type) Allocator.Error!Value {
4114 if (std.debug.runtime_safety) {4114 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 }
4116 }4136 }
4117 return .fromInterned(try pt.intern(.{ .undef = ty.toIntern() }));4137 return .fromInterned(try pt.intern(.{ .undef = ty.toIntern() }));
4118}4138}
src/codegen/spirv/CodeGen.zig+1-1
...@@ -689,7 +689,7 @@ fn constInt(cg: *CodeGen, ty: Type, value: anytype) !Id {...@@ -689,7 +689,7 @@ fn constInt(cg: *CodeGen, ty: Type, value: anytype) !Id {
689 .comptime_int => if (value < 0) .signed else .unsigned,689 .comptime_int => if (value < 0) .signed else .unsigned,
690 else => unreachable,690 else => unreachable,
691 };691 };
692 if (@sizeOf(@TypeOf(value)) >= 4 and big_int) {692 if (@TypeOf(value) != comptime_int and @sizeOf(@TypeOf(value)) >= 4 and big_int) {
693 const value64: u64 = switch (signedness) {693 const value64: u64 = switch (signedness) {
694 .signed => @bitCast(@as(i64, @intCast(value))),694 .signed => @bitCast(@as(i64, @intCast(value))),
695 .unsigned => @as(u64, @intCast(value)),695 .unsigned => @as(u64, @intCast(value)),
src/codegen/x86_64/CodeGen.zig+1-1
...@@ -181111,7 +181111,7 @@ fn resolveCallingConventionValues(...@@ -181111,7 +181111,7 @@ fn resolveCallingConventionValues(
181111 var ret_sse = abi.getCAbiSseReturnRegs(cc);181111 var ret_sse = abi.getCAbiSseReturnRegs(cc);
181112 var ret_x87 = abi.getCAbiX87ReturnRegs(cc);181112 var ret_x87 = abi.getCAbiX87ReturnRegs(cc);
181113181113
181114 const classes = switch (cc) {181114 const classes: []const abi.Class = switch (cc) {
181115 .x86_64_sysv => std.mem.sliceTo(&abi.classifySystemV(ret_ty, zcu, cg.target, .ret), .none),181115 .x86_64_sysv => std.mem.sliceTo(&abi.classifySystemV(ret_ty, zcu, cg.target, .ret), .none),
181116 .x86_64_win => &.{abi.classifyWindows(ret_ty, zcu, cg.target, .ret)},181116 .x86_64_win => &.{abi.classifyWindows(ret_ty, zcu, cg.target, .ret)},
181117 else => unreachable,181117 else => unreachable,