diff --git a/lib/std/zig/llvm/BitcodeReader.zig b/lib/std/zig/llvm/BitcodeReader.zig index 0e96d0ac5963d405384674d49bd94eeb88e017dc..4c990e30229f4b028c61b091de87ae0eeeea12fe 100644 --- a/lib/std/zig/llvm/BitcodeReader.zig +++ b/lib/std/zig/llvm/BitcodeReader.zig @@ -60,40 +60,40 @@ pub const Record = struct { blob: []const u8, fn toOwnedAbbrev(record: Record, allocator: std.mem.Allocator) !Abbrev { - var operands = std.array_list.Managed(Abbrev.Operand).init(allocator); - defer operands.deinit(); + var operands: std.ArrayList(Abbrev.Operand) = .empty; + defer operands.deinit(allocator); assert(record.id == Abbrev.Builtin.define_abbrev.toRecordId()); var i: usize = 0; while (i < record.operands.len) switch (record.operands[i]) { Abbrev.Operand.literal_id => { - try operands.append(.{ .literal = record.operands[i + 1] }); + try operands.append(allocator, .{ .literal = record.operands[i + 1] }); i += 2; }, @backingInt(Abbrev.Operand.Encoding.fixed) => { - try operands.append(.{ .encoding = .{ .fixed = @intCast(record.operands[i + 1]) } }); + try operands.append(allocator, .{ .encoding = .{ .fixed = @intCast(record.operands[i + 1]) } }); i += 2; }, @backingInt(Abbrev.Operand.Encoding.vbr) => { - try operands.append(.{ .encoding = .{ .vbr = @intCast(record.operands[i + 1]) } }); + try operands.append(allocator, .{ .encoding = .{ .vbr = @intCast(record.operands[i + 1]) } }); i += 2; }, @backingInt(Abbrev.Operand.Encoding.array) => { - try operands.append(.{ .encoding = .{ .array = 6 } }); + try operands.append(allocator, .{ .encoding = .{ .array = 6 } }); i += 1; }, @backingInt(Abbrev.Operand.Encoding.char6) => { - try operands.append(.{ .encoding = .char6 }); + try operands.append(allocator, .{ .encoding = .char6 }); i += 1; }, @backingInt(Abbrev.Operand.Encoding.blob) => { - try operands.append(.{ .encoding = .{ .blob = 6 } }); + try operands.append(allocator, .{ .encoding = .{ .blob = 6 } }); i += 1; }, else => unreachable, }; - return .{ .operands = try operands.toOwnedSlice() }; + return .{ .operands = try operands.toOwnedSlice(allocator) }; } }; @@ -198,8 +198,8 @@ fn nextRecord(bc: *BitcodeReader) !?Record { defer bc.record_arena = record_arena.state; _ = record_arena.reset(.retain_capacity); - var operands = try std.array_list.Managed(u64).initCapacity(record_arena.allocator(), abbrev.operands.len); - var blob = std.array_list.Managed(u8).init(record_arena.allocator()); + var operands: std.ArrayList(u64) = try .initCapacity(record_arena.allocator(), abbrev.operands.len); + var blob: std.ArrayList(u8) = .empty; for (abbrev.operands, 0..) |abbrev_operand, abbrev_operand_i| switch (abbrev_operand) { .literal => |value| operands.appendAssumeCapacity(value), .encoding => |abbrev_encoding| switch (abbrev_encoding) { @@ -208,7 +208,7 @@ fn nextRecord(bc: *BitcodeReader) !?Record { .array => |len_width| { assert(abbrev_operand_i + 2 == abbrev.operands.len); const len: usize = @intCast(try bc.readVbr(u32, len_width)); - try operands.ensureUnusedCapacity(len); + try operands.ensureUnusedCapacity(record_arena.allocator(), len); for (0..len) |_| switch (abbrev.operands[abbrev.operands.len - 1]) { .literal => |elem_value| operands.appendAssumeCapacity(elem_value), .encoding => |elem_encoding| switch (elem_encoding) { @@ -219,14 +219,14 @@ fn nextRecord(bc: *BitcodeReader) !?Record { }, .align_32_bits, .block_len => return error.UnsupportedArrayElement, .abbrev_op => switch (try bc.readFixed(u1, 1)) { - 1 => try operands.appendSlice(&.{ + 1 => try operands.appendSlice(record_arena.allocator(), &.{ Abbrev.Operand.literal_id, try bc.readVbr(u64, 8), }), 0 => { const encoding: Abbrev.Operand.Encoding = @fromBackingInt(@intCast(try bc.readFixed(u3, 3))); - try operands.append(@backingInt(encoding)); + try operands.append(record_arena.allocator(), @backingInt(encoding)); switch (encoding) { .fixed, .vbr => try operands.append(try bc.readVbr(u7, 5)), .array, .char6, .blob => {}, @@ -243,7 +243,7 @@ fn nextRecord(bc: *BitcodeReader) !?Record { const len = std.math.cast(usize, try bc.readVbr(u32, len_width)) orelse return error.Overflow; bc.align32Bits(); - try bc.readBytes(try blob.addManyAsSlice(len)); + try bc.readBytes(try blob.addManyAsSlice(record_arena.allocator(), len)); bc.align32Bits(); }, }, diff --git a/lib/std/zig/llvm/Builder.zig b/lib/std/zig/llvm/Builder.zig index 5cf1765116b517eafe92790d5cb2542ede043b83..87df03af0909cd3369498d3f9d5a0d93fa5c7e45 100644 --- a/lib/std/zig/llvm/Builder.zig +++ b/lib/std/zig/llvm/Builder.zig @@ -95,8 +95,8 @@ fn subArchName(target: *const std.Target, comptime family: std.Target.Cpu.Arch.F } pub fn tripleForTarget(allocator: Allocator, target: *const std.Target) ![]const u8 { - var llvm_triple = std.array_list.Managed(u8).init(allocator); - defer llvm_triple.deinit(); + var llvm_triple: std.ArrayList(u8) = .empty; + defer llvm_triple.deinit(allocator); const llvm_arch = switch (target.cpu.arch) { .arm => "arm", @@ -168,7 +168,7 @@ pub fn tripleForTarget(allocator: Allocator, target: *const std.Target) ![]const => unreachable, // Gated by hasLlvmSupport(). }; - try llvm_triple.appendSlice(llvm_arch); + try llvm_triple.appendSlice(allocator, llvm_arch); const llvm_sub_arch: ?[]const u8 = switch (target.cpu.arch) { .arm, .armeb, .thumb, .thumbeb => subArchName(target, .arm, .{ @@ -223,10 +223,10 @@ pub fn tripleForTarget(allocator: Allocator, target: *const std.Target) ![]const else => null, }; - if (llvm_sub_arch) |sub| try llvm_triple.appendSlice(sub); - try llvm_triple.append('-'); + if (llvm_sub_arch) |sub| try llvm_triple.appendSlice(allocator, sub); + try llvm_triple.append(allocator, '-'); - try llvm_triple.appendSlice(switch (target.os.tag) { + try llvm_triple.appendSlice(allocator, switch (target.os.tag) { .driverkit, .ios, .maccatalyst, @@ -248,7 +248,7 @@ pub fn tripleForTarget(allocator: Allocator, target: *const std.Target) ![]const => "mesa", else => "unknown", }); - try llvm_triple.append('-'); + try llvm_triple.append(allocator, '-'); const llvm_os = switch (target.os.tag) { .dragonfly => "dragonfly", @@ -298,28 +298,28 @@ pub fn tripleForTarget(allocator: Allocator, target: *const std.Target) ![]const .ashetos, => "unknown", }; - try llvm_triple.appendSlice(llvm_os); + try llvm_triple.appendSlice(allocator, llvm_os); switch (target.os.versionRange()) { .none, .windows, => {}, .semver => |ver| if (target.os.tag == .wasi and ver.min.major == 0) { - try llvm_triple.print("p{d}", .{ver.min.minor}); + try llvm_triple.print(allocator, "p{d}", .{ver.min.minor}); } else if (target.os.tag != .amdhsa) { - try llvm_triple.print("{d}.{d}.{d}", .{ + try llvm_triple.print(allocator, "{d}.{d}.{d}", .{ ver.min.major, ver.min.minor, ver.min.patch, }); }, - inline .linux, .hurd => |ver| try llvm_triple.print("{d}.{d}.{d}", .{ + inline .linux, .hurd => |ver| try llvm_triple.print(allocator, "{d}.{d}.{d}", .{ ver.range.min.major, ver.range.min.minor, ver.range.min.patch, }), } - try llvm_triple.append('-'); + try llvm_triple.append(allocator, '-'); const llvm_abi = switch (target.abi) { .none => if (target.os.tag == .maccatalyst) "macabi" else "unknown", @@ -357,7 +357,7 @@ pub fn tripleForTarget(allocator: Allocator, target: *const std.Target) ![]const .ohos, .ohoseabi => "ohos", .call0 => "unknown", }; - try llvm_triple.appendSlice(llvm_abi); + try llvm_triple.appendSlice(allocator, llvm_abi); switch (target.os.versionRange()) { .none, @@ -365,17 +365,17 @@ pub fn tripleForTarget(allocator: Allocator, target: *const std.Target) ![]const .windows, => {}, inline .hurd, .linux => |ver| if (target.abi.isGnu()) { - try llvm_triple.print("{d}.{d}.{d}", .{ + try llvm_triple.print(allocator, "{d}.{d}.{d}", .{ ver.glibc.major, ver.glibc.minor, ver.glibc.patch, }); } else if (@TypeOf(ver) == std.Target.Os.LinuxVersionRange and target.abi.isAndroid()) { - try llvm_triple.print("{d}", .{ver.android}); + try llvm_triple.print(allocator, "{d}", .{ver.android}); }, } - return llvm_triple.toOwnedSlice(); + return llvm_triple.toOwnedSlice(allocator); } pub const DataLayout = struct { @@ -10442,24 +10442,24 @@ pub fn getIntrinsic( var attributes: struct { builder: *Builder, - list: std.array_list.Managed(Attribute.Index), + list: std.ArrayList(Attribute.Index), - fn deinit(state: *@This()) void { - state.list.deinit(); + fn deinit(state: *@This(), gpa: Allocator) void { + state.list.deinit(gpa); state.* = undefined; } - fn get(state: *@This(), attributes: []const Attribute) Allocator.Error!Attributes { - try state.list.resize(attributes.len); + fn get(state: *@This(), gpa: Allocator, attributes: []const Attribute) Allocator.Error!Attributes { + try state.list.resize(gpa, attributes.len); for (state.list.items, attributes) |*item, attribute| item.* = try state.builder.attr(attribute); return state.builder.attrs(state.list.items); } - } = .{ .builder = self, .list = std.array_list.Managed(Attribute.Index).init(allocator) }; - defer attributes.deinit(); + } = .{ .builder = self, .list = .empty }; + defer attributes.deinit(allocator); var overload_index: usize = 0; - function_attributes[FunctionAttributes.function_index] = try attributes.get(signature.attrs); + function_attributes[FunctionAttributes.function_index] = try attributes.get(allocator, signature.attrs); function_attributes[FunctionAttributes.return_index] = .none; // needed for void return for (0.., param_types, signature.params) |param_index, *param_type, signature_param| { switch (signature_param.kind) { @@ -10475,7 +10475,7 @@ pub fn getIntrinsic( FunctionAttributes.return_index else FunctionAttributes.params_index + (param_index - signature.ret_len) - ] = try attributes.get(signature_param.attrs); + ] = try attributes.get(allocator, signature_param.attrs); } assert(overload_index == overload.len); for (param_types, signature.params) |*param_type, signature_param| { diff --git a/lib/std/zig/llvm/bitcode_writer.zig b/lib/std/zig/llvm/bitcode_writer.zig index 9c9e9d4473c26e2c1b9fa0e63befb5bbc420fc02..819ac61d9e7a1e705fedba68164664773aa007c3 100644 --- a/lib/std/zig/llvm/bitcode_writer.zig +++ b/lib/std/zig/llvm/bitcode_writer.zig @@ -19,7 +19,8 @@ pub fn BitcodeWriter(comptime types: []const type) type { return struct { const BcWriter = @This(); - buffer: std.array_list.Managed(u32), + buffer: std.ArrayList(u32), + allocator: std.mem.Allocator, bit_buffer: u32 = 0, bit_count: u5 = 0, @@ -31,18 +32,19 @@ pub fn BitcodeWriter(comptime types: []const type) type { pub fn init(allocator: std.mem.Allocator, widths: [types.len]u16) BcWriter { return .{ - .buffer = std.array_list.Managed(u32).init(allocator), + .buffer = .empty, + .allocator = allocator, .widths = widths, }; } pub fn deinit(self: BcWriter) void { - self.buffer.deinit(); + self.buffer.deinit(self.allocator); } pub fn toOwnedSlice(self: *BcWriter) Error![]const u32 { std.debug.assert(self.bit_count == 0); - return self.buffer.toOwnedSlice(); + return self.buffer.toOwnedSlice(self.allocator); } pub fn length(self: BcWriter) usize { @@ -53,6 +55,8 @@ pub fn BitcodeWriter(comptime types: []const type) type { pub fn writeBits(self: *BcWriter, value: anytype, bits: u16) Error!void { if (bits == 0) return; + const allocator = self.allocator; + var in_buffer = bufValue(value, 32); var in_bits = bits; @@ -68,13 +72,13 @@ pub fn BitcodeWriter(comptime types: []const type) type { in_bits -= n; if (self.bit_count != 0) return; - try self.buffer.append(std.mem.nativeToLittle(u32, self.bit_buffer)); + try self.buffer.append(allocator, std.mem.nativeToLittle(u32, self.bit_buffer)); self.bit_buffer = 0; } // Write 32-bit chunks of input bits while (in_bits >= 32) { - try self.buffer.append(std.mem.nativeToLittle(u32, @truncate(in_buffer))); + try self.buffer.append(allocator, std.mem.nativeToLittle(u32, @truncate(in_buffer))); in_buffer >>= 31; in_buffer >>= 1;