authorgravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2026-02-11 14:57:59+00:00
committergravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2026-03-10 10:26:11+00:00
log7170e0f02043d157cb4e10c6333e125c10395a63
tree3be7af479a7b667df1f4d4d93f8018bf2694fc2b
parent774911b4ce6c1aef44b33aee90ca341ab2fe669d
signaturelock-open Commit is signed but in an unrecognized format.

Sema: small fixes


2 files changed, 38 insertions(+), 20 deletions(-)

src/Sema.zig+36-18
......@@ -15263,17 +15263,29 @@ fn analyzeArithmetic(
1526315263 if (zir_tag != .sub) {
1526415264 return sema.failWithInvalidPtrArithmetic(block, src, "pointer-pointer", "subtraction");
1526515265 }
15266 if (!lhs_ty.childType(zcu).eql(rhs_ty.childType(zcu), zcu)) {
15266
15267 // MLUGG TODO: these semantics are insane and matching them is causing my soul to fragment into a thousand pieces
15268 const lhs_elem_ty = ty: {
15269 const ptr_elem_ty = lhs_ty.childType(zcu);
15270 if (lhs_ty.ptrSize(zcu) == .one and ptr_elem_ty.isArrayOrVector(zcu)) break :ty ptr_elem_ty.childType(zcu);
15271 break :ty ptr_elem_ty;
15272 };
15273 const rhs_elem_ty = ty: {
15274 const ptr_elem_ty = rhs_ty.childType(zcu);
15275 if (rhs_ty.ptrSize(zcu) == .one and ptr_elem_ty.isArrayOrVector(zcu)) break :ty ptr_elem_ty.childType(zcu);
15276 break :ty ptr_elem_ty;
15277 };
15278 if (lhs_elem_ty.toIntern() != rhs_elem_ty.toIntern()) {
1526715279 return sema.fail(block, src, "incompatible pointer arithmetic operands '{f}' and '{f}'", .{
1526815280 lhs_ty.fmt(pt), rhs_ty.fmt(pt),
1526915281 });
1527015282 }
1527115283
15272 try sema.ensureLayoutResolved(lhs_ty.childType(zcu), src, .ptr_offset);
15273 const elem_size = lhs_ty.childType(zcu).abiSize(zcu);
15284 try sema.ensureLayoutResolved(lhs_elem_ty, src, .ptr_offset);
15285 const elem_size = lhs_elem_ty.abiSize(zcu);
1527415286 if (elem_size == 0) {
1527515287 return sema.fail(block, src, "pointer subtraction requires element type '{f}' to have runtime bits", .{
15276 lhs_ty.childType(zcu).fmt(pt),
15288 lhs_elem_ty.fmt(pt),
1527715289 });
1527815290 }
1527915291
......@@ -16293,20 +16305,24 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1629316305 const func_ty_info = zcu.typeToFunc(ty).?;
1629416306 const param_vals = try sema.arena.alloc(InternPool.Index, func_ty_info.param_types.len);
1629516307 var func_is_generic = false;
16296 for (param_vals, 0..) |*param_val, i| {
16297 const param_ty = func_ty_info.param_types.get(ip)[i];
16308
16309 for (param_vals, 0..) |*param_val, param_index| {
16310 const param_ty = func_ty_info.param_types.get(ip)[param_index];
1629816311 const is_generic = param_ty == .generic_poison_type;
16299 if (is_generic or Type.fromInterned(param_ty).comptimeOnly(zcu)) func_is_generic = true;
16312 const is_noalias, const is_comptime = flags: {
16313 const i = std.math.cast(u5, param_index) orelse break :flags .{ false, false };
16314 break :flags .{ func_ty_info.paramIsNoalias(i), func_ty_info.paramIsComptime(i) };
16315 };
16316
16317 if (is_generic or is_comptime or Type.fromInterned(param_ty).comptimeOnly(zcu)) {
16318 func_is_generic = true;
16319 }
16320
1630016321 const param_ty_val = try pt.intern(.{ .opt = .{
1630116322 .ty = try pt.intern(.{ .opt_type = .type_type }),
1630216323 .val = if (is_generic) .none else param_ty,
1630316324 } });
1630416325
16305 const is_noalias = blk: {
16306 const index = std.math.cast(u5, i) orelse break :blk false;
16307 break :blk @as(u1, @truncate(func_ty_info.noalias_bits >> index)) != 0;
16308 };
16309
1631016326 const param_fields = .{
1631116327 // is_generic: bool,
1631216328 Value.makeBool(is_generic).toIntern(),
......@@ -16348,15 +16364,17 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1634816364
1634916365 const ret_ty_is_generic = generic: {
1635016366 const ret_ty: Type = .fromInterned(func_ty_info.return_type);
16351 if (ret_ty.toIntern() == .generic_poison_type) break :generic true;
16352 if (ret_ty.zigTypeTag(zcu) == .error_union) {
16353 if (ret_ty.errorUnionPayload(zcu).toIntern() == .generic_poison_type) {
16354 break :generic true;
16355 }
16367 if (ret_ty.toIntern() == .generic_poison_type or
16368 (ret_ty.zigTypeTag(zcu) == .error_union and
16369 ret_ty.errorUnionPayload(zcu).toIntern() == .generic_poison_type))
16370 {
16371 break :generic true;
1635616372 }
1635716373 break :generic false;
1635816374 };
16359 if (ret_ty_is_generic) func_is_generic = true;
16375 if (ret_ty_is_generic or Type.fromInterned(func_ty_info.return_type).comptimeOnly(zcu)) {
16376 func_is_generic = true;
16377 }
1636016378
1636116379 const ret_ty_opt = try pt.intern(.{ .opt = .{
1636216380 .ty = try pt.intern(.{ .opt_type = .type_type }),
src/Sema/type_resolution.zig+2-2
......@@ -585,8 +585,8 @@ pub fn resolveUnionLayout(sema: *Sema, union_ty: Type) CompileError!void {
585585 .int_tag_mode = switch (union_obj.is_reified) {
586586 true => .auto,
587587 false => switch (sema.code.getUnionDecl(zir_index).kind) {
588 .tagged_enum_explicit => .auto,
589 else => .explicit,
588 .tagged_enum_explicit => .explicit,
589 else => .auto,
590590 },
591591 },
592592 .fields_len = @intCast(union_obj.field_types.len),