Skip to content

Commit 749f10a

Browse files
committed
std.ArrayList: make unmanaged the default
1 parent d625158 commit 749f10a

File tree

161 files changed

+861
-870
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

161 files changed

+861
-870
lines changed

build.zig

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ const builtin = std.builtin;
33
const tests = @import("test/tests.zig");
44
const BufMap = std.BufMap;
55
const mem = std.mem;
6-
const ArrayList = std.ArrayList;
76
const io = std.io;
87
const fs = std.fs;
98
const InstallDirectoryOptions = std.Build.InstallDirectoryOptions;
@@ -925,7 +924,7 @@ fn addCxxKnownPath(
925924
return error.RequiredLibraryNotFound;
926925

927926
const path_padded = run: {
928-
var args = std.ArrayList([]const u8).init(b.allocator);
927+
var args = std.array_list.Managed([]const u8).init(b.allocator);
929928
try args.append(ctx.cxx_compiler);
930929
var it = std.mem.tokenizeAny(u8, ctx.cxx_compiler_arg1, &std.ascii.whitespace);
931930
while (it.next()) |arg| try args.append(arg);

doc/langref.html.in

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6241,9 +6241,8 @@ fn cmpxchgWeakButNotAtomic(comptime T: type, ptr: *T, expected_value: T, new_val
62416241
C has a default allocator - <code>malloc</code>, <code>realloc</code>, and <code>free</code>.
62426242
When linking against libc, Zig exposes this allocator with {#syntax#}std.heap.c_allocator{#endsyntax#}.
62436243
However, by convention, there is no default allocator in Zig. Instead, functions which need to
6244-
allocate accept an {#syntax#}Allocator{#endsyntax#} parameter. Likewise, data structures such as
6245-
{#syntax#}std.ArrayList{#endsyntax#} accept an {#syntax#}Allocator{#endsyntax#} parameter in
6246-
their initialization functions:
6244+
allocate accept an {#syntax#}Allocator{#endsyntax#} parameter. Likewise, some data structures
6245+
accept an {#syntax#}Allocator{#endsyntax#} parameter in their initialization functions:
62476246
</p>
62486247
{#code|test_allocator.zig#}
62496248

doc/langref/testing_detect_leak.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
const std = @import("std");
22

33
test "detect leak" {
4-
var list = std.ArrayList(u21).init(std.testing.allocator);
4+
var list = std.array_list.Managed(u21).init(std.testing.allocator);
55
// missing `defer list.deinit();`
66
try list.append('☔');
77

lib/compiler/aro/aro/Compilation.zig

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -533,7 +533,7 @@ fn generateSystemDefines(comp: *Compilation, w: anytype) !void {
533533
pub fn generateBuiltinMacros(comp: *Compilation, system_defines_mode: SystemDefinesMode) !Source {
534534
try comp.generateBuiltinTypes();
535535

536-
var buf = std.ArrayList(u8).init(comp.gpa);
536+
var buf = std.array_list.Managed(u8).init(comp.gpa);
537537
defer buf.deinit();
538538

539539
if (system_defines_mode == .include_system_defines) {
@@ -1143,7 +1143,7 @@ pub fn addSourceFromOwnedBuffer(comp: *Compilation, buf: []u8, path: []const u8,
11431143
const duped_path = try comp.gpa.dupe(u8, path);
11441144
errdefer comp.gpa.free(duped_path);
11451145

1146-
var splice_list = std.ArrayList(u32).init(comp.gpa);
1146+
var splice_list = std.array_list.Managed(u32).init(comp.gpa);
11471147
defer splice_list.deinit();
11481148

11491149
const source_id: Source.Id = @enumFromInt(comp.sources.count() + 2);
@@ -1428,7 +1428,7 @@ fn getFileContents(comp: *Compilation, path: []const u8, limit: ?u32) ![]const u
14281428
const file = try comp.cwd.openFile(path, .{});
14291429
defer file.close();
14301430

1431-
var buf = std.ArrayList(u8).init(comp.gpa);
1431+
var buf = std.array_list.Managed(u8).init(comp.gpa);
14321432
defer buf.deinit();
14331433

14341434
const max = limit orelse std.math.maxInt(u32);

lib/compiler/aro/aro/Driver.zig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -590,7 +590,7 @@ var stdout_buffer: [4096]u8 = undefined;
590590
/// The entry point of the Aro compiler.
591591
/// **MAY call `exit` if `fast_exit` is set.**
592592
pub fn main(d: *Driver, tc: *Toolchain, args: []const []const u8, comptime fast_exit: bool) !void {
593-
var macro_buf = std.ArrayList(u8).init(d.comp.gpa);
593+
var macro_buf = std.array_list.Managed(u8).init(d.comp.gpa);
594594
defer macro_buf.deinit();
595595

596596
const std_out = std.fs.File.stdout().deprecatedWriter();
@@ -817,7 +817,7 @@ fn dumpLinkerArgs(items: []const []const u8) !void {
817817
/// The entry point of the Aro compiler.
818818
/// **MAY call `exit` if `fast_exit` is set.**
819819
pub fn invokeLinker(d: *Driver, tc: *Toolchain, comptime fast_exit: bool) !void {
820-
var argv = std.ArrayList([]const u8).init(d.comp.gpa);
820+
var argv = std.array_list.Managed([]const u8).init(d.comp.gpa);
821821
defer argv.deinit();
822822

823823
var linker_path_buf: [std.fs.max_path_bytes]u8 = undefined;

lib/compiler/aro/aro/InitList.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const TokenIndex = Tree.TokenIndex;
99
const NodeIndex = Tree.NodeIndex;
1010
const Type = @import("Type.zig");
1111
const Diagnostics = @import("Diagnostics.zig");
12-
const NodeList = std.ArrayList(NodeIndex);
12+
const NodeList = std.array_list.Managed(NodeIndex);
1313
const Parser = @import("Parser.zig");
1414

1515
const Item = struct {

lib/compiler/aro/aro/Parser.zig

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const TokenIndex = Tree.TokenIndex;
1515
const NodeIndex = Tree.NodeIndex;
1616
const Type = @import("Type.zig");
1717
const Diagnostics = @import("Diagnostics.zig");
18-
const NodeList = std.ArrayList(NodeIndex);
18+
const NodeList = std.array_list.Managed(NodeIndex);
1919
const InitList = @import("InitList.zig");
2020
const Attribute = @import("Attribute.zig");
2121
const char_info = @import("char_info.zig");
@@ -33,7 +33,7 @@ const target_util = @import("target.zig");
3333

3434
const Switch = struct {
3535
default: ?TokenIndex = null,
36-
ranges: std.ArrayList(Range),
36+
ranges: std.array_list.Managed(Range),
3737
ty: Type,
3838
comp: *Compilation,
3939

@@ -101,16 +101,16 @@ value_map: Tree.ValueMap,
101101

102102
// buffers used during compilation
103103
syms: SymbolStack = .{},
104-
strings: std.ArrayListAligned(u8, .@"4"),
105-
labels: std.ArrayList(Label),
104+
strings: std.array_list.AlignedManaged(u8, .@"4"),
105+
labels: std.array_list.Managed(Label),
106106
list_buf: NodeList,
107107
decl_buf: NodeList,
108-
param_buf: std.ArrayList(Type.Func.Param),
109-
enum_buf: std.ArrayList(Type.Enum.Field),
110-
record_buf: std.ArrayList(Type.Record.Field),
108+
param_buf: std.array_list.Managed(Type.Func.Param),
109+
enum_buf: std.array_list.Managed(Type.Enum.Field),
110+
record_buf: std.array_list.Managed(Type.Record.Field),
111111
attr_buf: std.MultiArrayList(TentativeAttribute) = .{},
112112
attr_application_buf: std.ArrayListUnmanaged(Attribute) = .empty,
113-
field_attr_buf: std.ArrayList([]const Attribute),
113+
field_attr_buf: std.array_list.Managed([]const Attribute),
114114
/// type name -> variable name location for tentative definitions (top-level defs with thus-far-incomplete types)
115115
/// e.g. `struct Foo bar;` where `struct Foo` is not defined yet.
116116
/// The key is the StringId of `Foo` and the value is the TokenIndex of `bar`
@@ -693,16 +693,16 @@ pub fn parse(pp: *Preprocessor) Compilation.Error!Tree {
693693
.gpa = pp.comp.gpa,
694694
.arena = arena.allocator(),
695695
.tok_ids = pp.tokens.items(.id),
696-
.strings = std.ArrayListAligned(u8, .@"4").init(pp.comp.gpa),
696+
.strings = std.array_list.AlignedManaged(u8, .@"4").init(pp.comp.gpa),
697697
.value_map = Tree.ValueMap.init(pp.comp.gpa),
698698
.data = NodeList.init(pp.comp.gpa),
699-
.labels = std.ArrayList(Label).init(pp.comp.gpa),
699+
.labels = std.array_list.Managed(Label).init(pp.comp.gpa),
700700
.list_buf = NodeList.init(pp.comp.gpa),
701701
.decl_buf = NodeList.init(pp.comp.gpa),
702-
.param_buf = std.ArrayList(Type.Func.Param).init(pp.comp.gpa),
703-
.enum_buf = std.ArrayList(Type.Enum.Field).init(pp.comp.gpa),
704-
.record_buf = std.ArrayList(Type.Record.Field).init(pp.comp.gpa),
705-
.field_attr_buf = std.ArrayList([]const Attribute).init(pp.comp.gpa),
702+
.param_buf = std.array_list.Managed(Type.Func.Param).init(pp.comp.gpa),
703+
.enum_buf = std.array_list.Managed(Type.Enum.Field).init(pp.comp.gpa),
704+
.record_buf = std.array_list.Managed(Type.Record.Field).init(pp.comp.gpa),
705+
.field_attr_buf = std.array_list.Managed([]const Attribute).init(pp.comp.gpa),
706706
.string_ids = .{
707707
.declspec_id = try StrInt.intern(pp.comp, "__declspec"),
708708
.main_id = try StrInt.intern(pp.comp, "main"),
@@ -1222,7 +1222,7 @@ fn staticAssertMessage(p: *Parser, cond_node: NodeIndex, message: Result) !?[]co
12221222
const cond_tag = p.nodes.items(.tag)[@intFromEnum(cond_node)];
12231223
if (cond_tag != .builtin_types_compatible_p and message.node == .none) return null;
12241224

1225-
var buf = std.ArrayList(u8).init(p.gpa);
1225+
var buf = std.array_list.Managed(u8).init(p.gpa);
12261226
defer buf.deinit();
12271227

12281228
if (cond_tag == .builtin_types_compatible_p) {
@@ -3994,7 +3994,7 @@ fn msvcAsmStmt(p: *Parser) Error!?NodeIndex {
39943994
}
39953995

39963996
/// asmOperand : ('[' IDENTIFIER ']')? asmStr '(' expr ')'
3997-
fn asmOperand(p: *Parser, names: *std.ArrayList(?TokenIndex), constraints: *NodeList, exprs: *NodeList) Error!void {
3997+
fn asmOperand(p: *Parser, names: *std.array_list.Managed(?TokenIndex), constraints: *NodeList, exprs: *NodeList) Error!void {
39983998
if (p.eatToken(.l_bracket)) |l_bracket| {
39993999
const ident = (try p.eatIdentifier()) orelse {
40004000
try p.err(.expected_identifier);
@@ -4044,7 +4044,7 @@ fn gnuAsmStmt(p: *Parser, quals: Tree.GNUAssemblyQualifiers, asm_tok: TokenIndex
40444044
const allocator = stack_fallback.get();
40454045

40464046
// TODO: Consider using a TokenIndex of 0 instead of null if we need to store the names in the tree
4047-
var names = std.ArrayList(?TokenIndex).initCapacity(allocator, expected_items) catch unreachable; // stack allocation already succeeded
4047+
var names = std.array_list.Managed(?TokenIndex).initCapacity(allocator, expected_items) catch unreachable; // stack allocation already succeeded
40484048
defer names.deinit();
40494049
var constraints = NodeList.initCapacity(allocator, expected_items) catch unreachable; // stack allocation already succeeded
40504050
defer constraints.deinit();
@@ -4317,7 +4317,7 @@ fn stmt(p: *Parser) Error!NodeIndex {
43174317

43184318
const old_switch = p.@"switch";
43194319
var @"switch" = Switch{
4320-
.ranges = std.ArrayList(Switch.Range).init(p.gpa),
4320+
.ranges = std.array_list.Managed(Switch.Range).init(p.gpa),
43214321
.ty = cond.ty,
43224322
.comp = p.comp,
43234323
};
@@ -8268,7 +8268,7 @@ fn charLiteral(p: *Parser) Error!Result {
82688268

82698269
const max_chars_expected = 4;
82708270
var stack_fallback = std.heap.stackFallback(max_chars_expected * @sizeOf(u32), p.comp.gpa);
8271-
var chars = std.ArrayList(u32).initCapacity(stack_fallback.get(), max_chars_expected) catch unreachable; // stack allocation already succeeded
8271+
var chars = std.array_list.Managed(u32).initCapacity(stack_fallback.get(), max_chars_expected) catch unreachable; // stack allocation already succeeded
82728272
defer chars.deinit();
82738273

82748274
while (char_literal_parser.next()) |item| switch (item) {

lib/compiler/aro/aro/Preprocessor.zig

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ const features = @import("features.zig");
1717
const Hideset = @import("Hideset.zig");
1818

1919
const DefineMap = std.StringHashMapUnmanaged(Macro);
20-
const RawTokenList = std.ArrayList(RawToken);
20+
const RawTokenList = std.array_list.Managed(RawToken);
2121
const max_include_depth = 200;
2222

2323
/// Errors that can be returned when expanding a macro.
@@ -84,7 +84,7 @@ tokens: Token.List = .{},
8484
/// Do not directly mutate this; must be kept in sync with `tokens`
8585
expansion_entries: std.MultiArrayList(ExpansionEntry) = .{},
8686
token_buf: RawTokenList,
87-
char_buf: std.ArrayList(u8),
87+
char_buf: std.array_list.Managed(u8),
8888
/// Counter that is incremented each time preprocess() is called
8989
/// Can be used to distinguish multiple preprocessings of the same file
9090
preprocess_count: u32 = 0,
@@ -131,7 +131,7 @@ pub fn init(comp: *Compilation) Preprocessor {
131131
.gpa = comp.gpa,
132132
.arena = std.heap.ArenaAllocator.init(comp.gpa),
133133
.token_buf = RawTokenList.init(comp.gpa),
134-
.char_buf = std.ArrayList(u8).init(comp.gpa),
134+
.char_buf = std.array_list.Managed(u8).init(comp.gpa),
135135
.poisoned_identifiers = std.StringHashMap(void).init(comp.gpa),
136136
.top_expansion_buf = ExpandBuf.init(comp.gpa),
137137
.hideset = .{ .comp = comp },
@@ -982,7 +982,7 @@ fn expr(pp: *Preprocessor, tokenizer: *Tokenizer) MacroError!bool {
982982
.tok_i = @intCast(token_state.tokens_len),
983983
.arena = pp.arena.allocator(),
984984
.in_macro = true,
985-
.strings = std.ArrayListAligned(u8, .@"4").init(pp.comp.gpa),
985+
.strings = std.array_list.AlignedManaged(u8, .@"4").init(pp.comp.gpa),
986986

987987
.data = undefined,
988988
.value_map = undefined,
@@ -1140,7 +1140,7 @@ fn skipToNl(tokenizer: *Tokenizer) void {
11401140
}
11411141
}
11421142

1143-
const ExpandBuf = std.ArrayList(TokenWithExpansionLocs);
1143+
const ExpandBuf = std.array_list.Managed(TokenWithExpansionLocs);
11441144
fn removePlacemarkers(buf: *ExpandBuf) void {
11451145
var i: usize = buf.items.len -% 1;
11461146
while (i < buf.items.len) : (i -%= 1) {
@@ -1151,7 +1151,7 @@ fn removePlacemarkers(buf: *ExpandBuf) void {
11511151
}
11521152
}
11531153

1154-
const MacroArguments = std.ArrayList([]const TokenWithExpansionLocs);
1154+
const MacroArguments = std.array_list.Managed([]const TokenWithExpansionLocs);
11551155
fn deinitMacroArguments(allocator: Allocator, args: *const MacroArguments) void {
11561156
for (args.items) |item| {
11571157
for (item) |tok| TokenWithExpansionLocs.free(tok.expansion_locs, allocator);
@@ -2075,7 +2075,7 @@ fn collectMacroFuncArguments(
20752075
var parens: u32 = 0;
20762076
var args = MacroArguments.init(pp.gpa);
20772077
errdefer deinitMacroArguments(pp.gpa, &args);
2078-
var curArgument = std.ArrayList(TokenWithExpansionLocs).init(pp.gpa);
2078+
var curArgument = std.array_list.Managed(TokenWithExpansionLocs).init(pp.gpa);
20792079
defer curArgument.deinit();
20802080
while (true) {
20812081
var tok = try nextBufToken(pp, tokenizer, buf, start_idx, end_idx, extend_buf);
@@ -2645,7 +2645,7 @@ fn define(pp: *Preprocessor, tokenizer: *Tokenizer, define_tok: RawToken) Error!
26452645
/// Handle a function like #define directive.
26462646
fn defineFn(pp: *Preprocessor, tokenizer: *Tokenizer, define_tok: RawToken, macro_name: RawToken, l_paren: RawToken) Error!void {
26472647
assert(macro_name.id.isMacroIdentifier());
2648-
var params = std.ArrayList([]const u8).init(pp.gpa);
2648+
var params = std.array_list.Managed([]const u8).init(pp.gpa);
26492649
defer params.deinit();
26502650

26512651
// Parse the parameter list.
@@ -3471,7 +3471,7 @@ test "Preserve pragma tokens sometimes" {
34713471
const allocator = std.testing.allocator;
34723472
const Test = struct {
34733473
fn runPreprocessor(source_text: []const u8) ![]const u8 {
3474-
var buf = std.ArrayList(u8).init(allocator);
3474+
var buf = std.array_list.Managed(u8).init(allocator);
34753475
defer buf.deinit();
34763476

34773477
var comp = Compilation.init(allocator, std.fs.cwd());
@@ -3602,7 +3602,7 @@ test "Include guards" {
36023602

36033603
_ = try comp.addSourceFromBuffer(path, "int bar = 5;\n");
36043604

3605-
var buf = std.ArrayList(u8).init(allocator);
3605+
var buf = std.array_list.Managed(u8).init(allocator);
36063606
defer buf.deinit();
36073607

36083608
var writer = buf.writer();

lib/compiler/aro/aro/Toolchain.zig

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ pub fn getLinkerPath(tc: *const Toolchain, buf: []u8) ![]const u8 {
157157
return use_linker;
158158
}
159159
} else {
160-
var linker_name = try std.ArrayList(u8).initCapacity(tc.driver.comp.gpa, 5 + use_linker.len); // "ld64." ++ use_linker
160+
var linker_name = try std.array_list.Managed(u8).initCapacity(tc.driver.comp.gpa, 5 + use_linker.len); // "ld64." ++ use_linker
161161
defer linker_name.deinit();
162162
if (tc.getTarget().os.tag.isDarwin()) {
163163
linker_name.appendSliceAssumeCapacity("ld64.");
@@ -198,7 +198,7 @@ fn possibleProgramNames(raw_triple: ?[]const u8, name: []const u8, buf: *[64]u8)
198198
}
199199

200200
/// Add toolchain `file_paths` to argv as `-L` arguments
201-
pub fn addFilePathLibArgs(tc: *const Toolchain, argv: *std.ArrayList([]const u8)) !void {
201+
pub fn addFilePathLibArgs(tc: *const Toolchain, argv: *std.array_list.Managed([]const u8)) !void {
202202
try argv.ensureUnusedCapacity(tc.file_paths.items.len);
203203

204204
var bytes_needed: usize = 0;
@@ -332,7 +332,7 @@ pub fn addPathFromComponents(tc: *Toolchain, components: []const []const u8, des
332332

333333
/// Add linker args to `argv`. Does not add path to linker executable as first item; that must be handled separately
334334
/// Items added to `argv` will be string literals or owned by `tc.arena` so they must not be individually freed
335-
pub fn buildLinkerArgs(tc: *Toolchain, argv: *std.ArrayList([]const u8)) !void {
335+
pub fn buildLinkerArgs(tc: *Toolchain, argv: *std.array_list.Managed([]const u8)) !void {
336336
return switch (tc.inner) {
337337
.uninitialized => unreachable,
338338
.linux => |*linux| linux.buildLinkerArgs(tc, argv),
@@ -412,7 +412,7 @@ fn getAsNeededOption(is_solaris: bool, needed: bool) []const u8 {
412412
}
413413
}
414414

415-
fn addUnwindLibrary(tc: *const Toolchain, argv: *std.ArrayList([]const u8)) !void {
415+
fn addUnwindLibrary(tc: *const Toolchain, argv: *std.array_list.Managed([]const u8)) !void {
416416
const unw = try tc.getUnwindLibKind();
417417
const target = tc.getTarget();
418418
if ((target.abi.isAndroid() and unw == .libgcc) or
@@ -450,7 +450,7 @@ fn addUnwindLibrary(tc: *const Toolchain, argv: *std.ArrayList([]const u8)) !voi
450450
}
451451
}
452452

453-
fn addLibGCC(tc: *const Toolchain, argv: *std.ArrayList([]const u8)) !void {
453+
fn addLibGCC(tc: *const Toolchain, argv: *std.array_list.Managed([]const u8)) !void {
454454
const libgcc_kind = tc.getLibGCCKind();
455455
if (libgcc_kind == .static or libgcc_kind == .unspecified) {
456456
try argv.append("-lgcc");
@@ -461,7 +461,7 @@ fn addLibGCC(tc: *const Toolchain, argv: *std.ArrayList([]const u8)) !void {
461461
}
462462
}
463463

464-
pub fn addRuntimeLibs(tc: *const Toolchain, argv: *std.ArrayList([]const u8)) !void {
464+
pub fn addRuntimeLibs(tc: *const Toolchain, argv: *std.array_list.Managed([]const u8)) !void {
465465
const target = tc.getTarget();
466466
const rlt = tc.getRuntimeLibKind();
467467
switch (rlt) {

lib/compiler/aro/aro/Tree.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ pub const TokenWithExpansionLocs = struct {
4141

4242
pub fn addExpansionLocation(tok: *TokenWithExpansionLocs, gpa: std.mem.Allocator, new: []const Source.Location) !void {
4343
if (new.len == 0 or tok.id == .whitespace or tok.id == .macro_ws or tok.id == .placemarker) return;
44-
var list = std.ArrayList(Source.Location).init(gpa);
44+
var list = std.array_list.Managed(Source.Location).init(gpa);
4545
defer {
4646
@memset(list.items.ptr[list.items.len..list.capacity], .{});
4747
// Add a sentinel to indicate the end of the list since

0 commit comments

Comments
 (0)