| ... | ... | @@ -82,24 +82,24 @@ pub const TestContext = struct { |
| 82 | 82 | }; |
| 83 | 83 | |
| 84 | 84 | pub const ZIRUpdateType = enum { |
| 85 | | /// A transformation stage transforms the input ZIR and tests against |
| 85 | /// A transformation update transforms the input ZIR and tests against |
| 86 | 86 | /// the expected output |
| 87 | 87 | Transformation, |
| 88 | | /// An error stage attempts to compile bad code, and ensures that it |
| 88 | /// An error update attempts to compile bad code, and ensures that it |
| 89 | 89 | /// fails to compile, and for the expected reasons |
| 90 | 90 | Error, |
| 91 | | /// An execution stage compiles and runs the input ZIR, feeding in |
| 91 | /// An execution update compiles and runs the input ZIR, feeding in |
| 92 | 92 | /// provided input and ensuring that the outputs match what is expected |
| 93 | 93 | Execution, |
| 94 | | /// A compilation stage checks that the ZIR compiles without any issues |
| 94 | /// A compilation update checks that the ZIR compiles without any issues |
| 95 | 95 | Compiles, |
| 96 | 96 | }; |
| 97 | 97 | |
| 98 | 98 | pub const ZIRUpdate = struct { |
| 99 | | /// The input to the current stage. We simulate an incremental update |
| 100 | | /// with the file's contents changed to this value each stage. |
| 99 | /// The input to the current update. We simulate an incremental update |
| 100 | /// with the file's contents changed to this value each update. |
| 101 | 101 | /// |
| 102 | | /// This value can change entirely between stages, which would be akin |
| 102 | /// This value can change entirely between updates, which would be akin |
| 103 | 103 | /// to deleting the source file and creating a new one from scratch; or |
| 104 | 104 | /// you can keep it mostly consistent, with small changes, testing the |
| 105 | 105 | /// effects of the incremental compilation. |
| ... | ... | @@ -114,7 +114,7 @@ pub const TestContext = struct { |
| 114 | 114 | /// |
| 115 | 115 | /// If stdout, stderr, and exit_code are all null, addZIRCase will |
| 116 | 116 | /// discard the test. To test for successful compilation, use a |
| 117 | | /// dedicated Compile stage instead. |
| 117 | /// dedicated Compile update instead. |
| 118 | 118 | Execution: struct { |
| 119 | 119 | stdin: ?[]const u8, |
| 120 | 120 | stdout: ?[]const u8, |
| ... | ... | @@ -131,9 +131,9 @@ pub const TestContext = struct { |
| 131 | 131 | }, |
| 132 | 132 | }; |
| 133 | 133 | |
| 134 | | /// A ZIRCase consists of a set of *stages*. A stage can transform ZIR, |
| 134 | /// A ZIRCase consists of a set of *updates*. A update can transform ZIR, |
| 135 | 135 | /// compile it, ensure that compilation fails, and more. The same Module is |
| 136 | | /// used for each stage, so each stage's source is treated as a single file |
| 136 | /// used for each update, so each update's source is treated as a single file |
| 137 | 137 | /// being updated by the test harness and incrementally compiled. |
| 138 | 138 | pub const ZIRCase = struct { |
| 139 | 139 | name: []const u8, |
| ... | ... | @@ -141,19 +141,19 @@ pub const TestContext = struct { |
| 141 | 141 | /// such as QEMU is required for tests to complete. |
| 142 | 142 | /// |
| 143 | 143 | target: std.zig.CrossTarget, |
| 144 | | stages: []const ZIRUpdate, |
| 144 | updates: []const ZIRUpdate, |
| 145 | 145 | }; |
| 146 | 146 | |
| 147 | 147 | pub fn addZIRCase( |
| 148 | 148 | ctx: *TestContext, |
| 149 | 149 | name: []const u8, |
| 150 | 150 | target: std.zig.CrossTarget, |
| 151 | | stages: []const ZIRUpdate, |
| 151 | updates: []const ZIRUpdate, |
| 152 | 152 | ) void { |
| 153 | 153 | const case = ZIRCase{ |
| 154 | 154 | .name = name, |
| 155 | 155 | .target = target, |
| 156 | | .stages = stages, |
| 156 | .updates = updates, |
| 157 | 157 | }; |
| 158 | 158 | ctx.zir_cases.append(case) catch |err| std.debug.panic("Error: {}", .{err}); |
| 159 | 159 | } |
| ... | ... | @@ -297,7 +297,7 @@ pub const TestContext = struct { |
| 297 | 297 | const root_pkg = try Package.create(allocator, tmp.dir, ".", tmp_src_path); |
| 298 | 298 | defer root_pkg.destroy(); |
| 299 | 299 | |
| 300 | | var prg_node = root_node.start(case.name, case.stages.len); |
| 300 | var prg_node = root_node.start(case.name, case.updates.len); |
| 301 | 301 | prg_node.activate(); |
| 302 | 302 | defer prg_node.end(); |
| 303 | 303 | |
| ... | ... | @@ -318,33 +318,33 @@ pub const TestContext = struct { |
| 318 | 318 | }); |
| 319 | 319 | defer module.deinit(); |
| 320 | 320 | |
| 321 | | for (case.stages) |s| { |
| 321 | for (case.updates) |s| { |
| 322 | 322 | // TODO: remove before committing. This is for ZLS ;) |
| 323 | | const stage: ZIRUpdate = s; |
| 323 | const update: ZIRUpdate = s; |
| 324 | 324 | |
| 325 | | var stage_node = prg_node.start("update", 4); |
| 326 | | stage_node.activate(); |
| 327 | | defer stage_node.end(); |
| 325 | var update_node = prg_node.start("update", 4); |
| 326 | update_node.activate(); |
| 327 | defer update_node.end(); |
| 328 | 328 | |
| 329 | | var sync_node = stage_node.start("write", null); |
| 329 | var sync_node = update_node.start("write", null); |
| 330 | 330 | sync_node.activate(); |
| 331 | | try tmp.dir.writeFile(tmp_src_path, stage.src); |
| 331 | try tmp.dir.writeFile(tmp_src_path, update.src); |
| 332 | 332 | sync_node.end(); |
| 333 | 333 | |
| 334 | | var module_node = stage_node.start("parse/analysis/codegen", null); |
| 334 | var module_node = update_node.start("parse/analysis/codegen", null); |
| 335 | 335 | module_node.activate(); |
| 336 | 336 | try module.update(); |
| 337 | 337 | module_node.end(); |
| 338 | 338 | |
| 339 | | switch (stage.case) { |
| 339 | switch (update.case) { |
| 340 | 340 | .Transformation => |expected_output| { |
| 341 | | var emit_node = stage_node.start("emit", null); |
| 341 | var emit_node = update_node.start("emit", null); |
| 342 | 342 | emit_node.activate(); |
| 343 | 343 | var new_zir_module = try zir.emit(allocator, module); |
| 344 | 344 | defer new_zir_module.deinit(allocator); |
| 345 | 345 | emit_node.end(); |
| 346 | 346 | |
| 347 | | var write_node = stage_node.start("write", null); |
| 347 | var write_node = update_node.start("write", null); |
| 348 | 348 | write_node.activate(); |
| 349 | 349 | var out_zir = std.ArrayList(u8).init(allocator); |
| 350 | 350 | defer out_zir.deinit(); |