zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

commit abd649a50c500706c37e8e8859bb4bd6fec2006a (tree)
parent 4140c9a2c7f5caa626ba0246d5a0905e45ddb12d
Author: Krzysztof Wolicki <der.teufel.mail@gmail.com>
Date:   Tue,  2 Jun 2026 17:20:25 +0200

Fix TODO in `Type.eql`

Diffstat:
Msrc/RangeSet.zig | 8++++----
Msrc/Sema.zig | 38+++++++++++++++++++-------------------
Msrc/Type.zig | 3+--
Msrc/codegen/c.zig | 6+++---
Msrc/codegen/riscv64/CodeGen.zig | 2+-
Msrc/codegen/sparc64/CodeGen.zig | 12++++++------
Msrc/codegen/spirv/CodeGen.zig | 2+-
7 files changed, 35 insertions(+), 36 deletions(-)

diff --git a/src/RangeSet.zig b/src/RangeSet.zig @@ -20,8 +20,8 @@ pub fn ensureUnusedCapacity(self: *RangeSet, allocator: Allocator, additional_co } pub fn addAssumeCapacity(set: *RangeSet, new: Range, ty: Type, zcu: *Zcu) ?LazySrcLoc { - assert(new.first.typeOf(zcu).eql(ty, zcu)); - assert(new.last.typeOf(zcu).eql(ty, zcu)); + assert(new.first.typeOf(zcu).eql(ty)); + assert(new.last.typeOf(zcu).eql(ty)); for (set.ranges.items) |range| { if (new.last.compareScalar(.gte, range.first, ty, zcu) and @@ -56,8 +56,8 @@ pub fn spans( ty: Type, zcu: *Zcu, ) Allocator.Error!bool { - assert(first.typeOf(zcu).eql(ty, zcu)); - assert(last.typeOf(zcu).eql(ty, zcu)); + assert(first.typeOf(zcu).eql(ty)); + assert(last.typeOf(zcu).eql(ty)); if (set.ranges.items.len == 0) return false; std.mem.sort(Range, set.ranges.items, SortCtx{ .ty = ty, .zcu = zcu }, lessThan); diff --git a/src/Sema.zig b/src/Sema.zig @@ -5462,7 +5462,7 @@ fn resolveAnalyzedBlock( const br_operand = sema.air_instructions.items(.data)[@intFromEnum(br)].br.operand; const br_operand_src = src; const br_operand_ty = sema.typeOf(br_operand); - if (br_operand_ty.eql(resolved_ty, zcu)) { + if (br_operand_ty.eql(resolved_ty)) { // No type coercion needed. continue; } @@ -12092,7 +12092,7 @@ fn analyzeSwitchPayloadCaptureTaggedUnion( // PTR! This will also allow us to emit simpler code. const same_types = for (field_indices[1..]) |field_idx| { const field_ty: Type = .fromInterned(union_obj.field_types.get(ip)[field_idx]); - if (!field_ty.eql(first_field_ty, zcu)) break false; + if (!field_ty.eql(first_field_ty)) break false; } else true; const capture_ty: Type = capture_ty: { @@ -15301,7 +15301,7 @@ fn zirCmpEq( if (lhs_ty_tag == .type and rhs_ty_tag == .type) { const lhs_as_type = try sema.analyzeAsType(block, lhs_src, .type, lhs); const rhs_as_type = try sema.analyzeAsType(block, rhs_src, .type, rhs); - return if (lhs_as_type.eql(rhs_as_type, zcu) == (op == .eq)) .bool_true else .bool_false; + return if (lhs_as_type.eql(rhs_as_type) == (op == .eq)) .bool_true else .bool_false; } return sema.analyzeCmp(block, src, lhs, rhs, op, lhs_src, rhs_src, true); } @@ -26437,7 +26437,7 @@ fn fieldCallBind( (first_param_type.zigTypeTag(zcu) == .pointer and (first_param_type.ptrSize(zcu) == .one or first_param_type.ptrSize(zcu) == .c) and - first_param_type.childType(zcu).eql(concrete_ty, zcu))) + first_param_type.childType(zcu).eql(concrete_ty))) { // Note that if the param type is generic poison, we know that it must // specifically be `anytype` since it's the first parameter, meaning we @@ -26448,7 +26448,7 @@ fn fieldCallBind( .func_inst = decl_val, .arg0_inst = object_ptr, } }; - } else if (first_param_type.eql(concrete_ty, zcu)) { + } else if (first_param_type.eql(concrete_ty)) { const deref = try sema.analyzeLoad(block, src, object_ptr, src); return .{ .method = .{ .func_inst = decl_val, @@ -26456,7 +26456,7 @@ fn fieldCallBind( } }; } else if (first_param_type.zigTypeTag(zcu) == .optional) { const child = first_param_type.optionalChild(zcu); - if (child.eql(concrete_ty, zcu)) { + if (child.eql(concrete_ty)) { const deref = try sema.analyzeLoad(block, src, object_ptr, src); return .{ .method = .{ .func_inst = decl_val, @@ -26464,7 +26464,7 @@ fn fieldCallBind( } }; } else if (child.zigTypeTag(zcu) == .pointer and child.ptrSize(zcu) == .one and - child.childType(zcu).eql(concrete_ty, zcu)) + child.childType(zcu).eql(concrete_ty)) { return .{ .method = .{ .func_inst = decl_val, @@ -26472,7 +26472,7 @@ fn fieldCallBind( } }; } } else if (first_param_type.zigTypeTag(zcu) == .error_union and - first_param_type.errorUnionPayload(zcu).eql(concrete_ty, zcu)) + first_param_type.errorUnionPayload(zcu).eql(concrete_ty)) { const deref = try sema.analyzeLoad(block, src, object_ptr, src); return .{ .method = .{ @@ -27675,7 +27675,7 @@ fn coerceExtra( try sema.ensureLayoutResolved(dest_ty, inst_src, .coerce); // If the types are the same, we can return the operand. - if (dest_ty.eql(inst_ty, zcu)) + if (dest_ty.eql(inst_ty)) return inst; const maybe_inst_val = sema.resolveValue(inst); @@ -28726,7 +28726,7 @@ pub fn coerceInMemoryAllowed( assert(val.typeOf(zcu).toIntern() == src_ty.toIntern()); } - if (dest_ty.eql(src_ty, zcu)) + if (dest_ty.eql(src_ty)) return .ok; const dest_tag = dest_ty.zigTypeTag(zcu); @@ -32240,7 +32240,7 @@ fn resolvePeerTypesInner( .nullable => { for (peer_tys, 0..) |opt_ty, i| { const ty = opt_ty orelse continue; - if (!ty.eql(.null, zcu)) return .{ .conflict = .{ + if (!ty.eql(.null)) return .{ .conflict = .{ .peer_idx_a = strat_reason, .peer_idx_b = i, } }; @@ -32328,7 +32328,7 @@ fn resolvePeerTypesInner( } }; const peer_elem_ty = ty.childType(zcu); - if (!peer_elem_ty.eql(elem_ty, zcu)) coerce: { + if (!peer_elem_ty.eql(elem_ty)) coerce: { const peer_elem_coerces_to_elem = try sema.coerceInMemoryAllowed(block, elem_ty, peer_elem_ty, false, zcu.getTarget(), src, src, null); if (peer_elem_coerces_to_elem == .ok) { @@ -32909,11 +32909,11 @@ fn resolvePeerTypesInner( .@"enum" => switch (ty.zigTypeTag(zcu)) { .enum_literal => {}, .@"enum" => { - if (!ty.eql(cur_ty, zcu)) return generic_err; + if (!ty.eql(cur_ty)) return generic_err; }, .@"union" => { const tag_ty = ty.unionTagTypeHypothetical(zcu); - if (!tag_ty.eql(cur_ty, zcu)) return generic_err; + if (!tag_ty.eql(cur_ty)) return generic_err; opt_cur_ty = ty; cur_ty_idx = i; }, @@ -32923,10 +32923,10 @@ fn resolvePeerTypesInner( .enum_literal => {}, .@"enum" => { const cur_tag_ty = cur_ty.unionTagTypeHypothetical(zcu); - if (!ty.eql(cur_tag_ty, zcu)) return generic_err; + if (!ty.eql(cur_tag_ty)) return generic_err; }, .@"union" => { - if (!ty.eql(cur_ty, zcu)) return generic_err; + if (!ty.eql(cur_ty)) return generic_err; }, else => unreachable, }, @@ -33059,7 +33059,7 @@ fn resolvePeerTypesInner( .comptime_float, .comptime_int, .int => {}, .float => { if (opt_cur_ty) |cur_ty| { - if (cur_ty.eql(ty, zcu)) continue; + if (cur_ty.eql(ty)) continue; // Recreate the type so we eliminate any c_longdouble const bits = @max(cur_ty.floatBits(target), ty.floatBits(target)); opt_cur_ty = switch (bits) { @@ -33234,7 +33234,7 @@ fn resolvePeerTypesInner( for (peer_tys, 0..) |opt_ty, i| { const ty = opt_ty orelse continue; if (expect_ty) |expect| { - if (!ty.eql(expect, zcu)) return .{ .conflict = .{ + if (!ty.eql(expect)) return .{ .conflict = .{ .peer_idx_a = first_idx, .peer_idx_b = i, } }; @@ -33300,7 +33300,7 @@ fn typeIsArrayLike(sema: *Sema, ty: Type) ?ArrayLike { }; const elem_ty = ty.fieldType(0, zcu); for (1..field_count) |i| { - if (!ty.fieldType(i, zcu).eql(elem_ty, zcu)) { + if (!ty.fieldType(i, zcu).eql(elem_ty)) { return null; } } diff --git a/src/Type.zig b/src/Type.zig @@ -385,8 +385,7 @@ pub fn ptrInfo(ty: Type, zcu: *const Zcu) InternPool.Key.PtrType { }; } -pub fn eql(a: Type, b: Type, zcu: *const Zcu) bool { - _ = zcu; // TODO: remove this parameter +pub fn eql(a: Type, b: Type) bool { // The InternPool data structure hashes based on Key to make interned objects // unique. An Index can be treated simply as u32 value for the // purpose of Type/Value hashing and equality. diff --git a/src/codegen/c.zig b/src/codegen/c.zig @@ -1120,7 +1120,7 @@ pub const DeclGen = struct { } try w.writeByte('{'); const ai = ty.arrayInfo(zcu); - if (ai.elem_type.eql(.u8, zcu)) { + if (ai.elem_type.eql(.u8)) { var literal: StringLiteral = .init(w, @intCast(ty.arrayLenIncludingSentinel(zcu))); try literal.start(); var index: usize = 0; @@ -1539,7 +1539,7 @@ pub const DeclGen = struct { } try w.writeByte('{'); const ai = ty.arrayInfo(zcu); - if (ai.elem_type.eql(.u8, zcu)) { + if (ai.elem_type.eql(.u8)) { var literal: StringLiteral = .init(w, @intCast(ty.arrayLenIncludingSentinel(zcu))); try literal.start(); var index: u64 = 0; @@ -3428,7 +3428,7 @@ fn airStore(f: *Function, inst: Air.Inst.Index, safety: bool) !CValue { if (!is_aligned) { // For this memcpy to safely work we need the rhs to have the same // underlying type as the lhs (i.e. they must both be arrays of the same underlying type). - assert(src_ty.eql(.fromInterned(ptr_info.child), zcu)); + assert(src_ty.eql(.fromInterned(ptr_info.child))); const v = try Vectorize.start(f, inst, w, ptr_ty); try w.writeAll("memcpy((char *)"); diff --git a/src/codegen/riscv64/CodeGen.zig b/src/codegen/riscv64/CodeGen.zig @@ -3163,7 +3163,7 @@ fn airMulWithOverflow(func: *Func, inst: Air.Inst.Index) !void { switch (lhs_ty.zigTypeTag(zcu)) { else => |x| return func.fail("TODO: airMulWithOverflow {s}", .{@tagName(x)}), .int => { - if (std.debug.runtime_safety) assert(lhs_ty.eql(rhs_ty, zcu)); + if (std.debug.runtime_safety) assert(lhs_ty.eql(rhs_ty)); const trunc_reg = try func.copyToTmpRegister(lhs_ty, .{ .register = dest_reg }); const trunc_reg_lock = func.register_manager.lockRegAssumeUnused(trunc_reg); diff --git a/src/codegen/sparc64/CodeGen.zig b/src/codegen/sparc64/CodeGen.zig @@ -744,7 +744,7 @@ fn airAddSubWithOverflow(self: *Self, inst: Air.Inst.Index) !void { switch (lhs_ty.zigTypeTag(zcu)) { .vector => return self.fail("TODO implement add_with_overflow/sub_with_overflow for vectors", .{}), .int => { - assert(lhs_ty.eql(rhs_ty, zcu)); + assert(lhs_ty.eql(rhs_ty)); const int_info = lhs_ty.intInfo(zcu); switch (int_info.bits) { 32, 64 => { @@ -1797,7 +1797,7 @@ fn airMod(self: *Self, inst: Air.Inst.Index) !void { const rhs = try self.resolveInst(bin_op.rhs); const lhs_ty = self.typeOf(bin_op.lhs); const rhs_ty = self.typeOf(bin_op.rhs); - assert(lhs_ty.eql(rhs_ty, self.pt.zcu)); + assert(lhs_ty.eql(rhs_ty)); if (self.liveness.isUnused(inst)) return self.finishAir(inst, .dead, .{ bin_op.lhs, bin_op.rhs, .none }); @@ -1950,7 +1950,7 @@ fn airMulWithOverflow(self: *Self, inst: Air.Inst.Index) !void { switch (lhs_ty.zigTypeTag(zcu)) { .vector => return self.fail("TODO implement mul_with_overflow for vectors", .{}), .int => { - assert(lhs_ty.eql(rhs_ty, zcu)); + assert(lhs_ty.eql(rhs_ty)); const int_info = lhs_ty.intInfo(zcu); switch (int_info.bits) { 1...32 => { @@ -2780,7 +2780,7 @@ fn binOp( .float => return self.fail("TODO binary operations on floats", .{}), .vector => return self.fail("TODO binary operations on vectors", .{}), .int => { - assert(lhs_ty.eql(rhs_ty, zcu)); + assert(lhs_ty.eql(rhs_ty)); const int_info = lhs_ty.intInfo(zcu); if (int_info.bits <= 64) { // Only say yes if the operation is @@ -2870,7 +2870,7 @@ fn binOp( switch (lhs_ty.zigTypeTag(zcu)) { .vector => return self.fail("TODO binary operations on vectors", .{}), .int => { - assert(lhs_ty.eql(rhs_ty, zcu)); + assert(lhs_ty.eql(rhs_ty)); const int_info = lhs_ty.intInfo(zcu); if (int_info.bits <= 64) { const rhs_immediate_ok = switch (tag) { @@ -4226,7 +4226,7 @@ fn minMax( ) InnerError!MCValue { const pt = self.pt; const zcu = pt.zcu; - assert(lhs_ty.eql(rhs_ty, zcu)); + assert(lhs_ty.eql(rhs_ty)); switch (lhs_ty.zigTypeTag(zcu)) { .float => return self.fail("TODO min/max on floats", .{}), .vector => return self.fail("TODO min/max on vectors", .{}), diff --git a/src/codegen/spirv/CodeGen.zig b/src/codegen/spirv/CodeGen.zig @@ -4633,7 +4633,7 @@ fn unionInit( const layout_payload_ty_id = try cg.resolveType(layout.payload_ty, .indirect); const pl_ptr_ty_id = try cg.module.ptrType(layout_payload_ty_id, .function); const pl_ptr_id = try cg.accessChain(pl_ptr_ty_id, tmp_id, &.{layout.payload_index}); - const active_pl_ptr_id = if (!layout.payload_ty.eql(payload_ty, zcu)) blk: { + const active_pl_ptr_id = if (!layout.payload_ty.eql(payload_ty)) blk: { const payload_ty_id = try cg.resolveType(payload_ty, .indirect); const active_pl_ptr_ty_id = try cg.module.ptrType(payload_ty_id, .function); const active_pl_ptr_id = cg.module.allocId();