authorgravatar for noam@pixelhero.devNoam Preil <noam@pixelhero.dev> 2020-06-24 23:34:58-04:00
committergravatar for noam@pixelhero.devNoam Preil <noam@pixelhero.dev> 2020-06-24 23:34:58-04:00
logc88edbc46fbbdc5a97c9703d09097af5f8d2a653
tree839a36bb12fb8efc84c44481add210c34319ba17
parent5d7e981f95423b3b009e0d7eebccae6c856f68ca
signature Commit is signed but in an unrecognized format.

OOM -> catch unreachable


4 files changed, 46 insertions(+), 52 deletions(-)

src-self-hosted/test.zig+22-28
......@@ -66,26 +66,26 @@ pub const TestContext = struct {
6666
6767 /// Adds a subcase in which the module is updated with new ZIR, and the
6868 /// resulting ZIR is validated.
69 pub fn addTransform(self: *Case, src: [:0]const u8, result: [:0]const u8) !void {
70 try self.updates.append(.{
69 pub fn addTransform(self: *Case, src: [:0]const u8, result: [:0]const u8) void {
70 self.updates.append(.{
7171 .src = src,
7272 .case = .{ .Transformation = result },
73 });
73 }) catch unreachable;
7474 }
7575
76 pub fn addCompareOutput(self: *Case, src: [:0]const u8, result: []const u8) !void {
77 try self.updates.append(.{
76 pub fn addCompareOutput(self: *Case, src: [:0]const u8, result: []const u8) void {
77 self.updates.append(.{
7878 .src = src,
7979 .case = .{ .Execution = result },
80 });
80 }) catch unreachable;
8181 }
8282
8383 /// Adds a subcase in which the module is updated with invalid ZIR, and
8484 /// ensures that compilation fails for the expected reasons.
8585 ///
8686 /// Errors must be specified in sequential order.
87 pub fn addError(self: *Case, src: [:0]const u8, errors: []const []const u8) !void {
88 var array = try self.updates.allocator.alloc(ErrorMsg, errors.len);
87 pub fn addError(self: *Case, src: [:0]const u8, errors: []const []const u8) void {
88 var array = self.updates.allocator.alloc(ErrorMsg, errors.len) catch unreachable;
8989 for (errors) |e, i| {
9090 if (e[0] != ':') {
9191 @panic("Invalid test: error must be specified as follows:\n:line:column: error: message\n=========\n");
......@@ -118,7 +118,7 @@ pub const TestContext = struct {
118118 .column = column - 1,
119119 };
120120 }
121 try self.updates.append(.{ .src = src, .case = .{ .Error = array } });
121 self.updates.append(.{ .src = src, .case = .{ .Error = array } }) catch unreachable;
122122 }
123123 };
124124
......@@ -127,15 +127,14 @@ pub const TestContext = struct {
127127 name: []const u8,
128128 target: std.zig.CrossTarget,
129129 T: TestType,
130 ) !*Case {
131 const case = Case{
130 ) *Case {
131 ctx.cases.append(Case{
132132 .name = name,
133133 .target = target,
134134 .updates = std.ArrayList(Update).init(ctx.cases.allocator),
135135 .output_mode = .Exe,
136136 .@"type" = T,
137 };
138 try ctx.cases.append(case);
137 }) catch unreachable;
139138 return &ctx.cases.items[ctx.cases.items.len - 1];
140139 }
141140
......@@ -144,14 +143,14 @@ pub const TestContext = struct {
144143 name: []const u8,
145144 target: std.zig.CrossTarget,
146145 T: TestType,
147 ) !*Case {
148 try ctx.cases.append(Case{
146 ) *Case {
147 ctx.cases.append(Case{
149148 .name = name,
150149 .target = target,
151150 .updates = std.ArrayList(Update).init(ctx.cases.allocator),
152151 .output_mode = .Obj,
153152 .@"type" = T,
154 });
153 }) catch unreachable;
155154 return &ctx.cases.items[ctx.cases.items.len - 1];
156155 }
157156
......@@ -161,9 +160,8 @@ pub const TestContext = struct {
161160 T: TestType,
162161 src: [:0]const u8,
163162 expected_stdout: []const u8,
164 ) !void {
165 var c = try ctx.addExe(name, .{}, T);
166 try c.addCompareOutput(src, expected_stdout);
163 ) void {
164 ctx.addExe(name, .{}, T).addCompareOutput(src, expected_stdout);
167165 }
168166
169167 pub fn addTransform(
......@@ -173,9 +171,8 @@ pub const TestContext = struct {
173171 T: TestType,
174172 src: [:0]const u8,
175173 result: [:0]const u8,
176 ) !void {
177 var c = try ctx.addObj(name, target, T);
178 try c.addTransform(src, result);
174 ) void {
175 ctx.addObj(name, target, T).addTransform(src, result);
179176 }
180177
181178 pub fn addError(
......@@ -185,16 +182,13 @@ pub const TestContext = struct {
185182 T: TestType,
186183 src: [:0]const u8,
187184 expected_errors: []const []const u8,
188 ) !void {
189 var c = try ctx.addObj(name, target, T);
190 try c.addError(src, expected_errors);
185 ) void {
186 ctx.addObj(name, target, T).addError(src, expected_errors);
191187 }
192188
193189 fn init() TestContext {
194190 const allocator = std.heap.page_allocator;
195 return .{
196 .cases = std.ArrayList(Case).init(allocator),
197 };
191 return .{ .cases = std.ArrayList(Case).init(allocator) };
198192 }
199193
200194 fn deinit(self: *TestContext) void {
test/stage2/compare_output.zig+4-4
......@@ -17,9 +17,9 @@ pub fn addCases(ctx: *TestContext) !void {
1717 }
1818
1919 {
20 var case = try ctx.addExe("hello world with updates", linux_x64, .Zig);
20 var case = ctx.addExe("hello world with updates", linux_x64, .Zig);
2121 // Regular old hello world
22 try case.addCompareOutput(
22 case.addCompareOutput(
2323 \\export fn _start() noreturn {
2424 \\ print();
2525 \\
......@@ -51,7 +51,7 @@ pub fn addCases(ctx: *TestContext) !void {
5151 "Hello, World!\n",
5252 );
5353 // Now change the message only
54 try case.addCompareOutput(
54 case.addCompareOutput(
5555 \\export fn _start() noreturn {
5656 \\ print();
5757 \\
......@@ -83,7 +83,7 @@ pub fn addCases(ctx: *TestContext) !void {
8383 "What is up? This is a longer message that will force the data to be relocated in virtual address space.\n",
8484 );
8585 // Now we print it twice.
86 try case.addCompareOutput(
86 case.addCompareOutput(
8787 \\export fn _start() noreturn {
8888 \\ print();
8989 \\ print();
test/stage2/compile_errors.zig+12-12
......@@ -9,7 +9,7 @@ const linux_x64 = std.zig.CrossTarget{
99};
1010
1111pub fn addCases(ctx: *TestContext) !void {
12 try ctx.addError("call undefined local", linux_x64, .ZIR,
12 ctx.addError("call undefined local", linux_x64, .ZIR,
1313 \\@noreturn = primitive(noreturn)
1414 \\
1515 \\@start_fnty = fntype([], @noreturn, cc=Naked)
......@@ -19,7 +19,7 @@ pub fn addCases(ctx: *TestContext) !void {
1919 // TODO: address inconsistency in this message and the one in the next test
2020 , &[_][]const u8{":5:13: error: unrecognized identifier: %test"});
2121
22 try ctx.addError("call with non-existent target", linux_x64, .ZIR,
22 ctx.addError("call with non-existent target", linux_x64, .ZIR,
2323 \\@noreturn = primitive(noreturn)
2424 \\
2525 \\@start_fnty = fntype([], @noreturn, cc=Naked)
......@@ -31,7 +31,7 @@ pub fn addCases(ctx: *TestContext) !void {
3131 , &[_][]const u8{":5:13: error: decl 'notafunc' not found"});
3232
3333 // TODO: this error should occur at the call site, not the fntype decl
34 try ctx.addError("call naked function", linux_x64, .ZIR,
34 ctx.addError("call naked function", linux_x64, .ZIR,
3535 \\@noreturn = primitive(noreturn)
3636 \\
3737 \\@start_fnty = fntype([], @noreturn, cc=Naked)
......@@ -46,51 +46,51 @@ pub fn addCases(ctx: *TestContext) !void {
4646 // TODO: re-enable these tests.
4747 // https://github.com/ziglang/zig/issues/1364
4848
49 // try ctx.addError("Export same symbol twice", linux_x64, .Zig,
49 // ctx.addError("Export same symbol twice", linux_x64, .Zig,
5050 // \\export fn entry() void {}
5151 // \\export fn entry() void {}
5252 // , &[_][]const u8{":2:1: error: exported symbol collision"});
5353
54 // try ctx.addError("Missing function name", linux_x64, .Zig,
54 // ctx.addError("Missing function name", linux_x64, .Zig,
5555 // \\fn() void {}
5656 // , &[_][]const u8{":1:3: error: missing function name"});
57 //try ctx.testCompileError(
57 //ctx.testCompileError(
5858 // \\comptime {
5959 // \\ return;
6060 // \\}
6161 //, "1.zig", 2, 5, "return expression outside function definition");
6262
63 //try ctx.testCompileError(
63 //ctx.testCompileError(
6464 // \\export fn entry() void {
6565 // \\ defer return;
6666 // \\}
6767 //, "1.zig", 2, 11, "cannot return from defer expression");
6868
69 //try ctx.testCompileError(
69 //ctx.testCompileError(
7070 // \\export fn entry() c_int {
7171 // \\ return 36893488147419103232;
7272 // \\}
7373 //, "1.zig", 2, 12, "integer value '36893488147419103232' cannot be stored in type 'c_int'");
7474
75 //try ctx.testCompileError(
75 //ctx.testCompileError(
7676 // \\comptime {
7777 // \\ var a: *align(4) align(4) i32 = 0;
7878 // \\}
7979 //, "1.zig", 2, 22, "Extra align qualifier");
8080
81 //try ctx.testCompileError(
81 //ctx.testCompileError(
8282 // \\comptime {
8383 // \\ var b: *const const i32 = 0;
8484 // \\}
8585 //, "1.zig", 2, 19, "Extra align qualifier");
8686
87 //try ctx.testCompileError(
87 //ctx.testCompileError(
8888 // \\comptime {
8989 // \\ var c: *volatile volatile i32 = 0;
9090 // \\}
9191 //, "1.zig", 2, 22, "Extra align qualifier");
9292
93 //try ctx.testCompileError(
93 //ctx.testCompileError(
9494 // \\comptime {
9595 // \\ var d: *allowzero allowzero i32 = 0;
9696 // \\}
test/stage2/zir.zig+8-8
......@@ -9,7 +9,7 @@ const linux_x64 = std.zig.CrossTarget{
99};
1010
1111pub fn addCases(ctx: *TestContext) !void {
12 try ctx.addTransform("referencing decls which appear later in the file", linux_x64, .ZIR,
12 ctx.addTransform("referencing decls which appear later in the file", linux_x64, .ZIR,
1313 \\@void = primitive(void)
1414 \\@fnty = fntype([], @void, cc=C)
1515 \\
......@@ -32,7 +32,7 @@ pub fn addCases(ctx: *TestContext) !void {
3232 \\})
3333 \\
3434 );
35 try ctx.addTransform("elemptr, add, cmp, condbr, return, breakpoint", linux_x64, .ZIR,
35 ctx.addTransform("elemptr, add, cmp, condbr, return, breakpoint", linux_x64, .ZIR,
3636 \\@void = primitive(void)
3737 \\@usize = primitive(usize)
3838 \\@fnty = fntype([], @void, cc=C)
......@@ -86,8 +86,8 @@ pub fn addCases(ctx: *TestContext) !void {
8686 );
8787
8888 {
89 var case = try ctx.addObj("reference cycle with compile error in the cycle", linux_x64, .ZIR);
90 try case.addTransform(
89 var case = ctx.addObj("reference cycle with compile error in the cycle", linux_x64, .ZIR);
90 case.addTransform(
9191 \\@void = primitive(void)
9292 \\@fnty = fntype([], @void, cc=C)
9393 \\
......@@ -133,7 +133,7 @@ pub fn addCases(ctx: *TestContext) !void {
133133 \\
134134 );
135135 // Now we introduce a compile error
136 try case.addError(
136 case.addError(
137137 \\@void = primitive(void)
138138 \\@fnty = fntype([], @void, cc=C)
139139 \\
......@@ -163,7 +163,7 @@ pub fn addCases(ctx: *TestContext) !void {
163163 // Now we remove the call to `a`. `a` and `b` form a cycle, but no entry points are
164164 // referencing either of them. This tests that the cycle is detected, and the error
165165 // goes away.
166 try case.addTransform(
166 case.addTransform(
167167 \\@void = primitive(void)
168168 \\@fnty = fntype([], @void, cc=C)
169169 \\
......@@ -207,7 +207,7 @@ pub fn addCases(ctx: *TestContext) !void {
207207 return;
208208 }
209209
210 try ctx.addCompareOutput("hello world ZIR", .ZIR,
210 ctx.addCompareOutput("hello world ZIR", .ZIR,
211211 \\@noreturn = primitive(noreturn)
212212 \\@void = primitive(void)
213213 \\@usize = primitive(usize)
......@@ -265,7 +265,7 @@ pub fn addCases(ctx: *TestContext) !void {
265265 \\
266266 );
267267
268 try ctx.addCompareOutput("function call with no args no return value", .ZIR,
268 ctx.addCompareOutput("function call with no args no return value", .ZIR,
269269 \\@noreturn = primitive(noreturn)
270270 \\@void = primitive(void)
271271 \\@usize = primitive(usize)