authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-06-20 17:33:49-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-06-20 17:33:49-04:00
log4eca75c53b4679e7e31df1505d22a5b618a2d797
tree1682c01aac310e445a68830545f670d121ac38ea
parent55193cb13bbc69350474f6a66728319b41149274
parent85f928f8bff8c033f6ef0104d68b033669cb36e4

Merge branch 'kristate-stdmem-replace-create-with-construct'


16 files changed, 191 insertions(+), 216 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+21-14
......@@ -110,11 +110,12 @@ pub const Module = struct {
110110 parent: ?*CliPkg,
111111
112112 pub fn init(allocator: *mem.Allocator, name: []const u8, path: []const u8, parent: ?*CliPkg) !*CliPkg {
113 var pkg = try allocator.create(CliPkg);
114 pkg.name = name;
115 pkg.path = path;
116 pkg.children = ArrayList(*CliPkg).init(allocator);
117 pkg.parent = parent;
113 var pkg = try allocator.create(CliPkg{
114 .name = name,
115 .path = path,
116 .children = ArrayList(*CliPkg).init(allocator),
117 .parent = parent,
118 });
118119 return pkg;
119120 }
120121
......@@ -126,7 +127,16 @@ pub const Module = struct {
126127 }
127128 };
128129
129 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 {
130140 var name_buffer = try Buffer.init(allocator, name);
131141 errdefer name_buffer.deinit();
132142
......@@ -139,10 +149,7 @@ pub const Module = struct {
139149 const builder = c.LLVMCreateBuilderInContext(context) orelse return error.OutOfMemory;
140150 errdefer c.LLVMDisposeBuilder(builder);
141151
142 const module_ptr = try allocator.create(Module);
143 errdefer allocator.destroy(module_ptr);
144
145 module_ptr.* = Module{
152 const module_ptr = try allocator.create(Module{
146153 .allocator = allocator,
147154 .name = name_buffer,
148155 .root_src_path = root_src_path,
......@@ -196,7 +203,8 @@ pub const Module = struct {
196203 .test_filters = [][]const u8{},
197204 .test_name_prefix = null,
198205 .emit_file_type = Emit.Binary,
199 };
206 });
207 errdefer allocator.destroy(module_ptr);
200208 return module_ptr;
201209 }
202210
......@@ -279,13 +287,12 @@ pub const Module = struct {
279287 }
280288 }
281289
282 const link_lib = try self.allocator.create(LinkLib);
283 link_lib.* = LinkLib{
290 const link_lib = try self.allocator.create(LinkLib{
284291 .name = name,
285292 .path = null,
286293 .provided_explicitly = provided_explicitly,
287294 .symbols = ArrayList([]u8).init(self.allocator),
288 };
295 });
289296 try self.link_libs_list.append(link_lib);
290297 if (is_libc) {
291298 self.libc_link_lib = link_lib;
std/atomic/queue.zig+4-2
......@@ -114,8 +114,10 @@ fn startPuts(ctx: *Context) u8 {
114114 while (put_count != 0) : (put_count -= 1) {
115115 std.os.time.sleep(0, 1); // let the os scheduler be our fuzz
116116 const x = @bitCast(i32, r.random.scalar(u32));
117 const node = ctx.allocator.create(Queue(i32).Node) catch unreachable;
118 node.data = x;
117 const node = ctx.allocator.create(Queue(i32).Node{
118 .next = undefined,
119 .data = x,
120 }) catch unreachable;
119121 ctx.queue.put(node);
120122 _ = @atomicRmw(isize, &ctx.put_sum, builtin.AtomicRmwOp.Add, x, AtomicOrder.SeqCst);
121123 }
std/atomic/stack.zig+4-2
......@@ -117,8 +117,10 @@ fn startPuts(ctx: *Context) u8 {
117117 while (put_count != 0) : (put_count -= 1) {
118118 std.os.time.sleep(0, 1); // let the os scheduler be our fuzz
119119 const x = @bitCast(i32, r.random.scalar(u32));
120 const node = ctx.allocator.create(Stack(i32).Node) catch unreachable;
121 node.data = x;
120 const node = ctx.allocator.create(Stack(i32).Node{
121 .next = undefined,
122 .data = x,
123 }) catch unreachable;
122124 ctx.stack.push(node);
123125 _ = @atomicRmw(isize, &ctx.put_sum, builtin.AtomicRmwOp.Add, x, AtomicOrder.SeqCst);
124126 }
std/build.zig+20-35
......@@ -158,8 +158,7 @@ pub const Builder = struct {
158158 }
159159
160160 pub fn addTest(self: *Builder, root_src: []const u8) *TestStep {
161 const test_step = self.allocator.create(TestStep) catch unreachable;
162 test_step.* = TestStep.init(self, root_src);
161 const test_step = self.allocator.create(TestStep.init(self, root_src)) catch unreachable;
163162 return test_step;
164163 }
165164
......@@ -191,21 +190,18 @@ pub const Builder = struct {
191190 }
192191
193192 pub fn addWriteFile(self: *Builder, file_path: []const u8, data: []const u8) *WriteFileStep {
194 const write_file_step = self.allocator.create(WriteFileStep) catch unreachable;
195 write_file_step.* = WriteFileStep.init(self, file_path, data);
193 const write_file_step = self.allocator.create(WriteFileStep.init(self, file_path, data)) catch unreachable;
196194 return write_file_step;
197195 }
198196
199197 pub fn addLog(self: *Builder, comptime format: []const u8, args: ...) *LogStep {
200198 const data = self.fmt(format, args);
201 const log_step = self.allocator.create(LogStep) catch unreachable;
202 log_step.* = LogStep.init(self, data);
199 const log_step = self.allocator.create(LogStep.init(self, data)) catch unreachable;
203200 return log_step;
204201 }
205202
206203 pub fn addRemoveDirTree(self: *Builder, dir_path: []const u8) *RemoveDirStep {
207 const remove_dir_step = self.allocator.create(RemoveDirStep) catch unreachable;
208 remove_dir_step.* = RemoveDirStep.init(self, dir_path);
204 const remove_dir_step = self.allocator.create(RemoveDirStep.init(self, dir_path)) catch unreachable;
209205 return remove_dir_step;
210206 }
211207
......@@ -404,11 +400,10 @@ pub const Builder = struct {
404400 }
405401
406402 pub fn step(self: *Builder, name: []const u8, description: []const u8) *Step {
407 const step_info = self.allocator.create(TopLevelStep) catch unreachable;
408 step_info.* = TopLevelStep{
403 const step_info = self.allocator.create(TopLevelStep{
409404 .step = Step.initNoOp(name, self.allocator),
410405 .description = description,
411 };
406 }) catch unreachable;
412407 self.top_level_steps.append(step_info) catch unreachable;
413408 return &step_info.step;
414409 }
......@@ -598,8 +593,7 @@ pub const Builder = struct {
598593 const full_dest_path = os.path.resolve(self.allocator, self.prefix, dest_rel_path) catch unreachable;
599594 self.pushInstalledFile(full_dest_path);
600595
601 const install_step = self.allocator.create(InstallFileStep) catch unreachable;
602 install_step.* = InstallFileStep.init(self, src_path, full_dest_path);
596 const install_step = self.allocator.create(InstallFileStep.init(self, src_path, full_dest_path)) catch unreachable;
603597 return install_step;
604598 }
605599
......@@ -837,51 +831,43 @@ pub const LibExeObjStep = struct {
837831 };
838832
839833 pub fn createSharedLibrary(builder: *Builder, name: []const u8, root_src: ?[]const u8, ver: *const Version) *LibExeObjStep {
840 const self = builder.allocator.create(LibExeObjStep) catch unreachable;
841 self.* = initExtraArgs(builder, name, root_src, Kind.Lib, false, ver);
834 const self = builder.allocator.create(initExtraArgs(builder, name, root_src, Kind.Lib, false, ver)) catch unreachable;
842835 return self;
843836 }
844837
845838 pub fn createCSharedLibrary(builder: *Builder, name: []const u8, version: *const Version) *LibExeObjStep {
846 const self = builder.allocator.create(LibExeObjStep) catch unreachable;
847 self.* = initC(builder, name, Kind.Lib, version, false);
839 const self = builder.allocator.create(initC(builder, name, Kind.Lib, version, false)) catch unreachable;
848840 return self;
849841 }
850842
851843 pub fn createStaticLibrary(builder: *Builder, name: []const u8, root_src: ?[]const u8) *LibExeObjStep {
852 const self = builder.allocator.create(LibExeObjStep) catch unreachable;
853 self.* = initExtraArgs(builder, name, root_src, Kind.Lib, true, builder.version(0, 0, 0));
844 const self = builder.allocator.create(initExtraArgs(builder, name, root_src, Kind.Lib, true, builder.version(0, 0, 0))) catch unreachable;
854845 return self;
855846 }
856847
857848 pub fn createCStaticLibrary(builder: *Builder, name: []const u8) *LibExeObjStep {
858 const self = builder.allocator.create(LibExeObjStep) catch unreachable;
859 self.* = initC(builder, name, Kind.Lib, builder.version(0, 0, 0), true);
849 const self = builder.allocator.create(initC(builder, name, Kind.Lib, builder.version(0, 0, 0), true)) catch unreachable;
860850 return self;
861851 }
862852
863853 pub fn createObject(builder: *Builder, name: []const u8, root_src: []const u8) *LibExeObjStep {
864 const self = builder.allocator.create(LibExeObjStep) catch unreachable;
865 self.* = initExtraArgs(builder, name, root_src, Kind.Obj, false, builder.version(0, 0, 0));
854 const self = builder.allocator.create(initExtraArgs(builder, name, root_src, Kind.Obj, false, builder.version(0, 0, 0))) catch unreachable;
866855 return self;
867856 }
868857
869858 pub fn createCObject(builder: *Builder, name: []const u8, src: []const u8) *LibExeObjStep {
870 const self = builder.allocator.create(LibExeObjStep) catch unreachable;
871 self.* = initC(builder, name, Kind.Obj, builder.version(0, 0, 0), false);
859 const self = builder.allocator.create(initC(builder, name, Kind.Obj, builder.version(0, 0, 0), false)) catch unreachable;
872860 self.object_src = src;
873861 return self;
874862 }
875863
876864 pub fn createExecutable(builder: *Builder, name: []const u8, root_src: ?[]const u8) *LibExeObjStep {
877 const self = builder.allocator.create(LibExeObjStep) catch unreachable;
878 self.* = initExtraArgs(builder, name, root_src, Kind.Exe, false, builder.version(0, 0, 0));
865 const self = builder.allocator.create(initExtraArgs(builder, name, root_src, Kind.Exe, false, builder.version(0, 0, 0))) catch unreachable;
879866 return self;
880867 }
881868
882869 pub fn createCExecutable(builder: *Builder, name: []const u8) *LibExeObjStep {
883 const self = builder.allocator.create(LibExeObjStep) catch unreachable;
884 self.* = initC(builder, name, Kind.Exe, builder.version(0, 0, 0), false);
870 const self = builder.allocator.create(initC(builder, name, Kind.Exe, builder.version(0, 0, 0), false)) catch unreachable;
885871 return self;
886872 }
887873
......@@ -1748,14 +1734,14 @@ pub const CommandStep = struct {
17481734
17491735 /// ::argv is copied.
17501736 pub fn create(builder: *Builder, cwd: ?[]const u8, env_map: *const BufMap, argv: []const []const u8) *CommandStep {
1751 const self = builder.allocator.create(CommandStep) catch unreachable;
1752 self.* = CommandStep{
1737 const self = builder.allocator.create(CommandStep{
17531738 .builder = builder,
17541739 .step = Step.init(argv[0], builder.allocator, make),
17551740 .argv = builder.allocator.alloc([]u8, argv.len) catch unreachable,
17561741 .cwd = cwd,
17571742 .env_map = env_map,
1758 };
1743 }) catch unreachable;
1744
17591745 mem.copy([]const u8, self.argv, argv);
17601746 self.step.name = self.argv[0];
17611747 return self;
......@@ -1778,18 +1764,17 @@ const InstallArtifactStep = struct {
17781764 const Self = this;
17791765
17801766 pub fn create(builder: *Builder, artifact: *LibExeObjStep) *Self {
1781 const self = builder.allocator.create(Self) catch unreachable;
17821767 const dest_dir = switch (artifact.kind) {
17831768 LibExeObjStep.Kind.Obj => unreachable,
17841769 LibExeObjStep.Kind.Exe => builder.exe_dir,
17851770 LibExeObjStep.Kind.Lib => builder.lib_dir,
17861771 };
1787 self.* = Self{
1772 const self = builder.allocator.create(Self{
17881773 .builder = builder,
17891774 .step = Step.init(builder.fmt("install {}", artifact.step.name), builder.allocator, make),
17901775 .artifact = artifact,
17911776 .dest_file = os.path.join(builder.allocator, dest_dir, artifact.out_filename) catch unreachable,
1792 };
1777 }) catch unreachable;
17931778 self.step.dependOn(&artifact.step);
17941779 builder.pushInstalledFile(self.dest_file);
17951780 if (self.artifact.kind == LibExeObjStep.Kind.Lib and !self.artifact.static) {
std/debug/index.zig+5-10
......@@ -249,9 +249,7 @@ fn printSourceAtAddress(debug_info: *ElfStackTrace, out_stream: var, address: us
249249pub fn openSelfDebugInfo(allocator: *mem.Allocator) !*ElfStackTrace {
250250 switch (builtin.object_format) {
251251 builtin.ObjectFormat.elf => {
252 const st = try allocator.create(ElfStackTrace);
253 errdefer allocator.destroy(st);
254 st.* = ElfStackTrace{
252 const st = try allocator.create(ElfStackTrace{
255253 .self_exe_file = undefined,
256254 .elf = undefined,
257255 .debug_info = undefined,
......@@ -261,7 +259,8 @@ pub fn openSelfDebugInfo(allocator: *mem.Allocator) !*ElfStackTrace {
261259 .debug_ranges = null,
262260 .abbrev_table_list = ArrayList(AbbrevTableHeader).init(allocator),
263261 .compile_unit_list = ArrayList(CompileUnit).init(allocator),
264 };
262 });
263 errdefer allocator.destroy(st);
265264 st.self_exe_file = try os.openSelfExe();
266265 errdefer st.self_exe_file.close();
267266
......@@ -280,11 +279,8 @@ pub fn openSelfDebugInfo(allocator: *mem.Allocator) !*ElfStackTrace {
280279 var exe_file = try os.openSelfExe();
281280 defer exe_file.close();
282281
283 const st = try allocator.create(ElfStackTrace);
282 const st = try allocator.create(ElfStackTrace{ .symbol_table = try macho.loadSymbols(allocator, &io.FileInStream.init(&exe_file)) });
284283 errdefer allocator.destroy(st);
285
286 st.* = ElfStackTrace{ .symbol_table = try macho.loadSymbols(allocator, &io.FileInStream.init(&exe_file)) };
287
288284 return st;
289285 },
290286 builtin.ObjectFormat.coff => {
......@@ -974,8 +970,7 @@ fn scanAllCompileUnits(st: *ElfStackTrace) !void {
974970
975971 try st.self_exe_file.seekTo(compile_unit_pos);
976972
977 const compile_unit_die = try st.allocator().create(Die);
978 compile_unit_die.* = try parseDie(st, abbrev_table, is_64);
973 const compile_unit_die = try st.allocator().create(try parseDie(st, abbrev_table, is_64));
979974
980975 if (compile_unit_die.tag_id != DW.TAG_compile_unit) return error.InvalidDebugInfo;
981976
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);
411 item.*.* = @intCast(i32, i);
410 item.* = try allocator.create(@intCast(i32, i));
412411 }
413412
414413 for (slice) |item, i| {
std/io.zig+3-5
......@@ -414,14 +414,12 @@ pub const BufferedAtomicFile = struct {
414414
415415 pub fn create(allocator: *mem.Allocator, dest_path: []const u8) !*BufferedAtomicFile {
416416 // TODO with well defined copy elision we don't need this allocation
417 var self = try allocator.create(BufferedAtomicFile);
418 errdefer allocator.destroy(self);
419
420 self.* = BufferedAtomicFile{
417 var self = try allocator.create(BufferedAtomicFile{
421418 .atomic_file = undefined,
422419 .file_stream = undefined,
423420 .buffered_stream = undefined,
424 };
421 });
422 errdefer allocator.destroy(self);
425423
426424 self.atomic_file = try os.AtomicFile.init(allocator, dest_path, os.default_file_mode);
427425 errdefer self.atomic_file.deinit();
std/linked_list.zig+1-1
......@@ -193,7 +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);
196 return allocator.create(Node(undefined));
197197 }
198198
199199 /// Deallocate a node.
std/mem.zig+3-11
......@@ -31,16 +31,8 @@ pub const Allocator = struct {
3131 /// Guaranteed: `old_mem.len` is the same as what was returned from `allocFn` or `reallocFn`
3232 freeFn: fn (self: *Allocator, old_mem: []u8) void,
3333
34 /// Call destroy with the result
35 pub fn create(self: *Allocator, comptime T: type) !*T {
36 if (@sizeOf(T) == 0) return *{};
37 const slice = try self.alloc(T, 1);
38 return &slice[0];
39 }
40
41 /// Call destroy with the result
42 /// TODO once #733 is solved, this will replace create
43 pub fn construct(self: *Allocator, init: var) Error!*@typeOf(init) {
34 /// Call `destroy` with the result
35 pub fn create(self: *Allocator, init: var) Error!*@typeOf(init) {
4436 const T = @typeOf(init);
4537 if (@sizeOf(T) == 0) return &{};
4638 const slice = try self.alloc(T, 1);
......@@ -49,7 +41,7 @@ pub const Allocator = struct {
4941 return ptr;
5042 }
5143
52 /// `ptr` should be the return value of `construct` or `create`
44 /// `ptr` should be the return value of `create`
5345 pub fn destroy(self: *Allocator, ptr: var) void {
5446 const non_const_ptr = @intToPtr([*]u8, @ptrToInt(ptr));
5547 self.freeFn(self, non_const_ptr[0..@sizeOf(@typeOf(ptr).Child)]);
std/os/child_process.zig+3-6
......@@ -85,10 +85,7 @@ pub const ChildProcess = struct {
8585 /// First argument in argv is the executable.
8686 /// On success must call deinit.
8787 pub fn init(argv: []const []const u8, allocator: *mem.Allocator) !*ChildProcess {
88 const child = try allocator.create(ChildProcess);
89 errdefer allocator.destroy(child);
90
91 child.* = ChildProcess{
88 const child = try allocator.create(ChildProcess{
9289 .allocator = allocator,
9390 .argv = argv,
9491 .pid = undefined,
......@@ -109,8 +106,8 @@ pub const ChildProcess = struct {
109106 .stdin_behavior = StdIo.Inherit,
110107 .stdout_behavior = StdIo.Inherit,
111108 .stderr_behavior = StdIo.Inherit,
112 };
113
109 });
110 errdefer allocator.destroy(child);
114111 return child;
115112 }
116113
std/os/index.zig+11-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,
......@@ -2582,10 +2582,16 @@ pub fn spawnThread(context: var, comptime startFn: var) SpawnThreadError!*Thread
25822582 const bytes_ptr = windows.HeapAlloc(heap_handle, 0, byte_count) orelse return SpawnThreadError.OutOfMemory;
25832583 errdefer assert(windows.HeapFree(heap_handle, 0, bytes_ptr) != 0);
25842584 const bytes = @ptrCast([*]u8, bytes_ptr)[0..byte_count];
2585 const outer_context = std.heap.FixedBufferAllocator.init(bytes).allocator.create(WinThread.OuterContext) catch unreachable;
2586 outer_context.inner = context;
2587 outer_context.thread.data.heap_handle = heap_handle;
2588 outer_context.thread.data.alloc_start = bytes_ptr;
2585 const outer_context = std.heap.FixedBufferAllocator.init(bytes).allocator.create(WinThread.OuterContext{
2586 .thread = Thread{
2587 .data = Thread.Data{
2588 .heap_handle = heap_handle,
2589 .alloc_start = bytes_ptr,
2590 .handle = undefined,
2591 },
2592 },
2593 .inner = context,
2594 }) catch unreachable;
25892595
25902596 const parameter = if (@sizeOf(Context) == 0) null else @ptrCast(*c_void, &outer_context.inner);
25912597 outer_context.thread.data.handle = windows.CreateThread(null, default_stack_size, WinThread.threadMain, parameter, 0, null) orelse {
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 });
test/cases/null.zig+1-1
......@@ -146,7 +146,7 @@ test "null with default unwrap" {
146146
147147test "optional types" {
148148 comptime {
149 const opt_type_struct = StructWithOptionalType { .t=u8, };
149 const opt_type_struct = StructWithOptionalType{ .t = u8 };
150150 assert(opt_type_struct.t != null and opt_type_struct.t.? == u8);
151151 }
152152}
test/tests.zig+37-45
......@@ -48,13 +48,12 @@ const test_targets = []TestTarget{
4848const max_stdout_size = 1 * 1024 * 1024; // 1 MB
4949
5050pub fn addCompareOutputTests(b: *build.Builder, test_filter: ?[]const u8) *build.Step {
51 const cases = b.allocator.create(CompareOutputContext) catch unreachable;
52 cases.* = CompareOutputContext{
51 const cases = b.allocator.create(CompareOutputContext{
5352 .b = b,
5453 .step = b.step("test-compare-output", "Run the compare output tests"),
5554 .test_index = 0,
5655 .test_filter = test_filter,
57 };
56 }) catch unreachable;
5857
5958 compare_output.addCases(cases);
6059
......@@ -62,13 +61,12 @@ pub fn addCompareOutputTests(b: *build.Builder, test_filter: ?[]const u8) *build
6261}
6362
6463pub fn addRuntimeSafetyTests(b: *build.Builder, test_filter: ?[]const u8) *build.Step {
65 const cases = b.allocator.create(CompareOutputContext) catch unreachable;
66 cases.* = CompareOutputContext{
64 const cases = b.allocator.create(CompareOutputContext{
6765 .b = b,
6866 .step = b.step("test-runtime-safety", "Run the runtime safety tests"),
6967 .test_index = 0,
7068 .test_filter = test_filter,
71 };
69 }) catch unreachable;
7270
7371 runtime_safety.addCases(cases);
7472
......@@ -76,13 +74,12 @@ pub fn addRuntimeSafetyTests(b: *build.Builder, test_filter: ?[]const u8) *build
7674}
7775
7876pub fn addCompileErrorTests(b: *build.Builder, test_filter: ?[]const u8) *build.Step {
79 const cases = b.allocator.create(CompileErrorContext) catch unreachable;
80 cases.* = CompileErrorContext{
77 const cases = b.allocator.create(CompileErrorContext{
8178 .b = b,
8279 .step = b.step("test-compile-errors", "Run the compile error tests"),
8380 .test_index = 0,
8481 .test_filter = test_filter,
85 };
82 }) catch unreachable;
8683
8784 compile_errors.addCases(cases);
8885
......@@ -90,13 +87,12 @@ pub fn addCompileErrorTests(b: *build.Builder, test_filter: ?[]const u8) *build.
9087}
9188
9289pub fn addBuildExampleTests(b: *build.Builder, test_filter: ?[]const u8) *build.Step {
93 const cases = b.allocator.create(BuildExamplesContext) catch unreachable;
94 cases.* = BuildExamplesContext{
90 const cases = b.allocator.create(BuildExamplesContext{
9591 .b = b,
9692 .step = b.step("test-build-examples", "Build the examples"),
9793 .test_index = 0,
9894 .test_filter = test_filter,
99 };
95 }) catch unreachable;
10096
10197 build_examples.addCases(cases);
10298
......@@ -104,13 +100,12 @@ pub fn addBuildExampleTests(b: *build.Builder, test_filter: ?[]const u8) *build.
104100}
105101
106102pub fn addAssembleAndLinkTests(b: *build.Builder, test_filter: ?[]const u8) *build.Step {
107 const cases = b.allocator.create(CompareOutputContext) catch unreachable;
108 cases.* = CompareOutputContext{
103 const cases = b.allocator.create(CompareOutputContext{
109104 .b = b,
110105 .step = b.step("test-asm-link", "Run the assemble and link tests"),
111106 .test_index = 0,
112107 .test_filter = test_filter,
113 };
108 }) catch unreachable;
114109
115110 assemble_and_link.addCases(cases);
116111
......@@ -118,13 +113,12 @@ pub fn addAssembleAndLinkTests(b: *build.Builder, test_filter: ?[]const u8) *bui
118113}
119114
120115pub fn addTranslateCTests(b: *build.Builder, test_filter: ?[]const u8) *build.Step {
121 const cases = b.allocator.create(TranslateCContext) catch unreachable;
122 cases.* = TranslateCContext{
116 const cases = b.allocator.create(TranslateCContext{
123117 .b = b,
124118 .step = b.step("test-translate-c", "Run the C transation tests"),
125119 .test_index = 0,
126120 .test_filter = test_filter,
127 };
121 }) catch unreachable;
128122
129123 translate_c.addCases(cases);
130124
......@@ -132,13 +126,12 @@ pub fn addTranslateCTests(b: *build.Builder, test_filter: ?[]const u8) *build.St
132126}
133127
134128pub fn addGenHTests(b: *build.Builder, test_filter: ?[]const u8) *build.Step {
135 const cases = b.allocator.create(GenHContext) catch unreachable;
136 cases.* = GenHContext{
129 const cases = b.allocator.create(GenHContext{
137130 .b = b,
138131 .step = b.step("test-gen-h", "Run the C header file generation tests"),
139132 .test_index = 0,
140133 .test_filter = test_filter,
141 };
134 }) catch unreachable;
142135
143136 gen_h.addCases(cases);
144137
......@@ -240,8 +233,7 @@ pub const CompareOutputContext = struct {
240233
241234 pub fn create(context: *CompareOutputContext, exe_path: []const u8, name: []const u8, expected_output: []const u8, cli_args: []const []const u8) *RunCompareOutputStep {
242235 const allocator = context.b.allocator;
243 const ptr = allocator.create(RunCompareOutputStep) catch unreachable;
244 ptr.* = RunCompareOutputStep{
236 const ptr = allocator.create(RunCompareOutputStep{
245237 .context = context,
246238 .exe_path = exe_path,
247239 .name = name,
......@@ -249,7 +241,7 @@ pub const CompareOutputContext = struct {
249241 .test_index = context.test_index,
250242 .step = build.Step.init("RunCompareOutput", allocator, make),
251243 .cli_args = cli_args,
252 };
244 }) catch unreachable;
253245 context.test_index += 1;
254246 return ptr;
255247 }
......@@ -328,14 +320,14 @@ pub const CompareOutputContext = struct {
328320
329321 pub fn create(context: *CompareOutputContext, exe_path: []const u8, name: []const u8) *RuntimeSafetyRunStep {
330322 const allocator = context.b.allocator;
331 const ptr = allocator.create(RuntimeSafetyRunStep) catch unreachable;
332 ptr.* = RuntimeSafetyRunStep{
323 const ptr = allocator.create(RuntimeSafetyRunStep{
333324 .context = context,
334325 .exe_path = exe_path,
335326 .name = name,
336327 .test_index = context.test_index,
337328 .step = build.Step.init("RuntimeSafetyRun", allocator, make),
338 };
329 }) catch unreachable;
330
339331 context.test_index += 1;
340332 return ptr;
341333 }
......@@ -543,15 +535,15 @@ pub const CompileErrorContext = struct {
543535
544536 pub fn create(context: *CompileErrorContext, name: []const u8, case: *const TestCase, build_mode: Mode) *CompileCmpOutputStep {
545537 const allocator = context.b.allocator;
546 const ptr = allocator.create(CompileCmpOutputStep) catch unreachable;
547 ptr.* = CompileCmpOutputStep{
538 const ptr = allocator.create(CompileCmpOutputStep{
548539 .step = build.Step.init("CompileCmpOutput", allocator, make),
549540 .context = context,
550541 .name = name,
551542 .test_index = context.test_index,
552543 .case = case,
553544 .build_mode = build_mode,
554 };
545 }) catch unreachable;
546
555547 context.test_index += 1;
556548 return ptr;
557549 }
......@@ -662,14 +654,14 @@ pub const CompileErrorContext = struct {
662654 }
663655
664656 pub fn create(self: *CompileErrorContext, name: []const u8, source: []const u8, expected_lines: ...) *TestCase {
665 const tc = self.b.allocator.create(TestCase) catch unreachable;
666 tc.* = TestCase{
657 const tc = self.b.allocator.create(TestCase{
667658 .name = name,
668659 .sources = ArrayList(TestCase.SourceFile).init(self.b.allocator),
669660 .expected_errors = ArrayList([]const u8).init(self.b.allocator),
670661 .link_libc = false,
671662 .is_exe = false,
672 };
663 }) catch unreachable;
664
673665 tc.addSourceFile(".tmp_source.zig", source);
674666 comptime var arg_i = 0;
675667 inline while (arg_i < expected_lines.len) : (arg_i += 1) {
......@@ -829,14 +821,14 @@ pub const TranslateCContext = struct {
829821
830822 pub fn create(context: *TranslateCContext, name: []const u8, case: *const TestCase) *TranslateCCmpOutputStep {
831823 const allocator = context.b.allocator;
832 const ptr = allocator.create(TranslateCCmpOutputStep) catch unreachable;
833 ptr.* = TranslateCCmpOutputStep{
824 const ptr = allocator.create(TranslateCCmpOutputStep{
834825 .step = build.Step.init("ParseCCmpOutput", allocator, make),
835826 .context = context,
836827 .name = name,
837828 .test_index = context.test_index,
838829 .case = case,
839 };
830 }) catch unreachable;
831
840832 context.test_index += 1;
841833 return ptr;
842834 }
......@@ -936,13 +928,13 @@ pub const TranslateCContext = struct {
936928 }
937929
938930 pub fn create(self: *TranslateCContext, allow_warnings: bool, filename: []const u8, name: []const u8, source: []const u8, expected_lines: ...) *TestCase {
939 const tc = self.b.allocator.create(TestCase) catch unreachable;
940 tc.* = TestCase{
931 const tc = self.b.allocator.create(TestCase{
941932 .name = name,
942933 .sources = ArrayList(TestCase.SourceFile).init(self.b.allocator),
943934 .expected_lines = ArrayList([]const u8).init(self.b.allocator),
944935 .allow_warnings = allow_warnings,
945 };
936 }) catch unreachable;
937
946938 tc.addSourceFile(filename, source);
947939 comptime var arg_i = 0;
948940 inline while (arg_i < expected_lines.len) : (arg_i += 1) {
......@@ -1023,15 +1015,15 @@ pub const GenHContext = struct {
10231015
10241016 pub fn create(context: *GenHContext, h_path: []const u8, name: []const u8, case: *const TestCase) *GenHCmpOutputStep {
10251017 const allocator = context.b.allocator;
1026 const ptr = allocator.create(GenHCmpOutputStep) catch unreachable;
1027 ptr.* = GenHCmpOutputStep{
1018 const ptr = allocator.create(GenHCmpOutputStep{
10281019 .step = build.Step.init("ParseCCmpOutput", allocator, make),
10291020 .context = context,
10301021 .h_path = h_path,
10311022 .name = name,
10321023 .test_index = context.test_index,
10331024 .case = case,
1034 };
1025 }) catch unreachable;
1026
10351027 context.test_index += 1;
10361028 return ptr;
10371029 }
......@@ -1070,12 +1062,12 @@ pub const GenHContext = struct {
10701062 }
10711063
10721064 pub fn create(self: *GenHContext, filename: []const u8, name: []const u8, source: []const u8, expected_lines: ...) *TestCase {
1073 const tc = self.b.allocator.create(TestCase) catch unreachable;
1074 tc.* = TestCase{
1065 const tc = self.b.allocator.create(TestCase{
10751066 .name = name,
10761067 .sources = ArrayList(TestCase.SourceFile).init(self.b.allocator),
10771068 .expected_lines = ArrayList([]const u8).init(self.b.allocator),
1078 };
1069 }) catch unreachable;
1070
10791071 tc.addSourceFile(filename, source);
10801072 comptime var arg_i = 0;
10811073 inline while (arg_i < expected_lines.len) : (arg_i += 1) {