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.

The new semantics around PTR for comptime-known fixed-width integers did
require some small changes to parts of the compiler, std, and
compiler_rt. Regarding the MachO changes, I spoke to @kubkon about how
best to do them, and this is what he suggested.

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

Resolves: #9917
Resolves: #15644
Resolves: #15709
  • Loading branch information
mlugg committed May 17, 2023
1 parent b677b36 commit 139bd01
Show file tree
Hide file tree
Showing 12 changed files with 1,213 additions and 543 deletions.
2 changes: 1 addition & 1 deletion lib/compiler_rt/exp2.zig
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ pub fn exp2f(x: f32) callconv(.C) f32 {
}

pub fn exp2(x: f64) callconv(.C) f64 {
const tblsiz: u32 = @intCast(u32, exp2dt.len / 2);
const tblsiz: u16 = exp2dt.len / 2;
const redux: f64 = 0x1.8p52 / @intToFloat(f64, tblsiz);
const P1: f64 = 0x1.62e42fefa39efp-1;
const P2: f64 = 0x1.ebfbdff82c575p-3;
Expand Down
2 changes: 1 addition & 1 deletion lib/std/Build/Step/CheckObject.zig
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,7 @@ const MachODumper = struct {
}
try writer.print(" {s}\n", .{sym_name});
} else if (sym.undf()) {
const ordinal = @divTrunc(@bitCast(i16, sym.n_desc), macho.N_SYMBOL_RESOLVER);
const ordinal = sym.getDylibOrdinal();
const import_name = blk: {
if (ordinal <= 0) {
if (ordinal == macho.BIND_SPECIAL_DYLIB_SELF)
Expand Down
2 changes: 1 addition & 1 deletion lib/std/crypto/kyber_d00.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1021,7 +1021,7 @@ const Poly = struct {
// = ⌊((x << d) + q/2) / q⌋ mod⁺ 2ᵈ
// = DIV((x << d) + q/2, q) & ((1<<d) - 1)
const t = @intCast(u32, p.cs[in_off + i]) << d;
in[i] = @intCast(u16, @divFloor(t + q_over_2, Q) & two_d_min_1);
in[i] = @intCast(u16, @divFloor(t + q_over_2, @as(u32, Q)) & two_d_min_1);
}

// Now we pack the d-bit integers from `in' into out as bytes.
Expand Down
2 changes: 1 addition & 1 deletion lib/std/fmt/parse_float/parse.zig
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ fn parsePartialNumberBase(comptime T: type, stream: *FloatStream, negative: bool
};
}

n_digits -= info.max_mantissa_digits;
n_digits -= @as(isize, info.max_mantissa_digits);
var many_digits = false;
stream.reset(); // re-parse from beginning
while (stream.firstIs3('0', '.', '_')) {
Expand Down
4 changes: 4 additions & 0 deletions lib/std/macho.zig
Original file line number Diff line number Diff line change
Expand Up @@ -890,6 +890,10 @@ pub const nlist_64 = extern struct {
if (!sym.undf()) return false;
return sym.n_value != 0;
}

pub fn getDylibOrdinal(sym: nlist_64) i16 {
return @divTrunc(@bitCast(i16, sym.n_desc), @as(u15, N_SYMBOL_RESOLVER));
}
};

/// Format of a relocation entry of a Mach-O file. Modified from the 4.3BSD
Expand Down
Loading

0 comments on commit 139bd01

Please sign in to comment.