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(...@@ -35,7 +35,7 @@ pub fn createFromParseError(
35 var out_stream = &std.io.BufferOutStream.init(&text_buf).stream;35 var out_stream = &std.io.BufferOutStream.init(&text_buf).stream;
36 try parse_error.render(&tree.tokens, out_stream);36 try parse_error.render(&tree.tokens, out_stream);
3737
38 const msg = try allocator.construct(Msg{38 const msg = try allocator.create(Msg{
39 .tree = tree,39 .tree = tree,
40 .path = path,40 .path = path,
41 .text = text_buf.toOwnedSlice(),41 .text = text_buf.toOwnedSlice(),
src-self-hosted/main.zig+1-1
...@@ -707,7 +707,7 @@ const Fmt = struct {...@@ -707,7 +707,7 @@ const Fmt = struct {
707707
708 // file_path must outlive Fmt708 // file_path must outlive Fmt
709 fn addToQueue(self: *Fmt, file_path: []const u8) !void {709 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{
711 .prev = undefined,711 .prev = undefined,
712 .next = undefined,712 .next = undefined,
713 .data = file_path,713 .data = file_path,
src-self-hosted/module.zig+21-14
...@@ -110,11 +110,12 @@ pub const Module = struct {...@@ -110,11 +110,12 @@ pub const Module = struct {
110 parent: ?*CliPkg,110 parent: ?*CliPkg,
111111
112 pub fn init(allocator: *mem.Allocator, name: []const u8, path: []const u8, parent: ?*CliPkg) !*CliPkg {112 pub fn init(allocator: *mem.Allocator, name: []const u8, path: []const u8, parent: ?*CliPkg) !*CliPkg {
113 var pkg = try allocator.create(CliPkg);113 var pkg = try allocator.create(CliPkg{
114 pkg.name = name;114 .name = name,
115 pkg.path = path;115 .path = path,
116 pkg.children = ArrayList(*CliPkg).init(allocator);116 .children = ArrayList(*CliPkg).init(allocator),
117 pkg.parent = parent;117 .parent = parent,
118 });
118 return pkg;119 return pkg;
119 }120 }
120121
...@@ -126,7 +127,16 @@ pub const Module = struct {...@@ -126,7 +127,16 @@ pub const Module = struct {
126 }127 }
127 };128 };
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 {
130 var name_buffer = try Buffer.init(allocator, name);140 var name_buffer = try Buffer.init(allocator, name);
131 errdefer name_buffer.deinit();141 errdefer name_buffer.deinit();
132142
...@@ -139,10 +149,7 @@ pub const Module = struct {...@@ -139,10 +149,7 @@ pub const Module = struct {
139 const builder = c.LLVMCreateBuilderInContext(context) orelse return error.OutOfMemory;149 const builder = c.LLVMCreateBuilderInContext(context) orelse return error.OutOfMemory;
140 errdefer c.LLVMDisposeBuilder(builder);150 errdefer c.LLVMDisposeBuilder(builder);
141151
142 const module_ptr = try allocator.create(Module);152 const module_ptr = try allocator.create(Module{
143 errdefer allocator.destroy(module_ptr);
144
145 module_ptr.* = Module{
146 .allocator = allocator,153 .allocator = allocator,
147 .name = name_buffer,154 .name = name_buffer,
148 .root_src_path = root_src_path,155 .root_src_path = root_src_path,
...@@ -196,7 +203,8 @@ pub const Module = struct {...@@ -196,7 +203,8 @@ pub const Module = struct {
196 .test_filters = [][]const u8{},203 .test_filters = [][]const u8{},
197 .test_name_prefix = null,204 .test_name_prefix = null,
198 .emit_file_type = Emit.Binary,205 .emit_file_type = Emit.Binary,
199 };206 });
207 errdefer allocator.destroy(module_ptr);
200 return module_ptr;208 return module_ptr;
201 }209 }
202210
...@@ -279,13 +287,12 @@ pub const Module = struct {...@@ -279,13 +287,12 @@ pub const Module = struct {
279 }287 }
280 }288 }
281289
282 const link_lib = try self.allocator.create(LinkLib);290 const link_lib = try self.allocator.create(LinkLib{
283 link_lib.* = LinkLib{
284 .name = name,291 .name = name,
285 .path = null,292 .path = null,
286 .provided_explicitly = provided_explicitly,293 .provided_explicitly = provided_explicitly,
287 .symbols = ArrayList([]u8).init(self.allocator),294 .symbols = ArrayList([]u8).init(self.allocator),
288 };295 });
289 try self.link_libs_list.append(link_lib);296 try self.link_libs_list.append(link_lib);
290 if (is_libc) {297 if (is_libc) {
291 self.libc_link_lib = link_lib;298 self.libc_link_lib = link_lib;
std/atomic/queue.zig+4-2
...@@ -114,8 +114,10 @@ fn startPuts(ctx: *Context) u8 {...@@ -114,8 +114,10 @@ fn startPuts(ctx: *Context) u8 {
114 while (put_count != 0) : (put_count -= 1) {114 while (put_count != 0) : (put_count -= 1) {
115 std.os.time.sleep(0, 1); // let the os scheduler be our fuzz115 std.os.time.sleep(0, 1); // let the os scheduler be our fuzz
116 const x = @bitCast(i32, r.random.scalar(u32));116 const x = @bitCast(i32, r.random.scalar(u32));
117 const node = ctx.allocator.create(Queue(i32).Node) catch unreachable;117 const node = ctx.allocator.create(Queue(i32).Node{
118 node.data = x;118 .next = undefined,
119 .data = x,
120 }) catch unreachable;
119 ctx.queue.put(node);121 ctx.queue.put(node);
120 _ = @atomicRmw(isize, &ctx.put_sum, builtin.AtomicRmwOp.Add, x, AtomicOrder.SeqCst);122 _ = @atomicRmw(isize, &ctx.put_sum, builtin.AtomicRmwOp.Add, x, AtomicOrder.SeqCst);
121 }123 }
std/atomic/stack.zig+4-2
...@@ -117,8 +117,10 @@ fn startPuts(ctx: *Context) u8 {...@@ -117,8 +117,10 @@ fn startPuts(ctx: *Context) u8 {
117 while (put_count != 0) : (put_count -= 1) {117 while (put_count != 0) : (put_count -= 1) {
118 std.os.time.sleep(0, 1); // let the os scheduler be our fuzz118 std.os.time.sleep(0, 1); // let the os scheduler be our fuzz
119 const x = @bitCast(i32, r.random.scalar(u32));119 const x = @bitCast(i32, r.random.scalar(u32));
120 const node = ctx.allocator.create(Stack(i32).Node) catch unreachable;120 const node = ctx.allocator.create(Stack(i32).Node{
121 node.data = x;121 .next = undefined,
122 .data = x,
123 }) catch unreachable;
122 ctx.stack.push(node);124 ctx.stack.push(node);
123 _ = @atomicRmw(isize, &ctx.put_sum, builtin.AtomicRmwOp.Add, x, AtomicOrder.SeqCst);125 _ = @atomicRmw(isize, &ctx.put_sum, builtin.AtomicRmwOp.Add, x, AtomicOrder.SeqCst);
124 }126 }
std/build.zig+20-35
...@@ -158,8 +158,7 @@ pub const Builder = struct {...@@ -158,8 +158,7 @@ pub const Builder = struct {
158 }158 }
159159
160 pub fn addTest(self: *Builder, root_src: []const u8) *TestStep {160 pub fn addTest(self: *Builder, root_src: []const u8) *TestStep {
161 const test_step = self.allocator.create(TestStep) catch unreachable;161 const test_step = self.allocator.create(TestStep.init(self, root_src)) catch unreachable;
162 test_step.* = TestStep.init(self, root_src);
163 return test_step;162 return test_step;
164 }163 }
165164
...@@ -191,21 +190,18 @@ pub const Builder = struct {...@@ -191,21 +190,18 @@ pub const Builder = struct {
191 }190 }
192191
193 pub fn addWriteFile(self: *Builder, file_path: []const u8, data: []const u8) *WriteFileStep {192 pub fn addWriteFile(self: *Builder, file_path: []const u8, data: []const u8) *WriteFileStep {
194 const write_file_step = self.allocator.create(WriteFileStep) catch unreachable;193 const write_file_step = self.allocator.create(WriteFileStep.init(self, file_path, data)) catch unreachable;
195 write_file_step.* = WriteFileStep.init(self, file_path, data);
196 return write_file_step;194 return write_file_step;
197 }195 }
198196
199 pub fn addLog(self: *Builder, comptime format: []const u8, args: ...) *LogStep {197 pub fn addLog(self: *Builder, comptime format: []const u8, args: ...) *LogStep {
200 const data = self.fmt(format, args);198 const data = self.fmt(format, args);
201 const log_step = self.allocator.create(LogStep) catch unreachable;199 const log_step = self.allocator.create(LogStep.init(self, data)) catch unreachable;
202 log_step.* = LogStep.init(self, data);
203 return log_step;200 return log_step;
204 }201 }
205202
206 pub fn addRemoveDirTree(self: *Builder, dir_path: []const u8) *RemoveDirStep {203 pub fn addRemoveDirTree(self: *Builder, dir_path: []const u8) *RemoveDirStep {
207 const remove_dir_step = self.allocator.create(RemoveDirStep) catch unreachable;204 const remove_dir_step = self.allocator.create(RemoveDirStep.init(self, dir_path)) catch unreachable;
208 remove_dir_step.* = RemoveDirStep.init(self, dir_path);
209 return remove_dir_step;205 return remove_dir_step;
210 }206 }
211207
...@@ -404,11 +400,10 @@ pub const Builder = struct {...@@ -404,11 +400,10 @@ pub const Builder = struct {
404 }400 }
405401
406 pub fn step(self: *Builder, name: []const u8, description: []const u8) *Step {402 pub fn step(self: *Builder, name: []const u8, description: []const u8) *Step {
407 const step_info = self.allocator.create(TopLevelStep) catch unreachable;403 const step_info = self.allocator.create(TopLevelStep{
408 step_info.* = TopLevelStep{
409 .step = Step.initNoOp(name, self.allocator),404 .step = Step.initNoOp(name, self.allocator),
410 .description = description,405 .description = description,
411 };406 }) catch unreachable;
412 self.top_level_steps.append(step_info) catch unreachable;407 self.top_level_steps.append(step_info) catch unreachable;
413 return &step_info.step;408 return &step_info.step;
414 }409 }
...@@ -598,8 +593,7 @@ pub const Builder = struct {...@@ -598,8 +593,7 @@ pub const Builder = struct {
598 const full_dest_path = os.path.resolve(self.allocator, self.prefix, dest_rel_path) catch unreachable;593 const full_dest_path = os.path.resolve(self.allocator, self.prefix, dest_rel_path) catch unreachable;
599 self.pushInstalledFile(full_dest_path);594 self.pushInstalledFile(full_dest_path);
600595
601 const install_step = self.allocator.create(InstallFileStep) catch unreachable;596 const install_step = self.allocator.create(InstallFileStep.init(self, src_path, full_dest_path)) catch unreachable;
602 install_step.* = InstallFileStep.init(self, src_path, full_dest_path);
603 return install_step;597 return install_step;
604 }598 }
605599
...@@ -837,51 +831,43 @@ pub const LibExeObjStep = struct {...@@ -837,51 +831,43 @@ pub const LibExeObjStep = struct {
837 };831 };
838832
839 pub fn createSharedLibrary(builder: *Builder, name: []const u8, root_src: ?[]const u8, ver: *const Version) *LibExeObjStep {833 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;834 const self = builder.allocator.create(initExtraArgs(builder, name, root_src, Kind.Lib, false, ver)) catch unreachable;
841 self.* = initExtraArgs(builder, name, root_src, Kind.Lib, false, ver);
842 return self;835 return self;
843 }836 }
844837
845 pub fn createCSharedLibrary(builder: *Builder, name: []const u8, version: *const Version) *LibExeObjStep {838 pub fn createCSharedLibrary(builder: *Builder, name: []const u8, version: *const Version) *LibExeObjStep {
846 const self = builder.allocator.create(LibExeObjStep) catch unreachable;839 const self = builder.allocator.create(initC(builder, name, Kind.Lib, version, false)) catch unreachable;
847 self.* = initC(builder, name, Kind.Lib, version, false);
848 return self;840 return self;
849 }841 }
850842
851 pub fn createStaticLibrary(builder: *Builder, name: []const u8, root_src: ?[]const u8) *LibExeObjStep {843 pub fn createStaticLibrary(builder: *Builder, name: []const u8, root_src: ?[]const u8) *LibExeObjStep {
852 const self = builder.allocator.create(LibExeObjStep) catch unreachable;844 const self = builder.allocator.create(initExtraArgs(builder, name, root_src, Kind.Lib, true, builder.version(0, 0, 0))) catch unreachable;
853 self.* = initExtraArgs(builder, name, root_src, Kind.Lib, true, builder.version(0, 0, 0));
854 return self;845 return self;
855 }846 }
856847
857 pub fn createCStaticLibrary(builder: *Builder, name: []const u8) *LibExeObjStep {848 pub fn createCStaticLibrary(builder: *Builder, name: []const u8) *LibExeObjStep {
858 const self = builder.allocator.create(LibExeObjStep) catch unreachable;849 const self = builder.allocator.create(initC(builder, name, Kind.Lib, builder.version(0, 0, 0), true)) catch unreachable;
859 self.* = initC(builder, name, Kind.Lib, builder.version(0, 0, 0), true);
860 return self;850 return self;
861 }851 }
862852
863 pub fn createObject(builder: *Builder, name: []const u8, root_src: []const u8) *LibExeObjStep {853 pub fn createObject(builder: *Builder, name: []const u8, root_src: []const u8) *LibExeObjStep {
864 const self = builder.allocator.create(LibExeObjStep) catch unreachable;854 const self = builder.allocator.create(initExtraArgs(builder, name, root_src, Kind.Obj, false, builder.version(0, 0, 0))) catch unreachable;
865 self.* = initExtraArgs(builder, name, root_src, Kind.Obj, false, builder.version(0, 0, 0));
866 return self;855 return self;
867 }856 }
868857
869 pub fn createCObject(builder: *Builder, name: []const u8, src: []const u8) *LibExeObjStep {858 pub fn createCObject(builder: *Builder, name: []const u8, src: []const u8) *LibExeObjStep {
870 const self = builder.allocator.create(LibExeObjStep) catch unreachable;859 const self = builder.allocator.create(initC(builder, name, Kind.Obj, builder.version(0, 0, 0), false)) catch unreachable;
871 self.* = initC(builder, name, Kind.Obj, builder.version(0, 0, 0), false);
872 self.object_src = src;860 self.object_src = src;
873 return self;861 return self;
874 }862 }
875863
876 pub fn createExecutable(builder: *Builder, name: []const u8, root_src: ?[]const u8) *LibExeObjStep {864 pub fn createExecutable(builder: *Builder, name: []const u8, root_src: ?[]const u8) *LibExeObjStep {
877 const self = builder.allocator.create(LibExeObjStep) catch unreachable;865 const self = builder.allocator.create(initExtraArgs(builder, name, root_src, Kind.Exe, false, builder.version(0, 0, 0))) catch unreachable;
878 self.* = initExtraArgs(builder, name, root_src, Kind.Exe, false, builder.version(0, 0, 0));
879 return self;866 return self;
880 }867 }
881868
882 pub fn createCExecutable(builder: *Builder, name: []const u8) *LibExeObjStep {869 pub fn createCExecutable(builder: *Builder, name: []const u8) *LibExeObjStep {
883 const self = builder.allocator.create(LibExeObjStep) catch unreachable;870 const self = builder.allocator.create(initC(builder, name, Kind.Exe, builder.version(0, 0, 0), false)) catch unreachable;
884 self.* = initC(builder, name, Kind.Exe, builder.version(0, 0, 0), false);
885 return self;871 return self;
886 }872 }
887873
...@@ -1748,14 +1734,14 @@ pub const CommandStep = struct {...@@ -1748,14 +1734,14 @@ pub const CommandStep = struct {
17481734
1749 /// ::argv is copied.1735 /// ::argv is copied.
1750 pub fn create(builder: *Builder, cwd: ?[]const u8, env_map: *const BufMap, argv: []const []const u8) *CommandStep {1736 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;1737 const self = builder.allocator.create(CommandStep{
1752 self.* = CommandStep{
1753 .builder = builder,1738 .builder = builder,
1754 .step = Step.init(argv[0], builder.allocator, make),1739 .step = Step.init(argv[0], builder.allocator, make),
1755 .argv = builder.allocator.alloc([]u8, argv.len) catch unreachable,1740 .argv = builder.allocator.alloc([]u8, argv.len) catch unreachable,
1756 .cwd = cwd,1741 .cwd = cwd,
1757 .env_map = env_map,1742 .env_map = env_map,
1758 };1743 }) catch unreachable;
1744
1759 mem.copy([]const u8, self.argv, argv);1745 mem.copy([]const u8, self.argv, argv);
1760 self.step.name = self.argv[0];1746 self.step.name = self.argv[0];
1761 return self;1747 return self;
...@@ -1778,18 +1764,17 @@ const InstallArtifactStep = struct {...@@ -1778,18 +1764,17 @@ const InstallArtifactStep = struct {
1778 const Self = this;1764 const Self = this;
17791765
1780 pub fn create(builder: *Builder, artifact: *LibExeObjStep) *Self {1766 pub fn create(builder: *Builder, artifact: *LibExeObjStep) *Self {
1781 const self = builder.allocator.create(Self) catch unreachable;
1782 const dest_dir = switch (artifact.kind) {1767 const dest_dir = switch (artifact.kind) {
1783 LibExeObjStep.Kind.Obj => unreachable,1768 LibExeObjStep.Kind.Obj => unreachable,
1784 LibExeObjStep.Kind.Exe => builder.exe_dir,1769 LibExeObjStep.Kind.Exe => builder.exe_dir,
1785 LibExeObjStep.Kind.Lib => builder.lib_dir,1770 LibExeObjStep.Kind.Lib => builder.lib_dir,
1786 };1771 };
1787 self.* = Self{1772 const self = builder.allocator.create(Self{
1788 .builder = builder,1773 .builder = builder,
1789 .step = Step.init(builder.fmt("install {}", artifact.step.name), builder.allocator, make),1774 .step = Step.init(builder.fmt("install {}", artifact.step.name), builder.allocator, make),
1790 .artifact = artifact,1775 .artifact = artifact,
1791 .dest_file = os.path.join(builder.allocator, dest_dir, artifact.out_filename) catch unreachable,1776 .dest_file = os.path.join(builder.allocator, dest_dir, artifact.out_filename) catch unreachable,
1792 };1777 }) catch unreachable;
1793 self.step.dependOn(&artifact.step);1778 self.step.dependOn(&artifact.step);
1794 builder.pushInstalledFile(self.dest_file);1779 builder.pushInstalledFile(self.dest_file);
1795 if (self.artifact.kind == LibExeObjStep.Kind.Lib and !self.artifact.static) {1780 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...@@ -249,9 +249,7 @@ fn printSourceAtAddress(debug_info: *ElfStackTrace, out_stream: var, address: us
249pub fn openSelfDebugInfo(allocator: *mem.Allocator) !*ElfStackTrace {249pub fn openSelfDebugInfo(allocator: *mem.Allocator) !*ElfStackTrace {
250 switch (builtin.object_format) {250 switch (builtin.object_format) {
251 builtin.ObjectFormat.elf => {251 builtin.ObjectFormat.elf => {
252 const st = try allocator.create(ElfStackTrace);252 const st = try allocator.create(ElfStackTrace{
253 errdefer allocator.destroy(st);
254 st.* = ElfStackTrace{
255 .self_exe_file = undefined,253 .self_exe_file = undefined,
256 .elf = undefined,254 .elf = undefined,
257 .debug_info = undefined,255 .debug_info = undefined,
...@@ -261,7 +259,8 @@ pub fn openSelfDebugInfo(allocator: *mem.Allocator) !*ElfStackTrace {...@@ -261,7 +259,8 @@ pub fn openSelfDebugInfo(allocator: *mem.Allocator) !*ElfStackTrace {
261 .debug_ranges = null,259 .debug_ranges = null,
262 .abbrev_table_list = ArrayList(AbbrevTableHeader).init(allocator),260 .abbrev_table_list = ArrayList(AbbrevTableHeader).init(allocator),
263 .compile_unit_list = ArrayList(CompileUnit).init(allocator),261 .compile_unit_list = ArrayList(CompileUnit).init(allocator),
264 };262 });
263 errdefer allocator.destroy(st);
265 st.self_exe_file = try os.openSelfExe();264 st.self_exe_file = try os.openSelfExe();
266 errdefer st.self_exe_file.close();265 errdefer st.self_exe_file.close();
267266
...@@ -280,11 +279,8 @@ pub fn openSelfDebugInfo(allocator: *mem.Allocator) !*ElfStackTrace {...@@ -280,11 +279,8 @@ pub fn openSelfDebugInfo(allocator: *mem.Allocator) !*ElfStackTrace {
280 var exe_file = try os.openSelfExe();279 var exe_file = try os.openSelfExe();
281 defer exe_file.close();280 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)) });
284 errdefer allocator.destroy(st);283 errdefer allocator.destroy(st);
285
286 st.* = ElfStackTrace{ .symbol_table = try macho.loadSymbols(allocator, &io.FileInStream.init(&exe_file)) };
287
288 return st;284 return st;
289 },285 },
290 builtin.ObjectFormat.coff => {286 builtin.ObjectFormat.coff => {
...@@ -974,8 +970,7 @@ fn scanAllCompileUnits(st: *ElfStackTrace) !void {...@@ -974,8 +970,7 @@ fn scanAllCompileUnits(st: *ElfStackTrace) !void {
974970
975 try st.self_exe_file.seekTo(compile_unit_pos);971 try st.self_exe_file.seekTo(compile_unit_pos);
976972
977 const compile_unit_die = try st.allocator().create(Die);973 const compile_unit_die = try st.allocator().create(try parseDie(st, abbrev_table, is_64));
978 compile_unit_die.* = try parseDie(st, abbrev_table, is_64);
979974
980 if (compile_unit_die.tag_id != DW.TAG_compile_unit) return error.InvalidDebugInfo;975 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 {...@@ -407,8 +407,7 @@ fn testAllocator(allocator: *mem.Allocator) !void {
407 var slice = try allocator.alloc(*i32, 100);407 var slice = try allocator.alloc(*i32, 100);
408408
409 for (slice) |*item, i| {409 for (slice) |*item, i| {
410 item.* = try allocator.create(i32);410 item.* = try allocator.create(@intCast(i32, i));
411 item.*.* = @intCast(i32, i);
412 }411 }
413412
414 for (slice) |item, i| {413 for (slice) |item, i| {
std/io.zig+3-5
...@@ -414,14 +414,12 @@ pub const BufferedAtomicFile = struct {...@@ -414,14 +414,12 @@ pub const BufferedAtomicFile = struct {
414414
415 pub fn create(allocator: *mem.Allocator, dest_path: []const u8) !*BufferedAtomicFile {415 pub fn create(allocator: *mem.Allocator, dest_path: []const u8) !*BufferedAtomicFile {
416 // TODO with well defined copy elision we don't need this allocation416 // TODO with well defined copy elision we don't need this allocation
417 var self = try allocator.create(BufferedAtomicFile);417 var self = try allocator.create(BufferedAtomicFile{
418 errdefer allocator.destroy(self);
419
420 self.* = BufferedAtomicFile{
421 .atomic_file = undefined,418 .atomic_file = undefined,
422 .file_stream = undefined,419 .file_stream = undefined,
423 .buffered_stream = undefined,420 .buffered_stream = undefined,
424 };421 });
422 errdefer allocator.destroy(self);
425423
426 self.atomic_file = try os.AtomicFile.init(allocator, dest_path, os.default_file_mode);424 self.atomic_file = try os.AtomicFile.init(allocator, dest_path, os.default_file_mode);
427 errdefer self.atomic_file.deinit();425 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...@@ -193,7 +193,7 @@ fn BaseLinkedList(comptime T: type, comptime ParentType: type, comptime field_na
193 /// A pointer to the new node.193 /// A pointer to the new node.
194 pub fn allocateNode(list: *Self, allocator: *Allocator) !*Node {194 pub fn allocateNode(list: *Self, allocator: *Allocator) !*Node {
195 comptime assert(!isIntrusive());195 comptime assert(!isIntrusive());
196 return allocator.create(Node);196 return allocator.create(Node(undefined));
197 }197 }
198198
199 /// Deallocate a node.199 /// Deallocate a node.
std/mem.zig+3-11
...@@ -31,16 +31,8 @@ pub const Allocator = struct {...@@ -31,16 +31,8 @@ pub const Allocator = struct {
31 /// Guaranteed: `old_mem.len` is the same as what was returned from `allocFn` or `reallocFn`31 /// Guaranteed: `old_mem.len` is the same as what was returned from `allocFn` or `reallocFn`
32 freeFn: fn (self: *Allocator, old_mem: []u8) void,32 freeFn: fn (self: *Allocator, old_mem: []u8) void,
3333
34 /// Call destroy with the result34 /// Call `destroy` with the result
35 pub fn create(self: *Allocator, comptime T: type) !*T {35 pub fn create(self: *Allocator, init: var) Error!*@typeOf(init) {
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) {
44 const T = @typeOf(init);36 const T = @typeOf(init);
45 if (@sizeOf(T) == 0) return &{};37 if (@sizeOf(T) == 0) return &{};
46 const slice = try self.alloc(T, 1);38 const slice = try self.alloc(T, 1);
...@@ -49,7 +41,7 @@ pub const Allocator = struct {...@@ -49,7 +41,7 @@ pub const Allocator = struct {
49 return ptr;41 return ptr;
50 }42 }
5143
52 /// `ptr` should be the return value of `construct` or `create`44 /// `ptr` should be the return value of `create`
53 pub fn destroy(self: *Allocator, ptr: var) void {45 pub fn destroy(self: *Allocator, ptr: var) void {
54 const non_const_ptr = @intToPtr([*]u8, @ptrToInt(ptr));46 const non_const_ptr = @intToPtr([*]u8, @ptrToInt(ptr));
55 self.freeFn(self, non_const_ptr[0..@sizeOf(@typeOf(ptr).Child)]);47 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 {...@@ -85,10 +85,7 @@ pub const ChildProcess = struct {
85 /// First argument in argv is the executable.85 /// First argument in argv is the executable.
86 /// On success must call deinit.86 /// On success must call deinit.
87 pub fn init(argv: []const []const u8, allocator: *mem.Allocator) !*ChildProcess {87 pub fn init(argv: []const []const u8, allocator: *mem.Allocator) !*ChildProcess {
88 const child = try allocator.create(ChildProcess);88 const child = try allocator.create(ChildProcess{
89 errdefer allocator.destroy(child);
90
91 child.* = ChildProcess{
92 .allocator = allocator,89 .allocator = allocator,
93 .argv = argv,90 .argv = argv,
94 .pid = undefined,91 .pid = undefined,
...@@ -109,8 +106,8 @@ pub const ChildProcess = struct {...@@ -109,8 +106,8 @@ pub const ChildProcess = struct {
109 .stdin_behavior = StdIo.Inherit,106 .stdin_behavior = StdIo.Inherit,
110 .stdout_behavior = StdIo.Inherit,107 .stdout_behavior = StdIo.Inherit,
111 .stderr_behavior = StdIo.Inherit,108 .stderr_behavior = StdIo.Inherit,
112 };109 });
113110 errdefer allocator.destroy(child);
114 return child;111 return child;
115 }112 }
116113
std/os/index.zig+11-5
...@@ -2468,7 +2468,7 @@ pub const Thread = struct {...@@ -2468,7 +2468,7 @@ pub const Thread = struct {
2468 data: Data,2468 data: Data,
24692469
2470 pub const use_pthreads = is_posix and builtin.link_libc;2470 pub const use_pthreads = is_posix and builtin.link_libc;
2471 const Data = if (use_pthreads)2471 pub const Data = if (use_pthreads)
2472 struct {2472 struct {
2473 handle: c.pthread_t,2473 handle: c.pthread_t,
2474 stack_addr: usize,2474 stack_addr: usize,
...@@ -2582,10 +2582,16 @@ pub fn spawnThread(context: var, comptime startFn: var) SpawnThreadError!*Thread...@@ -2582,10 +2582,16 @@ pub fn spawnThread(context: var, comptime startFn: var) SpawnThreadError!*Thread
2582 const bytes_ptr = windows.HeapAlloc(heap_handle, 0, byte_count) orelse return SpawnThreadError.OutOfMemory;2582 const bytes_ptr = windows.HeapAlloc(heap_handle, 0, byte_count) orelse return SpawnThreadError.OutOfMemory;
2583 errdefer assert(windows.HeapFree(heap_handle, 0, bytes_ptr) != 0);2583 errdefer assert(windows.HeapFree(heap_handle, 0, bytes_ptr) != 0);
2584 const bytes = @ptrCast([*]u8, bytes_ptr)[0..byte_count];2584 const bytes = @ptrCast([*]u8, bytes_ptr)[0..byte_count];
2585 const outer_context = std.heap.FixedBufferAllocator.init(bytes).allocator.create(WinThread.OuterContext) catch unreachable;2585 const outer_context = std.heap.FixedBufferAllocator.init(bytes).allocator.create(WinThread.OuterContext{
2586 outer_context.inner = context;2586 .thread = Thread{
2587 outer_context.thread.data.heap_handle = heap_handle;2587 .data = Thread.Data{
2588 outer_context.thread.data.alloc_start = bytes_ptr;2588 .heap_handle = heap_handle,
2589 .alloc_start = bytes_ptr,
2590 .handle = undefined,
2591 },
2592 },
2593 .inner = context,
2594 }) catch unreachable;
25892595
2590 const parameter = if (@sizeOf(Context) == 0) null else @ptrCast(*c_void, &outer_context.inner);2596 const parameter = if (@sizeOf(Context) == 0) null else @ptrCast(*c_void, &outer_context.inner);
2591 outer_context.thread.data.handle = windows.CreateThread(null, default_stack_size, WinThread.threadMain, parameter, 0, null) orelse {2597 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 {...@@ -17,7 +17,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
17 defer stack.deinit();17 defer stack.deinit();
1818
19 const arena = &tree_arena.allocator;19 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{
21 .base = ast.Node{ .id = ast.Node.Id.Root },21 .base = ast.Node{ .id = ast.Node.Id.Root },
22 .decls = ast.Node.Root.DeclList.init(arena),22 .decls = ast.Node.Root.DeclList.init(arena),
23 .doc_comments = null,23 .doc_comments = null,
...@@ -65,14 +65,14 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {...@@ -65,14 +65,14 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
65 Token.Id.Keyword_test => {65 Token.Id.Keyword_test => {
66 stack.append(State.TopLevel) catch unreachable;66 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{
69 .base = ast.Node{ .id = ast.Node.Id.Block },69 .base = ast.Node{ .id = ast.Node.Id.Block },
70 .label = null,70 .label = null,
71 .lbrace = undefined,71 .lbrace = undefined,
72 .statements = ast.Node.Block.StatementList.init(arena),72 .statements = ast.Node.Block.StatementList.init(arena),
73 .rbrace = undefined,73 .rbrace = undefined,
74 });74 });
75 const test_node = try arena.construct(ast.Node.TestDecl{75 const test_node = try arena.create(ast.Node.TestDecl{
76 .base = ast.Node{ .id = ast.Node.Id.TestDecl },76 .base = ast.Node{ .id = ast.Node.Id.TestDecl },
77 .doc_comments = comments,77 .doc_comments = comments,
78 .test_token = token_index,78 .test_token = token_index,
...@@ -109,14 +109,14 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {...@@ -109,14 +109,14 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
109 continue;109 continue;
110 },110 },
111 Token.Id.Keyword_comptime => {111 Token.Id.Keyword_comptime => {
112 const block = try arena.construct(ast.Node.Block{112 const block = try arena.create(ast.Node.Block{
113 .base = ast.Node{ .id = ast.Node.Id.Block },113 .base = ast.Node{ .id = ast.Node.Id.Block },
114 .label = null,114 .label = null,
115 .lbrace = undefined,115 .lbrace = undefined,
116 .statements = ast.Node.Block.StatementList.init(arena),116 .statements = ast.Node.Block.StatementList.init(arena),
117 .rbrace = undefined,117 .rbrace = undefined,
118 });118 });
119 const node = try arena.construct(ast.Node.Comptime{119 const node = try arena.create(ast.Node.Comptime{
120 .base = ast.Node{ .id = ast.Node.Id.Comptime },120 .base = ast.Node{ .id = ast.Node.Id.Comptime },
121 .comptime_token = token_index,121 .comptime_token = token_index,
122 .expr = &block.base,122 .expr = &block.base,
...@@ -225,7 +225,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {...@@ -225,7 +225,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
225 return tree;225 return tree;
226 }226 }
227227
228 const node = try arena.construct(ast.Node.Use{228 const node = try arena.create(ast.Node.Use{
229 .base = ast.Node{ .id = ast.Node.Id.Use },229 .base = ast.Node{ .id = ast.Node.Id.Use },
230 .use_token = token_index,230 .use_token = token_index,
231 .visib_token = ctx.visib_token,231 .visib_token = ctx.visib_token,
...@@ -266,7 +266,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {...@@ -266,7 +266,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
266 continue;266 continue;
267 },267 },
268 Token.Id.Keyword_fn, Token.Id.Keyword_nakedcc, Token.Id.Keyword_stdcallcc, Token.Id.Keyword_async => {268 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{
270 .base = ast.Node{ .id = ast.Node.Id.FnProto },270 .base = ast.Node{ .id = ast.Node.Id.FnProto },
271 .doc_comments = ctx.comments,271 .doc_comments = ctx.comments,
272 .visib_token = ctx.visib_token,272 .visib_token = ctx.visib_token,
...@@ -298,7 +298,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {...@@ -298,7 +298,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
298 continue;298 continue;
299 },299 },
300 Token.Id.Keyword_async => {300 Token.Id.Keyword_async => {
301 const async_node = try arena.construct(ast.Node.AsyncAttribute{301 const async_node = try arena.create(ast.Node.AsyncAttribute{
302 .base = ast.Node{ .id = ast.Node.Id.AsyncAttribute },302 .base = ast.Node{ .id = ast.Node.Id.AsyncAttribute },
303 .async_token = token_index,303 .async_token = token_index,
304 .allocator_type = null,304 .allocator_type = null,
...@@ -330,7 +330,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {...@@ -330,7 +330,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
330 },330 },
331 State.TopLevelExternOrField => |ctx| {331 State.TopLevelExternOrField => |ctx| {
332 if (eatToken(&tok_it, &tree, Token.Id.Identifier)) |identifier| {332 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{
334 .base = ast.Node{ .id = ast.Node.Id.StructField },334 .base = ast.Node{ .id = ast.Node.Id.StructField },
335 .doc_comments = ctx.comments,335 .doc_comments = ctx.comments,
336 .visib_token = ctx.visib_token,336 .visib_token = ctx.visib_token,
...@@ -375,7 +375,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {...@@ -375,7 +375,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
375 const token = nextToken(&tok_it, &tree);375 const token = nextToken(&tok_it, &tree);
376 const token_index = token.index;376 const token_index = token.index;
377 const token_ptr = token.ptr;377 const token_ptr = token.ptr;
378 const node = try arena.construct(ast.Node.ContainerDecl{378 const node = try arena.create(ast.Node.ContainerDecl{
379 .base = ast.Node{ .id = ast.Node.Id.ContainerDecl },379 .base = ast.Node{ .id = ast.Node.Id.ContainerDecl },
380 .layout_token = ctx.layout_token,380 .layout_token = ctx.layout_token,
381 .kind_token = switch (token_ptr.id) {381 .kind_token = switch (token_ptr.id) {
...@@ -448,7 +448,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {...@@ -448,7 +448,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
448 Token.Id.Identifier => {448 Token.Id.Identifier => {
449 switch (tree.tokens.at(container_decl.kind_token).id) {449 switch (tree.tokens.at(container_decl.kind_token).id) {
450 Token.Id.Keyword_struct => {450 Token.Id.Keyword_struct => {
451 const node = try arena.construct(ast.Node.StructField{451 const node = try arena.create(ast.Node.StructField{
452 .base = ast.Node{ .id = ast.Node.Id.StructField },452 .base = ast.Node{ .id = ast.Node.Id.StructField },
453 .doc_comments = comments,453 .doc_comments = comments,
454 .visib_token = null,454 .visib_token = null,
...@@ -464,7 +464,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {...@@ -464,7 +464,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
464 continue;464 continue;
465 },465 },
466 Token.Id.Keyword_union => {466 Token.Id.Keyword_union => {
467 const node = try arena.construct(ast.Node.UnionTag{467 const node = try arena.create(ast.Node.UnionTag{
468 .base = ast.Node{ .id = ast.Node.Id.UnionTag },468 .base = ast.Node{ .id = ast.Node.Id.UnionTag },
469 .name_token = token_index,469 .name_token = token_index,
470 .type_expr = null,470 .type_expr = null,
...@@ -480,7 +480,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {...@@ -480,7 +480,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
480 continue;480 continue;
481 },481 },
482 Token.Id.Keyword_enum => {482 Token.Id.Keyword_enum => {
483 const node = try arena.construct(ast.Node.EnumTag{483 const node = try arena.create(ast.Node.EnumTag{
484 .base = ast.Node{ .id = ast.Node.Id.EnumTag },484 .base = ast.Node{ .id = ast.Node.Id.EnumTag },
485 .name_token = token_index,485 .name_token = token_index,
486 .value = null,486 .value = null,
...@@ -562,7 +562,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {...@@ -562,7 +562,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
562 },562 },
563563
564 State.VarDecl => |ctx| {564 State.VarDecl => |ctx| {
565 const var_decl = try arena.construct(ast.Node.VarDecl{565 const var_decl = try arena.create(ast.Node.VarDecl{
566 .base = ast.Node{ .id = ast.Node.Id.VarDecl },566 .base = ast.Node{ .id = ast.Node.Id.VarDecl },
567 .doc_comments = ctx.comments,567 .doc_comments = ctx.comments,
568 .visib_token = ctx.visib_token,568 .visib_token = ctx.visib_token,
...@@ -660,7 +660,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {...@@ -660,7 +660,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
660 const token_ptr = token.ptr;660 const token_ptr = token.ptr;
661 switch (token_ptr.id) {661 switch (token_ptr.id) {
662 Token.Id.LBrace => {662 Token.Id.LBrace => {
663 const block = try arena.construct(ast.Node.Block{663 const block = try arena.create(ast.Node.Block{
664 .base = ast.Node{ .id = ast.Node.Id.Block },664 .base = ast.Node{ .id = ast.Node.Id.Block },
665 .label = null,665 .label = null,
666 .lbrace = token_index,666 .lbrace = token_index,
...@@ -712,7 +712,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {...@@ -712,7 +712,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
712 // TODO: this is a special case. Remove this when #760 is fixed712 // TODO: this is a special case. Remove this when #760 is fixed
713 if (token_ptr.id == Token.Id.Keyword_error) {713 if (token_ptr.id == Token.Id.Keyword_error) {
714 if (tok_it.peek().?.id == Token.Id.LBrace) {714 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{
716 .base = ast.Node{ .id = ast.Node.Id.ErrorType },716 .base = ast.Node{ .id = ast.Node.Id.ErrorType },
717 .token = token_index,717 .token = token_index,
718 });718 });
...@@ -733,7 +733,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {...@@ -733,7 +733,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
733 if (eatToken(&tok_it, &tree, Token.Id.RParen)) |_| {733 if (eatToken(&tok_it, &tree, Token.Id.RParen)) |_| {
734 continue;734 continue;
735 }735 }
736 const param_decl = try arena.construct(ast.Node.ParamDecl{736 const param_decl = try arena.create(ast.Node.ParamDecl{
737 .base = ast.Node{ .id = ast.Node.Id.ParamDecl },737 .base = ast.Node{ .id = ast.Node.Id.ParamDecl },
738 .comptime_token = null,738 .comptime_token = null,
739 .noalias_token = null,739 .noalias_token = null,
...@@ -819,7 +819,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {...@@ -819,7 +819,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
819 const token_ptr = token.ptr;819 const token_ptr = token.ptr;
820 switch (token_ptr.id) {820 switch (token_ptr.id) {
821 Token.Id.LBrace => {821 Token.Id.LBrace => {
822 const block = try arena.construct(ast.Node.Block{822 const block = try arena.create(ast.Node.Block{
823 .base = ast.Node{ .id = ast.Node.Id.Block },823 .base = ast.Node{ .id = ast.Node.Id.Block },
824 .label = ctx.label,824 .label = ctx.label,
825 .lbrace = token_index,825 .lbrace = token_index,
...@@ -853,7 +853,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {...@@ -853,7 +853,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
853 continue;853 continue;
854 },854 },
855 Token.Id.Keyword_suspend => {855 Token.Id.Keyword_suspend => {
856 const node = try arena.construct(ast.Node.Suspend{856 const node = try arena.create(ast.Node.Suspend{
857 .base = ast.Node{ .id = ast.Node.Id.Suspend },857 .base = ast.Node{ .id = ast.Node.Id.Suspend },
858 .label = ctx.label,858 .label = ctx.label,
859 .suspend_token = token_index,859 .suspend_token = token_index,
...@@ -925,7 +925,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {...@@ -925,7 +925,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
925 }925 }
926 },926 },
927 State.While => |ctx| {927 State.While => |ctx| {
928 const node = try arena.construct(ast.Node.While{928 const node = try arena.create(ast.Node.While{
929 .base = ast.Node{ .id = ast.Node.Id.While },929 .base = ast.Node{ .id = ast.Node.Id.While },
930 .label = ctx.label,930 .label = ctx.label,
931 .inline_token = ctx.inline_token,931 .inline_token = ctx.inline_token,
...@@ -954,7 +954,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {...@@ -954,7 +954,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
954 continue;954 continue;
955 },955 },
956 State.For => |ctx| {956 State.For => |ctx| {
957 const node = try arena.construct(ast.Node.For{957 const node = try arena.create(ast.Node.For{
958 .base = ast.Node{ .id = ast.Node.Id.For },958 .base = ast.Node{ .id = ast.Node.Id.For },
959 .label = ctx.label,959 .label = ctx.label,
960 .inline_token = ctx.inline_token,960 .inline_token = ctx.inline_token,
...@@ -975,7 +975,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {...@@ -975,7 +975,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
975 },975 },
976 State.Else => |dest| {976 State.Else => |dest| {
977 if (eatToken(&tok_it, &tree, Token.Id.Keyword_else)) |else_token| {977 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{
979 .base = ast.Node{ .id = ast.Node.Id.Else },979 .base = ast.Node{ .id = ast.Node.Id.Else },
980 .else_token = else_token,980 .else_token = else_token,
981 .payload = null,981 .payload = null,
...@@ -1038,7 +1038,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {...@@ -1038,7 +1038,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
1038 continue;1038 continue;
1039 },1039 },
1040 Token.Id.Keyword_defer, Token.Id.Keyword_errdefer => {1040 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{
1042 .base = ast.Node{ .id = ast.Node.Id.Defer },1042 .base = ast.Node{ .id = ast.Node.Id.Defer },
1043 .defer_token = token_index,1043 .defer_token = token_index,
1044 .kind = switch (token_ptr.id) {1044 .kind = switch (token_ptr.id) {
...@@ -1056,7 +1056,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {...@@ -1056,7 +1056,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
1056 continue;1056 continue;
1057 },1057 },
1058 Token.Id.LBrace => {1058 Token.Id.LBrace => {
1059 const inner_block = try arena.construct(ast.Node.Block{1059 const inner_block = try arena.create(ast.Node.Block{
1060 .base = ast.Node{ .id = ast.Node.Id.Block },1060 .base = ast.Node{ .id = ast.Node.Id.Block },
1061 .label = null,1061 .label = null,
1062 .lbrace = token_index,1062 .lbrace = token_index,
...@@ -1124,7 +1124,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {...@@ -1124,7 +1124,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
1124 continue;1124 continue;
1125 }1125 }
11261126
1127 const node = try arena.construct(ast.Node.AsmOutput{1127 const node = try arena.create(ast.Node.AsmOutput{
1128 .base = ast.Node{ .id = ast.Node.Id.AsmOutput },1128 .base = ast.Node{ .id = ast.Node.Id.AsmOutput },
1129 .lbracket = lbracket_index,1129 .lbracket = lbracket_index,
1130 .symbolic_name = undefined,1130 .symbolic_name = undefined,
...@@ -1178,7 +1178,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {...@@ -1178,7 +1178,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
1178 continue;1178 continue;
1179 }1179 }
11801180
1181 const node = try arena.construct(ast.Node.AsmInput{1181 const node = try arena.create(ast.Node.AsmInput{
1182 .base = ast.Node{ .id = ast.Node.Id.AsmInput },1182 .base = ast.Node{ .id = ast.Node.Id.AsmInput },
1183 .lbracket = lbracket_index,1183 .lbracket = lbracket_index,
1184 .symbolic_name = undefined,1184 .symbolic_name = undefined,
...@@ -1243,7 +1243,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {...@@ -1243,7 +1243,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
1243 continue;1243 continue;
1244 }1244 }
12451245
1246 const node = try arena.construct(ast.Node.FieldInitializer{1246 const node = try arena.create(ast.Node.FieldInitializer{
1247 .base = ast.Node{ .id = ast.Node.Id.FieldInitializer },1247 .base = ast.Node{ .id = ast.Node.Id.FieldInitializer },
1248 .period_token = undefined,1248 .period_token = undefined,
1249 .name_token = undefined,1249 .name_token = undefined,
...@@ -1332,7 +1332,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {...@@ -1332,7 +1332,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
1332 }1332 }
13331333
1334 const comments = try eatDocComments(arena, &tok_it, &tree);1334 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{
1336 .base = ast.Node{ .id = ast.Node.Id.SwitchCase },1336 .base = ast.Node{ .id = ast.Node.Id.SwitchCase },
1337 .items = ast.Node.SwitchCase.ItemList.init(arena),1337 .items = ast.Node.SwitchCase.ItemList.init(arena),
1338 .payload = null,1338 .payload = null,
...@@ -1369,7 +1369,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {...@@ -1369,7 +1369,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
1369 const token_index = token.index;1369 const token_index = token.index;
1370 const token_ptr = token.ptr;1370 const token_ptr = token.ptr;
1371 if (token_ptr.id == Token.Id.Keyword_else) {1371 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{
1373 .base = ast.Node{ .id = ast.Node.Id.SwitchElse },1373 .base = ast.Node{ .id = ast.Node.Id.SwitchElse },
1374 .token = token_index,1374 .token = token_index,
1375 });1375 });
...@@ -1468,7 +1468,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {...@@ -1468,7 +1468,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
14681468
1469 State.ExternType => |ctx| {1469 State.ExternType => |ctx| {
1470 if (eatToken(&tok_it, &tree, Token.Id.Keyword_fn)) |fn_token| {1470 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{
1472 .base = ast.Node{ .id = ast.Node.Id.FnProto },1472 .base = ast.Node{ .id = ast.Node.Id.FnProto },
1473 .doc_comments = ctx.comments,1473 .doc_comments = ctx.comments,
1474 .visib_token = null,1474 .visib_token = null,
...@@ -1641,7 +1641,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {...@@ -1641,7 +1641,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
1641 continue;1641 continue;
1642 }1642 }
16431643
1644 const node = try arena.construct(ast.Node.Payload{1644 const node = try arena.create(ast.Node.Payload{
1645 .base = ast.Node{ .id = ast.Node.Id.Payload },1645 .base = ast.Node{ .id = ast.Node.Id.Payload },
1646 .lpipe = token_index,1646 .lpipe = token_index,
1647 .error_symbol = undefined,1647 .error_symbol = undefined,
...@@ -1677,7 +1677,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {...@@ -1677,7 +1677,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
1677 continue;1677 continue;
1678 }1678 }
16791679
1680 const node = try arena.construct(ast.Node.PointerPayload{1680 const node = try arena.create(ast.Node.PointerPayload{
1681 .base = ast.Node{ .id = ast.Node.Id.PointerPayload },1681 .base = ast.Node{ .id = ast.Node.Id.PointerPayload },
1682 .lpipe = token_index,1682 .lpipe = token_index,
1683 .ptr_token = null,1683 .ptr_token = null,
...@@ -1720,7 +1720,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {...@@ -1720,7 +1720,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
1720 continue;1720 continue;
1721 }1721 }
17221722
1723 const node = try arena.construct(ast.Node.PointerIndexPayload{1723 const node = try arena.create(ast.Node.PointerIndexPayload{
1724 .base = ast.Node{ .id = ast.Node.Id.PointerIndexPayload },1724 .base = ast.Node{ .id = ast.Node.Id.PointerIndexPayload },
1725 .lpipe = token_index,1725 .lpipe = token_index,
1726 .ptr_token = null,1726 .ptr_token = null,
...@@ -1754,7 +1754,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {...@@ -1754,7 +1754,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
1754 const token_ptr = token.ptr;1754 const token_ptr = token.ptr;
1755 switch (token_ptr.id) {1755 switch (token_ptr.id) {
1756 Token.Id.Keyword_return, Token.Id.Keyword_break, Token.Id.Keyword_continue => {1756 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{
1758 .base = ast.Node{ .id = ast.Node.Id.ControlFlowExpression },1758 .base = ast.Node{ .id = ast.Node.Id.ControlFlowExpression },
1759 .ltoken = token_index,1759 .ltoken = token_index,
1760 .kind = undefined,1760 .kind = undefined,
...@@ -1783,7 +1783,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {...@@ -1783,7 +1783,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
1783 continue;1783 continue;
1784 },1784 },
1785 Token.Id.Keyword_try, Token.Id.Keyword_cancel, Token.Id.Keyword_resume => {1785 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{
1787 .base = ast.Node{ .id = ast.Node.Id.PrefixOp },1787 .base = ast.Node{ .id = ast.Node.Id.PrefixOp },
1788 .op_token = token_index,1788 .op_token = token_index,
1789 .op = switch (token_ptr.id) {1789 .op = switch (token_ptr.id) {
...@@ -1817,7 +1817,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {...@@ -1817,7 +1817,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
1817 const lhs = opt_ctx.get() orelse continue;1817 const lhs = opt_ctx.get() orelse continue;
18181818
1819 if (eatToken(&tok_it, &tree, Token.Id.Ellipsis3)) |ellipsis3| {1819 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{
1821 .base = ast.Node{ .id = ast.Node.Id.InfixOp },1821 .base = ast.Node{ .id = ast.Node.Id.InfixOp },
1822 .lhs = lhs,1822 .lhs = lhs,
1823 .op_token = ellipsis3,1823 .op_token = ellipsis3,
...@@ -1842,7 +1842,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {...@@ -1842,7 +1842,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
1842 const token_index = token.index;1842 const token_index = token.index;
1843 const token_ptr = token.ptr;1843 const token_ptr = token.ptr;
1844 if (tokenIdToAssignment(token_ptr.id)) |ass_id| {1844 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{
1846 .base = ast.Node{ .id = ast.Node.Id.InfixOp },1846 .base = ast.Node{ .id = ast.Node.Id.InfixOp },
1847 .lhs = lhs,1847 .lhs = lhs,
1848 .op_token = token_index,1848 .op_token = token_index,
...@@ -1872,7 +1872,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {...@@ -1872,7 +1872,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
1872 const token_index = token.index;1872 const token_index = token.index;
1873 const token_ptr = token.ptr;1873 const token_ptr = token.ptr;
1874 if (tokenIdToUnwrapExpr(token_ptr.id)) |unwrap_id| {1874 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{
1876 .base = ast.Node{ .id = ast.Node.Id.InfixOp },1876 .base = ast.Node{ .id = ast.Node.Id.InfixOp },
1877 .lhs = lhs,1877 .lhs = lhs,
1878 .op_token = token_index,1878 .op_token = token_index,
...@@ -1904,7 +1904,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {...@@ -1904,7 +1904,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
1904 const lhs = opt_ctx.get() orelse continue;1904 const lhs = opt_ctx.get() orelse continue;
19051905
1906 if (eatToken(&tok_it, &tree, Token.Id.Keyword_or)) |or_token| {1906 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{
1908 .base = ast.Node{ .id = ast.Node.Id.InfixOp },1908 .base = ast.Node{ .id = ast.Node.Id.InfixOp },
1909 .lhs = lhs,1909 .lhs = lhs,
1910 .op_token = or_token,1910 .op_token = or_token,
...@@ -1928,7 +1928,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {...@@ -1928,7 +1928,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
1928 const lhs = opt_ctx.get() orelse continue;1928 const lhs = opt_ctx.get() orelse continue;
19291929
1930 if (eatToken(&tok_it, &tree, Token.Id.Keyword_and)) |and_token| {1930 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{
1932 .base = ast.Node{ .id = ast.Node.Id.InfixOp },1932 .base = ast.Node{ .id = ast.Node.Id.InfixOp },
1933 .lhs = lhs,1933 .lhs = lhs,
1934 .op_token = and_token,1934 .op_token = and_token,
...@@ -1955,7 +1955,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {...@@ -1955,7 +1955,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
1955 const token_index = token.index;1955 const token_index = token.index;
1956 const token_ptr = token.ptr;1956 const token_ptr = token.ptr;
1957 if (tokenIdToComparison(token_ptr.id)) |comp_id| {1957 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{
1959 .base = ast.Node{ .id = ast.Node.Id.InfixOp },1959 .base = ast.Node{ .id = ast.Node.Id.InfixOp },
1960 .lhs = lhs,1960 .lhs = lhs,
1961 .op_token = token_index,1961 .op_token = token_index,
...@@ -1982,7 +1982,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {...@@ -1982,7 +1982,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
1982 const lhs = opt_ctx.get() orelse continue;1982 const lhs = opt_ctx.get() orelse continue;
19831983
1984 if (eatToken(&tok_it, &tree, Token.Id.Pipe)) |pipe| {1984 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{
1986 .base = ast.Node{ .id = ast.Node.Id.InfixOp },1986 .base = ast.Node{ .id = ast.Node.Id.InfixOp },
1987 .lhs = lhs,1987 .lhs = lhs,
1988 .op_token = pipe,1988 .op_token = pipe,
...@@ -2006,7 +2006,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {...@@ -2006,7 +2006,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
2006 const lhs = opt_ctx.get() orelse continue;2006 const lhs = opt_ctx.get() orelse continue;
20072007
2008 if (eatToken(&tok_it, &tree, Token.Id.Caret)) |caret| {2008 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{
2010 .base = ast.Node{ .id = ast.Node.Id.InfixOp },2010 .base = ast.Node{ .id = ast.Node.Id.InfixOp },
2011 .lhs = lhs,2011 .lhs = lhs,
2012 .op_token = caret,2012 .op_token = caret,
...@@ -2030,7 +2030,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {...@@ -2030,7 +2030,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
2030 const lhs = opt_ctx.get() orelse continue;2030 const lhs = opt_ctx.get() orelse continue;
20312031
2032 if (eatToken(&tok_it, &tree, Token.Id.Ampersand)) |ampersand| {2032 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{
2034 .base = ast.Node{ .id = ast.Node.Id.InfixOp },2034 .base = ast.Node{ .id = ast.Node.Id.InfixOp },
2035 .lhs = lhs,2035 .lhs = lhs,
2036 .op_token = ampersand,2036 .op_token = ampersand,
...@@ -2057,7 +2057,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {...@@ -2057,7 +2057,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
2057 const token_index = token.index;2057 const token_index = token.index;
2058 const token_ptr = token.ptr;2058 const token_ptr = token.ptr;
2059 if (tokenIdToBitShift(token_ptr.id)) |bitshift_id| {2059 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{
2061 .base = ast.Node{ .id = ast.Node.Id.InfixOp },2061 .base = ast.Node{ .id = ast.Node.Id.InfixOp },
2062 .lhs = lhs,2062 .lhs = lhs,
2063 .op_token = token_index,2063 .op_token = token_index,
...@@ -2087,7 +2087,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {...@@ -2087,7 +2087,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
2087 const token_index = token.index;2087 const token_index = token.index;
2088 const token_ptr = token.ptr;2088 const token_ptr = token.ptr;
2089 if (tokenIdToAddition(token_ptr.id)) |add_id| {2089 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{
2091 .base = ast.Node{ .id = ast.Node.Id.InfixOp },2091 .base = ast.Node{ .id = ast.Node.Id.InfixOp },
2092 .lhs = lhs,2092 .lhs = lhs,
2093 .op_token = token_index,2093 .op_token = token_index,
...@@ -2117,7 +2117,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {...@@ -2117,7 +2117,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
2117 const token_index = token.index;2117 const token_index = token.index;
2118 const token_ptr = token.ptr;2118 const token_ptr = token.ptr;
2119 if (tokenIdToMultiply(token_ptr.id)) |mult_id| {2119 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{
2121 .base = ast.Node{ .id = ast.Node.Id.InfixOp },2121 .base = ast.Node{ .id = ast.Node.Id.InfixOp },
2122 .lhs = lhs,2122 .lhs = lhs,
2123 .op_token = token_index,2123 .op_token = token_index,
...@@ -2145,7 +2145,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {...@@ -2145,7 +2145,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
2145 const lhs = opt_ctx.get() orelse continue;2145 const lhs = opt_ctx.get() orelse continue;
21462146
2147 if (tok_it.peek().?.id == Token.Id.Period) {2147 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{
2149 .base = ast.Node{ .id = ast.Node.Id.SuffixOp },2149 .base = ast.Node{ .id = ast.Node.Id.SuffixOp },
2150 .lhs = lhs,2150 .lhs = lhs,
2151 .op = ast.Node.SuffixOp.Op{ .StructInitializer = ast.Node.SuffixOp.Op.InitList.init(arena) },2151 .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 {...@@ -2164,7 +2164,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
2164 continue;2164 continue;
2165 }2165 }
21662166
2167 const node = try arena.construct(ast.Node.SuffixOp{2167 const node = try arena.create(ast.Node.SuffixOp{
2168 .base = ast.Node{ .id = ast.Node.Id.SuffixOp },2168 .base = ast.Node{ .id = ast.Node.Id.SuffixOp },
2169 .lhs = lhs,2169 .lhs = lhs,
2170 .op = ast.Node.SuffixOp.Op{ .ArrayInitializer = ast.Node.SuffixOp.Op.InitList.init(arena) },2170 .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 {...@@ -2193,7 +2193,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
2193 const lhs = opt_ctx.get() orelse continue;2193 const lhs = opt_ctx.get() orelse continue;
21942194
2195 if (eatToken(&tok_it, &tree, Token.Id.Bang)) |bang| {2195 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{
2197 .base = ast.Node{ .id = ast.Node.Id.InfixOp },2197 .base = ast.Node{ .id = ast.Node.Id.InfixOp },
2198 .lhs = lhs,2198 .lhs = lhs,
2199 .op_token = bang,2199 .op_token = bang,
...@@ -2212,7 +2212,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {...@@ -2212,7 +2212,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
2212 const token_index = token.index;2212 const token_index = token.index;
2213 const token_ptr = token.ptr;2213 const token_ptr = token.ptr;
2214 if (tokenIdToPrefixOp(token_ptr.id)) |prefix_id| {2214 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{
2216 .base = ast.Node{ .id = ast.Node.Id.PrefixOp },2216 .base = ast.Node{ .id = ast.Node.Id.PrefixOp },
2217 .op_token = token_index,2217 .op_token = token_index,
2218 .op = prefix_id,2218 .op = prefix_id,
...@@ -2222,7 +2222,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {...@@ -2222,7 +2222,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
22222222
2223 // Treat '**' token as two pointer types2223 // Treat '**' token as two pointer types
2224 if (token_ptr.id == Token.Id.AsteriskAsterisk) {2224 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{
2226 .base = ast.Node{ .id = ast.Node.Id.PrefixOp },2226 .base = ast.Node{ .id = ast.Node.Id.PrefixOp },
2227 .op_token = token_index,2227 .op_token = token_index,
2228 .op = prefix_id,2228 .op = prefix_id,
...@@ -2246,7 +2246,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {...@@ -2246,7 +2246,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
22462246
2247 State.SuffixOpExpressionBegin => |opt_ctx| {2247 State.SuffixOpExpressionBegin => |opt_ctx| {
2248 if (eatToken(&tok_it, &tree, Token.Id.Keyword_async)) |async_token| {2248 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{
2250 .base = ast.Node{ .id = ast.Node.Id.AsyncAttribute },2250 .base = ast.Node{ .id = ast.Node.Id.AsyncAttribute },
2251 .async_token = async_token,2251 .async_token = async_token,
2252 .allocator_type = null,2252 .allocator_type = null,
...@@ -2277,7 +2277,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {...@@ -2277,7 +2277,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
2277 const token_ptr = token.ptr;2277 const token_ptr = token.ptr;
2278 switch (token_ptr.id) {2278 switch (token_ptr.id) {
2279 Token.Id.LParen => {2279 Token.Id.LParen => {
2280 const node = try arena.construct(ast.Node.SuffixOp{2280 const node = try arena.create(ast.Node.SuffixOp{
2281 .base = ast.Node{ .id = ast.Node.Id.SuffixOp },2281 .base = ast.Node{ .id = ast.Node.Id.SuffixOp },
2282 .lhs = lhs,2282 .lhs = lhs,
2283 .op = ast.Node.SuffixOp.Op{2283 .op = ast.Node.SuffixOp.Op{
...@@ -2301,7 +2301,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {...@@ -2301,7 +2301,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
2301 continue;2301 continue;
2302 },2302 },
2303 Token.Id.LBracket => {2303 Token.Id.LBracket => {
2304 const node = try arena.construct(ast.Node.SuffixOp{2304 const node = try arena.create(ast.Node.SuffixOp{
2305 .base = ast.Node{ .id = ast.Node.Id.SuffixOp },2305 .base = ast.Node{ .id = ast.Node.Id.SuffixOp },
2306 .lhs = lhs,2306 .lhs = lhs,
2307 .op = ast.Node.SuffixOp.Op{ .ArrayAccess = undefined },2307 .op = ast.Node.SuffixOp.Op{ .ArrayAccess = undefined },
...@@ -2316,7 +2316,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {...@@ -2316,7 +2316,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
2316 },2316 },
2317 Token.Id.Period => {2317 Token.Id.Period => {
2318 if (eatToken(&tok_it, &tree, Token.Id.Asterisk)) |asterisk_token| {2318 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{
2320 .base = ast.Node{ .id = ast.Node.Id.SuffixOp },2320 .base = ast.Node{ .id = ast.Node.Id.SuffixOp },
2321 .lhs = lhs,2321 .lhs = lhs,
2322 .op = ast.Node.SuffixOp.Op.Deref,2322 .op = ast.Node.SuffixOp.Op.Deref,
...@@ -2327,7 +2327,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {...@@ -2327,7 +2327,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
2327 continue;2327 continue;
2328 }2328 }
2329 if (eatToken(&tok_it, &tree, Token.Id.QuestionMark)) |question_token| {2329 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{
2331 .base = ast.Node{ .id = ast.Node.Id.SuffixOp },2331 .base = ast.Node{ .id = ast.Node.Id.SuffixOp },
2332 .lhs = lhs,2332 .lhs = lhs,
2333 .op = ast.Node.SuffixOp.Op.UnwrapOptional,2333 .op = ast.Node.SuffixOp.Op.UnwrapOptional,
...@@ -2337,7 +2337,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {...@@ -2337,7 +2337,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
2337 stack.append(State{ .SuffixOpExpressionEnd = opt_ctx.toRequired() }) catch unreachable;2337 stack.append(State{ .SuffixOpExpressionEnd = opt_ctx.toRequired() }) catch unreachable;
2338 continue;2338 continue;
2339 }2339 }
2340 const node = try arena.construct(ast.Node.InfixOp{2340 const node = try arena.create(ast.Node.InfixOp{
2341 .base = ast.Node{ .id = ast.Node.Id.InfixOp },2341 .base = ast.Node{ .id = ast.Node.Id.InfixOp },
2342 .lhs = lhs,2342 .lhs = lhs,
2343 .op_token = token_index,2343 .op_token = token_index,
...@@ -2397,7 +2397,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {...@@ -2397,7 +2397,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
2397 continue;2397 continue;
2398 },2398 },
2399 Token.Id.Keyword_promise => {2399 Token.Id.Keyword_promise => {
2400 const node = try arena.construct(ast.Node.PromiseType{2400 const node = try arena.create(ast.Node.PromiseType{
2401 .base = ast.Node{ .id = ast.Node.Id.PromiseType },2401 .base = ast.Node{ .id = ast.Node.Id.PromiseType },
2402 .promise_token = token.index,2402 .promise_token = token.index,
2403 .result = null,2403 .result = null,
...@@ -2423,7 +2423,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {...@@ -2423,7 +2423,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
2423 continue;2423 continue;
2424 },2424 },
2425 Token.Id.LParen => {2425 Token.Id.LParen => {
2426 const node = try arena.construct(ast.Node.GroupedExpression{2426 const node = try arena.create(ast.Node.GroupedExpression{
2427 .base = ast.Node{ .id = ast.Node.Id.GroupedExpression },2427 .base = ast.Node{ .id = ast.Node.Id.GroupedExpression },
2428 .lparen = token.index,2428 .lparen = token.index,
2429 .expr = undefined,2429 .expr = undefined,
...@@ -2441,7 +2441,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {...@@ -2441,7 +2441,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
2441 continue;2441 continue;
2442 },2442 },
2443 Token.Id.Builtin => {2443 Token.Id.Builtin => {
2444 const node = try arena.construct(ast.Node.BuiltinCall{2444 const node = try arena.create(ast.Node.BuiltinCall{
2445 .base = ast.Node{ .id = ast.Node.Id.BuiltinCall },2445 .base = ast.Node{ .id = ast.Node.Id.BuiltinCall },
2446 .builtin_token = token.index,2446 .builtin_token = token.index,
2447 .params = ast.Node.BuiltinCall.ParamList.init(arena),2447 .params = ast.Node.BuiltinCall.ParamList.init(arena),
...@@ -2460,7 +2460,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {...@@ -2460,7 +2460,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
2460 continue;2460 continue;
2461 },2461 },
2462 Token.Id.LBracket => {2462 Token.Id.LBracket => {
2463 const node = try arena.construct(ast.Node.PrefixOp{2463 const node = try arena.create(ast.Node.PrefixOp{
2464 .base = ast.Node{ .id = ast.Node.Id.PrefixOp },2464 .base = ast.Node{ .id = ast.Node.Id.PrefixOp },
2465 .op_token = token.index,2465 .op_token = token.index,
2466 .op = undefined,2466 .op = undefined,
...@@ -2519,7 +2519,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {...@@ -2519,7 +2519,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
2519 continue;2519 continue;
2520 },2520 },
2521 Token.Id.Keyword_fn => {2521 Token.Id.Keyword_fn => {
2522 const fn_proto = try arena.construct(ast.Node.FnProto{2522 const fn_proto = try arena.create(ast.Node.FnProto{
2523 .base = ast.Node{ .id = ast.Node.Id.FnProto },2523 .base = ast.Node{ .id = ast.Node.Id.FnProto },
2524 .doc_comments = null,2524 .doc_comments = null,
2525 .visib_token = null,2525 .visib_token = null,
...@@ -2540,7 +2540,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {...@@ -2540,7 +2540,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
2540 continue;2540 continue;
2541 },2541 },
2542 Token.Id.Keyword_nakedcc, Token.Id.Keyword_stdcallcc => {2542 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{
2544 .base = ast.Node{ .id = ast.Node.Id.FnProto },2544 .base = ast.Node{ .id = ast.Node.Id.FnProto },
2545 .doc_comments = null,2545 .doc_comments = null,
2546 .visib_token = null,2546 .visib_token = null,
...@@ -2567,7 +2567,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {...@@ -2567,7 +2567,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
2567 continue;2567 continue;
2568 },2568 },
2569 Token.Id.Keyword_asm => {2569 Token.Id.Keyword_asm => {
2570 const node = try arena.construct(ast.Node.Asm{2570 const node = try arena.create(ast.Node.Asm{
2571 .base = ast.Node{ .id = ast.Node.Id.Asm },2571 .base = ast.Node{ .id = ast.Node.Id.Asm },
2572 .asm_token = token.index,2572 .asm_token = token.index,
2573 .volatile_token = null,2573 .volatile_token = null,
...@@ -2629,7 +2629,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {...@@ -2629,7 +2629,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
2629 continue;2629 continue;
2630 }2630 }
26312631
2632 const node = try arena.construct(ast.Node.ErrorSetDecl{2632 const node = try arena.create(ast.Node.ErrorSetDecl{
2633 .base = ast.Node{ .id = ast.Node.Id.ErrorSetDecl },2633 .base = ast.Node{ .id = ast.Node.Id.ErrorSetDecl },
2634 .error_token = ctx.error_token,2634 .error_token = ctx.error_token,
2635 .decls = ast.Node.ErrorSetDecl.DeclList.init(arena),2635 .decls = ast.Node.ErrorSetDecl.DeclList.init(arena),
...@@ -2695,7 +2695,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {...@@ -2695,7 +2695,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
2695 return tree;2695 return tree;
2696 }2696 }
26972697
2698 const node = try arena.construct(ast.Node.ErrorTag{2698 const node = try arena.create(ast.Node.ErrorTag{
2699 .base = ast.Node{ .id = ast.Node.Id.ErrorTag },2699 .base = ast.Node{ .id = ast.Node.Id.ErrorTag },
2700 .doc_comments = comments,2700 .doc_comments = comments,
2701 .name_token = ident_token_index,2701 .name_token = ident_token_index,
...@@ -3032,7 +3032,7 @@ fn pushDocComment(arena: *mem.Allocator, line_comment: TokenIndex, result: *?*as...@@ -3032,7 +3032,7 @@ fn pushDocComment(arena: *mem.Allocator, line_comment: TokenIndex, result: *?*as
3032 if (result.*) |comment_node| {3032 if (result.*) |comment_node| {
3033 break :blk comment_node;3033 break :blk comment_node;
3034 } else {3034 } else {
3035 const comment_node = try arena.construct(ast.Node.DocComment{3035 const comment_node = try arena.create(ast.Node.DocComment{
3036 .base = ast.Node{ .id = ast.Node.Id.DocComment },3036 .base = ast.Node{ .id = ast.Node.Id.DocComment },
3037 .lines = ast.Node.DocComment.LineList.init(arena),3037 .lines = ast.Node.DocComment.LineList.init(arena),
3038 });3038 });
...@@ -3061,7 +3061,7 @@ fn parseStringLiteral(arena: *mem.Allocator, tok_it: *ast.Tree.TokenList.Iterato...@@ -3061,7 +3061,7 @@ fn parseStringLiteral(arena: *mem.Allocator, tok_it: *ast.Tree.TokenList.Iterato
3061 return &(try createLiteral(arena, ast.Node.StringLiteral, token_index)).base;3061 return &(try createLiteral(arena, ast.Node.StringLiteral, token_index)).base;
3062 },3062 },
3063 Token.Id.MultilineStringLiteralLine => {3063 Token.Id.MultilineStringLiteralLine => {
3064 const node = try arena.construct(ast.Node.MultilineStringLiteral{3064 const node = try arena.create(ast.Node.MultilineStringLiteral{
3065 .base = ast.Node{ .id = ast.Node.Id.MultilineStringLiteral },3065 .base = ast.Node{ .id = ast.Node.Id.MultilineStringLiteral },
3066 .lines = ast.Node.MultilineStringLiteral.LineList.init(arena),3066 .lines = ast.Node.MultilineStringLiteral.LineList.init(arena),
3067 });3067 });
...@@ -3089,7 +3089,7 @@ fn parseStringLiteral(arena: *mem.Allocator, tok_it: *ast.Tree.TokenList.Iterato...@@ -3089,7 +3089,7 @@ fn parseStringLiteral(arena: *mem.Allocator, tok_it: *ast.Tree.TokenList.Iterato
3089fn parseBlockExpr(stack: *std.ArrayList(State), arena: *mem.Allocator, ctx: *const OptionalCtx, token_ptr: *const Token, token_index: TokenIndex) !bool {3089fn parseBlockExpr(stack: *std.ArrayList(State), arena: *mem.Allocator, ctx: *const OptionalCtx, token_ptr: *const Token, token_index: TokenIndex) !bool {
3090 switch (token_ptr.id) {3090 switch (token_ptr.id) {
3091 Token.Id.Keyword_suspend => {3091 Token.Id.Keyword_suspend => {
3092 const node = try arena.construct(ast.Node.Suspend{3092 const node = try arena.create(ast.Node.Suspend{
3093 .base = ast.Node{ .id = ast.Node.Id.Suspend },3093 .base = ast.Node{ .id = ast.Node.Id.Suspend },
3094 .label = null,3094 .label = null,
3095 .suspend_token = token_index,3095 .suspend_token = token_index,
...@@ -3103,7 +3103,7 @@ fn parseBlockExpr(stack: *std.ArrayList(State), arena: *mem.Allocator, ctx: *con...@@ -3103,7 +3103,7 @@ fn parseBlockExpr(stack: *std.ArrayList(State), arena: *mem.Allocator, ctx: *con
3103 return true;3103 return true;
3104 },3104 },
3105 Token.Id.Keyword_if => {3105 Token.Id.Keyword_if => {
3106 const node = try arena.construct(ast.Node.If{3106 const node = try arena.create(ast.Node.If{
3107 .base = ast.Node{ .id = ast.Node.Id.If },3107 .base = ast.Node{ .id = ast.Node.Id.If },
3108 .if_token = token_index,3108 .if_token = token_index,
3109 .condition = undefined,3109 .condition = undefined,
...@@ -3144,7 +3144,7 @@ fn parseBlockExpr(stack: *std.ArrayList(State), arena: *mem.Allocator, ctx: *con...@@ -3144,7 +3144,7 @@ fn parseBlockExpr(stack: *std.ArrayList(State), arena: *mem.Allocator, ctx: *con
3144 return true;3144 return true;
3145 },3145 },
3146 Token.Id.Keyword_switch => {3146 Token.Id.Keyword_switch => {
3147 const node = try arena.construct(ast.Node.Switch{3147 const node = try arena.create(ast.Node.Switch{
3148 .base = ast.Node{ .id = ast.Node.Id.Switch },3148 .base = ast.Node{ .id = ast.Node.Id.Switch },
3149 .switch_token = token_index,3149 .switch_token = token_index,
3150 .expr = undefined,3150 .expr = undefined,
...@@ -3166,7 +3166,7 @@ fn parseBlockExpr(stack: *std.ArrayList(State), arena: *mem.Allocator, ctx: *con...@@ -3166,7 +3166,7 @@ fn parseBlockExpr(stack: *std.ArrayList(State), arena: *mem.Allocator, ctx: *con
3166 return true;3166 return true;
3167 },3167 },
3168 Token.Id.Keyword_comptime => {3168 Token.Id.Keyword_comptime => {
3169 const node = try arena.construct(ast.Node.Comptime{3169 const node = try arena.create(ast.Node.Comptime{
3170 .base = ast.Node{ .id = ast.Node.Id.Comptime },3170 .base = ast.Node{ .id = ast.Node.Id.Comptime },
3171 .comptime_token = token_index,3171 .comptime_token = token_index,
3172 .expr = undefined,3172 .expr = undefined,
...@@ -3178,7 +3178,7 @@ fn parseBlockExpr(stack: *std.ArrayList(State), arena: *mem.Allocator, ctx: *con...@@ -3178,7 +3178,7 @@ fn parseBlockExpr(stack: *std.ArrayList(State), arena: *mem.Allocator, ctx: *con
3178 return true;3178 return true;
3179 },3179 },
3180 Token.Id.LBrace => {3180 Token.Id.LBrace => {
3181 const block = try arena.construct(ast.Node.Block{3181 const block = try arena.create(ast.Node.Block{
3182 .base = ast.Node{ .id = ast.Node.Id.Block },3182 .base = ast.Node{ .id = ast.Node.Id.Block },
3183 .label = null,3183 .label = null,
3184 .lbrace = token_index,3184 .lbrace = token_index,
...@@ -3318,7 +3318,7 @@ fn tokenIdToPrefixOp(id: @TagType(Token.Id)) ?ast.Node.PrefixOp.Op {...@@ -3318,7 +3318,7 @@ fn tokenIdToPrefixOp(id: @TagType(Token.Id)) ?ast.Node.PrefixOp.Op {
3318}3318}
33193319
3320fn createLiteral(arena: *mem.Allocator, comptime T: type, token_index: TokenIndex) !*T {3320fn createLiteral(arena: *mem.Allocator, comptime T: type, token_index: TokenIndex) !*T {
3321 return arena.construct(T{3321 return arena.create(T{
3322 .base = ast.Node{ .id = ast.Node.typeToId(T) },3322 .base = ast.Node{ .id = ast.Node.typeToId(T) },
3323 .token = token_index,3323 .token = token_index,
3324 });3324 });
test/cases/null.zig+1-1
...@@ -146,7 +146,7 @@ test "null with default unwrap" {...@@ -146,7 +146,7 @@ test "null with default unwrap" {
146146
147test "optional types" {147test "optional types" {
148 comptime {148 comptime {
149 const opt_type_struct = StructWithOptionalType { .t=u8, };149 const opt_type_struct = StructWithOptionalType{ .t = u8 };
150 assert(opt_type_struct.t != null and opt_type_struct.t.? == u8);150 assert(opt_type_struct.t != null and opt_type_struct.t.? == u8);
151 }151 }
152}152}
test/tests.zig+37-45
...@@ -48,13 +48,12 @@ const test_targets = []TestTarget{...@@ -48,13 +48,12 @@ const test_targets = []TestTarget{
48const max_stdout_size = 1 * 1024 * 1024; // 1 MB48const max_stdout_size = 1 * 1024 * 1024; // 1 MB
4949
50pub fn addCompareOutputTests(b: *build.Builder, test_filter: ?[]const u8) *build.Step {50pub fn addCompareOutputTests(b: *build.Builder, test_filter: ?[]const u8) *build.Step {
51 const cases = b.allocator.create(CompareOutputContext) catch unreachable;51 const cases = b.allocator.create(CompareOutputContext{
52 cases.* = CompareOutputContext{
53 .b = b,52 .b = b,
54 .step = b.step("test-compare-output", "Run the compare output tests"),53 .step = b.step("test-compare-output", "Run the compare output tests"),
55 .test_index = 0,54 .test_index = 0,
56 .test_filter = test_filter,55 .test_filter = test_filter,
57 };56 }) catch unreachable;
5857
59 compare_output.addCases(cases);58 compare_output.addCases(cases);
6059
...@@ -62,13 +61,12 @@ pub fn addCompareOutputTests(b: *build.Builder, test_filter: ?[]const u8) *build...@@ -62,13 +61,12 @@ pub fn addCompareOutputTests(b: *build.Builder, test_filter: ?[]const u8) *build
62}61}
6362
64pub fn addRuntimeSafetyTests(b: *build.Builder, test_filter: ?[]const u8) *build.Step {63pub fn addRuntimeSafetyTests(b: *build.Builder, test_filter: ?[]const u8) *build.Step {
65 const cases = b.allocator.create(CompareOutputContext) catch unreachable;64 const cases = b.allocator.create(CompareOutputContext{
66 cases.* = CompareOutputContext{
67 .b = b,65 .b = b,
68 .step = b.step("test-runtime-safety", "Run the runtime safety tests"),66 .step = b.step("test-runtime-safety", "Run the runtime safety tests"),
69 .test_index = 0,67 .test_index = 0,
70 .test_filter = test_filter,68 .test_filter = test_filter,
71 };69 }) catch unreachable;
7270
73 runtime_safety.addCases(cases);71 runtime_safety.addCases(cases);
7472
...@@ -76,13 +74,12 @@ pub fn addRuntimeSafetyTests(b: *build.Builder, test_filter: ?[]const u8) *build...@@ -76,13 +74,12 @@ pub fn addRuntimeSafetyTests(b: *build.Builder, test_filter: ?[]const u8) *build
76}74}
7775
78pub fn addCompileErrorTests(b: *build.Builder, test_filter: ?[]const u8) *build.Step {76pub fn addCompileErrorTests(b: *build.Builder, test_filter: ?[]const u8) *build.Step {
79 const cases = b.allocator.create(CompileErrorContext) catch unreachable;77 const cases = b.allocator.create(CompileErrorContext{
80 cases.* = CompileErrorContext{
81 .b = b,78 .b = b,
82 .step = b.step("test-compile-errors", "Run the compile error tests"),79 .step = b.step("test-compile-errors", "Run the compile error tests"),
83 .test_index = 0,80 .test_index = 0,
84 .test_filter = test_filter,81 .test_filter = test_filter,
85 };82 }) catch unreachable;
8683
87 compile_errors.addCases(cases);84 compile_errors.addCases(cases);
8885
...@@ -90,13 +87,12 @@ pub fn addCompileErrorTests(b: *build.Builder, test_filter: ?[]const u8) *build....@@ -90,13 +87,12 @@ pub fn addCompileErrorTests(b: *build.Builder, test_filter: ?[]const u8) *build.
90}87}
9188
92pub fn addBuildExampleTests(b: *build.Builder, test_filter: ?[]const u8) *build.Step {89pub fn addBuildExampleTests(b: *build.Builder, test_filter: ?[]const u8) *build.Step {
93 const cases = b.allocator.create(BuildExamplesContext) catch unreachable;90 const cases = b.allocator.create(BuildExamplesContext{
94 cases.* = BuildExamplesContext{
95 .b = b,91 .b = b,
96 .step = b.step("test-build-examples", "Build the examples"),92 .step = b.step("test-build-examples", "Build the examples"),
97 .test_index = 0,93 .test_index = 0,
98 .test_filter = test_filter,94 .test_filter = test_filter,
99 };95 }) catch unreachable;
10096
101 build_examples.addCases(cases);97 build_examples.addCases(cases);
10298
...@@ -104,13 +100,12 @@ pub fn addBuildExampleTests(b: *build.Builder, test_filter: ?[]const u8) *build....@@ -104,13 +100,12 @@ pub fn addBuildExampleTests(b: *build.Builder, test_filter: ?[]const u8) *build.
104}100}
105101
106pub fn addAssembleAndLinkTests(b: *build.Builder, test_filter: ?[]const u8) *build.Step {102pub fn addAssembleAndLinkTests(b: *build.Builder, test_filter: ?[]const u8) *build.Step {
107 const cases = b.allocator.create(CompareOutputContext) catch unreachable;103 const cases = b.allocator.create(CompareOutputContext{
108 cases.* = CompareOutputContext{
109 .b = b,104 .b = b,
110 .step = b.step("test-asm-link", "Run the assemble and link tests"),105 .step = b.step("test-asm-link", "Run the assemble and link tests"),
111 .test_index = 0,106 .test_index = 0,
112 .test_filter = test_filter,107 .test_filter = test_filter,
113 };108 }) catch unreachable;
114109
115 assemble_and_link.addCases(cases);110 assemble_and_link.addCases(cases);
116111
...@@ -118,13 +113,12 @@ pub fn addAssembleAndLinkTests(b: *build.Builder, test_filter: ?[]const u8) *bui...@@ -118,13 +113,12 @@ pub fn addAssembleAndLinkTests(b: *build.Builder, test_filter: ?[]const u8) *bui
118}113}
119114
120pub fn addTranslateCTests(b: *build.Builder, test_filter: ?[]const u8) *build.Step {115pub fn addTranslateCTests(b: *build.Builder, test_filter: ?[]const u8) *build.Step {
121 const cases = b.allocator.create(TranslateCContext) catch unreachable;116 const cases = b.allocator.create(TranslateCContext{
122 cases.* = TranslateCContext{
123 .b = b,117 .b = b,
124 .step = b.step("test-translate-c", "Run the C transation tests"),118 .step = b.step("test-translate-c", "Run the C transation tests"),
125 .test_index = 0,119 .test_index = 0,
126 .test_filter = test_filter,120 .test_filter = test_filter,
127 };121 }) catch unreachable;
128122
129 translate_c.addCases(cases);123 translate_c.addCases(cases);
130124
...@@ -132,13 +126,12 @@ pub fn addTranslateCTests(b: *build.Builder, test_filter: ?[]const u8) *build.St...@@ -132,13 +126,12 @@ pub fn addTranslateCTests(b: *build.Builder, test_filter: ?[]const u8) *build.St
132}126}
133127
134pub fn addGenHTests(b: *build.Builder, test_filter: ?[]const u8) *build.Step {128pub fn addGenHTests(b: *build.Builder, test_filter: ?[]const u8) *build.Step {
135 const cases = b.allocator.create(GenHContext) catch unreachable;129 const cases = b.allocator.create(GenHContext{
136 cases.* = GenHContext{
137 .b = b,130 .b = b,
138 .step = b.step("test-gen-h", "Run the C header file generation tests"),131 .step = b.step("test-gen-h", "Run the C header file generation tests"),
139 .test_index = 0,132 .test_index = 0,
140 .test_filter = test_filter,133 .test_filter = test_filter,
141 };134 }) catch unreachable;
142135
143 gen_h.addCases(cases);136 gen_h.addCases(cases);
144137
...@@ -240,8 +233,7 @@ pub const CompareOutputContext = struct {...@@ -240,8 +233,7 @@ pub const CompareOutputContext = struct {
240233
241 pub fn create(context: *CompareOutputContext, exe_path: []const u8, name: []const u8, expected_output: []const u8, cli_args: []const []const u8) *RunCompareOutputStep {234 pub fn create(context: *CompareOutputContext, exe_path: []const u8, name: []const u8, expected_output: []const u8, cli_args: []const []const u8) *RunCompareOutputStep {
242 const allocator = context.b.allocator;235 const allocator = context.b.allocator;
243 const ptr = allocator.create(RunCompareOutputStep) catch unreachable;236 const ptr = allocator.create(RunCompareOutputStep{
244 ptr.* = RunCompareOutputStep{
245 .context = context,237 .context = context,
246 .exe_path = exe_path,238 .exe_path = exe_path,
247 .name = name,239 .name = name,
...@@ -249,7 +241,7 @@ pub const CompareOutputContext = struct {...@@ -249,7 +241,7 @@ pub const CompareOutputContext = struct {
249 .test_index = context.test_index,241 .test_index = context.test_index,
250 .step = build.Step.init("RunCompareOutput", allocator, make),242 .step = build.Step.init("RunCompareOutput", allocator, make),
251 .cli_args = cli_args,243 .cli_args = cli_args,
252 };244 }) catch unreachable;
253 context.test_index += 1;245 context.test_index += 1;
254 return ptr;246 return ptr;
255 }247 }
...@@ -328,14 +320,14 @@ pub const CompareOutputContext = struct {...@@ -328,14 +320,14 @@ pub const CompareOutputContext = struct {
328320
329 pub fn create(context: *CompareOutputContext, exe_path: []const u8, name: []const u8) *RuntimeSafetyRunStep {321 pub fn create(context: *CompareOutputContext, exe_path: []const u8, name: []const u8) *RuntimeSafetyRunStep {
330 const allocator = context.b.allocator;322 const allocator = context.b.allocator;
331 const ptr = allocator.create(RuntimeSafetyRunStep) catch unreachable;323 const ptr = allocator.create(RuntimeSafetyRunStep{
332 ptr.* = RuntimeSafetyRunStep{
333 .context = context,324 .context = context,
334 .exe_path = exe_path,325 .exe_path = exe_path,
335 .name = name,326 .name = name,
336 .test_index = context.test_index,327 .test_index = context.test_index,
337 .step = build.Step.init("RuntimeSafetyRun", allocator, make),328 .step = build.Step.init("RuntimeSafetyRun", allocator, make),
338 };329 }) catch unreachable;
330
339 context.test_index += 1;331 context.test_index += 1;
340 return ptr;332 return ptr;
341 }333 }
...@@ -543,15 +535,15 @@ pub const CompileErrorContext = struct {...@@ -543,15 +535,15 @@ pub const CompileErrorContext = struct {
543535
544 pub fn create(context: *CompileErrorContext, name: []const u8, case: *const TestCase, build_mode: Mode) *CompileCmpOutputStep {536 pub fn create(context: *CompileErrorContext, name: []const u8, case: *const TestCase, build_mode: Mode) *CompileCmpOutputStep {
545 const allocator = context.b.allocator;537 const allocator = context.b.allocator;
546 const ptr = allocator.create(CompileCmpOutputStep) catch unreachable;538 const ptr = allocator.create(CompileCmpOutputStep{
547 ptr.* = CompileCmpOutputStep{
548 .step = build.Step.init("CompileCmpOutput", allocator, make),539 .step = build.Step.init("CompileCmpOutput", allocator, make),
549 .context = context,540 .context = context,
550 .name = name,541 .name = name,
551 .test_index = context.test_index,542 .test_index = context.test_index,
552 .case = case,543 .case = case,
553 .build_mode = build_mode,544 .build_mode = build_mode,
554 };545 }) catch unreachable;
546
555 context.test_index += 1;547 context.test_index += 1;
556 return ptr;548 return ptr;
557 }549 }
...@@ -662,14 +654,14 @@ pub const CompileErrorContext = struct {...@@ -662,14 +654,14 @@ pub const CompileErrorContext = struct {
662 }654 }
663655
664 pub fn create(self: *CompileErrorContext, name: []const u8, source: []const u8, expected_lines: ...) *TestCase {656 pub fn create(self: *CompileErrorContext, name: []const u8, source: []const u8, expected_lines: ...) *TestCase {
665 const tc = self.b.allocator.create(TestCase) catch unreachable;657 const tc = self.b.allocator.create(TestCase{
666 tc.* = TestCase{
667 .name = name,658 .name = name,
668 .sources = ArrayList(TestCase.SourceFile).init(self.b.allocator),659 .sources = ArrayList(TestCase.SourceFile).init(self.b.allocator),
669 .expected_errors = ArrayList([]const u8).init(self.b.allocator),660 .expected_errors = ArrayList([]const u8).init(self.b.allocator),
670 .link_libc = false,661 .link_libc = false,
671 .is_exe = false,662 .is_exe = false,
672 };663 }) catch unreachable;
664
673 tc.addSourceFile(".tmp_source.zig", source);665 tc.addSourceFile(".tmp_source.zig", source);
674 comptime var arg_i = 0;666 comptime var arg_i = 0;
675 inline while (arg_i < expected_lines.len) : (arg_i += 1) {667 inline while (arg_i < expected_lines.len) : (arg_i += 1) {
...@@ -829,14 +821,14 @@ pub const TranslateCContext = struct {...@@ -829,14 +821,14 @@ pub const TranslateCContext = struct {
829821
830 pub fn create(context: *TranslateCContext, name: []const u8, case: *const TestCase) *TranslateCCmpOutputStep {822 pub fn create(context: *TranslateCContext, name: []const u8, case: *const TestCase) *TranslateCCmpOutputStep {
831 const allocator = context.b.allocator;823 const allocator = context.b.allocator;
832 const ptr = allocator.create(TranslateCCmpOutputStep) catch unreachable;824 const ptr = allocator.create(TranslateCCmpOutputStep{
833 ptr.* = TranslateCCmpOutputStep{
834 .step = build.Step.init("ParseCCmpOutput", allocator, make),825 .step = build.Step.init("ParseCCmpOutput", allocator, make),
835 .context = context,826 .context = context,
836 .name = name,827 .name = name,
837 .test_index = context.test_index,828 .test_index = context.test_index,
838 .case = case,829 .case = case,
839 };830 }) catch unreachable;
831
840 context.test_index += 1;832 context.test_index += 1;
841 return ptr;833 return ptr;
842 }834 }
...@@ -936,13 +928,13 @@ pub const TranslateCContext = struct {...@@ -936,13 +928,13 @@ pub const TranslateCContext = struct {
936 }928 }
937929
938 pub fn create(self: *TranslateCContext, allow_warnings: bool, filename: []const u8, name: []const u8, source: []const u8, expected_lines: ...) *TestCase {930 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;931 const tc = self.b.allocator.create(TestCase{
940 tc.* = TestCase{
941 .name = name,932 .name = name,
942 .sources = ArrayList(TestCase.SourceFile).init(self.b.allocator),933 .sources = ArrayList(TestCase.SourceFile).init(self.b.allocator),
943 .expected_lines = ArrayList([]const u8).init(self.b.allocator),934 .expected_lines = ArrayList([]const u8).init(self.b.allocator),
944 .allow_warnings = allow_warnings,935 .allow_warnings = allow_warnings,
945 };936 }) catch unreachable;
937
946 tc.addSourceFile(filename, source);938 tc.addSourceFile(filename, source);
947 comptime var arg_i = 0;939 comptime var arg_i = 0;
948 inline while (arg_i < expected_lines.len) : (arg_i += 1) {940 inline while (arg_i < expected_lines.len) : (arg_i += 1) {
...@@ -1023,15 +1015,15 @@ pub const GenHContext = struct {...@@ -1023,15 +1015,15 @@ pub const GenHContext = struct {
10231015
1024 pub fn create(context: *GenHContext, h_path: []const u8, name: []const u8, case: *const TestCase) *GenHCmpOutputStep {1016 pub fn create(context: *GenHContext, h_path: []const u8, name: []const u8, case: *const TestCase) *GenHCmpOutputStep {
1025 const allocator = context.b.allocator;1017 const allocator = context.b.allocator;
1026 const ptr = allocator.create(GenHCmpOutputStep) catch unreachable;1018 const ptr = allocator.create(GenHCmpOutputStep{
1027 ptr.* = GenHCmpOutputStep{
1028 .step = build.Step.init("ParseCCmpOutput", allocator, make),1019 .step = build.Step.init("ParseCCmpOutput", allocator, make),
1029 .context = context,1020 .context = context,
1030 .h_path = h_path,1021 .h_path = h_path,
1031 .name = name,1022 .name = name,
1032 .test_index = context.test_index,1023 .test_index = context.test_index,
1033 .case = case,1024 .case = case,
1034 };1025 }) catch unreachable;
1026
1035 context.test_index += 1;1027 context.test_index += 1;
1036 return ptr;1028 return ptr;
1037 }1029 }
...@@ -1070,12 +1062,12 @@ pub const GenHContext = struct {...@@ -1070,12 +1062,12 @@ pub const GenHContext = struct {
1070 }1062 }
10711063
1072 pub fn create(self: *GenHContext, filename: []const u8, name: []const u8, source: []const u8, expected_lines: ...) *TestCase {1064 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;1065 const tc = self.b.allocator.create(TestCase{
1074 tc.* = TestCase{
1075 .name = name,1066 .name = name,
1076 .sources = ArrayList(TestCase.SourceFile).init(self.b.allocator),1067 .sources = ArrayList(TestCase.SourceFile).init(self.b.allocator),
1077 .expected_lines = ArrayList([]const u8).init(self.b.allocator),1068 .expected_lines = ArrayList([]const u8).init(self.b.allocator),
1078 };1069 }) catch unreachable;
1070
1079 tc.addSourceFile(filename, source);1071 tc.addSourceFile(filename, source);
1080 comptime var arg_i = 0;1072 comptime var arg_i = 0;
1081 inline while (arg_i < expected_lines.len) : (arg_i += 1) {1073 inline while (arg_i < expected_lines.len) : (arg_i += 1) {