Skip to content

Commit 05c8d36

Browse files
committed
Sema: rewrite peer type resolution
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
1 parent b677b36 commit 05c8d36

File tree

12 files changed

+1253
-544
lines changed

12 files changed

+1253
-544
lines changed

lib/compiler_rt/exp2.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ pub fn exp2f(x: f32) callconv(.C) f32 {
8888
}
8989

9090
pub fn exp2(x: f64) callconv(.C) f64 {
91-
const tblsiz: u32 = @intCast(u32, exp2dt.len / 2);
91+
const tblsiz: u16 = exp2dt.len / 2;
9292
const redux: f64 = 0x1.8p52 / @intToFloat(f64, tblsiz);
9393
const P1: f64 = 0x1.62e42fefa39efp-1;
9494
const P2: f64 = 0x1.ebfbdff82c575p-3;

lib/std/Build/Step/CheckObject.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -503,7 +503,7 @@ const MachODumper = struct {
503503
}
504504
try writer.print(" {s}\n", .{sym_name});
505505
} else if (sym.undf()) {
506-
const ordinal = @divTrunc(@bitCast(i16, sym.n_desc), macho.N_SYMBOL_RESOLVER);
506+
const ordinal = sym.getDylibOrdinal();
507507
const import_name = blk: {
508508
if (ordinal <= 0) {
509509
if (ordinal == macho.BIND_SPECIAL_DYLIB_SELF)

lib/std/fmt/parse_float/parse.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ fn parsePartialNumberBase(comptime T: type, stream: *FloatStream, negative: bool
156156
};
157157
}
158158

159-
n_digits -= info.max_mantissa_digits;
159+
n_digits -= @as(isize, info.max_mantissa_digits);
160160
var many_digits = false;
161161
stream.reset(); // re-parse from beginning
162162
while (stream.firstIs3('0', '.', '_')) {

lib/std/macho.zig

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -890,6 +890,10 @@ pub const nlist_64 = extern struct {
890890
if (!sym.undf()) return false;
891891
return sym.n_value != 0;
892892
}
893+
894+
pub fn getDylibOrdinal(sym: nlist_64) i16 {
895+
return @divTrunc(@bitCast(i16, sym.n_desc), @as(u15, N_SYMBOL_RESOLVER));
896+
}
893897
};
894898

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

0 commit comments

Comments
 (0)