Skip to content

Commit 5bf1ae9

Browse files
committed
feat(std): Update Zig version to 0.16.0-dev
1 parent eb9b08e commit 5bf1ae9

File tree

5 files changed

+50
-40
lines changed

5 files changed

+50
-40
lines changed

build.zig.zon

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
.name = .zig_mcp,
33
.version = "0.0.0",
44
.fingerprint = 0x1c29ab0bcd4442bc,
5-
.minimum_zig_version = "0.16.0-dev.23+47a2f2dda",
5+
.minimum_zig_version = "0.16.0-dev.205+4c0127566",
66
.dependencies = .{},
77
.paths = .{
88
"build.zig",

docs/Decl.zig

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ const gpa = std.heap.wasm_allocator;
66
const assert = std.debug.assert;
77
const log = std.log;
88
const Oom = error{OutOfMemory};
9+
const ArrayList = std.ArrayList;
910

1011
ast_node: Ast.Node.Index,
1112
file: Walk.File.Index,
@@ -189,7 +190,7 @@ pub fn lookup(decl: *const Decl, name: []const u8) ?Decl.Index {
189190
}
190191

191192
/// Appends the fully qualified name to `out`.
192-
pub fn fqn(decl: *const Decl, out: *std.ArrayListUnmanaged(u8)) Oom!void {
193+
pub fn fqn(decl: *const Decl, out: *ArrayList(u8)) Oom!void {
193194
try decl.append_path(out);
194195
if (decl.parent != .none) {
195196
try append_parent_ns(out, decl.parent);
@@ -199,12 +200,12 @@ pub fn fqn(decl: *const Decl, out: *std.ArrayListUnmanaged(u8)) Oom!void {
199200
}
200201
}
201202

202-
pub fn reset_with_path(decl: *const Decl, list: *std.ArrayListUnmanaged(u8)) Oom!void {
203+
pub fn reset_with_path(decl: *const Decl, list: *ArrayList(u8)) Oom!void {
203204
list.clearRetainingCapacity();
204205
try append_path(decl, list);
205206
}
206207

207-
pub fn append_path(decl: *const Decl, list: *std.ArrayListUnmanaged(u8)) Oom!void {
208+
pub fn append_path(decl: *const Decl, list: *ArrayList(u8)) Oom!void {
208209
const start = list.items.len;
209210
// Prefer the module name alias.
210211
for (Walk.modules.keys(), Walk.modules.values()) |pkg_name, pkg_file| {
@@ -230,7 +231,7 @@ pub fn append_path(decl: *const Decl, list: *std.ArrayListUnmanaged(u8)) Oom!voi
230231
}
231232
}
232233

233-
pub fn append_parent_ns(list: *std.ArrayListUnmanaged(u8), parent: Decl.Index) Oom!void {
234+
pub fn append_parent_ns(list: *ArrayList(u8), parent: Decl.Index) Oom!void {
234235
assert(parent != .none);
235236
const decl = parent.get();
236237
if (decl.parent != .none) {

docs/html_render.zig

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
const std = @import("std");
22
const Ast = std.zig.Ast;
33
const assert = std.debug.assert;
4+
const ArrayList = std.ArrayList;
5+
const Writer = std.Io.Writer;
46

57
const Walk = @import("Walk");
68
const Decl = Walk.Decl;
@@ -32,7 +34,7 @@ pub const Annotation = struct {
3234

3335
pub fn fileSourceHtml(
3436
file_index: Walk.File.Index,
35-
out: *std.ArrayListUnmanaged(u8),
37+
out: *ArrayList(u8),
3638
root_node: Ast.Node.Index,
3739
options: RenderSourceOptions,
3840
) !void {
@@ -245,7 +247,7 @@ pub fn fileSourceHtml(
245247
}
246248
}
247249

248-
fn appendUnindented(out: *std.ArrayListUnmanaged(u8), s: []const u8, indent: usize) !void {
250+
fn appendUnindented(out: *ArrayList(u8), s: []const u8, indent: usize) !void {
249251
var it = std.mem.splitScalar(u8, s, '\n');
250252
var is_first_line = true;
251253
while (it.next()) |line| {
@@ -259,7 +261,7 @@ fn appendUnindented(out: *std.ArrayListUnmanaged(u8), s: []const u8, indent: usi
259261
}
260262
}
261263

262-
fn appendUnindentedPlain(out: *std.ArrayListUnmanaged(u8), s: []const u8, indent: usize) !void {
264+
fn appendUnindentedPlain(out: *ArrayList(u8), s: []const u8, indent: usize) !void {
263265
var it = std.mem.splitScalar(u8, s, '\n');
264266
var is_first_line = true;
265267
while (it.next()) |line| {
@@ -273,7 +275,7 @@ fn appendUnindentedPlain(out: *std.ArrayListUnmanaged(u8), s: []const u8, indent
273275
}
274276
}
275277

276-
pub fn appendEscaped(out: *std.ArrayListUnmanaged(u8), s: []const u8) !void {
278+
pub fn appendEscaped(out: *ArrayList(u8), s: []const u8) !void {
277279
for (s) |c| {
278280
try out.ensureUnusedCapacity(gpa, 6);
279281
switch (c) {
@@ -288,7 +290,7 @@ pub fn appendEscaped(out: *std.ArrayListUnmanaged(u8), s: []const u8) !void {
288290

289291
fn walkFieldAccesses(
290292
file_index: Walk.File.Index,
291-
out: *std.ArrayListUnmanaged(u8),
293+
out: *ArrayList(u8),
292294
node: Ast.Node.Index,
293295
) Oom!void {
294296
const ast = file_index.get_ast();
@@ -312,7 +314,7 @@ fn walkFieldAccesses(
312314

313315
fn resolveIdentLink(
314316
file_index: Walk.File.Index,
315-
out: *std.ArrayListUnmanaged(u8),
317+
out: *ArrayList(u8),
316318
ident_token: Ast.TokenIndex,
317319
) Oom!void {
318320
const decl_index = file_index.get().lookup_token(ident_token);
@@ -332,7 +334,7 @@ fn unindent(s: []const u8, indent: usize) []const u8 {
332334
return s[indent_idx..];
333335
}
334336

335-
pub fn resolveDeclLink(decl_index: Decl.Index, out: *std.ArrayListUnmanaged(u8)) Oom!void {
337+
pub fn resolveDeclLink(decl_index: Decl.Index, out: *ArrayList(u8)) Oom!void {
336338
const decl = decl_index.get();
337339
switch (decl.categorize()) {
338340
.alias => |alias_decl| try alias_decl.get().fqn(out),

docs/main.zig

Lines changed: 28 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ const Ast = std.zig.Ast;
55
const Walk = @import("Walk");
66
const markdown = @import("markdown.zig");
77
const Decl = Walk.Decl;
8+
const ArrayList = std.ArrayList;
9+
const Writer = std.Io.Writer;
810

911
const fileSourceHtml = @import("html_render.zig").fileSourceHtml;
1012
const appendEscaped = @import("html_render.zig").appendEscaped;
@@ -66,8 +68,8 @@ export fn unpack(tar_ptr: [*]u8, tar_len: usize) void {
6668
};
6769
}
6870

69-
var query_string: std.ArrayListUnmanaged(u8) = .empty;
70-
var query_results: std.ArrayListUnmanaged(Decl.Index) = .empty;
71+
var query_string: ArrayList(u8) = .empty;
72+
var query_results: ArrayList(Decl.Index) = .empty;
7173

7274
/// Resizes the query string to be the correct length; returns the pointer to
7375
/// the query string.
@@ -99,11 +101,11 @@ fn query_exec_fallible(query: []const u8, ignore_case: bool) !void {
99101
segments: u16,
100102
};
101103
const g = struct {
102-
var full_path_search_text: std.ArrayListUnmanaged(u8) = .empty;
103-
var full_path_search_text_lower: std.ArrayListUnmanaged(u8) = .empty;
104-
var doc_search_text: std.ArrayListUnmanaged(u8) = .empty;
104+
var full_path_search_text: ArrayList(u8) = .empty;
105+
var full_path_search_text_lower: ArrayList(u8) = .empty;
106+
var doc_search_text: ArrayList(u8) = .empty;
105107
/// Each element matches a corresponding query_results element.
106-
var scores: std.ArrayListUnmanaged(Score) = .empty;
108+
var scores: ArrayList(Score) = .empty;
107109
};
108110

109111
// First element stores the size of the list.
@@ -234,7 +236,7 @@ const ErrorIdentifier = packed struct(u64) {
234236
return ast.tokenTag(token_index - 1) == .doc_comment;
235237
}
236238

237-
fn html(ei: ErrorIdentifier, base_decl: Decl.Index, out: *std.ArrayListUnmanaged(u8)) Oom!void {
239+
fn html(ei: ErrorIdentifier, base_decl: Decl.Index, out: *ArrayList(u8)) Oom!void {
238240
const decl_index = ei.decl_index;
239241
const ast = decl_index.get().file.get_ast();
240242
const name = ast.tokenSlice(ei.token_index);
@@ -257,7 +259,7 @@ const ErrorIdentifier = packed struct(u64) {
257259
}
258260
};
259261

260-
var string_result: std.ArrayListUnmanaged(u8) = .empty;
262+
var string_result: ArrayList(u8) = .empty;
261263
var error_set_result: std.StringArrayHashMapUnmanaged(ErrorIdentifier) = .empty;
262264

263265
export fn decl_error_set(decl_index: Decl.Index) Slice(ErrorIdentifier) {
@@ -408,7 +410,7 @@ fn decl_fields_fallible(decl_index: Decl.Index) ![]Ast.Node.Index {
408410

409411
fn ast_decl_fields_fallible(ast: *Ast, ast_index: Ast.Node.Index) ![]Ast.Node.Index {
410412
const g = struct {
411-
var result: std.ArrayListUnmanaged(Ast.Node.Index) = .empty;
413+
var result: ArrayList(Ast.Node.Index) = .empty;
412414
};
413415
g.result.clearRetainingCapacity();
414416
var buf: [2]Ast.Node.Index = undefined;
@@ -426,7 +428,7 @@ fn ast_decl_fields_fallible(ast: *Ast, ast_index: Ast.Node.Index) ![]Ast.Node.In
426428

427429
fn decl_params_fallible(decl_index: Decl.Index) ![]Ast.Node.Index {
428430
const g = struct {
429-
var result: std.ArrayListUnmanaged(Ast.Node.Index) = .empty;
431+
var result: ArrayList(Ast.Node.Index) = .empty;
430432
};
431433
g.result.clearRetainingCapacity();
432434
const decl = decl_index.get();
@@ -457,7 +459,7 @@ export fn decl_param_html(decl_index: Decl.Index, param_node: Ast.Node.Index) St
457459
}
458460

459461
fn decl_field_html_fallible(
460-
out: *std.ArrayListUnmanaged(u8),
462+
out: *ArrayList(u8),
461463
decl_index: Decl.Index,
462464
field_node: Ast.Node.Index,
463465
) !void {
@@ -474,7 +476,7 @@ fn decl_field_html_fallible(
474476
}
475477

476478
fn decl_param_html_fallible(
477-
out: *std.ArrayListUnmanaged(u8),
479+
out: *ArrayList(u8),
478480
decl_index: Decl.Index,
479481
param_node: Ast.Node.Index,
480482
) !void {
@@ -642,7 +644,7 @@ export fn decl_docs_html(decl_index: Decl.Index, short: bool) String {
642644
}
643645

644646
fn collect_docs(
645-
list: *std.ArrayListUnmanaged(u8),
647+
list: *ArrayList(u8),
646648
ast: *const Ast,
647649
first_doc_comment: Ast.TokenIndex,
648650
) Oom!void {
@@ -660,7 +662,7 @@ fn collect_docs(
660662
}
661663

662664
fn render_docs(
663-
out: *std.ArrayListUnmanaged(u8),
665+
out: *ArrayList(u8),
664666
decl_index: Decl.Index,
665667
first_doc_comment: Ast.TokenIndex,
666668
short: bool,
@@ -683,17 +685,16 @@ fn render_docs(
683685
var parsed_doc = try parser.endInput();
684686
defer parsed_doc.deinit(gpa);
685687

686-
const Writer = std.ArrayListUnmanaged(u8).Writer;
687-
const Renderer = markdown.Renderer(Writer, Decl.Index);
688+
const Renderer = markdown.Renderer(Decl.Index);
688689
const renderer: Renderer = .{
689690
.context = decl_index,
690691
.renderFn = struct {
691692
fn render(
692693
r: Renderer,
693694
doc: markdown.Document,
694695
node: markdown.Document.Node.Index,
695-
writer: Writer,
696-
) !void {
696+
writer: *Writer,
697+
) Writer.Error!void {
697698
const data = doc.nodes.items(.data)[@intFromEnum(node)];
698699
switch (doc.nodes.items(.tag)[@intFromEnum(node)]) {
699700
.code_span => {
@@ -708,7 +709,12 @@ fn render_docs(
708709
}
709710
}.render,
710711
};
711-
try renderer.render(parsed_doc, out.writer(gpa));
712+
713+
var allocating = Writer.Allocating.fromArrayList(gpa, out);
714+
defer out.* = allocating.toArrayList();
715+
renderer.render(parsed_doc, &allocating.writer) catch |err| switch (err) {
716+
error.WriteFailed => return error.OutOfMemory,
717+
};
712718
}
713719

714720
fn resolve_decl_path(decl_index: Decl.Index, path: []const u8) ?Decl.Index {
@@ -806,7 +812,7 @@ export fn find_module_root(pkg: Walk.ModuleIndex) Decl.Index {
806812
}
807813

808814
/// Set by `set_input_string`.
809-
var input_string: std.ArrayListUnmanaged(u8) = .empty;
815+
var input_string: ArrayList(u8) = .empty;
810816

811817
export fn set_input_string(len: usize) [*]u8 {
812818
input_string.resize(gpa, len) catch @panic("OOM");
@@ -828,7 +834,7 @@ export fn find_decl() Decl.Index {
828834
if (result != .none) return result;
829835

830836
const g = struct {
831-
var match_fqn: std.ArrayListUnmanaged(u8) = .empty;
837+
var match_fqn: ArrayList(u8) = .empty;
832838
};
833839
for (Walk.decls.items, 0..) |*decl, decl_index| {
834840
g.match_fqn.clearRetainingCapacity();
@@ -884,7 +890,7 @@ export fn type_fn_members(parent: Decl.Index, include_private: bool) Slice(Decl.
884890

885891
export fn namespace_members(parent: Decl.Index, include_private: bool) Slice(Decl.Index) {
886892
const g = struct {
887-
var members: std.ArrayListUnmanaged(Decl.Index) = .empty;
893+
var members: ArrayList(Decl.Index) = .empty;
888894
};
889895

890896
g.members.clearRetainingCapacity();

docs/markdown/renderer.zig

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,33 +2,34 @@ const std = @import("std");
22
const Document = @import("Document.zig");
33
const Node = Document.Node;
44
const assert = std.debug.assert;
5+
const Writer = std.Io.Writer;
56

67
/// A Markdown document renderer.
78
///
89
/// Each concrete `Renderer` type has a `renderDefault` function, with the
910
/// intention that custom `renderFn` implementations can call `renderDefault`
1011
/// for node types for which they require no special rendering.
11-
pub fn Renderer(comptime Writer: type, comptime Context: type) type {
12+
pub fn Renderer(comptime Context: type) type {
1213
return struct {
1314
renderFn: *const fn (
1415
r: Self,
1516
doc: Document,
1617
node: Node.Index,
17-
writer: Writer,
18+
writer: *Writer,
1819
) Writer.Error!void = renderDefault,
1920
context: Context,
2021

2122
const Self = @This();
2223

23-
pub fn render(r: Self, doc: Document, writer: Writer) Writer.Error!void {
24+
pub fn render(r: Self, doc: Document, writer: *Writer) Writer.Error!void {
2425
try r.renderFn(r, doc, .root, writer);
2526
}
2627

2728
pub fn renderDefault(
2829
r: Self,
2930
doc: Document,
3031
node: Node.Index,
31-
writer: Writer,
32+
writer: *Writer,
3233
) Writer.Error!void {
3334
const data = doc.nodes.items(.data)[@intFromEnum(node)];
3435
switch (doc.nodes.items(.tag)[@intFromEnum(node)]) {
@@ -162,8 +163,8 @@ pub fn Renderer(comptime Writer: type, comptime Context: type) type {
162163
pub fn renderInlineNodeText(
163164
doc: Document,
164165
node: Node.Index,
165-
writer: anytype,
166-
) @TypeOf(writer).Error!void {
166+
writer: *Writer,
167+
) Writer.Error!void {
167168
const data = doc.nodes.items(.data)[@intFromEnum(node)];
168169
switch (doc.nodes.items(.tag)[@intFromEnum(node)]) {
169170
.root,

0 commit comments

Comments
 (0)