authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2026-10-24 23:07:01+02:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2026-10-24 23:07:01+02:00
log680ab55488798be67fd1744f69045b41580def07
treeb3779cd54b2912da4c5a07af2d7ed2c77a12e877
parent935a3b9c757283b4eaaf78b417e34d7d0fbc8737
parentbc2c709e18b72b31b4f65ff6b9b14b9229da491e

Merge pull request 'ArrayList: remove usages of Managed from `std/zig/llvm`, `lib/compiler/Maker`, `docs/wasm/markdown`' (#37385) from Der_Teufel/zig:arraylist-managed into master

Reviewed-on: https://codeberg.org/ziglang/zig/pulls/37385 Reviewed-by: Andrew Kelley <andrew@ziglang.org>

8 files changed, 61 insertions(+), 54 deletions(-)

lib/compiler/Maker.zig+11-8
......@@ -4681,12 +4681,13 @@ test sanitizeExampleName {
46814681const Templates = struct {
46824682 zig_lib_directory: Cache.Directory,
46834683 dir: Io.Dir,
4684 buffer: std.array_list.Managed(u8),
4684 buffer: std.ArrayList(u8),
4685 gpa: Allocator,
46854686
46864687 fn deinit(templates: *Templates, io: Io) void {
46874688 templates.zig_lib_directory.handle.close(io);
46884689 templates.dir.close(io);
4689 templates.buffer.deinit();
4690 templates.buffer.deinit(templates.gpa);
46904691 templates.* = undefined;
46914692 }
46924693
......@@ -4709,29 +4710,30 @@ const Templates = struct {
47094710 const contents = templates.dir.readFileAlloc(io, template_path, arena, .limited(max_bytes)) catch |err| {
47104711 fatal("unable to read template file {q}: {t}", .{ template_path, err });
47114712 };
4713 const gpa = templates.gpa;
47124714 templates.buffer.clearRetainingCapacity();
4713 try templates.buffer.ensureUnusedCapacity(contents.len);
4715 try templates.buffer.ensureUnusedCapacity(gpa, contents.len);
47144716 var i: usize = 0;
47154717 while (i < contents.len) {
47164718 if (contents[i] == '_' or contents[i] == '.') {
47174719 // Both '_' and '.' are allowed because depending on the context
47184720 // one prefix will be valid, while the other might not.
47194721 if (std.mem.startsWith(u8, contents[i + 1 ..], "NAME")) {
4720 try templates.buffer.appendSlice(root_name);
4722 try templates.buffer.appendSlice(gpa, root_name);
47214723 i += "_NAME".len;
47224724 continue;
47234725 } else if (std.mem.startsWith(u8, contents[i + 1 ..], "FINGERPRINT")) {
4724 try templates.buffer.print("0x{x}", .{fingerprint.int()});
4726 try templates.buffer.print(gpa, "0x{x}", .{fingerprint.int()});
47254727 i += "_FINGERPRINT".len;
47264728 continue;
47274729 } else if (std.mem.startsWith(u8, contents[i + 1 ..], "ZIGVER")) {
4728 try templates.buffer.appendSlice(builtin.zig_version_string);
4730 try templates.buffer.appendSlice(gpa, builtin.zig_version_string);
47294731 i += "_ZIGVER".len;
47304732 continue;
47314733 }
47324734 }
47334735
4734 try templates.buffer.append(contents[i]);
4736 try templates.buffer.append(gpa, contents[i]);
47354737 i += 1;
47364738 }
47374739
......@@ -4752,7 +4754,8 @@ const Templates = struct {
47524754 return .{
47534755 .zig_lib_directory = zig_lib_directory,
47544756 .dir = template_dir,
4755 .buffer = std.array_list.Managed(u8).init(gpa),
4757 .buffer = .empty,
4758 .gpa = gpa,
47564759 };
47574760 }
47584761
lib/compiler/Maker/Fetch.zig+6-6
......@@ -1756,11 +1756,11 @@ fn computeHash(f: *Fetch, pkg_path: Path, filter: Filter) RunError!ComputedHash
17561756 const root_dir = pkg_path.root_dir.handle;
17571757
17581758 // Collect all files, recursively, then sort.
1759 var all_files = std.array_list.Managed(*HashedFile).init(gpa);
1760 defer all_files.deinit();
1759 var all_files: std.ArrayList(*HashedFile) = .empty;
1760 defer all_files.deinit(gpa);
17611761
1762 var deleted_files = std.array_list.Managed(*DeletedFile).init(gpa);
1763 defer deleted_files.deinit();
1762 var deleted_files: std.ArrayList(*DeletedFile) = .empty;
1763 defer deleted_files.deinit(gpa);
17641764
17651765 // Track directories which had any files deleted from them so that empty directories
17661766 // can be deleted.
......@@ -1803,7 +1803,7 @@ fn computeHash(f: *Fetch, pkg_path: Path, filter: Filter) RunError!ComputedHash
18031803 .failure = undefined, // to be populated by the worker
18041804 };
18051805 group.async(io, workerDeleteFile, .{ io, root_dir, deleted_file });
1806 try deleted_files.append(deleted_file);
1806 try deleted_files.append(gpa, deleted_file);
18071807 continue;
18081808 }
18091809
......@@ -1831,7 +1831,7 @@ fn computeHash(f: *Fetch, pkg_path: Path, filter: Filter) RunError!ComputedHash
18311831 .size = undefined, // to be populated by the worker
18321832 };
18331833 group.async(io, workerHashFile, .{ io, root_dir, hashed_file });
1834 try all_files.append(hashed_file);
1834 try all_files.append(gpa, hashed_file);
18351835 }
18361836
18371837 try group.await(io);
lib/compiler/Maker/Step/Compile.zig+1-1
......@@ -867,7 +867,7 @@ fn lowerZigArgs(
867867 return step.fail(maker, "failed creating directory {f}: {t}", .{ args_path, err });
868868
869869 const args_to_escape = zig_args.items[2..];
870 var escaped_args = try std.array_list.Managed([]const u8).initCapacity(arena, args_to_escape.len);
870 var escaped_args: std.ArrayList([]const u8) = try .initCapacity(arena, args_to_escape.len);
871871 arg_blk: for (args_to_escape) |arg| {
872872 for (arg, 0..) |c, arg_idx| {
873873 if (c == '\\' or c == '"') {
lib/docs/wasm/markdown.zig+3-3
......@@ -1119,9 +1119,9 @@ fn testRender(input: []const u8, expected: []const u8) !void {
11191119 var doc = try parser.endInput();
11201120 defer doc.deinit(testing.allocator);
11211121
1122 var actual = std.array_list.Managed(u8).init(testing.allocator);
1122 var actual: std.Io.Writer.Allocating = .init(testing.allocator);
11231123 defer actual.deinit();
1124 try doc.render(actual.writer());
1124 try doc.render(&actual.writer);
11251125
1126 try testing.expectEqualStrings(expected, actual.items);
1126 try testing.expectEqualStrings(expected, actual.written());
11271127}
lib/docs/wasm/markdown/Document.zig+2-2
......@@ -160,8 +160,8 @@ pub fn deinit(doc: *Document, allocator: Allocator) void {
160160}
161161
162162/// Renders a document directly to a writer using the default renderer.
163pub fn render(doc: Document, writer: anytype) @TypeOf(writer).Error!void {
164 const renderer: Renderer(@TypeOf(writer), void) = .{ .context = {} };
163pub fn render(doc: Document, writer: *std.Io.Writer) std.Io.Writer.Error!void {
164 const renderer: Renderer(void) = .{ .context = {} };
165165 try renderer.render(doc, writer);
166166}
167167
lib/std/zig/llvm/BitcodeReader.zig+16-16
......@@ -60,40 +60,40 @@ pub const Record = struct {
6060 blob: []const u8,
6161
6262 fn toOwnedAbbrev(record: Record, allocator: std.mem.Allocator) !Abbrev {
63 var operands = std.array_list.Managed(Abbrev.Operand).init(allocator);
64 defer operands.deinit();
63 var operands: std.ArrayList(Abbrev.Operand) = .empty;
64 defer operands.deinit(allocator);
6565
6666 assert(record.id == Abbrev.Builtin.define_abbrev.toRecordId());
6767 var i: usize = 0;
6868 while (i < record.operands.len) switch (record.operands[i]) {
6969 Abbrev.Operand.literal_id => {
70 try operands.append(.{ .literal = record.operands[i + 1] });
70 try operands.append(allocator, .{ .literal = record.operands[i + 1] });
7171 i += 2;
7272 },
7373 @backingInt(Abbrev.Operand.Encoding.fixed) => {
74 try operands.append(.{ .encoding = .{ .fixed = @intCast(record.operands[i + 1]) } });
74 try operands.append(allocator, .{ .encoding = .{ .fixed = @intCast(record.operands[i + 1]) } });
7575 i += 2;
7676 },
7777 @backingInt(Abbrev.Operand.Encoding.vbr) => {
78 try operands.append(.{ .encoding = .{ .vbr = @intCast(record.operands[i + 1]) } });
78 try operands.append(allocator, .{ .encoding = .{ .vbr = @intCast(record.operands[i + 1]) } });
7979 i += 2;
8080 },
8181 @backingInt(Abbrev.Operand.Encoding.array) => {
82 try operands.append(.{ .encoding = .{ .array = 6 } });
82 try operands.append(allocator, .{ .encoding = .{ .array = 6 } });
8383 i += 1;
8484 },
8585 @backingInt(Abbrev.Operand.Encoding.char6) => {
86 try operands.append(.{ .encoding = .char6 });
86 try operands.append(allocator, .{ .encoding = .char6 });
8787 i += 1;
8888 },
8989 @backingInt(Abbrev.Operand.Encoding.blob) => {
90 try operands.append(.{ .encoding = .{ .blob = 6 } });
90 try operands.append(allocator, .{ .encoding = .{ .blob = 6 } });
9191 i += 1;
9292 },
9393 else => unreachable,
9494 };
9595
96 return .{ .operands = try operands.toOwnedSlice() };
96 return .{ .operands = try operands.toOwnedSlice(allocator) };
9797 }
9898};
9999
......@@ -198,8 +198,8 @@ fn nextRecord(bc: *BitcodeReader) !?Record {
198198 defer bc.record_arena = record_arena.state;
199199 _ = record_arena.reset(.retain_capacity);
200200
201 var operands = try std.array_list.Managed(u64).initCapacity(record_arena.allocator(), abbrev.operands.len);
202 var blob = std.array_list.Managed(u8).init(record_arena.allocator());
201 var operands: std.ArrayList(u64) = try .initCapacity(record_arena.allocator(), abbrev.operands.len);
202 var blob: std.ArrayList(u8) = .empty;
203203 for (abbrev.operands, 0..) |abbrev_operand, abbrev_operand_i| switch (abbrev_operand) {
204204 .literal => |value| operands.appendAssumeCapacity(value),
205205 .encoding => |abbrev_encoding| switch (abbrev_encoding) {
......@@ -208,7 +208,7 @@ fn nextRecord(bc: *BitcodeReader) !?Record {
208208 .array => |len_width| {
209209 assert(abbrev_operand_i + 2 == abbrev.operands.len);
210210 const len: usize = @intCast(try bc.readVbr(u32, len_width));
211 try operands.ensureUnusedCapacity(len);
211 try operands.ensureUnusedCapacity(record_arena.allocator(), len);
212212 for (0..len) |_| switch (abbrev.operands[abbrev.operands.len - 1]) {
213213 .literal => |elem_value| operands.appendAssumeCapacity(elem_value),
214214 .encoding => |elem_encoding| switch (elem_encoding) {
......@@ -219,16 +219,16 @@ fn nextRecord(bc: *BitcodeReader) !?Record {
219219 },
220220 .align_32_bits, .block_len => return error.UnsupportedArrayElement,
221221 .abbrev_op => switch (try bc.readFixed(u1, 1)) {
222 1 => try operands.appendSlice(&.{
222 1 => try operands.appendSlice(record_arena.allocator(), &.{
223223 Abbrev.Operand.literal_id,
224224 try bc.readVbr(u64, 8),
225225 }),
226226 0 => {
227227 const encoding: Abbrev.Operand.Encoding =
228228 @fromBackingInt(@intCast(try bc.readFixed(u3, 3)));
229 try operands.append(@backingInt(encoding));
229 try operands.append(record_arena.allocator(), @backingInt(encoding));
230230 switch (encoding) {
231 .fixed, .vbr => try operands.append(try bc.readVbr(u7, 5)),
231 .fixed, .vbr => try operands.append(record_arena.allocator(), try bc.readVbr(u7, 5)),
232232 .array, .char6, .blob => {},
233233 _ => return error.UnsuportedAbbrevEncoding,
234234 }
......@@ -243,7 +243,7 @@ fn nextRecord(bc: *BitcodeReader) !?Record {
243243 const len = std.math.cast(usize, try bc.readVbr(u32, len_width)) orelse
244244 return error.Overflow;
245245 bc.align32Bits();
246 try bc.readBytes(try blob.addManyAsSlice(len));
246 try bc.readBytes(try blob.addManyAsSlice(record_arena.allocator(), len));
247247 bc.align32Bits();
248248 },
249249 },
lib/std/zig/llvm/Builder.zig+9-9
......@@ -10505,24 +10505,24 @@ pub fn getIntrinsic(
1050510505
1050610506 var attributes: struct {
1050710507 builder: *Builder,
10508 list: std.array_list.Managed(Attribute.Index),
10508 list: std.ArrayList(Attribute.Index),
1050910509
10510 fn deinit(state: *@This()) void {
10511 state.list.deinit();
10510 fn deinit(state: *@This(), gpa: Allocator) void {
10511 state.list.deinit(gpa);
1051210512 state.* = undefined;
1051310513 }
1051410514
10515 fn get(state: *@This(), attributes: []const Attribute) Allocator.Error!Attributes {
10516 try state.list.resize(attributes.len);
10515 fn get(state: *@This(), gpa: Allocator, attributes: []const Attribute) Allocator.Error!Attributes {
10516 try state.list.resize(gpa, attributes.len);
1051710517 for (state.list.items, attributes) |*item, attribute|
1051810518 item.* = try state.builder.attr(attribute);
1051910519 return state.builder.attrs(state.list.items);
1052010520 }
10521 } = .{ .builder = self, .list = std.array_list.Managed(Attribute.Index).init(allocator) };
10522 defer attributes.deinit();
10521 } = .{ .builder = self, .list = .empty };
10522 defer attributes.deinit(allocator);
1052310523
1052410524 var overload_index: usize = 0;
10525 function_attributes[FunctionAttributes.function_index] = try attributes.get(signature.attrs);
10525 function_attributes[FunctionAttributes.function_index] = try attributes.get(allocator, signature.attrs);
1052610526 function_attributes[FunctionAttributes.return_index] = .none; // needed for void return
1052710527 for (0.., param_types, signature.params) |param_index, *param_type, signature_param| {
1052810528 switch (signature_param.kind) {
......@@ -10538,7 +10538,7 @@ pub fn getIntrinsic(
1053810538 FunctionAttributes.return_index
1053910539 else
1054010540 FunctionAttributes.params_index + (param_index - signature.ret_len)
10541 ] = try attributes.get(signature_param.attrs);
10541 ] = try attributes.get(allocator, signature_param.attrs);
1054210542 }
1054310543 assert(overload_index == overload.len);
1054410544 for (param_types, signature.params) |*param_type, signature_param| {
lib/std/zig/llvm/bitcode_writer.zig+13-9
......@@ -19,7 +19,8 @@ pub fn BitcodeWriter(comptime types: []const type) type {
1919 return struct {
2020 const BcWriter = @This();
2121
22 buffer: std.array_list.Managed(u32),
22 buffer: std.ArrayList(u32),
23 allocator: std.mem.Allocator,
2324 bit_buffer: u32 = 0,
2425 bit_count: u5 = 0,
2526
......@@ -31,18 +32,19 @@ pub fn BitcodeWriter(comptime types: []const type) type {
3132
3233 pub fn init(allocator: std.mem.Allocator, widths: [types.len]u16) BcWriter {
3334 return .{
34 .buffer = std.array_list.Managed(u32).init(allocator),
35 .buffer = .empty,
36 .allocator = allocator,
3537 .widths = widths,
3638 };
3739 }
3840
39 pub fn deinit(self: BcWriter) void {
40 self.buffer.deinit();
41 pub fn deinit(self: *BcWriter) void {
42 self.buffer.deinit(self.allocator);
4143 }
4244
4345 pub fn toOwnedSlice(self: *BcWriter) Error![]const u32 {
4446 std.debug.assert(self.bit_count == 0);
45 return self.buffer.toOwnedSlice();
47 return self.buffer.toOwnedSlice(self.allocator);
4648 }
4749
4850 pub fn length(self: BcWriter) usize {
......@@ -53,6 +55,8 @@ pub fn BitcodeWriter(comptime types: []const type) type {
5355 pub fn writeBits(self: *BcWriter, value: anytype, bits: u16) Error!void {
5456 if (bits == 0) return;
5557
58 const allocator = self.allocator;
59
5660 var in_buffer = bufValue(value, 32);
5761 var in_bits = bits;
5862
......@@ -68,13 +72,13 @@ pub fn BitcodeWriter(comptime types: []const type) type {
6872 in_bits -= n;
6973
7074 if (self.bit_count != 0) return;
71 try self.buffer.append(std.mem.nativeToLittle(u32, self.bit_buffer));
75 try self.buffer.append(allocator, std.mem.nativeToLittle(u32, self.bit_buffer));
7276 self.bit_buffer = 0;
7377 }
7478
7579 // Write 32-bit chunks of input bits
7680 while (in_bits >= 32) {
77 try self.buffer.append(std.mem.nativeToLittle(u32, @truncate(in_buffer)));
81 try self.buffer.append(allocator, std.mem.nativeToLittle(u32, @truncate(in_buffer)));
7882
7983 in_buffer >>= 31;
8084 in_buffer >>= 1;
......@@ -141,7 +145,7 @@ pub fn BitcodeWriter(comptime types: []const type) type {
141145
142146 pub fn writeBlob(self: *BcWriter, blob: []const u8) Error!void {
143147 const blob_word_size = std.mem.alignForward(usize, blob.len, 4);
144 try self.buffer.ensureUnusedCapacity(blob_word_size + 1);
148 try self.buffer.ensureUnusedCapacity(self.allocator, blob_word_size + 1);
145149 self.alignTo32() catch unreachable;
146150
147151 const slice = self.buffer.addManyAsSliceAssumeCapacity(blob_word_size / 4);
......@@ -153,7 +157,7 @@ pub fn BitcodeWriter(comptime types: []const type) type {
153157 pub fn alignTo32(self: *BcWriter) Error!void {
154158 if (self.bit_count == 0) return;
155159
156 try self.buffer.append(std.mem.nativeToLittle(u32, self.bit_buffer));
160 try self.buffer.append(self.allocator, std.mem.nativeToLittle(u32, self.bit_buffer));
157161 self.bit_buffer = 0;
158162 self.bit_count = 0;
159163 }