Skip to content

Commit

Permalink
Sema: allow in-memory coercion of equivalent tuples
Browse files Browse the repository at this point in the history
This is a workaround to the issue that tuple equality is currently
broken for explicit tuple types (created using `struct { .. }` syntax).
After the PTR changes in the previous commit, self-hosting was broken
without this change due to a tuple type being recreated in a peer
resolution.

This doesn't add any InMemoryCoercionResult field for this case, because
this is a temporary addition to the compiler which can be removed when
some bugs surrounding tuples are fixed.
  • Loading branch information
mlugg committed May 21, 2023
1 parent b5e2760 commit ec965b9
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/Sema.zig
Original file line number Diff line number Diff line change
Expand Up @@ -26594,6 +26594,23 @@ fn coerceInMemoryAllowed(
return .ok;
}

// Tuples
// TODO: this can go away once tuple type equality works
if (dest_ty.isTuple() and src_ty.isTuple()) tuple: {
if (dest_ty.containerLayout() != src_ty.containerLayout()) break :tuple;
if (dest_ty.structFieldCount() != src_ty.structFieldCount()) break :tuple;
const field_count = dest_ty.structFieldCount();
for (0..field_count) |field_idx| {
if (dest_ty.structFieldIsComptime(field_idx) != src_ty.structFieldIsComptime(field_idx)) break :tuple;
if (dest_ty.structFieldAlign(field_idx, target) != src_ty.structFieldAlign(field_idx, target)) break :tuple;
const dest_field_ty = dest_ty.structFieldType(field_idx);
const src_field_ty = src_ty.structFieldType(field_idx);
const field = try sema.coerceInMemoryAllowed(block, dest_field_ty, src_field_ty, dest_is_mut, target, dest_src, src_src);
if (field != .ok) break :tuple;
}
return .ok;
}

return InMemoryCoercionResult{ .no_match = .{
.actual = dest_ty,
.wanted = src_ty,
Expand Down

0 comments on commit ec965b9

Please sign in to comment.