authorgravatar for der.teufel.mail@gmail.comKrzysztof Wolicki <der.teufel.mail@gmail.com> 2026-06-02 17:20:25+02:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2026-06-07 05:44:13+02:00
logabd649a50c500706c37e8e8859bb4bd6fec2006a
treee8b964d45d729743a7b06e0fea8de961c4051d6c
parent4140c9a2c7f5caa626ba0246d5a0905e45ddb12d

Fix TODO in `Type.eql`


7 files changed, 35 insertions(+), 36 deletions(-)

src/RangeSet.zig+4-4
......@@ -20,8 +20,8 @@ pub fn ensureUnusedCapacity(self: *RangeSet, allocator: Allocator, additional_co
2020}
2121
2222pub fn addAssumeCapacity(set: *RangeSet, new: Range, ty: Type, zcu: *Zcu) ?LazySrcLoc {
23 assert(new.first.typeOf(zcu).eql(ty, zcu));
24 assert(new.last.typeOf(zcu).eql(ty, zcu));
23 assert(new.first.typeOf(zcu).eql(ty));
24 assert(new.last.typeOf(zcu).eql(ty));
2525
2626 for (set.ranges.items) |range| {
2727 if (new.last.compareScalar(.gte, range.first, ty, zcu) and
......@@ -56,8 +56,8 @@ pub fn spans(
5656 ty: Type,
5757 zcu: *Zcu,
5858) Allocator.Error!bool {
59 assert(first.typeOf(zcu).eql(ty, zcu));
60 assert(last.typeOf(zcu).eql(ty, zcu));
59 assert(first.typeOf(zcu).eql(ty));
60 assert(last.typeOf(zcu).eql(ty));
6161 if (set.ranges.items.len == 0) return false;
6262
6363 std.mem.sort(Range, set.ranges.items, SortCtx{ .ty = ty, .zcu = zcu }, lessThan);
src/Sema.zig+19-19
......@@ -5462,7 +5462,7 @@ fn resolveAnalyzedBlock(
54625462 const br_operand = sema.air_instructions.items(.data)[@intFromEnum(br)].br.operand;
54635463 const br_operand_src = src;
54645464 const br_operand_ty = sema.typeOf(br_operand);
5465 if (br_operand_ty.eql(resolved_ty, zcu)) {
5465 if (br_operand_ty.eql(resolved_ty)) {
54665466 // No type coercion needed.
54675467 continue;
54685468 }
......@@ -12092,7 +12092,7 @@ fn analyzeSwitchPayloadCaptureTaggedUnion(
1209212092 // PTR! This will also allow us to emit simpler code.
1209312093 const same_types = for (field_indices[1..]) |field_idx| {
1209412094 const field_ty: Type = .fromInterned(union_obj.field_types.get(ip)[field_idx]);
12095 if (!field_ty.eql(first_field_ty, zcu)) break false;
12095 if (!field_ty.eql(first_field_ty)) break false;
1209612096 } else true;
1209712097
1209812098 const capture_ty: Type = capture_ty: {
......@@ -15301,7 +15301,7 @@ fn zirCmpEq(
1530115301 if (lhs_ty_tag == .type and rhs_ty_tag == .type) {
1530215302 const lhs_as_type = try sema.analyzeAsType(block, lhs_src, .type, lhs);
1530315303 const rhs_as_type = try sema.analyzeAsType(block, rhs_src, .type, rhs);
15304 return if (lhs_as_type.eql(rhs_as_type, zcu) == (op == .eq)) .bool_true else .bool_false;
15304 return if (lhs_as_type.eql(rhs_as_type) == (op == .eq)) .bool_true else .bool_false;
1530515305 }
1530615306 return sema.analyzeCmp(block, src, lhs, rhs, op, lhs_src, rhs_src, true);
1530715307}
......@@ -26437,7 +26437,7 @@ fn fieldCallBind(
2643726437 (first_param_type.zigTypeTag(zcu) == .pointer and
2643826438 (first_param_type.ptrSize(zcu) == .one or
2643926439 first_param_type.ptrSize(zcu) == .c) and
26440 first_param_type.childType(zcu).eql(concrete_ty, zcu)))
26440 first_param_type.childType(zcu).eql(concrete_ty)))
2644126441 {
2644226442 // Note that if the param type is generic poison, we know that it must
2644326443 // specifically be `anytype` since it's the first parameter, meaning we
......@@ -26448,7 +26448,7 @@ fn fieldCallBind(
2644826448 .func_inst = decl_val,
2644926449 .arg0_inst = object_ptr,
2645026450 } };
26451 } else if (first_param_type.eql(concrete_ty, zcu)) {
26451 } else if (first_param_type.eql(concrete_ty)) {
2645226452 const deref = try sema.analyzeLoad(block, src, object_ptr, src);
2645326453 return .{ .method = .{
2645426454 .func_inst = decl_val,
......@@ -26456,7 +26456,7 @@ fn fieldCallBind(
2645626456 } };
2645726457 } else if (first_param_type.zigTypeTag(zcu) == .optional) {
2645826458 const child = first_param_type.optionalChild(zcu);
26459 if (child.eql(concrete_ty, zcu)) {
26459 if (child.eql(concrete_ty)) {
2646026460 const deref = try sema.analyzeLoad(block, src, object_ptr, src);
2646126461 return .{ .method = .{
2646226462 .func_inst = decl_val,
......@@ -26464,7 +26464,7 @@ fn fieldCallBind(
2646426464 } };
2646526465 } else if (child.zigTypeTag(zcu) == .pointer and
2646626466 child.ptrSize(zcu) == .one and
26467 child.childType(zcu).eql(concrete_ty, zcu))
26467 child.childType(zcu).eql(concrete_ty))
2646826468 {
2646926469 return .{ .method = .{
2647026470 .func_inst = decl_val,
......@@ -26472,7 +26472,7 @@ fn fieldCallBind(
2647226472 } };
2647326473 }
2647426474 } else if (first_param_type.zigTypeTag(zcu) == .error_union and
26475 first_param_type.errorUnionPayload(zcu).eql(concrete_ty, zcu))
26475 first_param_type.errorUnionPayload(zcu).eql(concrete_ty))
2647626476 {
2647726477 const deref = try sema.analyzeLoad(block, src, object_ptr, src);
2647826478 return .{ .method = .{
......@@ -27675,7 +27675,7 @@ fn coerceExtra(
2767527675 try sema.ensureLayoutResolved(dest_ty, inst_src, .coerce);
2767627676
2767727677 // If the types are the same, we can return the operand.
27678 if (dest_ty.eql(inst_ty, zcu))
27678 if (dest_ty.eql(inst_ty))
2767927679 return inst;
2768027680
2768127681 const maybe_inst_val = sema.resolveValue(inst);
......@@ -28726,7 +28726,7 @@ pub fn coerceInMemoryAllowed(
2872628726 assert(val.typeOf(zcu).toIntern() == src_ty.toIntern());
2872728727 }
2872828728
28729 if (dest_ty.eql(src_ty, zcu))
28729 if (dest_ty.eql(src_ty))
2873028730 return .ok;
2873128731
2873228732 const dest_tag = dest_ty.zigTypeTag(zcu);
......@@ -32240,7 +32240,7 @@ fn resolvePeerTypesInner(
3224032240 .nullable => {
3224132241 for (peer_tys, 0..) |opt_ty, i| {
3224232242 const ty = opt_ty orelse continue;
32243 if (!ty.eql(.null, zcu)) return .{ .conflict = .{
32243 if (!ty.eql(.null)) return .{ .conflict = .{
3224432244 .peer_idx_a = strat_reason,
3224532245 .peer_idx_b = i,
3224632246 } };
......@@ -32328,7 +32328,7 @@ fn resolvePeerTypesInner(
3232832328 } };
3232932329
3233032330 const peer_elem_ty = ty.childType(zcu);
32331 if (!peer_elem_ty.eql(elem_ty, zcu)) coerce: {
32331 if (!peer_elem_ty.eql(elem_ty)) coerce: {
3233232332 const peer_elem_coerces_to_elem =
3233332333 try sema.coerceInMemoryAllowed(block, elem_ty, peer_elem_ty, false, zcu.getTarget(), src, src, null);
3233432334 if (peer_elem_coerces_to_elem == .ok) {
......@@ -32909,11 +32909,11 @@ fn resolvePeerTypesInner(
3290932909 .@"enum" => switch (ty.zigTypeTag(zcu)) {
3291032910 .enum_literal => {},
3291132911 .@"enum" => {
32912 if (!ty.eql(cur_ty, zcu)) return generic_err;
32912 if (!ty.eql(cur_ty)) return generic_err;
3291332913 },
3291432914 .@"union" => {
3291532915 const tag_ty = ty.unionTagTypeHypothetical(zcu);
32916 if (!tag_ty.eql(cur_ty, zcu)) return generic_err;
32916 if (!tag_ty.eql(cur_ty)) return generic_err;
3291732917 opt_cur_ty = ty;
3291832918 cur_ty_idx = i;
3291932919 },
......@@ -32923,10 +32923,10 @@ fn resolvePeerTypesInner(
3292332923 .enum_literal => {},
3292432924 .@"enum" => {
3292532925 const cur_tag_ty = cur_ty.unionTagTypeHypothetical(zcu);
32926 if (!ty.eql(cur_tag_ty, zcu)) return generic_err;
32926 if (!ty.eql(cur_tag_ty)) return generic_err;
3292732927 },
3292832928 .@"union" => {
32929 if (!ty.eql(cur_ty, zcu)) return generic_err;
32929 if (!ty.eql(cur_ty)) return generic_err;
3293032930 },
3293132931 else => unreachable,
3293232932 },
......@@ -33059,7 +33059,7 @@ fn resolvePeerTypesInner(
3305933059 .comptime_float, .comptime_int, .int => {},
3306033060 .float => {
3306133061 if (opt_cur_ty) |cur_ty| {
33062 if (cur_ty.eql(ty, zcu)) continue;
33062 if (cur_ty.eql(ty)) continue;
3306333063 // Recreate the type so we eliminate any c_longdouble
3306433064 const bits = @max(cur_ty.floatBits(target), ty.floatBits(target));
3306533065 opt_cur_ty = switch (bits) {
......@@ -33234,7 +33234,7 @@ fn resolvePeerTypesInner(
3323433234 for (peer_tys, 0..) |opt_ty, i| {
3323533235 const ty = opt_ty orelse continue;
3323633236 if (expect_ty) |expect| {
33237 if (!ty.eql(expect, zcu)) return .{ .conflict = .{
33237 if (!ty.eql(expect)) return .{ .conflict = .{
3323833238 .peer_idx_a = first_idx,
3323933239 .peer_idx_b = i,
3324033240 } };
......@@ -33300,7 +33300,7 @@ fn typeIsArrayLike(sema: *Sema, ty: Type) ?ArrayLike {
3330033300 };
3330133301 const elem_ty = ty.fieldType(0, zcu);
3330233302 for (1..field_count) |i| {
33303 if (!ty.fieldType(i, zcu).eql(elem_ty, zcu)) {
33303 if (!ty.fieldType(i, zcu).eql(elem_ty)) {
3330433304 return null;
3330533305 }
3330633306 }
src/Type.zig+1-2
......@@ -385,8 +385,7 @@ pub fn ptrInfo(ty: Type, zcu: *const Zcu) InternPool.Key.PtrType {
385385 };
386386}
387387
388pub fn eql(a: Type, b: Type, zcu: *const Zcu) bool {
389 _ = zcu; // TODO: remove this parameter
388pub fn eql(a: Type, b: Type) bool {
390389 // The InternPool data structure hashes based on Key to make interned objects
391390 // unique. An Index can be treated simply as u32 value for the
392391 // purpose of Type/Value hashing and equality.
src/codegen/c.zig+3-3
......@@ -1120,7 +1120,7 @@ pub const DeclGen = struct {
11201120 }
11211121 try w.writeByte('{');
11221122 const ai = ty.arrayInfo(zcu);
1123 if (ai.elem_type.eql(.u8, zcu)) {
1123 if (ai.elem_type.eql(.u8)) {
11241124 var literal: StringLiteral = .init(w, @intCast(ty.arrayLenIncludingSentinel(zcu)));
11251125 try literal.start();
11261126 var index: usize = 0;
......@@ -1539,7 +1539,7 @@ pub const DeclGen = struct {
15391539 }
15401540 try w.writeByte('{');
15411541 const ai = ty.arrayInfo(zcu);
1542 if (ai.elem_type.eql(.u8, zcu)) {
1542 if (ai.elem_type.eql(.u8)) {
15431543 var literal: StringLiteral = .init(w, @intCast(ty.arrayLenIncludingSentinel(zcu)));
15441544 try literal.start();
15451545 var index: u64 = 0;
......@@ -3428,7 +3428,7 @@ fn airStore(f: *Function, inst: Air.Inst.Index, safety: bool) !CValue {
34283428 if (!is_aligned) {
34293429 // For this memcpy to safely work we need the rhs to have the same
34303430 // underlying type as the lhs (i.e. they must both be arrays of the same underlying type).
3431 assert(src_ty.eql(.fromInterned(ptr_info.child), zcu));
3431 assert(src_ty.eql(.fromInterned(ptr_info.child)));
34323432
34333433 const v = try Vectorize.start(f, inst, w, ptr_ty);
34343434 try w.writeAll("memcpy((char *)");
src/codegen/riscv64/CodeGen.zig+1-1
......@@ -3163,7 +3163,7 @@ fn airMulWithOverflow(func: *Func, inst: Air.Inst.Index) !void {
31633163 switch (lhs_ty.zigTypeTag(zcu)) {
31643164 else => |x| return func.fail("TODO: airMulWithOverflow {s}", .{@tagName(x)}),
31653165 .int => {
3166 if (std.debug.runtime_safety) assert(lhs_ty.eql(rhs_ty, zcu));
3166 if (std.debug.runtime_safety) assert(lhs_ty.eql(rhs_ty));
31673167
31683168 const trunc_reg = try func.copyToTmpRegister(lhs_ty, .{ .register = dest_reg });
31693169 const trunc_reg_lock = func.register_manager.lockRegAssumeUnused(trunc_reg);
src/codegen/sparc64/CodeGen.zig+6-6
......@@ -744,7 +744,7 @@ fn airAddSubWithOverflow(self: *Self, inst: Air.Inst.Index) !void {
744744 switch (lhs_ty.zigTypeTag(zcu)) {
745745 .vector => return self.fail("TODO implement add_with_overflow/sub_with_overflow for vectors", .{}),
746746 .int => {
747 assert(lhs_ty.eql(rhs_ty, zcu));
747 assert(lhs_ty.eql(rhs_ty));
748748 const int_info = lhs_ty.intInfo(zcu);
749749 switch (int_info.bits) {
750750 32, 64 => {
......@@ -1797,7 +1797,7 @@ fn airMod(self: *Self, inst: Air.Inst.Index) !void {
17971797 const rhs = try self.resolveInst(bin_op.rhs);
17981798 const lhs_ty = self.typeOf(bin_op.lhs);
17991799 const rhs_ty = self.typeOf(bin_op.rhs);
1800 assert(lhs_ty.eql(rhs_ty, self.pt.zcu));
1800 assert(lhs_ty.eql(rhs_ty));
18011801
18021802 if (self.liveness.isUnused(inst))
18031803 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 {
19501950 switch (lhs_ty.zigTypeTag(zcu)) {
19511951 .vector => return self.fail("TODO implement mul_with_overflow for vectors", .{}),
19521952 .int => {
1953 assert(lhs_ty.eql(rhs_ty, zcu));
1953 assert(lhs_ty.eql(rhs_ty));
19541954 const int_info = lhs_ty.intInfo(zcu);
19551955 switch (int_info.bits) {
19561956 1...32 => {
......@@ -2780,7 +2780,7 @@ fn binOp(
27802780 .float => return self.fail("TODO binary operations on floats", .{}),
27812781 .vector => return self.fail("TODO binary operations on vectors", .{}),
27822782 .int => {
2783 assert(lhs_ty.eql(rhs_ty, zcu));
2783 assert(lhs_ty.eql(rhs_ty));
27842784 const int_info = lhs_ty.intInfo(zcu);
27852785 if (int_info.bits <= 64) {
27862786 // Only say yes if the operation is
......@@ -2870,7 +2870,7 @@ fn binOp(
28702870 switch (lhs_ty.zigTypeTag(zcu)) {
28712871 .vector => return self.fail("TODO binary operations on vectors", .{}),
28722872 .int => {
2873 assert(lhs_ty.eql(rhs_ty, zcu));
2873 assert(lhs_ty.eql(rhs_ty));
28742874 const int_info = lhs_ty.intInfo(zcu);
28752875 if (int_info.bits <= 64) {
28762876 const rhs_immediate_ok = switch (tag) {
......@@ -4226,7 +4226,7 @@ fn minMax(
42264226) InnerError!MCValue {
42274227 const pt = self.pt;
42284228 const zcu = pt.zcu;
4229 assert(lhs_ty.eql(rhs_ty, zcu));
4229 assert(lhs_ty.eql(rhs_ty));
42304230 switch (lhs_ty.zigTypeTag(zcu)) {
42314231 .float => return self.fail("TODO min/max on floats", .{}),
42324232 .vector => return self.fail("TODO min/max on vectors", .{}),
src/codegen/spirv/CodeGen.zig+1-1
......@@ -4633,7 +4633,7 @@ fn unionInit(
46334633 const layout_payload_ty_id = try cg.resolveType(layout.payload_ty, .indirect);
46344634 const pl_ptr_ty_id = try cg.module.ptrType(layout_payload_ty_id, .function);
46354635 const pl_ptr_id = try cg.accessChain(pl_ptr_ty_id, tmp_id, &.{layout.payload_index});
4636 const active_pl_ptr_id = if (!layout.payload_ty.eql(payload_ty, zcu)) blk: {
4636 const active_pl_ptr_id = if (!layout.payload_ty.eql(payload_ty)) blk: {
46374637 const payload_ty_id = try cg.resolveType(payload_ty, .indirect);
46384638 const active_pl_ptr_ty_id = try cg.module.ptrType(payload_ty_id, .function);
46394639 const active_pl_ptr_id = cg.module.allocId();