Skip to content

Commit

Permalink
Sema: rewrite peer type resolution
Browse files Browse the repository at this point in the history
The existing logic for peer type resolution was quite convoluted and
buggy. This rewrite makes it much more resilient, readable, and
extensible. The algorithm works by first iterating over the types to
select a "strategy", then applying that strategy, possibly applying peer
resolution recursively.

Several new tests have been added to cover cases which the old logic did
not correctly handle.

Resolves: ziglang#15138
Resolves: ziglang#15644
Resolves: ziglang#15693
Resolves: ziglang#15709
Resolves: ziglang#15752
  • Loading branch information
mlugg authored and wooster0 committed Jun 14, 2023
1 parent 4ca224e commit 6eae832
Show file tree
Hide file tree
Showing 6 changed files with 2,111 additions and 558 deletions.
2 changes: 1 addition & 1 deletion src/Module.zig
Original file line number Diff line number Diff line change
Expand Up @@ -6978,7 +6978,7 @@ pub fn intBitsForValue(mod: *Module, val: Value, sign: bool) u16 {
assert(sign);
// Protect against overflow in the following negation.
if (x == std.math.minInt(i64)) return 64;
return Type.smallestUnsignedBits(@intCast(u64, -x - 1)) + 1;
return Type.smallestUnsignedBits(@intCast(u64, -(x + 1))) + 1;
},
.u64 => |x| {
return Type.smallestUnsignedBits(x) + @boolToInt(sign);
Expand Down
Loading

0 comments on commit 6eae832

Please sign in to comment.