authorgravatar for andrew.kraevskii@gmail.comAndrew Kraevskiii <andrew.kraevskii@gmail.com> 2025-09-12 21:25:48+03:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-09-18 22:39:33-07:00
logde489031d873193ca94de1292828c00a02e3b3ea
tree2a9e8a8e5e0b78311005d455d81e8bd2f0845b6e
parent37ecaae6390d238dce21ef4b97e6994dd229c2c3

Remove usages of deprecatedWriter


6 files changed, 59 insertions(+), 12 deletions(-)

lib/compiler/reduce.zig+1-1
...@@ -68,7 +68,7 @@ pub fn main() !void {...@@ -68,7 +68,7 @@ pub fn main() !void {
68 const arg = args[i];68 const arg = args[i];
69 if (mem.startsWith(u8, arg, "-")) {69 if (mem.startsWith(u8, arg, "-")) {
70 if (mem.eql(u8, arg, "-h") or mem.eql(u8, arg, "--help")) {70 if (mem.eql(u8, arg, "-h") or mem.eql(u8, arg, "--help")) {
71 const stdout = std.fs.File.stdout().deprecatedWriter();71 const stdout = std.fs.File.stdout();
72 try stdout.writeAll(usage);72 try stdout.writeAll(usage);
73 return std.process.cleanExit();73 return std.process.cleanExit();
74 } else if (mem.eql(u8, arg, "--")) {74 } else if (mem.eql(u8, arg, "--")) {
lib/std/Random/benchmark.zig+13-1
...@@ -122,7 +122,9 @@ fn mode(comptime x: comptime_int) comptime_int {...@@ -122,7 +122,9 @@ fn mode(comptime x: comptime_int) comptime_int {
122}122}
123123
124pub fn main() !void {124pub fn main() !void {
125 const stdout = std.fs.File.stdout().deprecatedWriter();125 var stdout_buffer: [0x100]u8 = undefined;
126 var stdout_writer = std.fs.File.stdout().writer(&stdout_buffer);
127 const stdout = &stdout_writer.interface;
126128
127 var buffer: [1024]u8 = undefined;129 var buffer: [1024]u8 = undefined;
128 var fixed = std.heap.FixedBufferAllocator.init(buffer[0..]);130 var fixed = std.heap.FixedBufferAllocator.init(buffer[0..]);
...@@ -139,6 +141,7 @@ pub fn main() !void {...@@ -139,6 +141,7 @@ pub fn main() !void {
139 while (i < args.len) : (i += 1) {141 while (i < args.len) : (i += 1) {
140 if (std.mem.eql(u8, args[i], "--mode")) {142 if (std.mem.eql(u8, args[i], "--mode")) {
141 try stdout.print("{}\n", .{builtin.mode});143 try stdout.print("{}\n", .{builtin.mode});
144 try stdout.flush();
142 return;145 return;
143 } else if (std.mem.eql(u8, args[i], "--filter")) {146 } else if (std.mem.eql(u8, args[i], "--filter")) {
144 i += 1;147 i += 1;
...@@ -179,6 +182,8 @@ pub fn main() !void {...@@ -179,6 +182,8 @@ pub fn main() !void {
179 inline for (prngs) |R| {182 inline for (prngs) |R| {
180 if (filter == null or std.mem.indexOf(u8, R.name, filter.?) != null) {183 if (filter == null or std.mem.indexOf(u8, R.name, filter.?) != null) {
181 try stdout.print("{s} (long outputs)\n", .{R.name});184 try stdout.print("{s} (long outputs)\n", .{R.name});
185 try stdout.flush();
186
182 const result_long = try benchmark(R, count, long_block_size);187 const result_long = try benchmark(R, count, long_block_size);
183 try stdout.print(" {:5} MiB/s\n", .{result_long.throughput / (1 * MiB)});188 try stdout.print(" {:5} MiB/s\n", .{result_long.throughput / (1 * MiB)});
184 }189 }
...@@ -188,6 +193,8 @@ pub fn main() !void {...@@ -188,6 +193,8 @@ pub fn main() !void {
188 inline for (prngs) |R| {193 inline for (prngs) |R| {
189 if (filter == null or std.mem.indexOf(u8, R.name, filter.?) != null) {194 if (filter == null or std.mem.indexOf(u8, R.name, filter.?) != null) {
190 try stdout.print("{s} (short outputs)\n", .{R.name});195 try stdout.print("{s} (short outputs)\n", .{R.name});
196 try stdout.flush();
197
191 const result_short = try benchmark(R, count, short_block_size);198 const result_short = try benchmark(R, count, short_block_size);
192 try stdout.print(" {:5} MiB/s\n", .{result_short.throughput / (1 * MiB)});199 try stdout.print(" {:5} MiB/s\n", .{result_short.throughput / (1 * MiB)});
193 }200 }
...@@ -199,6 +206,8 @@ pub fn main() !void {...@@ -199,6 +206,8 @@ pub fn main() !void {
199 inline for (csprngs) |R| {206 inline for (csprngs) |R| {
200 if (filter == null or std.mem.indexOf(u8, R.name, filter.?) != null) {207 if (filter == null or std.mem.indexOf(u8, R.name, filter.?) != null) {
201 try stdout.print("{s} (cryptographic, long outputs)\n", .{R.name});208 try stdout.print("{s} (cryptographic, long outputs)\n", .{R.name});
209 try stdout.flush();
210
202 const result_long = try benchmark(R, count, long_block_size);211 const result_long = try benchmark(R, count, long_block_size);
203 try stdout.print(" {:5} MiB/s\n", .{result_long.throughput / (1 * MiB)});212 try stdout.print(" {:5} MiB/s\n", .{result_long.throughput / (1 * MiB)});
204 }213 }
...@@ -208,10 +217,13 @@ pub fn main() !void {...@@ -208,10 +217,13 @@ pub fn main() !void {
208 inline for (csprngs) |R| {217 inline for (csprngs) |R| {
209 if (filter == null or std.mem.indexOf(u8, R.name, filter.?) != null) {218 if (filter == null or std.mem.indexOf(u8, R.name, filter.?) != null) {
210 try stdout.print("{s} (cryptographic, short outputs)\n", .{R.name});219 try stdout.print("{s} (cryptographic, short outputs)\n", .{R.name});
220 try stdout.flush();
221
211 const result_short = try benchmark(R, count, short_block_size);222 const result_short = try benchmark(R, count, short_block_size);
212 try stdout.print(" {:5} MiB/s\n", .{result_short.throughput / (1 * MiB)});223 try stdout.print(" {:5} MiB/s\n", .{result_short.throughput / (1 * MiB)});
213 }224 }
214 }225 }
215 }226 }
216 }227 }
228 try stdout.flush();
217}229}
lib/std/crypto/benchmark.zig+2-1
...@@ -460,7 +460,8 @@ fn mode(comptime x: comptime_int) comptime_int {...@@ -460,7 +460,8 @@ fn mode(comptime x: comptime_int) comptime_int {
460}460}
461461
462pub fn main() !void {462pub fn main() !void {
463 var stdout_buffer: [4096]u8 = undefined;463 // Size of buffer is about size of printed message.
464 var stdout_buffer: [0x100]u8 = undefined;
464 var stdout_writer = std.fs.File.stdout().writer(&stdout_buffer);465 var stdout_writer = std.fs.File.stdout().writer(&stdout_buffer);
465 const stdout = &stdout_writer.interface;466 const stdout = &stdout_writer.interface;
466467
lib/std/hash/benchmark.zig+31-6
...@@ -19,8 +19,11 @@ const Hash = struct {...@@ -19,8 +19,11 @@ const Hash = struct {
19 has_iterative_api: bool = true,19 has_iterative_api: bool = true,
20 has_crypto_api: bool = false,20 has_crypto_api: bool = false,
21 has_anytype_api: ?[]const comptime_int = null,21 has_anytype_api: ?[]const comptime_int = null,
22 /// `final` value should be read from this field.
23 has_struct_api: ?[]const u8 = null,
22 init_u8s: ?[]const u8 = null,24 init_u8s: ?[]const u8 = null,
23 init_u64: ?u64 = null,25 init_u64: ?u64 = null,
26 init_default: bool = false,
24};27};
2528
26const hashes = [_]Hash{29const hashes = [_]Hash{
...@@ -54,6 +57,8 @@ const hashes = [_]Hash{...@@ -54,6 +57,8 @@ const hashes = [_]Hash{
54 Hash{57 Hash{
55 .ty = hash.Adler32,58 .ty = hash.Adler32,
56 .name = "adler32",59 .name = "adler32",
60 .has_struct_api = "adler",
61 .init_default = true,
57 },62 },
58 Hash{63 Hash{
59 .ty = hash.crc.Crc32,64 .ty = hash.crc.Crc32,
...@@ -112,21 +117,29 @@ pub fn benchmarkHash(comptime H: anytype, bytes: usize, allocator: std.mem.Alloc...@@ -112,21 +117,29 @@ pub fn benchmarkHash(comptime H: anytype, bytes: usize, allocator: std.mem.Alloc
112117
113 const block_count = bytes / block_size;118 const block_count = bytes / block_size;
114119
115 var h = blk: {120 var h: H.ty = blk: {
116 if (H.init_u8s) |init| {121 if (H.init_u8s) |init| {
117 break :blk H.ty.init(init[0..H.ty.key_length]);122 break :blk .init(init[0..H.ty.key_length]);
118 }123 }
119 if (H.init_u64) |init| {124 if (H.init_u64) |init| {
120 break :blk H.ty.init(init);125 break :blk .init(init);
121 }126 }
122 break :blk H.ty.init();127 if (H.init_default) {
128 break :blk .{};
129 }
130 break :blk .init();
123 };131 };
124132
125 var timer = try Timer.start();133 var timer = try Timer.start();
126 for (0..block_count) |i| {134 for (0..block_count) |i| {
127 h.update(blocks[i * block_size ..][0..block_size]);135 h.update(blocks[i * block_size ..][0..block_size]);
128 }136 }
129 const final = if (H.has_crypto_api) @as(u64, @truncate(h.finalInt())) else h.final();137 const final = if (H.has_struct_api) |field_name|
138 @field(h, field_name)
139 else if (H.has_crypto_api)
140 @as(u64, @truncate(h.finalInt()))
141 else
142 h.final();
130 std.mem.doNotOptimizeAway(final);143 std.mem.doNotOptimizeAway(final);
131144
132 const elapsed_ns = timer.read();145 const elapsed_ns = timer.read();
...@@ -340,7 +353,9 @@ fn mode(comptime x: comptime_int) comptime_int {...@@ -340,7 +353,9 @@ fn mode(comptime x: comptime_int) comptime_int {
340}353}
341354
342pub fn main() !void {355pub fn main() !void {
343 const stdout = std.fs.File.stdout().deprecatedWriter();356 var stdout_buffer: [0x100]u8 = undefined;
357 var stdout_writer = std.fs.File.stdout().writer(&stdout_buffer);
358 const stdout = &stdout_writer.interface;
344359
345 var buffer: [1024]u8 = undefined;360 var buffer: [1024]u8 = undefined;
346 var fixed = std.heap.FixedBufferAllocator.init(buffer[0..]);361 var fixed = std.heap.FixedBufferAllocator.init(buffer[0..]);
...@@ -360,6 +375,7 @@ pub fn main() !void {...@@ -360,6 +375,7 @@ pub fn main() !void {
360 while (i < args.len) : (i += 1) {375 while (i < args.len) : (i += 1) {
361 if (std.mem.eql(u8, args[i], "--mode")) {376 if (std.mem.eql(u8, args[i], "--mode")) {
362 try stdout.print("{}\n", .{builtin.mode});377 try stdout.print("{}\n", .{builtin.mode});
378 try stdout.flush();
363 return;379 return;
364 } else if (std.mem.eql(u8, args[i], "--seed")) {380 } else if (std.mem.eql(u8, args[i], "--seed")) {
365 i += 1;381 i += 1;
...@@ -397,6 +413,7 @@ pub fn main() !void {...@@ -397,6 +413,7 @@ pub fn main() !void {
397 key_size = try std.fmt.parseUnsigned(usize, args[i], 10);413 key_size = try std.fmt.parseUnsigned(usize, args[i], 10);
398 if (key_size.? > block_size) {414 if (key_size.? > block_size) {
399 try stdout.print("key_size cannot exceed block size of {}\n", .{block_size});415 try stdout.print("key_size cannot exceed block size of {}\n", .{block_size});
416 try stdout.flush();
400 std.process.exit(1);417 std.process.exit(1);
401 }418 }
402 } else if (std.mem.eql(u8, args[i], "--iterative-only")) {419 } else if (std.mem.eql(u8, args[i], "--iterative-only")) {
...@@ -416,6 +433,7 @@ pub fn main() !void {...@@ -416,6 +433,7 @@ pub fn main() !void {
416433
417 if (test_iterative_only and test_small_key_only) {434 if (test_iterative_only and test_small_key_only) {
418 try stdout.print("Cannot use iterative-only and small-key-only together!\n", .{});435 try stdout.print("Cannot use iterative-only and small-key-only together!\n", .{});
436 try stdout.flush();
419 usage();437 usage();
420 std.process.exit(1);438 std.process.exit(1);
421 }439 }
...@@ -428,6 +446,7 @@ pub fn main() !void {...@@ -428,6 +446,7 @@ pub fn main() !void {
428 if (filter == null or std.mem.indexOf(u8, H.name, filter.?) != null) hash: {446 if (filter == null or std.mem.indexOf(u8, H.name, filter.?) != null) hash: {
429 if (!test_iterative_only or H.has_iterative_api) {447 if (!test_iterative_only or H.has_iterative_api) {
430 try stdout.print("{s}\n", .{H.name});448 try stdout.print("{s}\n", .{H.name});
449 try stdout.flush();
431450
432 // Always reseed prior to every call so we are hashing the same buffer contents.451 // Always reseed prior to every call so we are hashing the same buffer contents.
433 // This allows easier comparison between different implementations.452 // This allows easier comparison between different implementations.
...@@ -435,6 +454,7 @@ pub fn main() !void {...@@ -435,6 +454,7 @@ pub fn main() !void {
435 prng.seed(seed);454 prng.seed(seed);
436 const result = try benchmarkHash(H, count, allocator);455 const result = try benchmarkHash(H, count, allocator);
437 try stdout.print(" iterative: {:5} MiB/s [{x:0<16}]\n", .{ result.throughput / (1 * MiB), result.hash });456 try stdout.print(" iterative: {:5} MiB/s [{x:0<16}]\n", .{ result.throughput / (1 * MiB), result.hash });
457 try stdout.flush();
438 }458 }
439459
440 if (!test_iterative_only) {460 if (!test_iterative_only) {
...@@ -447,6 +467,7 @@ pub fn main() !void {...@@ -447,6 +467,7 @@ pub fn main() !void {
447 result_small.throughput / size,467 result_small.throughput / size,
448 result_small.hash,468 result_small.hash,
449 });469 });
470 try stdout.flush();
450471
451 if (!test_arrays) break :hash;472 if (!test_arrays) break :hash;
452 if (H.has_anytype_api) |sizes| {473 if (H.has_anytype_api) |sizes| {
...@@ -464,6 +485,7 @@ pub fn main() !void {...@@ -464,6 +485,7 @@ pub fn main() !void {
464 result_ptr.throughput / (1 * MiB),485 result_ptr.throughput / (1 * MiB),
465 result_ptr.hash,486 result_ptr.hash,
466 });487 });
488 try stdout.flush();
467 }489 }
468 }490 }
469 }491 }
...@@ -476,6 +498,7 @@ pub fn main() !void {...@@ -476,6 +498,7 @@ pub fn main() !void {
476 result_small.throughput / default_small_key_size,498 result_small.throughput / default_small_key_size,
477 result_small.hash,499 result_small.hash,
478 });500 });
501 try stdout.flush();
479502
480 if (!test_arrays) break :hash;503 if (!test_arrays) break :hash;
481 if (H.has_anytype_api) |sizes| {504 if (H.has_anytype_api) |sizes| {
...@@ -488,6 +511,7 @@ pub fn main() !void {...@@ -488,6 +511,7 @@ pub fn main() !void {
488 result.throughput / (1 * MiB),511 result.throughput / (1 * MiB),
489 result.hash,512 result.hash,
490 });513 });
514 try stdout.flush();
491 }515 }
492 try stdout.print(" array ptr: \n", .{});516 try stdout.print(" array ptr: \n", .{});
493 inline for (sizes) |exact_size| {517 inline for (sizes) |exact_size| {
...@@ -498,6 +522,7 @@ pub fn main() !void {...@@ -498,6 +522,7 @@ pub fn main() !void {
498 result.throughput / (1 * MiB),522 result.throughput / (1 * MiB),
499 result.hash,523 result.hash,
500 });524 });
525 try stdout.flush();
501 }526 }
502 }527 }
503 }528 }
lib/std/log.zig+2-2
...@@ -47,8 +47,8 @@...@@ -47,8 +47,8 @@
47//! // Print the message to stderr, silently ignoring any errors47//! // Print the message to stderr, silently ignoring any errors
48//! std.debug.lockStdErr();48//! std.debug.lockStdErr();
49//! defer std.debug.unlockStdErr();49//! defer std.debug.unlockStdErr();
50//! const stderr = std.fs.File.stderr().deprecatedWriter();50//! var stderr = std.fs.File.stderr().writer(&.{});
51//! nosuspend stderr.print(prefix ++ format ++ "\n", args) catch return;51//! nosuspend stderr.interface.print(prefix ++ format ++ "\n", args) catch return;
52//! }52//! }
53//!53//!
54//! pub fn main() void {54//! pub fn main() void {
lib/std/unicode/throughput_test.zig+10-1
...@@ -39,35 +39,44 @@ fn benchmarkCodepointCount(buf: []const u8) !ResultCount {...@@ -39,35 +39,44 @@ fn benchmarkCodepointCount(buf: []const u8) !ResultCount {
39}39}
4040
41pub fn main() !void {41pub fn main() !void {
42 const stdout = std.fs.File.stdout().deprecatedWriter();42 // Size of buffer is about size of printed message.
43 var stdout_buffer: [0x100]u8 = undefined;
44 var stdout_writer = std.fs.File.stdout().writer(&stdout_buffer);
45 const stdout = &stdout_writer.interface;
4346
44 try stdout.print("short ASCII strings\n", .{});47 try stdout.print("short ASCII strings\n", .{});
48 try stdout.flush();
45 {49 {
46 const result = try benchmarkCodepointCount("abc");50 const result = try benchmarkCodepointCount("abc");
47 try stdout.print(" count: {:5} MiB/s [{d}]\n", .{ result.throughput / (1 * MiB), result.count });51 try stdout.print(" count: {:5} MiB/s [{d}]\n", .{ result.throughput / (1 * MiB), result.count });
48 }52 }
4953
50 try stdout.print("short Unicode strings\n", .{});54 try stdout.print("short Unicode strings\n", .{});
55 try stdout.flush();
51 {56 {
52 const result = try benchmarkCodepointCount("ŌŌŌ");57 const result = try benchmarkCodepointCount("ŌŌŌ");
53 try stdout.print(" count: {:5} MiB/s [{d}]\n", .{ result.throughput / (1 * MiB), result.count });58 try stdout.print(" count: {:5} MiB/s [{d}]\n", .{ result.throughput / (1 * MiB), result.count });
54 }59 }
5560
56 try stdout.print("pure ASCII strings\n", .{});61 try stdout.print("pure ASCII strings\n", .{});
62 try stdout.flush();
57 {63 {
58 const result = try benchmarkCodepointCount("hello" ** 16);64 const result = try benchmarkCodepointCount("hello" ** 16);
59 try stdout.print(" count: {:5} MiB/s [{d}]\n", .{ result.throughput / (1 * MiB), result.count });65 try stdout.print(" count: {:5} MiB/s [{d}]\n", .{ result.throughput / (1 * MiB), result.count });
60 }66 }
6167
62 try stdout.print("pure Unicode strings\n", .{});68 try stdout.print("pure Unicode strings\n", .{});
69 try stdout.flush();
63 {70 {
64 const result = try benchmarkCodepointCount("こんにちは" ** 16);71 const result = try benchmarkCodepointCount("こんにちは" ** 16);
65 try stdout.print(" count: {:5} MiB/s [{d}]\n", .{ result.throughput / (1 * MiB), result.count });72 try stdout.print(" count: {:5} MiB/s [{d}]\n", .{ result.throughput / (1 * MiB), result.count });
66 }73 }
6774
68 try stdout.print("mixed ASCII/Unicode strings\n", .{});75 try stdout.print("mixed ASCII/Unicode strings\n", .{});
76 try stdout.flush();
69 {77 {
70 const result = try benchmarkCodepointCount("Hyvää huomenta" ** 16);78 const result = try benchmarkCodepointCount("Hyvää huomenta" ** 16);
71 try stdout.print(" count: {:5} MiB/s [{d}]\n", .{ result.throughput / (1 * MiB), result.count });79 try stdout.print(" count: {:5} MiB/s [{d}]\n", .{ result.throughput / (1 * MiB), result.count });
72 }80 }
81 try stdout.flush();
73}82}