Commit c88edbc46f

Noam Preil <pleasantatk@gmail.com>
2020-06-25 05:34:58
OOM -> catch unreachable
1 parent 5d7e981
Changed files (4)
src-self-hosted/test.zig
@@ -66,26 +66,26 @@ pub const TestContext = struct {
 
         /// Adds a subcase in which the module is updated with new ZIR, and the
         /// resulting ZIR is validated.
-        pub fn addTransform(self: *Case, src: [:0]const u8, result: [:0]const u8) !void {
-            try self.updates.append(.{
+        pub fn addTransform(self: *Case, src: [:0]const u8, result: [:0]const u8) void {
+            self.updates.append(.{
                 .src = src,
                 .case = .{ .Transformation = result },
-            });
+            }) catch unreachable;
         }
 
-        pub fn addCompareOutput(self: *Case, src: [:0]const u8, result: []const u8) !void {
-            try self.updates.append(.{
+        pub fn addCompareOutput(self: *Case, src: [:0]const u8, result: []const u8) void {
+            self.updates.append(.{
                 .src = src,
                 .case = .{ .Execution = result },
-            });
+            }) catch unreachable;
         }
 
         /// Adds a subcase in which the module is updated with invalid ZIR, and
         /// ensures that compilation fails for the expected reasons.
         ///
         /// Errors must be specified in sequential order.
-        pub fn addError(self: *Case, src: [:0]const u8, errors: []const []const u8) !void {
-            var array = try self.updates.allocator.alloc(ErrorMsg, errors.len);
+        pub fn addError(self: *Case, src: [:0]const u8, errors: []const []const u8) void {
+            var array = self.updates.allocator.alloc(ErrorMsg, errors.len) catch unreachable;
             for (errors) |e, i| {
                 if (e[0] != ':') {
                     @panic("Invalid test: error must be specified as follows:\n:line:column: error: message\n=========\n");
@@ -118,7 +118,7 @@ pub const TestContext = struct {
                     .column = column - 1,
                 };
             }
-            try self.updates.append(.{ .src = src, .case = .{ .Error = array } });
+            self.updates.append(.{ .src = src, .case = .{ .Error = array } }) catch unreachable;
         }
     };
 
@@ -127,15 +127,14 @@ pub const TestContext = struct {
         name: []const u8,
         target: std.zig.CrossTarget,
         T: TestType,
-    ) !*Case {
-        const case = Case{
+    ) *Case {
+        ctx.cases.append(Case{
             .name = name,
             .target = target,
             .updates = std.ArrayList(Update).init(ctx.cases.allocator),
             .output_mode = .Exe,
             .@"type" = T,
-        };
-        try ctx.cases.append(case);
+        }) catch unreachable;
         return &ctx.cases.items[ctx.cases.items.len - 1];
     }
 
@@ -144,14 +143,14 @@ pub const TestContext = struct {
         name: []const u8,
         target: std.zig.CrossTarget,
         T: TestType,
-    ) !*Case {
-        try ctx.cases.append(Case{
+    ) *Case {
+        ctx.cases.append(Case{
             .name = name,
             .target = target,
             .updates = std.ArrayList(Update).init(ctx.cases.allocator),
             .output_mode = .Obj,
             .@"type" = T,
-        });
+        }) catch unreachable;
         return &ctx.cases.items[ctx.cases.items.len - 1];
     }
 
@@ -161,9 +160,8 @@ pub const TestContext = struct {
         T: TestType,
         src: [:0]const u8,
         expected_stdout: []const u8,
-    ) !void {
-        var c = try ctx.addExe(name, .{}, T);
-        try c.addCompareOutput(src, expected_stdout);
+    ) void {
+        ctx.addExe(name, .{}, T).addCompareOutput(src, expected_stdout);
     }
 
     pub fn addTransform(
@@ -173,9 +171,8 @@ pub const TestContext = struct {
         T: TestType,
         src: [:0]const u8,
         result: [:0]const u8,
-    ) !void {
-        var c = try ctx.addObj(name, target, T);
-        try c.addTransform(src, result);
+    ) void {
+        ctx.addObj(name, target, T).addTransform(src, result);
     }
 
     pub fn addError(
@@ -185,16 +182,13 @@ pub const TestContext = struct {
         T: TestType,
         src: [:0]const u8,
         expected_errors: []const []const u8,
-    ) !void {
-        var c = try ctx.addObj(name, target, T);
-        try c.addError(src, expected_errors);
+    ) void {
+        ctx.addObj(name, target, T).addError(src, expected_errors);
     }
 
     fn init() TestContext {
         const allocator = std.heap.page_allocator;
-        return .{
-            .cases = std.ArrayList(Case).init(allocator),
-        };
+        return .{ .cases = std.ArrayList(Case).init(allocator) };
     }
 
     fn deinit(self: *TestContext) void {
test/stage2/compare_output.zig
@@ -17,9 +17,9 @@ pub fn addCases(ctx: *TestContext) !void {
     }
 
     {
-        var case = try ctx.addExe("hello world with updates", linux_x64, .Zig);
+        var case = ctx.addExe("hello world with updates", linux_x64, .Zig);
         // Regular old hello world
-        try case.addCompareOutput(
+        case.addCompareOutput(
             \\export fn _start() noreturn {
             \\    print();
             \\
@@ -51,7 +51,7 @@ pub fn addCases(ctx: *TestContext) !void {
             "Hello, World!\n",
         );
         // Now change the message only
-        try case.addCompareOutput(
+        case.addCompareOutput(
             \\export fn _start() noreturn {
             \\    print();
             \\
@@ -83,7 +83,7 @@ pub fn addCases(ctx: *TestContext) !void {
             "What is up? This is a longer message that will force the data to be relocated in virtual address space.\n",
         );
         // Now we print it twice.
-        try case.addCompareOutput(
+        case.addCompareOutput(
             \\export fn _start() noreturn {
             \\    print();
             \\    print();
test/stage2/compile_errors.zig
@@ -9,7 +9,7 @@ const linux_x64 = std.zig.CrossTarget{
 };
 
 pub fn addCases(ctx: *TestContext) !void {
-    try ctx.addError("call undefined local", linux_x64, .ZIR,
+    ctx.addError("call undefined local", linux_x64, .ZIR,
         \\@noreturn = primitive(noreturn)
         \\
         \\@start_fnty = fntype([], @noreturn, cc=Naked)
@@ -19,7 +19,7 @@ pub fn addCases(ctx: *TestContext) !void {
  // TODO: address inconsistency in this message and the one in the next test
             , &[_][]const u8{":5:13: error: unrecognized identifier: %test"});
 
-    try ctx.addError("call with non-existent target", linux_x64, .ZIR,
+    ctx.addError("call with non-existent target", linux_x64, .ZIR,
         \\@noreturn = primitive(noreturn)
         \\
         \\@start_fnty = fntype([], @noreturn, cc=Naked)
@@ -31,7 +31,7 @@ pub fn addCases(ctx: *TestContext) !void {
     , &[_][]const u8{":5:13: error: decl 'notafunc' not found"});
 
     // TODO: this error should occur at the call site, not the fntype decl
-    try ctx.addError("call naked function", linux_x64, .ZIR,
+    ctx.addError("call naked function", linux_x64, .ZIR,
         \\@noreturn = primitive(noreturn)
         \\
         \\@start_fnty = fntype([], @noreturn, cc=Naked)
@@ -46,51 +46,51 @@ pub fn addCases(ctx: *TestContext) !void {
     // TODO: re-enable these tests.
     // https://github.com/ziglang/zig/issues/1364
 
-    //  try ctx.addError("Export same symbol twice", linux_x64, .Zig,
+    //  ctx.addError("Export same symbol twice", linux_x64, .Zig,
     //      \\export fn entry() void {}
     //      \\export fn entry() void {}
     //  , &[_][]const u8{":2:1: error: exported symbol collision"});
 
-    //    try ctx.addError("Missing function name", linux_x64, .Zig,
+    //    ctx.addError("Missing function name", linux_x64, .Zig,
     //        \\fn() void {}
     //    , &[_][]const u8{":1:3: error: missing function name"});
-    //try ctx.testCompileError(
+    //ctx.testCompileError(
     //    \\comptime {
     //    \\    return;
     //    \\}
     //, "1.zig", 2, 5, "return expression outside function definition");
 
-    //try ctx.testCompileError(
+    //ctx.testCompileError(
     //    \\export fn entry() void {
     //    \\    defer return;
     //    \\}
     //, "1.zig", 2, 11, "cannot return from defer expression");
 
-    //try ctx.testCompileError(
+    //ctx.testCompileError(
     //    \\export fn entry() c_int {
     //    \\    return 36893488147419103232;
     //    \\}
     //, "1.zig", 2, 12, "integer value '36893488147419103232' cannot be stored in type 'c_int'");
 
-    //try ctx.testCompileError(
+    //ctx.testCompileError(
     //    \\comptime {
     //    \\    var a: *align(4) align(4) i32 = 0;
     //    \\}
     //, "1.zig", 2, 22, "Extra align qualifier");
 
-    //try ctx.testCompileError(
+    //ctx.testCompileError(
     //    \\comptime {
     //    \\    var b: *const const i32 = 0;
     //    \\}
     //, "1.zig", 2, 19, "Extra align qualifier");
 
-    //try ctx.testCompileError(
+    //ctx.testCompileError(
     //    \\comptime {
     //    \\    var c: *volatile volatile i32 = 0;
     //    \\}
     //, "1.zig", 2, 22, "Extra align qualifier");
 
-    //try ctx.testCompileError(
+    //ctx.testCompileError(
     //    \\comptime {
     //    \\    var d: *allowzero allowzero i32 = 0;
     //    \\}
test/stage2/zir.zig
@@ -9,7 +9,7 @@ const linux_x64 = std.zig.CrossTarget{
 };
 
 pub fn addCases(ctx: *TestContext) !void {
-    try ctx.addTransform("referencing decls which appear later in the file", linux_x64, .ZIR,
+    ctx.addTransform("referencing decls which appear later in the file", linux_x64, .ZIR,
         \\@void = primitive(void)
         \\@fnty = fntype([], @void, cc=C)
         \\
@@ -32,7 +32,7 @@ pub fn addCases(ctx: *TestContext) !void {
         \\})
         \\
     );
-    try ctx.addTransform("elemptr, add, cmp, condbr, return, breakpoint", linux_x64, .ZIR,
+    ctx.addTransform("elemptr, add, cmp, condbr, return, breakpoint", linux_x64, .ZIR,
         \\@void = primitive(void)
         \\@usize = primitive(usize)
         \\@fnty = fntype([], @void, cc=C)
@@ -86,8 +86,8 @@ pub fn addCases(ctx: *TestContext) !void {
     );
 
     {
-        var case = try ctx.addObj("reference cycle with compile error in the cycle", linux_x64, .ZIR);
-        try case.addTransform(
+        var case = ctx.addObj("reference cycle with compile error in the cycle", linux_x64, .ZIR);
+        case.addTransform(
             \\@void = primitive(void)
             \\@fnty = fntype([], @void, cc=C)
             \\
@@ -133,7 +133,7 @@ pub fn addCases(ctx: *TestContext) !void {
             \\
         );
         // Now we introduce a compile error
-        try case.addError(
+        case.addError(
             \\@void = primitive(void)
             \\@fnty = fntype([], @void, cc=C)
             \\
@@ -163,7 +163,7 @@ pub fn addCases(ctx: *TestContext) !void {
         // Now we remove the call to `a`. `a` and `b` form a cycle, but no entry points are
         // referencing either of them. This tests that the cycle is detected, and the error
         // goes away.
-        try case.addTransform(
+        case.addTransform(
             \\@void = primitive(void)
             \\@fnty = fntype([], @void, cc=C)
             \\
@@ -207,7 +207,7 @@ pub fn addCases(ctx: *TestContext) !void {
         return;
     }
 
-    try ctx.addCompareOutput("hello world ZIR", .ZIR,
+    ctx.addCompareOutput("hello world ZIR", .ZIR,
         \\@noreturn = primitive(noreturn)
         \\@void = primitive(void)
         \\@usize = primitive(usize)
@@ -265,7 +265,7 @@ pub fn addCases(ctx: *TestContext) !void {
         \\
     );
 
-    try ctx.addCompareOutput("function call with no args no return value", .ZIR,
+    ctx.addCompareOutput("function call with no args no return value", .ZIR,
         \\@noreturn = primitive(noreturn)
         \\@void = primitive(void)
         \\@usize = primitive(usize)