Skip to content

Commit bfe9a48

Browse files
committed
update tools and other miscellaneous things to new APIs
1 parent e9bed3b commit bfe9a48

20 files changed

+55
-53
lines changed

lib/compiler/resinator/main.zig

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -164,13 +164,14 @@ pub fn main() !void {
164164
} else {
165165
switch (options.input_source) {
166166
.stdio => |file| {
167-
break :full_input file.readToEndAlloc(allocator, std.math.maxInt(usize)) catch |err| {
167+
var file_reader = file.reader(&.{});
168+
break :full_input file_reader.interface.allocRemaining(allocator, .unlimited) catch |err| {
168169
try error_handler.emitMessage(allocator, .err, "unable to read input from stdin: {s}", .{@errorName(err)});
169170
std.process.exit(1);
170171
};
171172
},
172173
.filename => |input_filename| {
173-
break :full_input std.fs.cwd().readFileAlloc(allocator, input_filename, std.math.maxInt(usize)) catch |err| {
174+
break :full_input std.fs.cwd().readFileAlloc(input_filename, allocator, .unlimited) catch |err| {
174175
try error_handler.emitMessage(allocator, .err, "unable to read input file path '{s}': {s}", .{ input_filename, @errorName(err) });
175176
std.process.exit(1);
176177
};
@@ -462,7 +463,10 @@ const IoStream = struct {
462463
pub fn readAll(self: Source, allocator: std.mem.Allocator) !Data {
463464
return switch (self) {
464465
inline .file, .stdio => |file| .{
465-
.bytes = try file.readToEndAlloc(allocator, std.math.maxInt(usize)),
466+
.bytes = b: {
467+
var file_reader = file.reader(&.{});
468+
break :b try file_reader.interface.allocRemaining(allocator, .unlimited);
469+
},
466470
.needs_free = true,
467471
},
468472
.memory => |list| .{ .bytes = list.items, .needs_free = false },

test/src/check-stack-trace.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ pub fn main() !void {
1313
const input_path = args[1];
1414
const optimize_mode_text = args[2];
1515

16-
const input_bytes = try std.fs.cwd().readFileAlloc(arena, input_path, 5 * 1024 * 1024);
16+
const input_bytes = try std.fs.cwd().readFileAlloc(input_path, arena, .limited(5 * 1024 * 1024));
1717
const optimize_mode = std.meta.stringToEnum(std.builtin.OptimizeMode, optimize_mode_text).?;
1818

1919
var stderr = input_bytes;

test/standalone/child_process/main.zig

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ pub fn main() !void {
3232

3333
const hello_stdout = "hello from stdout";
3434
var buf: [hello_stdout.len]u8 = undefined;
35-
const n = try child.stdout.?.deprecatedReader().readAll(&buf);
35+
var stdout_reader = child.stdout.?.reader(&.{});
36+
const n = try stdout_reader.interface.readSliceShort(&buf);
3637
if (!std.mem.eql(u8, buf[0..n], hello_stdout)) {
3738
testError("child stdout: '{s}'; want '{s}'", .{ buf[0..n], hello_stdout });
3839
}

test/standalone/cmakedefine/check.zig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ pub fn main() !void {
99
const actual_path = args[1];
1010
const expected_path = args[2];
1111

12-
const actual = try std.fs.cwd().readFileAlloc(arena, actual_path, 1024 * 1024);
13-
const expected = try std.fs.cwd().readFileAlloc(arena, expected_path, 1024 * 1024);
12+
const actual = try std.fs.cwd().readFileAlloc(actual_path, arena, .limited(1024 * 1024));
13+
const expected = try std.fs.cwd().readFileAlloc(expected_path, arena, .limited(1024 * 1024));
1414

1515
// The actual output starts with a comment which we should strip out before comparing.
1616
const comment_str = "/* This file was generated by ConfigHeader using the Zig Build System. */\n";

test/standalone/entry_point/check_differ.zig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ pub fn main() !void {
66
const args = try std.process.argsAlloc(arena);
77
if (args.len != 3) return error.BadUsage; // usage: 'check_differ <path a> <path b>'
88

9-
const contents_1 = try std.fs.cwd().readFileAlloc(arena, args[1], 1024 * 1024 * 64); // 64 MiB ought to be plenty
10-
const contents_2 = try std.fs.cwd().readFileAlloc(arena, args[2], 1024 * 1024 * 64); // 64 MiB ought to be plenty
9+
const contents_1 = try std.fs.cwd().readFileAlloc(args[1], arena, .limited(1024 * 1024 * 64)); // 64 MiB ought to be plenty
10+
const contents_2 = try std.fs.cwd().readFileAlloc(args[2], arena, .limited(1024 * 1024 * 64)); // 64 MiB ought to be plenty
1111

1212
if (std.mem.eql(u8, contents_1, contents_2)) {
1313
return error.FilesMatch;

tools/docgen.zig

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,8 @@ pub fn main() !void {
7777
var code_dir = try fs.cwd().openDir(code_dir_path, .{});
7878
defer code_dir.close();
7979

80-
const input_file_bytes = try in_file.deprecatedReader().readAllAlloc(arena, max_doc_file_size);
80+
var in_file_reader = in_file.reader(&.{});
81+
const input_file_bytes = try in_file_reader.interface.allocRemaining(arena, .limited(max_doc_file_size));
8182

8283
var tokenizer = Tokenizer.init(input_path, input_file_bytes);
8384
var toc = try genToc(arena, &tokenizer);
@@ -1039,10 +1040,8 @@ fn genHtml(
10391040
});
10401041
defer allocator.free(out_basename);
10411042

1042-
const contents = code_dir.readFileAlloc(allocator, out_basename, std.math.maxInt(u32)) catch |err| {
1043-
return parseError(tokenizer, code.token, "unable to open '{s}': {s}", .{
1044-
out_basename, @errorName(err),
1045-
});
1043+
const contents = code_dir.readFileAlloc(out_basename, allocator, .limited(std.math.maxInt(u32))) catch |err| {
1044+
return parseError(tokenizer, code.token, "unable to open '{s}': {t}", .{ out_basename, err });
10461045
};
10471046
defer allocator.free(contents);
10481047

tools/doctest.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ pub fn main() !void {
7070
const zig_path = opt_zig orelse fatal("missing zig compiler path (--zig)", .{});
7171
const cache_root = opt_cache_root orelse fatal("missing cache root path (--cache-root)", .{});
7272

73-
const source_bytes = try fs.cwd().readFileAlloc(arena, input_path, std.math.maxInt(u32));
73+
const source_bytes = try fs.cwd().readFileAlloc(input_path, arena, .limited(std.math.maxInt(u32)));
7474
const code = try parseManifest(arena, source_bytes);
7575
const source = stripManifest(source_bytes);
7676

tools/dump-cov.zig

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,9 @@ pub fn main() !void {
3838
defer debug_info.deinit(gpa);
3939

4040
const cov_bytes = cov_path.root_dir.handle.readFileAllocOptions(
41-
arena,
4241
cov_path.sub_path,
43-
1 << 30,
44-
null,
42+
arena,
43+
.limited(1 << 30),
4544
.of(SeenPcsHeader),
4645
null,
4746
) catch |err| {

tools/fetch_them_macos_headers.zig

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
const std = @import("std");
22
const fs = std.fs;
3-
const io = std.io;
43
const mem = std.mem;
54
const process = std.process;
65
const assert = std.debug.assert;
@@ -93,7 +92,7 @@ pub fn main() anyerror!void {
9392

9493
var sdk_dir = try std.fs.cwd().openDir(sysroot_path, .{});
9594
defer sdk_dir.close();
96-
const sdk_info = try sdk_dir.readFileAlloc(allocator, "SDKSettings.json", std.math.maxInt(u32));
95+
const sdk_info = try sdk_dir.readFileAlloc("SDKSettings.json", allocator, .limited(std.math.maxInt(u32)));
9796

9897
const parsed_json = try std.json.parseFromSlice(struct {
9998
DefaultProperties: struct { MACOSX_DEPLOYMENT_TARGET: []const u8 },
@@ -198,7 +197,8 @@ fn fetchTarget(
198197
var dirs = std.StringHashMap(fs.Dir).init(arena);
199198
try dirs.putNoClobber(".", dest_dir);
200199

201-
const headers_list_str = try headers_list_file.deprecatedReader().readAllAlloc(arena, std.math.maxInt(usize));
200+
var headers_list_file_reader = headers_list_file.reader(&.{});
201+
const headers_list_str = try headers_list_file_reader.interface.allocRemaining(arena, .unlimited);
202202
const prefix = "/usr/include";
203203

204204
var it = mem.splitScalar(u8, headers_list_str, '\n');

tools/gen_spirv_spec.zig

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ fn readExtRegistry(exts: *std.array_list.Managed(Extension), dir: std.fs.Dir, su
136136
}
137137

138138
fn readRegistry(comptime RegistryType: type, dir: std.fs.Dir, path: []const u8) !RegistryType {
139-
const spec = try dir.readFileAlloc(allocator, path, std.math.maxInt(usize));
139+
const spec = try dir.readFileAlloc(path, allocator, .unlimited);
140140
// Required for json parsing.
141141
// TODO: ALI
142142
@setEvalBranchQuota(10000);
@@ -189,7 +189,7 @@ fn tagPriorityScore(tag: []const u8) usize {
189189
}
190190

191191
fn render(
192-
writer: *std.io.Writer,
192+
writer: *std.Io.Writer,
193193
registry: CoreRegistry,
194194
extensions: []const Extension,
195195
) !void {
@@ -214,7 +214,7 @@ fn render(
214214
\\ none,
215215
\\ _,
216216
\\
217-
\\ pub fn format(self: Id, writer: *std.io.Writer) std.io.Writer.Error!void {
217+
\\ pub fn format(self: Id, writer: *std.Io.Writer) std.Io.Writer.Error!void {
218218
\\ switch (self) {
219219
\\ .none => try writer.writeAll("(none)"),
220220
\\ else => try writer.print("%{d}", .{@intFromEnum(self)}),
@@ -327,7 +327,7 @@ fn render(
327327
}
328328

329329
fn renderInstructionSet(
330-
writer: *std.io.Writer,
330+
writer: *std.Io.Writer,
331331
core: CoreRegistry,
332332
extensions: []const Extension,
333333
all_operand_kinds: OperandKindMap,
@@ -362,7 +362,7 @@ fn renderInstructionSet(
362362
}
363363

364364
fn renderInstructionsCase(
365-
writer: *std.io.Writer,
365+
writer: *std.Io.Writer,
366366
set_name: []const u8,
367367
instructions: []const Instruction,
368368
all_operand_kinds: OperandKindMap,
@@ -409,7 +409,7 @@ fn renderInstructionsCase(
409409
);
410410
}
411411

412-
fn renderClass(writer: *std.io.Writer, instructions: []const Instruction) !void {
412+
fn renderClass(writer: *std.Io.Writer, instructions: []const Instruction) !void {
413413
var class_map = std.StringArrayHashMap(void).init(allocator);
414414

415415
for (instructions) |inst| {
@@ -427,7 +427,7 @@ fn renderClass(writer: *std.io.Writer, instructions: []const Instruction) !void
427427
const Formatter = struct {
428428
data: []const u8,
429429

430-
fn format(f: Formatter, writer: *std.Io.Writer) std.io.Writer.Error!void {
430+
fn format(f: Formatter, writer: *std.Io.Writer) std.Io.Writer.Error!void {
431431
var id_buf: [128]u8 = undefined;
432432
var fw: std.Io.Writer = .fixed(&id_buf);
433433
for (f.data, 0..) |c, i| {
@@ -457,7 +457,7 @@ fn formatId(identifier: []const u8) std.fmt.Alt(Formatter, Formatter.format) {
457457
return .{ .data = .{ .data = identifier } };
458458
}
459459

460-
fn renderOperandKind(writer: *std.io.Writer, operands: []const OperandKind) !void {
460+
fn renderOperandKind(writer: *std.Io.Writer, operands: []const OperandKind) !void {
461461
try writer.writeAll(
462462
\\pub const OperandKind = enum {
463463
\\ opcode,
@@ -513,7 +513,7 @@ fn renderOperandKind(writer: *std.io.Writer, operands: []const OperandKind) !voi
513513
try writer.writeAll("};\n}\n};\n");
514514
}
515515

516-
fn renderEnumerant(writer: *std.io.Writer, enumerant: Enumerant) !void {
516+
fn renderEnumerant(writer: *std.Io.Writer, enumerant: Enumerant) !void {
517517
try writer.print(".{{.name = \"{s}\", .value = ", .{enumerant.enumerant});
518518
switch (enumerant.value) {
519519
.bitflag => |flag| try writer.writeAll(flag),
@@ -530,7 +530,7 @@ fn renderEnumerant(writer: *std.io.Writer, enumerant: Enumerant) !void {
530530
}
531531

532532
fn renderOpcodes(
533-
writer: *std.io.Writer,
533+
writer: *std.Io.Writer,
534534
opcode_type_name: []const u8,
535535
want_operands: bool,
536536
instructions: []const Instruction,
@@ -629,7 +629,7 @@ fn renderOpcodes(
629629
}
630630

631631
fn renderOperandKinds(
632-
writer: *std.io.Writer,
632+
writer: *std.Io.Writer,
633633
kinds: []const OperandKind,
634634
extended_structs: ExtendedStructSet,
635635
) !void {
@@ -643,7 +643,7 @@ fn renderOperandKinds(
643643
}
644644

645645
fn renderValueEnum(
646-
writer: *std.io.Writer,
646+
writer: *std.Io.Writer,
647647
enumeration: OperandKind,
648648
extended_structs: ExtendedStructSet,
649649
) !void {
@@ -721,7 +721,7 @@ fn renderValueEnum(
721721
}
722722

723723
fn renderBitEnum(
724-
writer: *std.io.Writer,
724+
writer: *std.Io.Writer,
725725
enumeration: OperandKind,
726726
extended_structs: ExtendedStructSet,
727727
) !void {
@@ -804,7 +804,7 @@ fn renderBitEnum(
804804
}
805805

806806
fn renderOperand(
807-
writer: *std.io.Writer,
807+
writer: *std.Io.Writer,
808808
kind: enum {
809809
@"union",
810810
instruction,
@@ -888,7 +888,7 @@ fn renderOperand(
888888
try writer.writeAll(",\n");
889889
}
890890

891-
fn renderFieldName(writer: *std.io.Writer, operands: []const Operand, field_index: usize) !void {
891+
fn renderFieldName(writer: *std.Io.Writer, operands: []const Operand, field_index: usize) !void {
892892
const operand = operands[field_index];
893893

894894
derive_from_kind: {

0 commit comments

Comments
 (0)