authorgravatar for 58830309+g-w1@users.noreply.github.comg-w1 <58830309+g-w1@users.noreply.github.com> 2021-04-09 02:11:33-04:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2021-04-09 02:11:33-04:00
logc6791d87d4f49598aab54064df683fc86e97dbd9
tree1622d848a9bdb17eacf8bf69678c12c1bd3861f2
parent23db96931e5226f09a451663ba1c8bf2398af91b
signature Signed by PGP key 4AEE18F83AFDEB23

stage2: delete allowing input (and output) zir from the pipeline (#8471)

Remove -femit-zir as we aren't going to need it. Also remove zir test code This removes a TODO that asserts the file is not zir.

3 files changed, 18 insertions(+), 62 deletions(-)

src/Compilation.zig+1-11
...@@ -939,11 +939,6 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation {...@@ -939,11 +939,6 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation {
939 // However we currently do not have serialization of such metadata, so for now939 // However we currently do not have serialization of such metadata, so for now
940 // we set up an empty Module that does the entire compilation fresh.940 // we set up an empty Module that does the entire compilation fresh.
941941
942 // TODO remove CLI support for .zir files and then we can remove this error
943 // handling and assertion.
944 if (mem.endsWith(u8, root_pkg.root_src_path, ".zir")) return error.ZirFilesUnsupported;
945 assert(mem.endsWith(u8, root_pkg.root_src_path, ".zig"));
946
947 const root_scope = try gpa.create(Module.Scope.File);942 const root_scope = try gpa.create(Module.Scope.File);
948 errdefer gpa.destroy(root_scope);943 errdefer gpa.destroy(root_scope);
949944
...@@ -2487,7 +2482,7 @@ pub fn addCCArgs(...@@ -2487,7 +2482,7 @@ pub fn addCCArgs(
2487 try argv.append("-fPIC");2482 try argv.append("-fPIC");
2488 }2483 }
2489 },2484 },
2490 .shared_library, .assembly, .ll, .bc, .unknown, .static_library, .object, .zig, .zir => {},2485 .shared_library, .assembly, .ll, .bc, .unknown, .static_library, .object, .zig => {},
2491 }2486 }
2492 if (out_dep_path) |p| {2487 if (out_dep_path) |p| {
2493 try argv.appendSlice(&[_][]const u8{ "-MD", "-MV", "-MF", p });2488 try argv.appendSlice(&[_][]const u8{ "-MD", "-MV", "-MF", p });
...@@ -2561,7 +2556,6 @@ pub const FileExt = enum {...@@ -2561,7 +2556,6 @@ pub const FileExt = enum {
2561 object,2556 object,
2562 static_library,2557 static_library,
2563 zig,2558 zig,
2564 zir,
2565 unknown,2559 unknown,
25662560
2567 pub fn clangSupportsDepFile(ext: FileExt) bool {2561 pub fn clangSupportsDepFile(ext: FileExt) bool {
...@@ -2575,7 +2569,6 @@ pub const FileExt = enum {...@@ -2575,7 +2569,6 @@ pub const FileExt = enum {
2575 .object,2569 .object,
2576 .static_library,2570 .static_library,
2577 .zig,2571 .zig,
2578 .zir,
2579 .unknown,2572 .unknown,
2580 => false,2573 => false,
2581 };2574 };
...@@ -2647,8 +2640,6 @@ pub fn classifyFileExt(filename: []const u8) FileExt {...@@ -2647,8 +2640,6 @@ pub fn classifyFileExt(filename: []const u8) FileExt {
2647 return .h;2640 return .h;
2648 } else if (mem.endsWith(u8, filename, ".zig")) {2641 } else if (mem.endsWith(u8, filename, ".zig")) {
2649 return .zig;2642 return .zig;
2650 } else if (mem.endsWith(u8, filename, ".zir")) {
2651 return .zir;
2652 } else if (hasSharedLibraryExt(filename)) {2643 } else if (hasSharedLibraryExt(filename)) {
2653 return .shared_library;2644 return .shared_library;
2654 } else if (hasStaticLibraryExt(filename)) {2645 } else if (hasStaticLibraryExt(filename)) {
...@@ -2669,7 +2660,6 @@ test "classifyFileExt" {...@@ -2669,7 +2660,6 @@ test "classifyFileExt" {
2669 std.testing.expectEqual(FileExt.shared_library, classifyFileExt("foo.so.1.2.3"));2660 std.testing.expectEqual(FileExt.shared_library, classifyFileExt("foo.so.1.2.3"));
2670 std.testing.expectEqual(FileExt.unknown, classifyFileExt("foo.so.1.2.3~"));2661 std.testing.expectEqual(FileExt.unknown, classifyFileExt("foo.so.1.2.3~"));
2671 std.testing.expectEqual(FileExt.zig, classifyFileExt("foo.zig"));2662 std.testing.expectEqual(FileExt.zig, classifyFileExt("foo.zig"));
2672 std.testing.expectEqual(FileExt.zir, classifyFileExt("foo.zir"));
2673}2663}
26742664
2675fn haveFramePointer(comp: *const Compilation) bool {2665fn haveFramePointer(comp: *const Compilation) bool {
src/main.zig+2-16
...@@ -505,7 +505,6 @@ fn buildOutputType(...@@ -505,7 +505,6 @@ fn buildOutputType(
505 var emit_bin: EmitBin = .yes_default_path;505 var emit_bin: EmitBin = .yes_default_path;
506 var emit_asm: Emit = .no;506 var emit_asm: Emit = .no;
507 var emit_llvm_ir: Emit = .no;507 var emit_llvm_ir: Emit = .no;
508 var emit_zir: Emit = .no;
509 var emit_docs: Emit = .no;508 var emit_docs: Emit = .no;
510 var emit_analysis: Emit = .no;509 var emit_analysis: Emit = .no;
511 var target_arch_os_abi: []const u8 = "native";510 var target_arch_os_abi: []const u8 = "native";
...@@ -923,12 +922,6 @@ fn buildOutputType(...@@ -923,12 +922,6 @@ fn buildOutputType(
923 emit_bin = .{ .yes = arg["-femit-bin=".len..] };922 emit_bin = .{ .yes = arg["-femit-bin=".len..] };
924 } else if (mem.eql(u8, arg, "-fno-emit-bin")) {923 } else if (mem.eql(u8, arg, "-fno-emit-bin")) {
925 emit_bin = .no;924 emit_bin = .no;
926 } else if (mem.eql(u8, arg, "-femit-zir")) {
927 emit_zir = .yes_default_path;
928 } else if (mem.startsWith(u8, arg, "-femit-zir=")) {
929 emit_zir = .{ .yes = arg["-femit-zir=".len..] };
930 } else if (mem.eql(u8, arg, "-fno-emit-zir")) {
931 emit_zir = .no;
932 } else if (mem.eql(u8, arg, "-femit-h")) {925 } else if (mem.eql(u8, arg, "-femit-h")) {
933 emit_h = .yes_default_path;926 emit_h = .yes_default_path;
934 } else if (mem.startsWith(u8, arg, "-femit-h=")) {927 } else if (mem.startsWith(u8, arg, "-femit-h=")) {
...@@ -1025,7 +1018,7 @@ fn buildOutputType(...@@ -1025,7 +1018,7 @@ fn buildOutputType(
1025 .extra_flags = try arena.dupe([]const u8, extra_cflags.items),1018 .extra_flags = try arena.dupe([]const u8, extra_cflags.items),
1026 });1019 });
1027 },1020 },
1028 .zig, .zir => {1021 .zig => {
1029 if (root_src_file) |other| {1022 if (root_src_file) |other| {
1030 fatal("found another zig file '{s}' after root source file '{s}'", .{ arg, other });1023 fatal("found another zig file '{s}' after root source file '{s}'", .{ arg, other });
1031 } else {1024 } else {
...@@ -1086,7 +1079,7 @@ fn buildOutputType(...@@ -1086,7 +1079,7 @@ fn buildOutputType(
1086 .unknown, .shared_library, .object, .static_library => {1079 .unknown, .shared_library, .object, .static_library => {
1087 try link_objects.append(it.only_arg);1080 try link_objects.append(it.only_arg);
1088 },1081 },
1089 .zig, .zir => {1082 .zig => {
1090 if (root_src_file) |other| {1083 if (root_src_file) |other| {
1091 fatal("found another zig file '{s}' after root source file '{s}'", .{ it.only_arg, other });1084 fatal("found another zig file '{s}' after root source file '{s}'", .{ it.only_arg, other });
1092 } else {1085 } else {
...@@ -1724,13 +1717,6 @@ fn buildOutputType(...@@ -1724,13 +1717,6 @@ fn buildOutputType(
1724 var emit_docs_resolved = try emit_docs.resolve("docs");1717 var emit_docs_resolved = try emit_docs.resolve("docs");
1725 defer emit_docs_resolved.deinit();1718 defer emit_docs_resolved.deinit();
17261719
1727 switch (emit_zir) {
1728 .no => {},
1729 .yes_default_path, .yes => {
1730 fatal("The -femit-zir implementation has been intentionally deleted so that it can be rewritten as a proper backend.", .{});
1731 },
1732 }
1733
1734 const root_pkg: ?*Package = if (root_src_file) |src_path| blk: {1720 const root_pkg: ?*Package = if (root_src_file) |src_path| blk: {
1735 if (main_pkg_path) |p| {1721 if (main_pkg_path) |p| {
1736 const rel_src_path = try fs.path.relative(gpa, p, src_path);1722 const rel_src_path = try fs.path.relative(gpa, p, src_path);
src/test.zig+15-35
...@@ -122,11 +122,6 @@ pub const TestContext = struct {...@@ -122,11 +122,6 @@ pub const TestContext = struct {
122 path: []const u8,122 path: []const u8,
123 };123 };
124124
125 pub const Extension = enum {
126 Zig,
127 ZIR,
128 };
129
130 /// A `Case` consists of a list of `Update`. The same `Compilation` is used for each125 /// A `Case` consists of a list of `Update`. The same `Compilation` is used for each
131 /// update, so each update's source is treated as a single file being126 /// update, so each update's source is treated as a single file being
132 /// updated by the test harness and incrementally compiled.127 /// updated by the test harness and incrementally compiled.
...@@ -141,7 +136,6 @@ pub const TestContext = struct {...@@ -141,7 +136,6 @@ pub const TestContext = struct {
141 /// to Executable.136 /// to Executable.
142 output_mode: std.builtin.OutputMode,137 output_mode: std.builtin.OutputMode,
143 updates: std.ArrayList(Update),138 updates: std.ArrayList(Update),
144 extension: Extension,
145 object_format: ?std.builtin.ObjectFormat = null,139 object_format: ?std.builtin.ObjectFormat = null,
146 emit_h: bool = false,140 emit_h: bool = false,
147 llvm_backend: bool = false,141 llvm_backend: bool = false,
...@@ -238,14 +232,12 @@ pub const TestContext = struct {...@@ -238,14 +232,12 @@ pub const TestContext = struct {
238 ctx: *TestContext,232 ctx: *TestContext,
239 name: []const u8,233 name: []const u8,
240 target: CrossTarget,234 target: CrossTarget,
241 extension: Extension,
242 ) *Case {235 ) *Case {
243 ctx.cases.append(Case{236 ctx.cases.append(Case{
244 .name = name,237 .name = name,
245 .target = target,238 .target = target,
246 .updates = std.ArrayList(Update).init(ctx.cases.allocator),239 .updates = std.ArrayList(Update).init(ctx.cases.allocator),
247 .output_mode = .Exe,240 .output_mode = .Exe,
248 .extension = extension,
249 .files = std.ArrayList(File).init(ctx.cases.allocator),241 .files = std.ArrayList(File).init(ctx.cases.allocator),
250 }) catch @panic("out of memory");242 }) catch @panic("out of memory");
251 return &ctx.cases.items[ctx.cases.items.len - 1];243 return &ctx.cases.items[ctx.cases.items.len - 1];
...@@ -253,7 +245,7 @@ pub const TestContext = struct {...@@ -253,7 +245,7 @@ pub const TestContext = struct {
253245
254 /// Adds a test case for Zig input, producing an executable246 /// Adds a test case for Zig input, producing an executable
255 pub fn exe(ctx: *TestContext, name: []const u8, target: CrossTarget) *Case {247 pub fn exe(ctx: *TestContext, name: []const u8, target: CrossTarget) *Case {
256 return ctx.addExe(name, target, .Zig);248 return ctx.addExe(name, target);
257 }249 }
258250
259 /// Adds a test case for ZIR input, producing an executable251 /// Adds a test case for ZIR input, producing an executable
...@@ -269,7 +261,6 @@ pub const TestContext = struct {...@@ -269,7 +261,6 @@ pub const TestContext = struct {
269 .target = target,261 .target = target,
270 .updates = std.ArrayList(Update).init(ctx.cases.allocator),262 .updates = std.ArrayList(Update).init(ctx.cases.allocator),
271 .output_mode = .Exe,263 .output_mode = .Exe,
272 .extension = .Zig,
273 .object_format = .c,264 .object_format = .c,
274 .files = std.ArrayList(File).init(ctx.cases.allocator),265 .files = std.ArrayList(File).init(ctx.cases.allocator),
275 }) catch @panic("out of memory");266 }) catch @panic("out of memory");
...@@ -284,7 +275,6 @@ pub const TestContext = struct {...@@ -284,7 +275,6 @@ pub const TestContext = struct {
284 .target = target,275 .target = target,
285 .updates = std.ArrayList(Update).init(ctx.cases.allocator),276 .updates = std.ArrayList(Update).init(ctx.cases.allocator),
286 .output_mode = .Exe,277 .output_mode = .Exe,
287 .extension = .Zig,
288 .files = std.ArrayList(File).init(ctx.cases.allocator),278 .files = std.ArrayList(File).init(ctx.cases.allocator),
289 .llvm_backend = true,279 .llvm_backend = true,
290 }) catch @panic("out of memory");280 }) catch @panic("out of memory");
...@@ -295,14 +285,12 @@ pub const TestContext = struct {...@@ -295,14 +285,12 @@ pub const TestContext = struct {
295 ctx: *TestContext,285 ctx: *TestContext,
296 name: []const u8,286 name: []const u8,
297 target: CrossTarget,287 target: CrossTarget,
298 extension: Extension,
299 ) *Case {288 ) *Case {
300 ctx.cases.append(Case{289 ctx.cases.append(Case{
301 .name = name,290 .name = name,
302 .target = target,291 .target = target,
303 .updates = std.ArrayList(Update).init(ctx.cases.allocator),292 .updates = std.ArrayList(Update).init(ctx.cases.allocator),
304 .output_mode = .Obj,293 .output_mode = .Obj,
305 .extension = extension,
306 .files = std.ArrayList(File).init(ctx.cases.allocator),294 .files = std.ArrayList(File).init(ctx.cases.allocator),
307 }) catch @panic("out of memory");295 }) catch @panic("out of memory");
308 return &ctx.cases.items[ctx.cases.items.len - 1];296 return &ctx.cases.items[ctx.cases.items.len - 1];
...@@ -310,7 +298,7 @@ pub const TestContext = struct {...@@ -310,7 +298,7 @@ pub const TestContext = struct {
310298
311 /// Adds a test case for Zig input, producing an object file.299 /// Adds a test case for Zig input, producing an object file.
312 pub fn obj(ctx: *TestContext, name: []const u8, target: CrossTarget) *Case {300 pub fn obj(ctx: *TestContext, name: []const u8, target: CrossTarget) *Case {
313 return ctx.addObj(name, target, .Zig);301 return ctx.addObj(name, target);
314 }302 }
315303
316 /// Adds a test case for ZIR input, producing an object file.304 /// Adds a test case for ZIR input, producing an object file.
...@@ -319,13 +307,12 @@ pub const TestContext = struct {...@@ -319,13 +307,12 @@ pub const TestContext = struct {
319 }307 }
320308
321 /// Adds a test case for Zig or ZIR input, producing C code.309 /// Adds a test case for Zig or ZIR input, producing C code.
322 pub fn addC(ctx: *TestContext, name: []const u8, target: CrossTarget, ext: Extension) *Case {310 pub fn addC(ctx: *TestContext, name: []const u8, target: CrossTarget) *Case {
323 ctx.cases.append(Case{311 ctx.cases.append(Case{
324 .name = name,312 .name = name,
325 .target = target,313 .target = target,
326 .updates = std.ArrayList(Update).init(ctx.cases.allocator),314 .updates = std.ArrayList(Update).init(ctx.cases.allocator),
327 .output_mode = .Obj,315 .output_mode = .Obj,
328 .extension = ext,
329 .object_format = .c,316 .object_format = .c,
330 .files = std.ArrayList(File).init(ctx.cases.allocator),317 .files = std.ArrayList(File).init(ctx.cases.allocator),
331 }) catch @panic("out of memory");318 }) catch @panic("out of memory");
...@@ -333,21 +320,20 @@ pub const TestContext = struct {...@@ -333,21 +320,20 @@ pub const TestContext = struct {
333 }320 }
334321
335 pub fn c(ctx: *TestContext, name: []const u8, target: CrossTarget, src: [:0]const u8, comptime out: [:0]const u8) void {322 pub fn c(ctx: *TestContext, name: []const u8, target: CrossTarget, src: [:0]const u8, comptime out: [:0]const u8) void {
336 ctx.addC(name, target, .Zig).addCompareObjectFile(src, zig_h ++ out);323 ctx.addC(name, target).addCompareObjectFile(src, zig_h ++ out);
337 }324 }
338325
339 pub fn h(ctx: *TestContext, name: []const u8, target: CrossTarget, src: [:0]const u8, comptime out: [:0]const u8) void {326 pub fn h(ctx: *TestContext, name: []const u8, target: CrossTarget, src: [:0]const u8, comptime out: [:0]const u8) void {
340 ctx.addC(name, target, .Zig).addHeader(src, zig_h ++ out);327 ctx.addC(name, target).addHeader(src, zig_h ++ out);
341 }328 }
342329
343 pub fn addCompareOutput(330 pub fn addCompareOutput(
344 ctx: *TestContext,331 ctx: *TestContext,
345 name: []const u8,332 name: []const u8,
346 extension: Extension,
347 src: [:0]const u8,333 src: [:0]const u8,
348 expected_stdout: []const u8,334 expected_stdout: []const u8,
349 ) void {335 ) void {
350 ctx.addExe(name, .{}, extension).addCompareOutput(src, expected_stdout);336 ctx.addExe(name, .{}).addCompareOutput(src, expected_stdout);
351 }337 }
352338
353 /// Adds a test case that compiles the Zig source given in `src`, executes339 /// Adds a test case that compiles the Zig source given in `src`, executes
...@@ -358,7 +344,7 @@ pub const TestContext = struct {...@@ -358,7 +344,7 @@ pub const TestContext = struct {
358 src: [:0]const u8,344 src: [:0]const u8,
359 expected_stdout: []const u8,345 expected_stdout: []const u8,
360 ) void {346 ) void {
361 return ctx.addCompareOutput(name, .Zig, src, expected_stdout);347 return ctx.addCompareOutput(name, src, expected_stdout);
362 }348 }
363349
364 /// Adds a test case that compiles the ZIR source given in `src`, executes350 /// Adds a test case that compiles the ZIR source given in `src`, executes
...@@ -376,11 +362,10 @@ pub const TestContext = struct {...@@ -376,11 +362,10 @@ pub const TestContext = struct {
376 ctx: *TestContext,362 ctx: *TestContext,
377 name: []const u8,363 name: []const u8,
378 target: CrossTarget,364 target: CrossTarget,
379 extension: Extension,
380 src: [:0]const u8,365 src: [:0]const u8,
381 result: [:0]const u8,366 result: [:0]const u8,
382 ) void {367 ) void {
383 ctx.addObj(name, target, extension).addTransform(src, result);368 ctx.addObj(name, target).addTransform(src, result);
384 }369 }
385370
386 /// Adds a test case that compiles the Zig given in `src` to ZIR and tests371 /// Adds a test case that compiles the Zig given in `src` to ZIR and tests
...@@ -392,7 +377,7 @@ pub const TestContext = struct {...@@ -392,7 +377,7 @@ pub const TestContext = struct {
392 src: [:0]const u8,377 src: [:0]const u8,
393 result: [:0]const u8,378 result: [:0]const u8,
394 ) void {379 ) void {
395 ctx.addTransform(name, target, .Zig, src, result);380 ctx.addTransform(name, target, src, result);
396 }381 }
397382
398 /// Adds a test case that cleans up the ZIR source given in `src`, and383 /// Adds a test case that cleans up the ZIR source given in `src`, and
...@@ -411,11 +396,10 @@ pub const TestContext = struct {...@@ -411,11 +396,10 @@ pub const TestContext = struct {
411 ctx: *TestContext,396 ctx: *TestContext,
412 name: []const u8,397 name: []const u8,
413 target: CrossTarget,398 target: CrossTarget,
414 extension: Extension,
415 src: [:0]const u8,399 src: [:0]const u8,
416 expected_errors: []const []const u8,400 expected_errors: []const []const u8,
417 ) void {401 ) void {
418 ctx.addObj(name, target, extension).addError(src, expected_errors);402 ctx.addObj(name, target).addError(src, expected_errors);
419 }403 }
420404
421 /// Adds a test case that ensures that the Zig given in `src` fails to405 /// Adds a test case that ensures that the Zig given in `src` fails to
...@@ -428,7 +412,7 @@ pub const TestContext = struct {...@@ -428,7 +412,7 @@ pub const TestContext = struct {
428 src: [:0]const u8,412 src: [:0]const u8,
429 expected_errors: []const []const u8,413 expected_errors: []const []const u8,
430 ) void {414 ) void {
431 ctx.addError(name, target, .Zig, src, expected_errors);415 ctx.addError(name, target, src, expected_errors);
432 }416 }
433417
434 /// Adds a test case that ensures that the ZIR given in `src` fails to418 /// Adds a test case that ensures that the ZIR given in `src` fails to
...@@ -448,10 +432,9 @@ pub const TestContext = struct {...@@ -448,10 +432,9 @@ pub const TestContext = struct {
448 ctx: *TestContext,432 ctx: *TestContext,
449 name: []const u8,433 name: []const u8,
450 target: CrossTarget,434 target: CrossTarget,
451 extension: Extension,
452 src: [:0]const u8,435 src: [:0]const u8,
453 ) void {436 ) void {
454 ctx.addObj(name, target, extension).compiles(src);437 ctx.addObj(name, target).compiles(src);
455 }438 }
456439
457 /// Adds a test case that asserts that the Zig given in `src` compiles440 /// Adds a test case that asserts that the Zig given in `src` compiles
...@@ -462,7 +445,7 @@ pub const TestContext = struct {...@@ -462,7 +445,7 @@ pub const TestContext = struct {
462 target: CrossTarget,445 target: CrossTarget,
463 src: [:0]const u8,446 src: [:0]const u8,
464 ) void {447 ) void {
465 ctx.addCompiles(name, target, .Zig, src);448 ctx.addCompiles(name, target, src);
466 }449 }
467450
468 /// Adds a test case that asserts that the ZIR given in `src` compiles451 /// Adds a test case that asserts that the ZIR given in `src` compiles
...@@ -489,7 +472,7 @@ pub const TestContext = struct {...@@ -489,7 +472,7 @@ pub const TestContext = struct {
489 expected_errors: []const []const u8,472 expected_errors: []const []const u8,
490 fixed_src: [:0]const u8,473 fixed_src: [:0]const u8,
491 ) void {474 ) void {
492 var case = ctx.addObj(name, target, .Zig);475 var case = ctx.addObj(name, target);
493 case.addError(src, expected_errors);476 case.addError(src, expected_errors);
494 case.compiles(fixed_src);477 case.compiles(fixed_src);
495 }478 }
...@@ -614,10 +597,7 @@ pub const TestContext = struct {...@@ -614,10 +597,7 @@ pub const TestContext = struct {
614 .path = try std.fs.path.join(arena, &[_][]const u8{ tmp_dir_path, "zig-cache" }),597 .path = try std.fs.path.join(arena, &[_][]const u8{ tmp_dir_path, "zig-cache" }),
615 };598 };
616599
617 const tmp_src_path = switch (case.extension) {600 const tmp_src_path = "test_case.zig";
618 .Zig => "test_case.zig",
619 .ZIR => "test_case.zir",
620 };
621601
622 var root_pkg: Package = .{602 var root_pkg: Package = .{
623 .root_src_directory = .{ .path = tmp_dir_path, .handle = tmp.dir },603 .root_src_directory = .{ .path = tmp_dir_path, .handle = tmp.dir },