Skip to content

Commit 51a9046

Browse files
authored
update depreciated code (#7502)
* `zig env`: * fix depreciated interface, update outStream -> writer * make code more readable by updating `anytype` -> `std.fs.File.Writer`
1 parent 4128eea commit 51a9046

File tree

5 files changed

+29
-29
lines changed

5 files changed

+29
-29
lines changed

doc/docgen.zig

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,15 @@ pub fn main() !void {
4242

4343
const input_file_bytes = try in_file.inStream().readAllAlloc(allocator, max_doc_file_size);
4444

45-
var buffered_out_stream = io.bufferedOutStream(out_file.outStream());
45+
var buffered_out_stream = io.bufferedOutStream(out_file.writer());
4646

4747
var tokenizer = Tokenizer.init(in_file_name, input_file_bytes);
4848
var toc = try genToc(allocator, &tokenizer);
4949

5050
try fs.cwd().makePath(tmp_dir_name);
5151
defer fs.cwd().deleteTree(tmp_dir_name) catch {};
5252

53-
try genHtml(allocator, &tokenizer, &toc, buffered_out_stream.outStream(), zig_exe);
53+
try genHtml(allocator, &tokenizer, &toc, buffered_out_stream.writer(), zig_exe);
5454
try buffered_out_stream.flush();
5555
}
5656

@@ -325,7 +325,7 @@ fn genToc(allocator: *mem.Allocator, tokenizer: *Tokenizer) !Toc {
325325
var toc_buf = std.ArrayList(u8).init(allocator);
326326
defer toc_buf.deinit();
327327

328-
var toc = toc_buf.outStream();
328+
var toc = toc_buf.writer();
329329

330330
var nodes = std.ArrayList(Node).init(allocator);
331331
defer nodes.deinit();
@@ -615,7 +615,7 @@ fn urlize(allocator: *mem.Allocator, input: []const u8) ![]u8 {
615615
var buf = std.ArrayList(u8).init(allocator);
616616
defer buf.deinit();
617617

618-
const out = buf.outStream();
618+
const out = buf.writer();
619619
for (input) |c| {
620620
switch (c) {
621621
'a'...'z', 'A'...'Z', '_', '-', '0'...'9' => {
@@ -634,7 +634,7 @@ fn escapeHtml(allocator: *mem.Allocator, input: []const u8) ![]u8 {
634634
var buf = std.ArrayList(u8).init(allocator);
635635
defer buf.deinit();
636636

637-
const out = buf.outStream();
637+
const out = buf.writer();
638638
try writeEscaped(out, input);
639639
return buf.toOwnedSlice();
640640
}
@@ -680,7 +680,7 @@ fn termColor(allocator: *mem.Allocator, input: []const u8) ![]u8 {
680680
var buf = std.ArrayList(u8).init(allocator);
681681
defer buf.deinit();
682682

683-
var out = buf.outStream();
683+
var out = buf.writer();
684684
var number_start_index: usize = undefined;
685685
var first_number: usize = undefined;
686686
var second_number: usize = undefined;

src/main.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ pub fn mainArgs(gpa: *Allocator, arena: *Allocator, args: []const []const u8) !v
200200
} else if (mem.eql(u8, cmd, "version")) {
201201
try std.io.getStdOut().writeAll(build_options.version ++ "\n");
202202
} else if (mem.eql(u8, cmd, "env")) {
203-
try @import("print_env.zig").cmdEnv(arena, cmd_args, io.getStdOut().outStream());
203+
try @import("print_env.zig").cmdEnv(arena, cmd_args, io.getStdOut().writer());
204204
} else if (mem.eql(u8, cmd, "zen")) {
205205
try io.getStdOut().writeAll(info_zen);
206206
} else if (mem.eql(u8, cmd, "help") or mem.eql(u8, cmd, "-h") or mem.eql(u8, cmd, "--help")) {

src/print_env.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const introspect = @import("introspect.zig");
44
const Allocator = std.mem.Allocator;
55
const fatal = @import("main.zig").fatal;
66

7-
pub fn cmdEnv(gpa: *Allocator, args: []const []const u8, stdout: anytype) !void {
7+
pub fn cmdEnv(gpa: *Allocator, args: []const []const u8, stdout: std.fs.File.Writer) !void {
88
const self_exe_path = try std.fs.selfExePathAlloc(gpa);
99
defer gpa.free(self_exe_path);
1010

tools/merge_anal_dumps.zig

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@ pub fn main() anyerror!void {
1717
var dump = Dump.init(allocator);
1818
for (args[1..]) |arg| {
1919
parser = json.Parser.init(allocator, false);
20-
const json_text = try std.io.readFileAlloc(allocator, arg);
20+
const json_text = try std.fs.cwd().readFileAlloc(allocator, arg, std.math.maxInt(usize));
2121
const tree = try parser.parse(json_text);
2222
try dump.mergeJson(tree.root);
2323
}
2424

2525
const stdout = try std.io.getStdOut();
26-
try dump.render(stdout.outStream());
26+
try dump.render(stdout.writer());
2727
}
2828

2929
/// AST source node
@@ -33,12 +33,12 @@ const Node = struct {
3333
col: usize,
3434
fields: []usize,
3535

36-
fn hash(n: Node) u32 {
36+
fn hash(n: Node) u64 {
3737
var hasher = std.hash.Wyhash.init(0);
3838
std.hash.autoHash(&hasher, n.file);
3939
std.hash.autoHash(&hasher, n.line);
4040
std.hash.autoHash(&hasher, n.col);
41-
return @truncate(u32, hasher.final());
41+
return hasher.final();
4242
}
4343

4444
fn eql(a: Node, b: Node) bool {
@@ -52,10 +52,10 @@ const Error = struct {
5252
src: usize,
5353
name: []const u8,
5454

55-
fn hash(n: Error) u32 {
55+
fn hash(n: Error) u64 {
5656
var hasher = std.hash.Wyhash.init(0);
5757
std.hash.autoHash(&hasher, n.src);
58-
return @truncate(u32, hasher.final());
58+
return hasher.final();
5959
}
6060

6161
fn eql(a: Error, b: Error) bool {
@@ -103,7 +103,6 @@ const Type = union(builtin.TypeId) {
103103
Union, // TODO
104104
Fn, // TODO
105105
BoundFn, // TODO
106-
ArgTuple, // TODO
107106
Opaque, // TODO
108107
Frame, // TODO
109108

@@ -127,10 +126,10 @@ const Type = union(builtin.TypeId) {
127126
len: usize,
128127
};
129128

130-
fn hash(t: Type) u32 {
129+
fn hash(t: Type) u64 {
131130
var hasher = std.hash.Wyhash.init(0);
132-
std.hash.autoHash(&hasher, builtin.TypeId(t));
133-
return @truncate(u32, hasher.final());
131+
std.hash.autoHash(&hasher, t);
132+
return hasher.final();
134133
}
135134

136135
fn eql(a: Type, b: Type) bool {
@@ -144,22 +143,23 @@ const Dump = struct {
144143
root_name: ?[]const u8 = null,
145144
targets: std.ArrayList([]const u8),
146145

147-
const FileMap = std.StringHashMap(usize);
148146
file_list: std.ArrayList([]const u8),
149147
file_map: FileMap,
150148

151-
const NodeMap = std.HashMap(Node, usize, Node.hash, Node.eql);
152149
node_list: std.ArrayList(Node),
153150
node_map: NodeMap,
154151

155-
const ErrorMap = std.HashMap(Error, usize, Error.hash, Error.eql);
156152
error_list: std.ArrayList(Error),
157153
error_map: ErrorMap,
158154

159-
const TypeMap = std.HashMap(Type, usize, Type.hash, Type.eql);
160155
type_list: std.ArrayList(Type),
161156
type_map: TypeMap,
162157

158+
const FileMap = std.StringHashMap(usize);
159+
const NodeMap = std.HashMap(Node, usize, Node.hash, Node.eql, 80);
160+
const ErrorMap = std.HashMap(Error, usize, Error.hash, Error.eql, 80);
161+
const TypeMap = std.HashMap(Type, usize, Type.hash, Type.eql, 80);
162+
163163
fn init(allocator: *mem.Allocator) Dump {
164164
return Dump{
165165
.targets = std.ArrayList([]const u8).init(allocator),
@@ -310,7 +310,7 @@ const Dump = struct {
310310
try other_types_to_mine.putNoClobber(other_type_index, gop.kv.value);
311311
}
312312

313-
fn render(self: *Dump, stream: var) !void {
313+
fn render(self: *Dump, stream: anytype) !void {
314314
var jw = json.WriteStream(@TypeOf(stream).Child, 10).init(stream);
315315
try jw.beginObject();
316316

tools/update_glibc.zig

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -239,8 +239,8 @@ pub fn main() !void {
239239
const vers_txt_path = try fs.path.join(allocator, &[_][]const u8{ glibc_out_dir, "vers.txt" });
240240
const vers_txt_file = try fs.cwd().createFile(vers_txt_path, .{});
241241
defer vers_txt_file.close();
242-
var buffered = std.io.bufferedOutStream(vers_txt_file.outStream());
243-
const vers_txt = buffered.outStream();
242+
var buffered = std.io.bufferedOutStream(vers_txt_file.writer());
243+
const vers_txt = buffered.writer();
244244
for (global_ver_list) |name, i| {
245245
_ = global_ver_set.put(name, i) catch unreachable;
246246
try vers_txt.print("{}\n", .{name});
@@ -251,8 +251,8 @@ pub fn main() !void {
251251
const fns_txt_path = try fs.path.join(allocator, &[_][]const u8{ glibc_out_dir, "fns.txt" });
252252
const fns_txt_file = try fs.cwd().createFile(fns_txt_path, .{});
253253
defer fns_txt_file.close();
254-
var buffered = std.io.bufferedOutStream(fns_txt_file.outStream());
255-
const fns_txt = buffered.outStream();
254+
var buffered = std.io.bufferedOutStream(fns_txt_file.writer());
255+
const fns_txt = buffered.writer();
256256
for (global_fn_list) |name, i| {
257257
const entry = global_fn_set.getEntry(name).?;
258258
entry.value.index = i;
@@ -282,8 +282,8 @@ pub fn main() !void {
282282
const abilist_txt_path = try fs.path.join(allocator, &[_][]const u8{ glibc_out_dir, "abi.txt" });
283283
const abilist_txt_file = try fs.cwd().createFile(abilist_txt_path, .{});
284284
defer abilist_txt_file.close();
285-
var buffered = std.io.bufferedOutStream(abilist_txt_file.outStream());
286-
const abilist_txt = buffered.outStream();
285+
var buffered = std.io.bufferedOutStream(abilist_txt_file.writer());
286+
const abilist_txt = buffered.writer();
287287

288288
// first iterate over the abi lists
289289
for (abi_lists) |*abi_list, abi_index| {

0 commit comments

Comments
 (0)