authorgravatar for der.teufel.mail@gmail.comKrzysztof Wolicki <der.teufel.mail@gmail.com> 2026-10-23 10:08:11+02:00
committergravatar for der.teufel.mail@gmail.comKrzysztof Wolicki <der.teufel.mail@gmail.com> 2026-10-23 10:09:57+02:00
logfdb4cdfff1efb93eda20bf8033c7b3fd4366e688
treea24596026154fda89008669134d9ad2aeed55bc2
parent1c26a0e8dd32c38df5a751d33456c7ed0da29006

Remove usages of array_list.Managed in std/zig/llvm


3 files changed, 50 insertions(+), 46 deletions(-)

lib/std/zig/llvm/BitcodeReader.zig+15-15
......@@ -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,14 +219,14 @@ 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) {
231231 .fixed, .vbr => try operands.append(try bc.readVbr(u7, 5)),
232232 .array, .char6, .blob => {},
......@@ -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+25-25
......@@ -95,8 +95,8 @@ fn subArchName(target: *const std.Target, comptime family: std.Target.Cpu.Arch.F
9595}
9696
9797pub fn tripleForTarget(allocator: Allocator, target: *const std.Target) ![]const u8 {
98 var llvm_triple = std.array_list.Managed(u8).init(allocator);
99 defer llvm_triple.deinit();
98 var llvm_triple: std.ArrayList(u8) = .empty;
99 defer llvm_triple.deinit(allocator);
100100
101101 const llvm_arch = switch (target.cpu.arch) {
102102 .arm => "arm",
......@@ -168,7 +168,7 @@ pub fn tripleForTarget(allocator: Allocator, target: *const std.Target) ![]const
168168 => unreachable, // Gated by hasLlvmSupport().
169169 };
170170
171 try llvm_triple.appendSlice(llvm_arch);
171 try llvm_triple.appendSlice(allocator, llvm_arch);
172172
173173 const llvm_sub_arch: ?[]const u8 = switch (target.cpu.arch) {
174174 .arm, .armeb, .thumb, .thumbeb => subArchName(target, .arm, .{
......@@ -223,10 +223,10 @@ pub fn tripleForTarget(allocator: Allocator, target: *const std.Target) ![]const
223223 else => null,
224224 };
225225
226 if (llvm_sub_arch) |sub| try llvm_triple.appendSlice(sub);
227 try llvm_triple.append('-');
226 if (llvm_sub_arch) |sub| try llvm_triple.appendSlice(allocator, sub);
227 try llvm_triple.append(allocator, '-');
228228
229 try llvm_triple.appendSlice(switch (target.os.tag) {
229 try llvm_triple.appendSlice(allocator, switch (target.os.tag) {
230230 .driverkit,
231231 .ios,
232232 .maccatalyst,
......@@ -248,7 +248,7 @@ pub fn tripleForTarget(allocator: Allocator, target: *const std.Target) ![]const
248248 => "mesa",
249249 else => "unknown",
250250 });
251 try llvm_triple.append('-');
251 try llvm_triple.append(allocator, '-');
252252
253253 const llvm_os = switch (target.os.tag) {
254254 .dragonfly => "dragonfly",
......@@ -298,28 +298,28 @@ pub fn tripleForTarget(allocator: Allocator, target: *const std.Target) ![]const
298298 .ashetos,
299299 => "unknown",
300300 };
301 try llvm_triple.appendSlice(llvm_os);
301 try llvm_triple.appendSlice(allocator, llvm_os);
302302
303303 switch (target.os.versionRange()) {
304304 .none,
305305 .windows,
306306 => {},
307307 .semver => |ver| if (target.os.tag == .wasi and ver.min.major == 0) {
308 try llvm_triple.print("p{d}", .{ver.min.minor});
308 try llvm_triple.print(allocator, "p{d}", .{ver.min.minor});
309309 } else if (target.os.tag != .amdhsa) {
310 try llvm_triple.print("{d}.{d}.{d}", .{
310 try llvm_triple.print(allocator, "{d}.{d}.{d}", .{
311311 ver.min.major,
312312 ver.min.minor,
313313 ver.min.patch,
314314 });
315315 },
316 inline .linux, .hurd => |ver| try llvm_triple.print("{d}.{d}.{d}", .{
316 inline .linux, .hurd => |ver| try llvm_triple.print(allocator, "{d}.{d}.{d}", .{
317317 ver.range.min.major,
318318 ver.range.min.minor,
319319 ver.range.min.patch,
320320 }),
321321 }
322 try llvm_triple.append('-');
322 try llvm_triple.append(allocator, '-');
323323
324324 const llvm_abi = switch (target.abi) {
325325 .none => if (target.os.tag == .maccatalyst) "macabi" else "unknown",
......@@ -357,7 +357,7 @@ pub fn tripleForTarget(allocator: Allocator, target: *const std.Target) ![]const
357357 .ohos, .ohoseabi => "ohos",
358358 .call0 => "unknown",
359359 };
360 try llvm_triple.appendSlice(llvm_abi);
360 try llvm_triple.appendSlice(allocator, llvm_abi);
361361
362362 switch (target.os.versionRange()) {
363363 .none,
......@@ -365,17 +365,17 @@ pub fn tripleForTarget(allocator: Allocator, target: *const std.Target) ![]const
365365 .windows,
366366 => {},
367367 inline .hurd, .linux => |ver| if (target.abi.isGnu()) {
368 try llvm_triple.print("{d}.{d}.{d}", .{
368 try llvm_triple.print(allocator, "{d}.{d}.{d}", .{
369369 ver.glibc.major,
370370 ver.glibc.minor,
371371 ver.glibc.patch,
372372 });
373373 } else if (@TypeOf(ver) == std.Target.Os.LinuxVersionRange and target.abi.isAndroid()) {
374 try llvm_triple.print("{d}", .{ver.android});
374 try llvm_triple.print(allocator, "{d}", .{ver.android});
375375 },
376376 }
377377
378 return llvm_triple.toOwnedSlice();
378 return llvm_triple.toOwnedSlice(allocator);
379379}
380380
381381pub const DataLayout = struct {
......@@ -10442,24 +10442,24 @@ pub fn getIntrinsic(
1044210442
1044310443 var attributes: struct {
1044410444 builder: *Builder,
10445 list: std.array_list.Managed(Attribute.Index),
10445 list: std.ArrayList(Attribute.Index),
1044610446
10447 fn deinit(state: *@This()) void {
10448 state.list.deinit();
10447 fn deinit(state: *@This(), gpa: Allocator) void {
10448 state.list.deinit(gpa);
1044910449 state.* = undefined;
1045010450 }
1045110451
10452 fn get(state: *@This(), attributes: []const Attribute) Allocator.Error!Attributes {
10453 try state.list.resize(attributes.len);
10452 fn get(state: *@This(), gpa: Allocator, attributes: []const Attribute) Allocator.Error!Attributes {
10453 try state.list.resize(gpa, attributes.len);
1045410454 for (state.list.items, attributes) |*item, attribute|
1045510455 item.* = try state.builder.attr(attribute);
1045610456 return state.builder.attrs(state.list.items);
1045710457 }
10458 } = .{ .builder = self, .list = std.array_list.Managed(Attribute.Index).init(allocator) };
10459 defer attributes.deinit();
10458 } = .{ .builder = self, .list = .empty };
10459 defer attributes.deinit(allocator);
1046010460
1046110461 var overload_index: usize = 0;
10462 function_attributes[FunctionAttributes.function_index] = try attributes.get(signature.attrs);
10462 function_attributes[FunctionAttributes.function_index] = try attributes.get(allocator, signature.attrs);
1046310463 function_attributes[FunctionAttributes.return_index] = .none; // needed for void return
1046410464 for (0.., param_types, signature.params) |param_index, *param_type, signature_param| {
1046510465 switch (signature_param.kind) {
......@@ -10475,7 +10475,7 @@ pub fn getIntrinsic(
1047510475 FunctionAttributes.return_index
1047610476 else
1047710477 FunctionAttributes.params_index + (param_index - signature.ret_len)
10478 ] = try attributes.get(signature_param.attrs);
10478 ] = try attributes.get(allocator, signature_param.attrs);
1047910479 }
1048010480 assert(overload_index == overload.len);
1048110481 for (param_types, signature.params) |*param_type, signature_param| {
lib/std/zig/llvm/bitcode_writer.zig+10-6
......@@ -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
3941 pub fn deinit(self: BcWriter) void {
40 self.buffer.deinit();
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;