authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-06-20 17:33:29-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-06-20 17:33:29-04:00
log85f928f8bff8c033f6ef0104d68b033669cb36e4
tree1682c01aac310e445a68830545f670d121ac38ea
parente891f9cd9dc52b4bc63ae63115822fbf5e724348

remove std.mem.Allocator.construct and other fixups


10 files changed, 101 insertions(+), 100 deletions(-)

src-self-hosted/errmsg.zig+1-1
......@@ -35,7 +35,7 @@ pub fn createFromParseError(
3535 var out_stream = &std.io.BufferOutStream.init(&text_buf).stream;
3636 try parse_error.render(&tree.tokens, out_stream);
3737
38 const msg = try allocator.construct(Msg{
38 const msg = try allocator.create(Msg{
3939 .tree = tree,
4040 .path = path,
4141 .text = text_buf.toOwnedSlice(),
src-self-hosted/main.zig+1-1
......@@ -707,7 +707,7 @@ const Fmt = struct {
707707
708708 // file_path must outlive Fmt
709709 fn addToQueue(self: *Fmt, file_path: []const u8) !void {
710 const new_node = try self.seen.allocator.construct(std.LinkedList([]const u8).Node{
710 const new_node = try self.seen.allocator.create(std.LinkedList([]const u8).Node{
711711 .prev = undefined,
712712 .next = undefined,
713713 .data = file_path,
src-self-hosted/module.zig+11-2
......@@ -114,7 +114,7 @@ pub const Module = struct {
114114 .name = name,
115115 .path = path,
116116 .children = ArrayList(*CliPkg).init(allocator),
117 .parent = parent
117 .parent = parent,
118118 });
119119 return pkg;
120120 }
......@@ -127,7 +127,16 @@ pub const Module = struct {
127127 }
128128 };
129129
130 pub fn create(allocator: *mem.Allocator, name: []const u8, root_src_path: ?[]const u8, target: *const Target, kind: Kind, build_mode: builtin.Mode, zig_lib_dir: []const u8, cache_dir: []const u8) !*Module {
130 pub fn create(
131 allocator: *mem.Allocator,
132 name: []const u8,
133 root_src_path: ?[]const u8,
134 target: *const Target,
135 kind: Kind,
136 build_mode: builtin.Mode,
137 zig_lib_dir: []const u8,
138 cache_dir: []const u8,
139 ) !*Module {
131140 var name_buffer = try Buffer.init(allocator, name);
132141 errdefer name_buffer.deinit();
133142
std/atomic/queue.zig+1-1
......@@ -115,7 +115,7 @@ fn startPuts(ctx: *Context) u8 {
115115 std.os.time.sleep(0, 1); // let the os scheduler be our fuzz
116116 const x = @bitCast(i32, r.random.scalar(u32));
117117 const node = ctx.allocator.create(Queue(i32).Node{
118 .next = null,
118 .next = undefined,
119119 .data = x,
120120 }) catch unreachable;
121121 ctx.queue.put(node);
std/atomic/stack.zig+1-1
......@@ -118,7 +118,7 @@ fn startPuts(ctx: *Context) u8 {
118118 std.os.time.sleep(0, 1); // let the os scheduler be our fuzz
119119 const x = @bitCast(i32, r.random.scalar(u32));
120120 const node = ctx.allocator.create(Stack(i32).Node{
121 .next = null,
121 .next = undefined,
122122 .data = x,
123123 }) catch unreachable;
124124 ctx.stack.push(node);
std/heap.zig+1-2
......@@ -407,8 +407,7 @@ fn testAllocator(allocator: *mem.Allocator) !void {
407407 var slice = try allocator.alloc(*i32, 100);
408408
409409 for (slice) |*item, i| {
410 item.* = try allocator.create(i32(0));
411 item.*.* = @intCast(i32, i);
410 item.* = try allocator.create(@intCast(i32, i));
412411 }
413412
414413 for (slice) |item, i| {
std/linked_list.zig+1-5
......@@ -193,11 +193,7 @@ fn BaseLinkedList(comptime T: type, comptime ParentType: type, comptime field_na
193193 /// A pointer to the new node.
194194 pub fn allocateNode(list: *Self, allocator: *Allocator) !*Node {
195195 comptime assert(!isIntrusive());
196 return allocator.create(Node{
197 .prev = null,
198 .next = null,
199 .data = undefined,
200 });
196 return allocator.create(Node(undefined));
201197 }
202198
203199 /// Deallocate a node.
std/mem.zig+1-7
......@@ -41,13 +41,7 @@ pub const Allocator = struct {
4141 return ptr;
4242 }
4343
44 /// Alias of `create`
45 /// Call `destroy` with the result
46 pub fn construct(self: *Allocator, init: var) Error!*@typeOf(init) {
47 return self.create(init);
48 }
49
50 /// `ptr` should be the return value of `construct` or `create`
44 /// `ptr` should be the return value of `create`
5145 pub fn destroy(self: *Allocator, ptr: var) void {
5246 const non_const_ptr = @intToPtr([*]u8, @ptrToInt(ptr));
5347 self.freeFn(self, non_const_ptr[0..@sizeOf(@typeOf(ptr).Child)]);
std/os/index.zig+8-5
......@@ -2468,7 +2468,7 @@ pub const Thread = struct {
24682468 data: Data,
24692469
24702470 pub const use_pthreads = is_posix and builtin.link_libc;
2471 const Data = if (use_pthreads)
2471 pub const Data = if (use_pthreads)
24722472 struct {
24732473 handle: c.pthread_t,
24742474 stack_addr: usize,
......@@ -2583,13 +2583,16 @@ pub fn spawnThread(context: var, comptime startFn: var) SpawnThreadError!*Thread
25832583 errdefer assert(windows.HeapFree(heap_handle, 0, bytes_ptr) != 0);
25842584 const bytes = @ptrCast([*]u8, bytes_ptr)[0..byte_count];
25852585 const outer_context = std.heap.FixedBufferAllocator.init(bytes).allocator.create(WinThread.OuterContext{
2586 .thread = undefined,
2586 .thread = Thread{
2587 .data = Thread.Data{
2588 .heap_handle = heap_handle,
2589 .alloc_start = bytes_ptr,
2590 .handle = undefined,
2591 },
2592 },
25872593 .inner = context,
25882594 }) catch unreachable;
25892595
2590 outer_context.thread.data.heap_handle = heap_handle;
2591 outer_context.thread.data.alloc_start = bytes_ptr;
2592
25932596 const parameter = if (@sizeOf(Context) == 0) null else @ptrCast(*c_void, &outer_context.inner);
25942597 outer_context.thread.data.handle = windows.CreateThread(null, default_stack_size, WinThread.threadMain, parameter, 0, null) orelse {
25952598 const err = windows.GetLastError();
std/zig/parse.zig+75-75
......@@ -17,7 +17,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
1717 defer stack.deinit();
1818
1919 const arena = &tree_arena.allocator;
20 const root_node = try arena.construct(ast.Node.Root{
20 const root_node = try arena.create(ast.Node.Root{
2121 .base = ast.Node{ .id = ast.Node.Id.Root },
2222 .decls = ast.Node.Root.DeclList.init(arena),
2323 .doc_comments = null,
......@@ -65,14 +65,14 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
6565 Token.Id.Keyword_test => {
6666 stack.append(State.TopLevel) catch unreachable;
6767
68 const block = try arena.construct(ast.Node.Block{
68 const block = try arena.create(ast.Node.Block{
6969 .base = ast.Node{ .id = ast.Node.Id.Block },
7070 .label = null,
7171 .lbrace = undefined,
7272 .statements = ast.Node.Block.StatementList.init(arena),
7373 .rbrace = undefined,
7474 });
75 const test_node = try arena.construct(ast.Node.TestDecl{
75 const test_node = try arena.create(ast.Node.TestDecl{
7676 .base = ast.Node{ .id = ast.Node.Id.TestDecl },
7777 .doc_comments = comments,
7878 .test_token = token_index,
......@@ -109,14 +109,14 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
109109 continue;
110110 },
111111 Token.Id.Keyword_comptime => {
112 const block = try arena.construct(ast.Node.Block{
112 const block = try arena.create(ast.Node.Block{
113113 .base = ast.Node{ .id = ast.Node.Id.Block },
114114 .label = null,
115115 .lbrace = undefined,
116116 .statements = ast.Node.Block.StatementList.init(arena),
117117 .rbrace = undefined,
118118 });
119 const node = try arena.construct(ast.Node.Comptime{
119 const node = try arena.create(ast.Node.Comptime{
120120 .base = ast.Node{ .id = ast.Node.Id.Comptime },
121121 .comptime_token = token_index,
122122 .expr = &block.base,
......@@ -225,7 +225,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
225225 return tree;
226226 }
227227
228 const node = try arena.construct(ast.Node.Use{
228 const node = try arena.create(ast.Node.Use{
229229 .base = ast.Node{ .id = ast.Node.Id.Use },
230230 .use_token = token_index,
231231 .visib_token = ctx.visib_token,
......@@ -266,7 +266,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
266266 continue;
267267 },
268268 Token.Id.Keyword_fn, Token.Id.Keyword_nakedcc, Token.Id.Keyword_stdcallcc, Token.Id.Keyword_async => {
269 const fn_proto = try arena.construct(ast.Node.FnProto{
269 const fn_proto = try arena.create(ast.Node.FnProto{
270270 .base = ast.Node{ .id = ast.Node.Id.FnProto },
271271 .doc_comments = ctx.comments,
272272 .visib_token = ctx.visib_token,
......@@ -298,7 +298,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
298298 continue;
299299 },
300300 Token.Id.Keyword_async => {
301 const async_node = try arena.construct(ast.Node.AsyncAttribute{
301 const async_node = try arena.create(ast.Node.AsyncAttribute{
302302 .base = ast.Node{ .id = ast.Node.Id.AsyncAttribute },
303303 .async_token = token_index,
304304 .allocator_type = null,
......@@ -330,7 +330,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
330330 },
331331 State.TopLevelExternOrField => |ctx| {
332332 if (eatToken(&tok_it, &tree, Token.Id.Identifier)) |identifier| {
333 const node = try arena.construct(ast.Node.StructField{
333 const node = try arena.create(ast.Node.StructField{
334334 .base = ast.Node{ .id = ast.Node.Id.StructField },
335335 .doc_comments = ctx.comments,
336336 .visib_token = ctx.visib_token,
......@@ -375,7 +375,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
375375 const token = nextToken(&tok_it, &tree);
376376 const token_index = token.index;
377377 const token_ptr = token.ptr;
378 const node = try arena.construct(ast.Node.ContainerDecl{
378 const node = try arena.create(ast.Node.ContainerDecl{
379379 .base = ast.Node{ .id = ast.Node.Id.ContainerDecl },
380380 .layout_token = ctx.layout_token,
381381 .kind_token = switch (token_ptr.id) {
......@@ -448,7 +448,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
448448 Token.Id.Identifier => {
449449 switch (tree.tokens.at(container_decl.kind_token).id) {
450450 Token.Id.Keyword_struct => {
451 const node = try arena.construct(ast.Node.StructField{
451 const node = try arena.create(ast.Node.StructField{
452452 .base = ast.Node{ .id = ast.Node.Id.StructField },
453453 .doc_comments = comments,
454454 .visib_token = null,
......@@ -464,7 +464,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
464464 continue;
465465 },
466466 Token.Id.Keyword_union => {
467 const node = try arena.construct(ast.Node.UnionTag{
467 const node = try arena.create(ast.Node.UnionTag{
468468 .base = ast.Node{ .id = ast.Node.Id.UnionTag },
469469 .name_token = token_index,
470470 .type_expr = null,
......@@ -480,7 +480,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
480480 continue;
481481 },
482482 Token.Id.Keyword_enum => {
483 const node = try arena.construct(ast.Node.EnumTag{
483 const node = try arena.create(ast.Node.EnumTag{
484484 .base = ast.Node{ .id = ast.Node.Id.EnumTag },
485485 .name_token = token_index,
486486 .value = null,
......@@ -562,7 +562,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
562562 },
563563
564564 State.VarDecl => |ctx| {
565 const var_decl = try arena.construct(ast.Node.VarDecl{
565 const var_decl = try arena.create(ast.Node.VarDecl{
566566 .base = ast.Node{ .id = ast.Node.Id.VarDecl },
567567 .doc_comments = ctx.comments,
568568 .visib_token = ctx.visib_token,
......@@ -660,7 +660,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
660660 const token_ptr = token.ptr;
661661 switch (token_ptr.id) {
662662 Token.Id.LBrace => {
663 const block = try arena.construct(ast.Node.Block{
663 const block = try arena.create(ast.Node.Block{
664664 .base = ast.Node{ .id = ast.Node.Id.Block },
665665 .label = null,
666666 .lbrace = token_index,
......@@ -712,7 +712,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
712712 // TODO: this is a special case. Remove this when #760 is fixed
713713 if (token_ptr.id == Token.Id.Keyword_error) {
714714 if (tok_it.peek().?.id == Token.Id.LBrace) {
715 const error_type_node = try arena.construct(ast.Node.ErrorType{
715 const error_type_node = try arena.create(ast.Node.ErrorType{
716716 .base = ast.Node{ .id = ast.Node.Id.ErrorType },
717717 .token = token_index,
718718 });
......@@ -733,7 +733,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
733733 if (eatToken(&tok_it, &tree, Token.Id.RParen)) |_| {
734734 continue;
735735 }
736 const param_decl = try arena.construct(ast.Node.ParamDecl{
736 const param_decl = try arena.create(ast.Node.ParamDecl{
737737 .base = ast.Node{ .id = ast.Node.Id.ParamDecl },
738738 .comptime_token = null,
739739 .noalias_token = null,
......@@ -819,7 +819,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
819819 const token_ptr = token.ptr;
820820 switch (token_ptr.id) {
821821 Token.Id.LBrace => {
822 const block = try arena.construct(ast.Node.Block{
822 const block = try arena.create(ast.Node.Block{
823823 .base = ast.Node{ .id = ast.Node.Id.Block },
824824 .label = ctx.label,
825825 .lbrace = token_index,
......@@ -853,7 +853,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
853853 continue;
854854 },
855855 Token.Id.Keyword_suspend => {
856 const node = try arena.construct(ast.Node.Suspend{
856 const node = try arena.create(ast.Node.Suspend{
857857 .base = ast.Node{ .id = ast.Node.Id.Suspend },
858858 .label = ctx.label,
859859 .suspend_token = token_index,
......@@ -925,7 +925,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
925925 }
926926 },
927927 State.While => |ctx| {
928 const node = try arena.construct(ast.Node.While{
928 const node = try arena.create(ast.Node.While{
929929 .base = ast.Node{ .id = ast.Node.Id.While },
930930 .label = ctx.label,
931931 .inline_token = ctx.inline_token,
......@@ -954,7 +954,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
954954 continue;
955955 },
956956 State.For => |ctx| {
957 const node = try arena.construct(ast.Node.For{
957 const node = try arena.create(ast.Node.For{
958958 .base = ast.Node{ .id = ast.Node.Id.For },
959959 .label = ctx.label,
960960 .inline_token = ctx.inline_token,
......@@ -975,7 +975,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
975975 },
976976 State.Else => |dest| {
977977 if (eatToken(&tok_it, &tree, Token.Id.Keyword_else)) |else_token| {
978 const node = try arena.construct(ast.Node.Else{
978 const node = try arena.create(ast.Node.Else{
979979 .base = ast.Node{ .id = ast.Node.Id.Else },
980980 .else_token = else_token,
981981 .payload = null,
......@@ -1038,7 +1038,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
10381038 continue;
10391039 },
10401040 Token.Id.Keyword_defer, Token.Id.Keyword_errdefer => {
1041 const node = try arena.construct(ast.Node.Defer{
1041 const node = try arena.create(ast.Node.Defer{
10421042 .base = ast.Node{ .id = ast.Node.Id.Defer },
10431043 .defer_token = token_index,
10441044 .kind = switch (token_ptr.id) {
......@@ -1056,7 +1056,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
10561056 continue;
10571057 },
10581058 Token.Id.LBrace => {
1059 const inner_block = try arena.construct(ast.Node.Block{
1059 const inner_block = try arena.create(ast.Node.Block{
10601060 .base = ast.Node{ .id = ast.Node.Id.Block },
10611061 .label = null,
10621062 .lbrace = token_index,
......@@ -1124,7 +1124,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
11241124 continue;
11251125 }
11261126
1127 const node = try arena.construct(ast.Node.AsmOutput{
1127 const node = try arena.create(ast.Node.AsmOutput{
11281128 .base = ast.Node{ .id = ast.Node.Id.AsmOutput },
11291129 .lbracket = lbracket_index,
11301130 .symbolic_name = undefined,
......@@ -1178,7 +1178,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
11781178 continue;
11791179 }
11801180
1181 const node = try arena.construct(ast.Node.AsmInput{
1181 const node = try arena.create(ast.Node.AsmInput{
11821182 .base = ast.Node{ .id = ast.Node.Id.AsmInput },
11831183 .lbracket = lbracket_index,
11841184 .symbolic_name = undefined,
......@@ -1243,7 +1243,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
12431243 continue;
12441244 }
12451245
1246 const node = try arena.construct(ast.Node.FieldInitializer{
1246 const node = try arena.create(ast.Node.FieldInitializer{
12471247 .base = ast.Node{ .id = ast.Node.Id.FieldInitializer },
12481248 .period_token = undefined,
12491249 .name_token = undefined,
......@@ -1332,7 +1332,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
13321332 }
13331333
13341334 const comments = try eatDocComments(arena, &tok_it, &tree);
1335 const node = try arena.construct(ast.Node.SwitchCase{
1335 const node = try arena.create(ast.Node.SwitchCase{
13361336 .base = ast.Node{ .id = ast.Node.Id.SwitchCase },
13371337 .items = ast.Node.SwitchCase.ItemList.init(arena),
13381338 .payload = null,
......@@ -1369,7 +1369,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
13691369 const token_index = token.index;
13701370 const token_ptr = token.ptr;
13711371 if (token_ptr.id == Token.Id.Keyword_else) {
1372 const else_node = try arena.construct(ast.Node.SwitchElse{
1372 const else_node = try arena.create(ast.Node.SwitchElse{
13731373 .base = ast.Node{ .id = ast.Node.Id.SwitchElse },
13741374 .token = token_index,
13751375 });
......@@ -1468,7 +1468,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
14681468
14691469 State.ExternType => |ctx| {
14701470 if (eatToken(&tok_it, &tree, Token.Id.Keyword_fn)) |fn_token| {
1471 const fn_proto = try arena.construct(ast.Node.FnProto{
1471 const fn_proto = try arena.create(ast.Node.FnProto{
14721472 .base = ast.Node{ .id = ast.Node.Id.FnProto },
14731473 .doc_comments = ctx.comments,
14741474 .visib_token = null,
......@@ -1641,7 +1641,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
16411641 continue;
16421642 }
16431643
1644 const node = try arena.construct(ast.Node.Payload{
1644 const node = try arena.create(ast.Node.Payload{
16451645 .base = ast.Node{ .id = ast.Node.Id.Payload },
16461646 .lpipe = token_index,
16471647 .error_symbol = undefined,
......@@ -1677,7 +1677,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
16771677 continue;
16781678 }
16791679
1680 const node = try arena.construct(ast.Node.PointerPayload{
1680 const node = try arena.create(ast.Node.PointerPayload{
16811681 .base = ast.Node{ .id = ast.Node.Id.PointerPayload },
16821682 .lpipe = token_index,
16831683 .ptr_token = null,
......@@ -1720,7 +1720,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
17201720 continue;
17211721 }
17221722
1723 const node = try arena.construct(ast.Node.PointerIndexPayload{
1723 const node = try arena.create(ast.Node.PointerIndexPayload{
17241724 .base = ast.Node{ .id = ast.Node.Id.PointerIndexPayload },
17251725 .lpipe = token_index,
17261726 .ptr_token = null,
......@@ -1754,7 +1754,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
17541754 const token_ptr = token.ptr;
17551755 switch (token_ptr.id) {
17561756 Token.Id.Keyword_return, Token.Id.Keyword_break, Token.Id.Keyword_continue => {
1757 const node = try arena.construct(ast.Node.ControlFlowExpression{
1757 const node = try arena.create(ast.Node.ControlFlowExpression{
17581758 .base = ast.Node{ .id = ast.Node.Id.ControlFlowExpression },
17591759 .ltoken = token_index,
17601760 .kind = undefined,
......@@ -1783,7 +1783,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
17831783 continue;
17841784 },
17851785 Token.Id.Keyword_try, Token.Id.Keyword_cancel, Token.Id.Keyword_resume => {
1786 const node = try arena.construct(ast.Node.PrefixOp{
1786 const node = try arena.create(ast.Node.PrefixOp{
17871787 .base = ast.Node{ .id = ast.Node.Id.PrefixOp },
17881788 .op_token = token_index,
17891789 .op = switch (token_ptr.id) {
......@@ -1817,7 +1817,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
18171817 const lhs = opt_ctx.get() orelse continue;
18181818
18191819 if (eatToken(&tok_it, &tree, Token.Id.Ellipsis3)) |ellipsis3| {
1820 const node = try arena.construct(ast.Node.InfixOp{
1820 const node = try arena.create(ast.Node.InfixOp{
18211821 .base = ast.Node{ .id = ast.Node.Id.InfixOp },
18221822 .lhs = lhs,
18231823 .op_token = ellipsis3,
......@@ -1842,7 +1842,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
18421842 const token_index = token.index;
18431843 const token_ptr = token.ptr;
18441844 if (tokenIdToAssignment(token_ptr.id)) |ass_id| {
1845 const node = try arena.construct(ast.Node.InfixOp{
1845 const node = try arena.create(ast.Node.InfixOp{
18461846 .base = ast.Node{ .id = ast.Node.Id.InfixOp },
18471847 .lhs = lhs,
18481848 .op_token = token_index,
......@@ -1872,7 +1872,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
18721872 const token_index = token.index;
18731873 const token_ptr = token.ptr;
18741874 if (tokenIdToUnwrapExpr(token_ptr.id)) |unwrap_id| {
1875 const node = try arena.construct(ast.Node.InfixOp{
1875 const node = try arena.create(ast.Node.InfixOp{
18761876 .base = ast.Node{ .id = ast.Node.Id.InfixOp },
18771877 .lhs = lhs,
18781878 .op_token = token_index,
......@@ -1904,7 +1904,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
19041904 const lhs = opt_ctx.get() orelse continue;
19051905
19061906 if (eatToken(&tok_it, &tree, Token.Id.Keyword_or)) |or_token| {
1907 const node = try arena.construct(ast.Node.InfixOp{
1907 const node = try arena.create(ast.Node.InfixOp{
19081908 .base = ast.Node{ .id = ast.Node.Id.InfixOp },
19091909 .lhs = lhs,
19101910 .op_token = or_token,
......@@ -1928,7 +1928,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
19281928 const lhs = opt_ctx.get() orelse continue;
19291929
19301930 if (eatToken(&tok_it, &tree, Token.Id.Keyword_and)) |and_token| {
1931 const node = try arena.construct(ast.Node.InfixOp{
1931 const node = try arena.create(ast.Node.InfixOp{
19321932 .base = ast.Node{ .id = ast.Node.Id.InfixOp },
19331933 .lhs = lhs,
19341934 .op_token = and_token,
......@@ -1955,7 +1955,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
19551955 const token_index = token.index;
19561956 const token_ptr = token.ptr;
19571957 if (tokenIdToComparison(token_ptr.id)) |comp_id| {
1958 const node = try arena.construct(ast.Node.InfixOp{
1958 const node = try arena.create(ast.Node.InfixOp{
19591959 .base = ast.Node{ .id = ast.Node.Id.InfixOp },
19601960 .lhs = lhs,
19611961 .op_token = token_index,
......@@ -1982,7 +1982,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
19821982 const lhs = opt_ctx.get() orelse continue;
19831983
19841984 if (eatToken(&tok_it, &tree, Token.Id.Pipe)) |pipe| {
1985 const node = try arena.construct(ast.Node.InfixOp{
1985 const node = try arena.create(ast.Node.InfixOp{
19861986 .base = ast.Node{ .id = ast.Node.Id.InfixOp },
19871987 .lhs = lhs,
19881988 .op_token = pipe,
......@@ -2006,7 +2006,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
20062006 const lhs = opt_ctx.get() orelse continue;
20072007
20082008 if (eatToken(&tok_it, &tree, Token.Id.Caret)) |caret| {
2009 const node = try arena.construct(ast.Node.InfixOp{
2009 const node = try arena.create(ast.Node.InfixOp{
20102010 .base = ast.Node{ .id = ast.Node.Id.InfixOp },
20112011 .lhs = lhs,
20122012 .op_token = caret,
......@@ -2030,7 +2030,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
20302030 const lhs = opt_ctx.get() orelse continue;
20312031
20322032 if (eatToken(&tok_it, &tree, Token.Id.Ampersand)) |ampersand| {
2033 const node = try arena.construct(ast.Node.InfixOp{
2033 const node = try arena.create(ast.Node.InfixOp{
20342034 .base = ast.Node{ .id = ast.Node.Id.InfixOp },
20352035 .lhs = lhs,
20362036 .op_token = ampersand,
......@@ -2057,7 +2057,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
20572057 const token_index = token.index;
20582058 const token_ptr = token.ptr;
20592059 if (tokenIdToBitShift(token_ptr.id)) |bitshift_id| {
2060 const node = try arena.construct(ast.Node.InfixOp{
2060 const node = try arena.create(ast.Node.InfixOp{
20612061 .base = ast.Node{ .id = ast.Node.Id.InfixOp },
20622062 .lhs = lhs,
20632063 .op_token = token_index,
......@@ -2087,7 +2087,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
20872087 const token_index = token.index;
20882088 const token_ptr = token.ptr;
20892089 if (tokenIdToAddition(token_ptr.id)) |add_id| {
2090 const node = try arena.construct(ast.Node.InfixOp{
2090 const node = try arena.create(ast.Node.InfixOp{
20912091 .base = ast.Node{ .id = ast.Node.Id.InfixOp },
20922092 .lhs = lhs,
20932093 .op_token = token_index,
......@@ -2117,7 +2117,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
21172117 const token_index = token.index;
21182118 const token_ptr = token.ptr;
21192119 if (tokenIdToMultiply(token_ptr.id)) |mult_id| {
2120 const node = try arena.construct(ast.Node.InfixOp{
2120 const node = try arena.create(ast.Node.InfixOp{
21212121 .base = ast.Node{ .id = ast.Node.Id.InfixOp },
21222122 .lhs = lhs,
21232123 .op_token = token_index,
......@@ -2145,7 +2145,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
21452145 const lhs = opt_ctx.get() orelse continue;
21462146
21472147 if (tok_it.peek().?.id == Token.Id.Period) {
2148 const node = try arena.construct(ast.Node.SuffixOp{
2148 const node = try arena.create(ast.Node.SuffixOp{
21492149 .base = ast.Node{ .id = ast.Node.Id.SuffixOp },
21502150 .lhs = lhs,
21512151 .op = ast.Node.SuffixOp.Op{ .StructInitializer = ast.Node.SuffixOp.Op.InitList.init(arena) },
......@@ -2164,7 +2164,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
21642164 continue;
21652165 }
21662166
2167 const node = try arena.construct(ast.Node.SuffixOp{
2167 const node = try arena.create(ast.Node.SuffixOp{
21682168 .base = ast.Node{ .id = ast.Node.Id.SuffixOp },
21692169 .lhs = lhs,
21702170 .op = ast.Node.SuffixOp.Op{ .ArrayInitializer = ast.Node.SuffixOp.Op.InitList.init(arena) },
......@@ -2193,7 +2193,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
21932193 const lhs = opt_ctx.get() orelse continue;
21942194
21952195 if (eatToken(&tok_it, &tree, Token.Id.Bang)) |bang| {
2196 const node = try arena.construct(ast.Node.InfixOp{
2196 const node = try arena.create(ast.Node.InfixOp{
21972197 .base = ast.Node{ .id = ast.Node.Id.InfixOp },
21982198 .lhs = lhs,
21992199 .op_token = bang,
......@@ -2212,7 +2212,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
22122212 const token_index = token.index;
22132213 const token_ptr = token.ptr;
22142214 if (tokenIdToPrefixOp(token_ptr.id)) |prefix_id| {
2215 var node = try arena.construct(ast.Node.PrefixOp{
2215 var node = try arena.create(ast.Node.PrefixOp{
22162216 .base = ast.Node{ .id = ast.Node.Id.PrefixOp },
22172217 .op_token = token_index,
22182218 .op = prefix_id,
......@@ -2222,7 +2222,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
22222222
22232223 // Treat '**' token as two pointer types
22242224 if (token_ptr.id == Token.Id.AsteriskAsterisk) {
2225 const child = try arena.construct(ast.Node.PrefixOp{
2225 const child = try arena.create(ast.Node.PrefixOp{
22262226 .base = ast.Node{ .id = ast.Node.Id.PrefixOp },
22272227 .op_token = token_index,
22282228 .op = prefix_id,
......@@ -2246,7 +2246,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
22462246
22472247 State.SuffixOpExpressionBegin => |opt_ctx| {
22482248 if (eatToken(&tok_it, &tree, Token.Id.Keyword_async)) |async_token| {
2249 const async_node = try arena.construct(ast.Node.AsyncAttribute{
2249 const async_node = try arena.create(ast.Node.AsyncAttribute{
22502250 .base = ast.Node{ .id = ast.Node.Id.AsyncAttribute },
22512251 .async_token = async_token,
22522252 .allocator_type = null,
......@@ -2277,7 +2277,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
22772277 const token_ptr = token.ptr;
22782278 switch (token_ptr.id) {
22792279 Token.Id.LParen => {
2280 const node = try arena.construct(ast.Node.SuffixOp{
2280 const node = try arena.create(ast.Node.SuffixOp{
22812281 .base = ast.Node{ .id = ast.Node.Id.SuffixOp },
22822282 .lhs = lhs,
22832283 .op = ast.Node.SuffixOp.Op{
......@@ -2301,7 +2301,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
23012301 continue;
23022302 },
23032303 Token.Id.LBracket => {
2304 const node = try arena.construct(ast.Node.SuffixOp{
2304 const node = try arena.create(ast.Node.SuffixOp{
23052305 .base = ast.Node{ .id = ast.Node.Id.SuffixOp },
23062306 .lhs = lhs,
23072307 .op = ast.Node.SuffixOp.Op{ .ArrayAccess = undefined },
......@@ -2316,7 +2316,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
23162316 },
23172317 Token.Id.Period => {
23182318 if (eatToken(&tok_it, &tree, Token.Id.Asterisk)) |asterisk_token| {
2319 const node = try arena.construct(ast.Node.SuffixOp{
2319 const node = try arena.create(ast.Node.SuffixOp{
23202320 .base = ast.Node{ .id = ast.Node.Id.SuffixOp },
23212321 .lhs = lhs,
23222322 .op = ast.Node.SuffixOp.Op.Deref,
......@@ -2327,7 +2327,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
23272327 continue;
23282328 }
23292329 if (eatToken(&tok_it, &tree, Token.Id.QuestionMark)) |question_token| {
2330 const node = try arena.construct(ast.Node.SuffixOp{
2330 const node = try arena.create(ast.Node.SuffixOp{
23312331 .base = ast.Node{ .id = ast.Node.Id.SuffixOp },
23322332 .lhs = lhs,
23332333 .op = ast.Node.SuffixOp.Op.UnwrapOptional,
......@@ -2337,7 +2337,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
23372337 stack.append(State{ .SuffixOpExpressionEnd = opt_ctx.toRequired() }) catch unreachable;
23382338 continue;
23392339 }
2340 const node = try arena.construct(ast.Node.InfixOp{
2340 const node = try arena.create(ast.Node.InfixOp{
23412341 .base = ast.Node{ .id = ast.Node.Id.InfixOp },
23422342 .lhs = lhs,
23432343 .op_token = token_index,
......@@ -2397,7 +2397,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
23972397 continue;
23982398 },
23992399 Token.Id.Keyword_promise => {
2400 const node = try arena.construct(ast.Node.PromiseType{
2400 const node = try arena.create(ast.Node.PromiseType{
24012401 .base = ast.Node{ .id = ast.Node.Id.PromiseType },
24022402 .promise_token = token.index,
24032403 .result = null,
......@@ -2423,7 +2423,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
24232423 continue;
24242424 },
24252425 Token.Id.LParen => {
2426 const node = try arena.construct(ast.Node.GroupedExpression{
2426 const node = try arena.create(ast.Node.GroupedExpression{
24272427 .base = ast.Node{ .id = ast.Node.Id.GroupedExpression },
24282428 .lparen = token.index,
24292429 .expr = undefined,
......@@ -2441,7 +2441,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
24412441 continue;
24422442 },
24432443 Token.Id.Builtin => {
2444 const node = try arena.construct(ast.Node.BuiltinCall{
2444 const node = try arena.create(ast.Node.BuiltinCall{
24452445 .base = ast.Node{ .id = ast.Node.Id.BuiltinCall },
24462446 .builtin_token = token.index,
24472447 .params = ast.Node.BuiltinCall.ParamList.init(arena),
......@@ -2460,7 +2460,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
24602460 continue;
24612461 },
24622462 Token.Id.LBracket => {
2463 const node = try arena.construct(ast.Node.PrefixOp{
2463 const node = try arena.create(ast.Node.PrefixOp{
24642464 .base = ast.Node{ .id = ast.Node.Id.PrefixOp },
24652465 .op_token = token.index,
24662466 .op = undefined,
......@@ -2519,7 +2519,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
25192519 continue;
25202520 },
25212521 Token.Id.Keyword_fn => {
2522 const fn_proto = try arena.construct(ast.Node.FnProto{
2522 const fn_proto = try arena.create(ast.Node.FnProto{
25232523 .base = ast.Node{ .id = ast.Node.Id.FnProto },
25242524 .doc_comments = null,
25252525 .visib_token = null,
......@@ -2540,7 +2540,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
25402540 continue;
25412541 },
25422542 Token.Id.Keyword_nakedcc, Token.Id.Keyword_stdcallcc => {
2543 const fn_proto = try arena.construct(ast.Node.FnProto{
2543 const fn_proto = try arena.create(ast.Node.FnProto{
25442544 .base = ast.Node{ .id = ast.Node.Id.FnProto },
25452545 .doc_comments = null,
25462546 .visib_token = null,
......@@ -2567,7 +2567,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
25672567 continue;
25682568 },
25692569 Token.Id.Keyword_asm => {
2570 const node = try arena.construct(ast.Node.Asm{
2570 const node = try arena.create(ast.Node.Asm{
25712571 .base = ast.Node{ .id = ast.Node.Id.Asm },
25722572 .asm_token = token.index,
25732573 .volatile_token = null,
......@@ -2629,7 +2629,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
26292629 continue;
26302630 }
26312631
2632 const node = try arena.construct(ast.Node.ErrorSetDecl{
2632 const node = try arena.create(ast.Node.ErrorSetDecl{
26332633 .base = ast.Node{ .id = ast.Node.Id.ErrorSetDecl },
26342634 .error_token = ctx.error_token,
26352635 .decls = ast.Node.ErrorSetDecl.DeclList.init(arena),
......@@ -2695,7 +2695,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
26952695 return tree;
26962696 }
26972697
2698 const node = try arena.construct(ast.Node.ErrorTag{
2698 const node = try arena.create(ast.Node.ErrorTag{
26992699 .base = ast.Node{ .id = ast.Node.Id.ErrorTag },
27002700 .doc_comments = comments,
27012701 .name_token = ident_token_index,
......@@ -3032,7 +3032,7 @@ fn pushDocComment(arena: *mem.Allocator, line_comment: TokenIndex, result: *?*as
30323032 if (result.*) |comment_node| {
30333033 break :blk comment_node;
30343034 } else {
3035 const comment_node = try arena.construct(ast.Node.DocComment{
3035 const comment_node = try arena.create(ast.Node.DocComment{
30363036 .base = ast.Node{ .id = ast.Node.Id.DocComment },
30373037 .lines = ast.Node.DocComment.LineList.init(arena),
30383038 });
......@@ -3061,7 +3061,7 @@ fn parseStringLiteral(arena: *mem.Allocator, tok_it: *ast.Tree.TokenList.Iterato
30613061 return &(try createLiteral(arena, ast.Node.StringLiteral, token_index)).base;
30623062 },
30633063 Token.Id.MultilineStringLiteralLine => {
3064 const node = try arena.construct(ast.Node.MultilineStringLiteral{
3064 const node = try arena.create(ast.Node.MultilineStringLiteral{
30653065 .base = ast.Node{ .id = ast.Node.Id.MultilineStringLiteral },
30663066 .lines = ast.Node.MultilineStringLiteral.LineList.init(arena),
30673067 });
......@@ -3089,7 +3089,7 @@ fn parseStringLiteral(arena: *mem.Allocator, tok_it: *ast.Tree.TokenList.Iterato
30893089fn parseBlockExpr(stack: *std.ArrayList(State), arena: *mem.Allocator, ctx: *const OptionalCtx, token_ptr: *const Token, token_index: TokenIndex) !bool {
30903090 switch (token_ptr.id) {
30913091 Token.Id.Keyword_suspend => {
3092 const node = try arena.construct(ast.Node.Suspend{
3092 const node = try arena.create(ast.Node.Suspend{
30933093 .base = ast.Node{ .id = ast.Node.Id.Suspend },
30943094 .label = null,
30953095 .suspend_token = token_index,
......@@ -3103,7 +3103,7 @@ fn parseBlockExpr(stack: *std.ArrayList(State), arena: *mem.Allocator, ctx: *con
31033103 return true;
31043104 },
31053105 Token.Id.Keyword_if => {
3106 const node = try arena.construct(ast.Node.If{
3106 const node = try arena.create(ast.Node.If{
31073107 .base = ast.Node{ .id = ast.Node.Id.If },
31083108 .if_token = token_index,
31093109 .condition = undefined,
......@@ -3144,7 +3144,7 @@ fn parseBlockExpr(stack: *std.ArrayList(State), arena: *mem.Allocator, ctx: *con
31443144 return true;
31453145 },
31463146 Token.Id.Keyword_switch => {
3147 const node = try arena.construct(ast.Node.Switch{
3147 const node = try arena.create(ast.Node.Switch{
31483148 .base = ast.Node{ .id = ast.Node.Id.Switch },
31493149 .switch_token = token_index,
31503150 .expr = undefined,
......@@ -3166,7 +3166,7 @@ fn parseBlockExpr(stack: *std.ArrayList(State), arena: *mem.Allocator, ctx: *con
31663166 return true;
31673167 },
31683168 Token.Id.Keyword_comptime => {
3169 const node = try arena.construct(ast.Node.Comptime{
3169 const node = try arena.create(ast.Node.Comptime{
31703170 .base = ast.Node{ .id = ast.Node.Id.Comptime },
31713171 .comptime_token = token_index,
31723172 .expr = undefined,
......@@ -3178,7 +3178,7 @@ fn parseBlockExpr(stack: *std.ArrayList(State), arena: *mem.Allocator, ctx: *con
31783178 return true;
31793179 },
31803180 Token.Id.LBrace => {
3181 const block = try arena.construct(ast.Node.Block{
3181 const block = try arena.create(ast.Node.Block{
31823182 .base = ast.Node{ .id = ast.Node.Id.Block },
31833183 .label = null,
31843184 .lbrace = token_index,
......@@ -3318,7 +3318,7 @@ fn tokenIdToPrefixOp(id: @TagType(Token.Id)) ?ast.Node.PrefixOp.Op {
33183318}
33193319
33203320fn createLiteral(arena: *mem.Allocator, comptime T: type, token_index: TokenIndex) !*T {
3321 return arena.construct(T{
3321 return arena.create(T{
33223322 .base = ast.Node{ .id = ast.Node.typeToId(T) },
33233323 .token = token_index,
33243324 });