Skip to content

Commit ffa700e

Browse files
authored
Merge pull request #11837 from Vexu/stage2
Fix (nearly) all stage2 crashes when testing stdlib
2 parents 6e42d45 + 0a9d695 commit ffa700e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+501
-626
lines changed

ci/zinc/linux_test.sh

+1
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ stage2/bin/zig build -Dtarget=arm-linux-musleabihf # test building self-hosted f
5959
# * https://github.com/ziglang/zig/issues/11367 (and corresponding workaround in compiler source)
6060
# * https://github.com/ziglang/zig/pull/11492#issuecomment-1112871321
6161
stage2/bin/zig build test-behavior -fqemu -fwasmtime
62+
stage2/bin/zig test lib/std/std.zig --zig-lib-dir lib
6263

6364
$ZIG build test-behavior -fqemu -fwasmtime -Domit-stage2
6465
$ZIG build test-compiler-rt -fqemu -fwasmtime

lib/std/bit_set.zig

+4
Original file line numberDiff line numberDiff line change
@@ -1330,6 +1330,7 @@ fn testStaticBitSet(comptime Set: type) !void {
13301330
}
13311331

13321332
test "IntegerBitSet" {
1333+
if (@import("builtin").zig_backend != .stage1) return error.SkipZigTest; // TODO
13331334
try testStaticBitSet(IntegerBitSet(0));
13341335
try testStaticBitSet(IntegerBitSet(1));
13351336
try testStaticBitSet(IntegerBitSet(2));
@@ -1341,6 +1342,7 @@ test "IntegerBitSet" {
13411342
}
13421343

13431344
test "ArrayBitSet" {
1345+
if (@import("builtin").zig_backend != .stage1) return error.SkipZigTest; // TODO
13441346
if (@import("builtin").cpu.arch == .aarch64) {
13451347
// https://github.com/ziglang/zig/issues/9879
13461348
return error.SkipZigTest;
@@ -1355,6 +1357,7 @@ test "ArrayBitSet" {
13551357
}
13561358

13571359
test "DynamicBitSetUnmanaged" {
1360+
if (@import("builtin").zig_backend != .stage1) return error.SkipZigTest; // TODO
13581361
const allocator = std.testing.allocator;
13591362
var a = try DynamicBitSetUnmanaged.initEmpty(allocator, 300);
13601363
try testing.expectEqual(@as(usize, 0), a.count());
@@ -1395,6 +1398,7 @@ test "DynamicBitSetUnmanaged" {
13951398
}
13961399

13971400
test "DynamicBitSet" {
1401+
if (@import("builtin").zig_backend != .stage1) return error.SkipZigTest; // TODO
13981402
const allocator = std.testing.allocator;
13991403
var a = try DynamicBitSet.initEmpty(allocator, 300);
14001404
try testing.expectEqual(@as(usize, 0), a.count());

lib/std/compress.zig

-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ pub const gzip = @import("compress/gzip.zig");
55
pub const zlib = @import("compress/zlib.zig");
66

77
test {
8-
if (@import("builtin").zig_backend != .stage1) return error.SkipZigTest;
98
_ = deflate;
109
_ = gzip;
1110
_ = zlib;

lib/std/compress/deflate/compressor.zig

+4-1
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,10 @@ pub fn Compressor(comptime WriterType: anytype) type {
254254

255255
// Inner writer wrapped in a HuffmanBitWriter
256256
hm_bw: hm_bw.HuffmanBitWriter(WriterType) = undefined,
257-
bulk_hasher: fn ([]u8, []u32) u32,
257+
bulk_hasher: if (@import("builtin").zig_backend == .stage1)
258+
fn ([]u8, []u32) u32
259+
else
260+
*const fn ([]u8, []u32) u32,
258261

259262
sync: bool, // requesting flush
260263
best_speed_enc: *fast.DeflateFast, // Encoder for best_speed

lib/std/compress/deflate/compressor_test.zig

+13-24
Original file line numberDiff line numberDiff line change
@@ -122,11 +122,8 @@ fn testToFromWithLevelAndLimit(level: deflate.Compression, input: []const u8, li
122122
try expect(compressed.items.len <= limit);
123123
}
124124

125-
var decomp = try decompressor(
126-
testing.allocator,
127-
io.fixedBufferStream(compressed.items).reader(),
128-
null,
129-
);
125+
var fib = io.fixedBufferStream(compressed.items);
126+
var decomp = try decompressor(testing.allocator, fib.reader(), null);
130127
defer decomp.deinit();
131128

132129
var decompressed = try testing.allocator.alloc(u8, input.len);
@@ -136,7 +133,9 @@ fn testToFromWithLevelAndLimit(level: deflate.Compression, input: []const u8, li
136133
try expect(read == input.len);
137134
try expect(mem.eql(u8, input, decompressed));
138135

139-
try testSync(level, input);
136+
if (builtin.zig_backend == .stage1) {
137+
try testSync(level, input);
138+
}
140139
}
141140

142141
fn testToFromWithLimit(input: []const u8, limit: [11]u32) !void {
@@ -475,21 +474,16 @@ test "inflate reset" {
475474
try comp.close();
476475
}
477476

478-
var decomp = try decompressor(
479-
testing.allocator,
480-
io.fixedBufferStream(compressed_strings[0].items).reader(),
481-
null,
482-
);
477+
var fib = io.fixedBufferStream(compressed_strings[0].items);
478+
var decomp = try decompressor(testing.allocator, fib.reader(), null);
483479
defer decomp.deinit();
484480

485481
var decompressed_0: []u8 = try decomp.reader()
486482
.readAllAlloc(testing.allocator, math.maxInt(usize));
487483
defer testing.allocator.free(decompressed_0);
488484

489-
try decomp.reset(
490-
io.fixedBufferStream(compressed_strings[1].items).reader(),
491-
null,
492-
);
485+
fib = io.fixedBufferStream(compressed_strings[1].items);
486+
try decomp.reset(fib.reader(), null);
493487

494488
var decompressed_1: []u8 = try decomp.reader()
495489
.readAllAlloc(testing.allocator, math.maxInt(usize));
@@ -530,21 +524,16 @@ test "inflate reset dictionary" {
530524
try comp.close();
531525
}
532526

533-
var decomp = try decompressor(
534-
testing.allocator,
535-
io.fixedBufferStream(compressed_strings[0].items).reader(),
536-
dict,
537-
);
527+
var fib = io.fixedBufferStream(compressed_strings[0].items);
528+
var decomp = try decompressor(testing.allocator, fib.reader(), dict);
538529
defer decomp.deinit();
539530

540531
var decompressed_0: []u8 = try decomp.reader()
541532
.readAllAlloc(testing.allocator, math.maxInt(usize));
542533
defer testing.allocator.free(decompressed_0);
543534

544-
try decomp.reset(
545-
io.fixedBufferStream(compressed_strings[1].items).reader(),
546-
dict,
547-
);
535+
fib = io.fixedBufferStream(compressed_strings[1].items);
536+
try decomp.reset(fib.reader(), dict);
548537

549538
var decompressed_1: []u8 = try decomp.reader()
550539
.readAllAlloc(testing.allocator, math.maxInt(usize));

lib/std/compress/deflate/decompressor.zig

+19-6
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,10 @@ pub fn Decompressor(comptime ReaderType: type) type {
334334

335335
// Next step in the decompression,
336336
// and decompression state.
337-
step: fn (*Self) Error!void,
337+
step: if (@import("builtin").zig_backend == .stage1)
338+
fn (*Self) Error!void
339+
else
340+
*const fn (*Self) Error!void,
338341
step_state: DecompressorState,
339342
final: bool,
340343
err: ?Error,
@@ -479,7 +482,13 @@ pub fn Decompressor(comptime ReaderType: type) type {
479482
}
480483

481484
pub fn close(self: *Self) ?Error {
482-
if (self.err == Error.EndOfStreamWithNoError) {
485+
if (@import("builtin").zig_backend == .stage1) {
486+
if (self.err == Error.EndOfStreamWithNoError) {
487+
return null;
488+
}
489+
return self.err;
490+
}
491+
if (self.err == @as(?Error, error.EndOfStreamWithNoError)) {
483492
return null;
484493
}
485494
return self.err;
@@ -920,7 +929,8 @@ test "truncated input" {
920929
};
921930

922931
for (tests) |t| {
923-
var r = io.fixedBufferStream(t.input).reader();
932+
var fib = io.fixedBufferStream(t.input);
933+
const r = fib.reader();
924934
var z = try decompressor(testing.allocator, r, null);
925935
defer z.deinit();
926936
var zr = z.reader();
@@ -959,7 +969,8 @@ test "Go non-regression test for 9842" {
959969
};
960970

961971
for (tests) |t| {
962-
const reader = std.io.fixedBufferStream(t.input).reader();
972+
var fib = std.io.fixedBufferStream(t.input);
973+
const reader = fib.reader();
963974
var decomp = try decompressor(testing.allocator, reader, null);
964975
defer decomp.deinit();
965976

@@ -1017,7 +1028,8 @@ test "inflate A Tale of Two Cities (1859) intro" {
10171028
\\
10181029
;
10191030

1020-
const reader = std.io.fixedBufferStream(&compressed).reader();
1031+
var fib = std.io.fixedBufferStream(&compressed);
1032+
const reader = fib.reader();
10211033
var decomp = try decompressor(testing.allocator, reader, null);
10221034
defer decomp.deinit();
10231035

@@ -1082,7 +1094,8 @@ test "fuzzing" {
10821094

10831095
fn decompress(input: []const u8) !void {
10841096
const allocator = testing.allocator;
1085-
const reader = std.io.fixedBufferStream(input).reader();
1097+
var fib = std.io.fixedBufferStream(input);
1098+
const reader = fib.reader();
10861099
var decomp = try decompressor(allocator, reader, null);
10871100
defer decomp.deinit();
10881101
var output = try decomp.reader().readAllAlloc(allocator, math.maxInt(usize));

lib/std/compress/deflate/deflate_fast_test.zig

+6-12
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,8 @@ test "best speed" {
7878
var decompressed = try testing.allocator.alloc(u8, want.items.len);
7979
defer testing.allocator.free(decompressed);
8080

81-
var decomp = try inflate.decompressor(
82-
testing.allocator,
83-
io.fixedBufferStream(compressed.items).reader(),
84-
null,
85-
);
81+
var fib = io.fixedBufferStream(compressed.items);
82+
var decomp = try inflate.decompressor(testing.allocator, fib.reader(), null);
8683
defer decomp.deinit();
8784

8885
var read = try decomp.reader().readAll(decompressed);
@@ -122,13 +119,13 @@ test "best speed max match offset" {
122119
// zeros1 is between 0 and 30 zeros.
123120
// The difference between the two abc's will be offset, which
124121
// is max_match_offset plus or minus a small adjustment.
125-
var src_len: usize = @intCast(usize, offset + abc.len + @intCast(i32, extra));
122+
var src_len: usize = @intCast(usize, offset + @as(i32, abc.len) + @intCast(i32, extra));
126123
var src = try testing.allocator.alloc(u8, src_len);
127124
defer testing.allocator.free(src);
128125

129126
mem.copy(u8, src, abc);
130127
if (!do_match_before) {
131-
var src_offset: usize = @intCast(usize, offset - xyz.len);
128+
var src_offset: usize = @intCast(usize, offset - @as(i32, xyz.len));
132129
mem.copy(u8, src[src_offset..], xyz);
133130
}
134131
var src_offset: usize = @intCast(usize, offset);
@@ -149,11 +146,8 @@ test "best speed max match offset" {
149146
var decompressed = try testing.allocator.alloc(u8, src.len);
150147
defer testing.allocator.free(decompressed);
151148

152-
var decomp = try inflate.decompressor(
153-
testing.allocator,
154-
io.fixedBufferStream(compressed.items).reader(),
155-
null,
156-
);
149+
var fib = io.fixedBufferStream(compressed.items);
150+
var decomp = try inflate.decompressor(testing.allocator, fib.reader(), null);
157151
defer decomp.deinit();
158152
var read = try decomp.reader().readAll(decompressed);
159153
_ = decomp.close();

lib/std/crypto/argon2.zig

+2
Original file line numberDiff line numberDiff line change
@@ -897,6 +897,7 @@ test "kdf" {
897897
}
898898

899899
test "phc format hasher" {
900+
if (@import("builtin").zig_backend != .stage1) return error.SkipZigTest; // TODO
900901
const allocator = std.testing.allocator;
901902
const password = "testpass";
902903

@@ -912,6 +913,7 @@ test "phc format hasher" {
912913
}
913914

914915
test "password hash and password verify" {
916+
if (@import("builtin").zig_backend != .stage1) return error.SkipZigTest; // TODO
915917
const allocator = std.testing.allocator;
916918
const password = "testpass";
917919

lib/std/crypto/bcrypt.zig

+1
Original file line numberDiff line numberDiff line change
@@ -802,6 +802,7 @@ test "bcrypt crypt format" {
802802
}
803803

804804
test "bcrypt phc format" {
805+
if (@import("builtin").zig_backend != .stage1) return error.SkipZigTest; // TODO
805806
const hash_options = HashOptions{
806807
.params = .{ .rounds_log = 5 },
807808
.encoding = .phc,

lib/std/crypto/phc_encoding.zig

+1
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,7 @@ fn kvSplit(str: []const u8) !struct { key: []const u8, value: []const u8 } {
260260
}
261261

262262
test "phc format - encoding/decoding" {
263+
if (@import("builtin").zig_backend != .stage1) return error.SkipZigTest; // TODO
263264
const Input = struct {
264265
str: []const u8,
265266
HashResult: type,

lib/std/crypto/scrypt.zig

+1
Original file line numberDiff line numberDiff line change
@@ -683,6 +683,7 @@ test "unix-scrypt" {
683683
}
684684

685685
test "crypt format" {
686+
if (@import("builtin").zig_backend != .stage1) return error.SkipZigTest; // TODO
686687
const str = "$7$C6..../....SodiumChloride$kBGj9fHznVYFQMEn/qDCfrDevf9YDtcDdKvEqHJLV8D";
687688
const params = try crypt_format.deserialize(crypt_format.HashResult(32), str);
688689
var buf: [str.len]u8 = undefined;

0 commit comments

Comments
 (0)