| author | |
| committer | |
| log | 680ab55488798be67fd1744f69045b41580def07 |
| tree | b3779cd54b2912da4c5a07af2d7ed2c77a12e877 |
| parent | 935a3b9c757283b4eaaf78b417e34d7d0fbc8737 |
| parent | bc2c709e18b72b31b4f65ff6b9b14b9229da491e |
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 { |
| 4681 | 4681 | const Templates = struct { |
| 4682 | 4682 | zig_lib_directory: Cache.Directory, |
| 4683 | 4683 | dir: Io.Dir, |
| 4684 | buffer: std.array_list.Managed(u8), | |
| 4684 | buffer: std.ArrayList(u8), | |
| 4685 | gpa: Allocator, | |
| 4685 | 4686 | |
| 4686 | 4687 | fn deinit(templates: *Templates, io: Io) void { |
| 4687 | 4688 | templates.zig_lib_directory.handle.close(io); |
| 4688 | 4689 | templates.dir.close(io); |
| 4689 | templates.buffer.deinit(); | |
| 4690 | templates.buffer.deinit(templates.gpa); | |
| 4690 | 4691 | templates.* = undefined; |
| 4691 | 4692 | } |
| 4692 | 4693 | |
| ... | ... | @@ -4709,29 +4710,30 @@ const Templates = struct { |
| 4709 | 4710 | const contents = templates.dir.readFileAlloc(io, template_path, arena, .limited(max_bytes)) catch |err| { |
| 4710 | 4711 | fatal("unable to read template file {q}: {t}", .{ template_path, err }); |
| 4711 | 4712 | }; |
| 4713 | const gpa = templates.gpa; | |
| 4712 | 4714 | templates.buffer.clearRetainingCapacity(); |
| 4713 | try templates.buffer.ensureUnusedCapacity(contents.len); | |
| 4715 | try templates.buffer.ensureUnusedCapacity(gpa, contents.len); | |
| 4714 | 4716 | var i: usize = 0; |
| 4715 | 4717 | while (i < contents.len) { |
| 4716 | 4718 | if (contents[i] == '_' or contents[i] == '.') { |
| 4717 | 4719 | // Both '_' and '.' are allowed because depending on the context |
| 4718 | 4720 | // one prefix will be valid, while the other might not. |
| 4719 | 4721 | if (std.mem.startsWith(u8, contents[i + 1 ..], "NAME")) { |
| 4720 | try templates.buffer.appendSlice(root_name); | |
| 4722 | try templates.buffer.appendSlice(gpa, root_name); | |
| 4721 | 4723 | i += "_NAME".len; |
| 4722 | 4724 | continue; |
| 4723 | 4725 | } 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()}); | |
| 4725 | 4727 | i += "_FINGERPRINT".len; |
| 4726 | 4728 | continue; |
| 4727 | 4729 | } 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); | |
| 4729 | 4731 | i += "_ZIGVER".len; |
| 4730 | 4732 | continue; |
| 4731 | 4733 | } |
| 4732 | 4734 | } |
| 4733 | 4735 | |
| 4734 | try templates.buffer.append(contents[i]); | |
| 4736 | try templates.buffer.append(gpa, contents[i]); | |
| 4735 | 4737 | i += 1; |
| 4736 | 4738 | } |
| 4737 | 4739 | |
| ... | ... | @@ -4752,7 +4754,8 @@ const Templates = struct { |
| 4752 | 4754 | return .{ |
| 4753 | 4755 | .zig_lib_directory = zig_lib_directory, |
| 4754 | 4756 | .dir = template_dir, |
| 4755 | .buffer = std.array_list.Managed(u8).init(gpa), | |
| 4757 | .buffer = .empty, | |
| 4758 | .gpa = gpa, | |
| 4756 | 4759 | }; |
| 4757 | 4760 | } |
| 4758 | 4761 |
lib/compiler/Maker/Fetch.zig+6-6| ... | ... | @@ -1756,11 +1756,11 @@ fn computeHash(f: *Fetch, pkg_path: Path, filter: Filter) RunError!ComputedHash |
| 1756 | 1756 | const root_dir = pkg_path.root_dir.handle; |
| 1757 | 1757 | |
| 1758 | 1758 | // 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); | |
| 1761 | 1761 | |
| 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); | |
| 1764 | 1764 | |
| 1765 | 1765 | // Track directories which had any files deleted from them so that empty directories |
| 1766 | 1766 | // can be deleted. |
| ... | ... | @@ -1803,7 +1803,7 @@ fn computeHash(f: *Fetch, pkg_path: Path, filter: Filter) RunError!ComputedHash |
| 1803 | 1803 | .failure = undefined, // to be populated by the worker |
| 1804 | 1804 | }; |
| 1805 | 1805 | group.async(io, workerDeleteFile, .{ io, root_dir, deleted_file }); |
| 1806 | try deleted_files.append(deleted_file); | |
| 1806 | try deleted_files.append(gpa, deleted_file); | |
| 1807 | 1807 | continue; |
| 1808 | 1808 | } |
| 1809 | 1809 | |
| ... | ... | @@ -1831,7 +1831,7 @@ fn computeHash(f: *Fetch, pkg_path: Path, filter: Filter) RunError!ComputedHash |
| 1831 | 1831 | .size = undefined, // to be populated by the worker |
| 1832 | 1832 | }; |
| 1833 | 1833 | group.async(io, workerHashFile, .{ io, root_dir, hashed_file }); |
| 1834 | try all_files.append(hashed_file); | |
| 1834 | try all_files.append(gpa, hashed_file); | |
| 1835 | 1835 | } |
| 1836 | 1836 | |
| 1837 | 1837 | try group.await(io); |
lib/compiler/Maker/Step/Compile.zig+1-1| ... | ... | @@ -867,7 +867,7 @@ fn lowerZigArgs( |
| 867 | 867 | return step.fail(maker, "failed creating directory {f}: {t}", .{ args_path, err }); |
| 868 | 868 | |
| 869 | 869 | 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); | |
| 871 | 871 | arg_blk: for (args_to_escape) |arg| { |
| 872 | 872 | for (arg, 0..) |c, arg_idx| { |
| 873 | 873 | if (c == '\\' or c == '"') { |
lib/docs/wasm/markdown.zig+3-3| ... | ... | @@ -1119,9 +1119,9 @@ fn testRender(input: []const u8, expected: []const u8) !void { |
| 1119 | 1119 | var doc = try parser.endInput(); |
| 1120 | 1120 | defer doc.deinit(testing.allocator); |
| 1121 | 1121 | |
| 1122 | var actual = std.array_list.Managed(u8).init(testing.allocator); | |
| 1122 | var actual: std.Io.Writer.Allocating = .init(testing.allocator); | |
| 1123 | 1123 | defer actual.deinit(); |
| 1124 | try doc.render(actual.writer()); | |
| 1124 | try doc.render(&actual.writer); | |
| 1125 | 1125 | |
| 1126 | try testing.expectEqualStrings(expected, actual.items); | |
| 1126 | try testing.expectEqualStrings(expected, actual.written()); | |
| 1127 | 1127 | } |
lib/docs/wasm/markdown/Document.zig+2-2| ... | ... | @@ -160,8 +160,8 @@ pub fn deinit(doc: *Document, allocator: Allocator) void { |
| 160 | 160 | } |
| 161 | 161 | |
| 162 | 162 | /// Renders a document directly to a writer using the default renderer. |
| 163 | pub fn render(doc: Document, writer: anytype) @TypeOf(writer).Error!void { | |
| 164 | const renderer: Renderer(@TypeOf(writer), void) = .{ .context = {} }; | |
| 163 | pub fn render(doc: Document, writer: *std.Io.Writer) std.Io.Writer.Error!void { | |
| 164 | const renderer: Renderer(void) = .{ .context = {} }; | |
| 165 | 165 | try renderer.render(doc, writer); |
| 166 | 166 | } |
| 167 | 167 |
lib/std/zig/llvm/BitcodeReader.zig+16-16| ... | ... | @@ -60,40 +60,40 @@ pub const Record = struct { |
| 60 | 60 | blob: []const u8, |
| 61 | 61 | |
| 62 | 62 | 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); | |
| 65 | 65 | |
| 66 | 66 | assert(record.id == Abbrev.Builtin.define_abbrev.toRecordId()); |
| 67 | 67 | var i: usize = 0; |
| 68 | 68 | while (i < record.operands.len) switch (record.operands[i]) { |
| 69 | 69 | Abbrev.Operand.literal_id => { |
| 70 | try operands.append(.{ .literal = record.operands[i + 1] }); | |
| 70 | try operands.append(allocator, .{ .literal = record.operands[i + 1] }); | |
| 71 | 71 | i += 2; |
| 72 | 72 | }, |
| 73 | 73 | @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]) } }); | |
| 75 | 75 | i += 2; |
| 76 | 76 | }, |
| 77 | 77 | @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]) } }); | |
| 79 | 79 | i += 2; |
| 80 | 80 | }, |
| 81 | 81 | @backingInt(Abbrev.Operand.Encoding.array) => { |
| 82 | try operands.append(.{ .encoding = .{ .array = 6 } }); | |
| 82 | try operands.append(allocator, .{ .encoding = .{ .array = 6 } }); | |
| 83 | 83 | i += 1; |
| 84 | 84 | }, |
| 85 | 85 | @backingInt(Abbrev.Operand.Encoding.char6) => { |
| 86 | try operands.append(.{ .encoding = .char6 }); | |
| 86 | try operands.append(allocator, .{ .encoding = .char6 }); | |
| 87 | 87 | i += 1; |
| 88 | 88 | }, |
| 89 | 89 | @backingInt(Abbrev.Operand.Encoding.blob) => { |
| 90 | try operands.append(.{ .encoding = .{ .blob = 6 } }); | |
| 90 | try operands.append(allocator, .{ .encoding = .{ .blob = 6 } }); | |
| 91 | 91 | i += 1; |
| 92 | 92 | }, |
| 93 | 93 | else => unreachable, |
| 94 | 94 | }; |
| 95 | 95 | |
| 96 | return .{ .operands = try operands.toOwnedSlice() }; | |
| 96 | return .{ .operands = try operands.toOwnedSlice(allocator) }; | |
| 97 | 97 | } |
| 98 | 98 | }; |
| 99 | 99 | |
| ... | ... | @@ -198,8 +198,8 @@ fn nextRecord(bc: *BitcodeReader) !?Record { |
| 198 | 198 | defer bc.record_arena = record_arena.state; |
| 199 | 199 | _ = record_arena.reset(.retain_capacity); |
| 200 | 200 | |
| 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; | |
| 203 | 203 | for (abbrev.operands, 0..) |abbrev_operand, abbrev_operand_i| switch (abbrev_operand) { |
| 204 | 204 | .literal => |value| operands.appendAssumeCapacity(value), |
| 205 | 205 | .encoding => |abbrev_encoding| switch (abbrev_encoding) { |
| ... | ... | @@ -208,7 +208,7 @@ fn nextRecord(bc: *BitcodeReader) !?Record { |
| 208 | 208 | .array => |len_width| { |
| 209 | 209 | assert(abbrev_operand_i + 2 == abbrev.operands.len); |
| 210 | 210 | const len: usize = @intCast(try bc.readVbr(u32, len_width)); |
| 211 | try operands.ensureUnusedCapacity(len); | |
| 211 | try operands.ensureUnusedCapacity(record_arena.allocator(), len); | |
| 212 | 212 | for (0..len) |_| switch (abbrev.operands[abbrev.operands.len - 1]) { |
| 213 | 213 | .literal => |elem_value| operands.appendAssumeCapacity(elem_value), |
| 214 | 214 | .encoding => |elem_encoding| switch (elem_encoding) { |
| ... | ... | @@ -219,16 +219,16 @@ fn nextRecord(bc: *BitcodeReader) !?Record { |
| 219 | 219 | }, |
| 220 | 220 | .align_32_bits, .block_len => return error.UnsupportedArrayElement, |
| 221 | 221 | .abbrev_op => switch (try bc.readFixed(u1, 1)) { |
| 222 | 1 => try operands.appendSlice(&.{ | |
| 222 | 1 => try operands.appendSlice(record_arena.allocator(), &.{ | |
| 223 | 223 | Abbrev.Operand.literal_id, |
| 224 | 224 | try bc.readVbr(u64, 8), |
| 225 | 225 | }), |
| 226 | 226 | 0 => { |
| 227 | 227 | const encoding: Abbrev.Operand.Encoding = |
| 228 | 228 | @fromBackingInt(@intCast(try bc.readFixed(u3, 3))); |
| 229 | try operands.append(@backingInt(encoding)); | |
| 229 | try operands.append(record_arena.allocator(), @backingInt(encoding)); | |
| 230 | 230 | 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)), | |
| 232 | 232 | .array, .char6, .blob => {}, |
| 233 | 233 | _ => return error.UnsuportedAbbrevEncoding, |
| 234 | 234 | } |
| ... | ... | @@ -243,7 +243,7 @@ fn nextRecord(bc: *BitcodeReader) !?Record { |
| 243 | 243 | const len = std.math.cast(usize, try bc.readVbr(u32, len_width)) orelse |
| 244 | 244 | return error.Overflow; |
| 245 | 245 | bc.align32Bits(); |
| 246 | try bc.readBytes(try blob.addManyAsSlice(len)); | |
| 246 | try bc.readBytes(try blob.addManyAsSlice(record_arena.allocator(), len)); | |
| 247 | 247 | bc.align32Bits(); |
| 248 | 248 | }, |
| 249 | 249 | }, |
lib/std/zig/llvm/Builder.zig+9-9| ... | ... | @@ -10505,24 +10505,24 @@ pub fn getIntrinsic( |
| 10505 | 10505 | |
| 10506 | 10506 | var attributes: struct { |
| 10507 | 10507 | builder: *Builder, |
| 10508 | list: std.array_list.Managed(Attribute.Index), | |
| 10508 | list: std.ArrayList(Attribute.Index), | |
| 10509 | 10509 | |
| 10510 | fn deinit(state: *@This()) void { | |
| 10511 | state.list.deinit(); | |
| 10510 | fn deinit(state: *@This(), gpa: Allocator) void { | |
| 10511 | state.list.deinit(gpa); | |
| 10512 | 10512 | state.* = undefined; |
| 10513 | 10513 | } |
| 10514 | 10514 | |
| 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); | |
| 10517 | 10517 | for (state.list.items, attributes) |*item, attribute| |
| 10518 | 10518 | item.* = try state.builder.attr(attribute); |
| 10519 | 10519 | return state.builder.attrs(state.list.items); |
| 10520 | 10520 | } |
| 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); | |
| 10523 | 10523 | |
| 10524 | 10524 | 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); | |
| 10526 | 10526 | function_attributes[FunctionAttributes.return_index] = .none; // needed for void return |
| 10527 | 10527 | for (0.., param_types, signature.params) |param_index, *param_type, signature_param| { |
| 10528 | 10528 | switch (signature_param.kind) { |
| ... | ... | @@ -10538,7 +10538,7 @@ pub fn getIntrinsic( |
| 10538 | 10538 | FunctionAttributes.return_index |
| 10539 | 10539 | else |
| 10540 | 10540 | FunctionAttributes.params_index + (param_index - signature.ret_len) |
| 10541 | ] = try attributes.get(signature_param.attrs); | |
| 10541 | ] = try attributes.get(allocator, signature_param.attrs); | |
| 10542 | 10542 | } |
| 10543 | 10543 | assert(overload_index == overload.len); |
| 10544 | 10544 | 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 { |
| 19 | 19 | return struct { |
| 20 | 20 | const BcWriter = @This(); |
| 21 | 21 | |
| 22 | buffer: std.array_list.Managed(u32), | |
| 22 | buffer: std.ArrayList(u32), | |
| 23 | allocator: std.mem.Allocator, | |
| 23 | 24 | bit_buffer: u32 = 0, |
| 24 | 25 | bit_count: u5 = 0, |
| 25 | 26 | |
| ... | ... | @@ -31,18 +32,19 @@ pub fn BitcodeWriter(comptime types: []const type) type { |
| 31 | 32 | |
| 32 | 33 | pub fn init(allocator: std.mem.Allocator, widths: [types.len]u16) BcWriter { |
| 33 | 34 | return .{ |
| 34 | .buffer = std.array_list.Managed(u32).init(allocator), | |
| 35 | .buffer = .empty, | |
| 36 | .allocator = allocator, | |
| 35 | 37 | .widths = widths, |
| 36 | 38 | }; |
| 37 | 39 | } |
| 38 | 40 | |
| 39 | pub fn deinit(self: BcWriter) void { | |
| 40 | self.buffer.deinit(); | |
| 41 | pub fn deinit(self: *BcWriter) void { | |
| 42 | self.buffer.deinit(self.allocator); | |
| 41 | 43 | } |
| 42 | 44 | |
| 43 | 45 | pub fn toOwnedSlice(self: *BcWriter) Error![]const u32 { |
| 44 | 46 | std.debug.assert(self.bit_count == 0); |
| 45 | return self.buffer.toOwnedSlice(); | |
| 47 | return self.buffer.toOwnedSlice(self.allocator); | |
| 46 | 48 | } |
| 47 | 49 | |
| 48 | 50 | pub fn length(self: BcWriter) usize { |
| ... | ... | @@ -53,6 +55,8 @@ pub fn BitcodeWriter(comptime types: []const type) type { |
| 53 | 55 | pub fn writeBits(self: *BcWriter, value: anytype, bits: u16) Error!void { |
| 54 | 56 | if (bits == 0) return; |
| 55 | 57 | |
| 58 | const allocator = self.allocator; | |
| 59 | ||
| 56 | 60 | var in_buffer = bufValue(value, 32); |
| 57 | 61 | var in_bits = bits; |
| 58 | 62 | |
| ... | ... | @@ -68,13 +72,13 @@ pub fn BitcodeWriter(comptime types: []const type) type { |
| 68 | 72 | in_bits -= n; |
| 69 | 73 | |
| 70 | 74 | 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)); | |
| 72 | 76 | self.bit_buffer = 0; |
| 73 | 77 | } |
| 74 | 78 | |
| 75 | 79 | // Write 32-bit chunks of input bits |
| 76 | 80 | 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))); | |
| 78 | 82 | |
| 79 | 83 | in_buffer >>= 31; |
| 80 | 84 | in_buffer >>= 1; |
| ... | ... | @@ -141,7 +145,7 @@ pub fn BitcodeWriter(comptime types: []const type) type { |
| 141 | 145 | |
| 142 | 146 | pub fn writeBlob(self: *BcWriter, blob: []const u8) Error!void { |
| 143 | 147 | 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); | |
| 145 | 149 | self.alignTo32() catch unreachable; |
| 146 | 150 | |
| 147 | 151 | const slice = self.buffer.addManyAsSliceAssumeCapacity(blob_word_size / 4); |
| ... | ... | @@ -153,7 +157,7 @@ pub fn BitcodeWriter(comptime types: []const type) type { |
| 153 | 157 | pub fn alignTo32(self: *BcWriter) Error!void { |
| 154 | 158 | if (self.bit_count == 0) return; |
| 155 | 159 | |
| 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)); | |
| 157 | 161 | self.bit_buffer = 0; |
| 158 | 162 | self.bit_count = 0; |
| 159 | 163 | } |