authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-01-17 21:55:49-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-01-17 21:55:49-07:00
log4d05f2ae5f7b79f8abb4aa07d846a46470ffdb1a
tree930c4dc2aa77d420fd66917136cb1c0e2514f2e6
parent84c2c47fae82e913286a2306d8947252ae3a42f7

remove `zig_is_stage2` from `@import("builtin")`

Instead use the standarized option for communicating the zig compiler backend at comptime, which is `zig_backend`. This was introduced in commit 1c24ef0d0b09a12a1fe98056f2fc04de78a82df3.

17 files changed, 20 insertions(+), 23 deletions(-)

lib/std/builtin.zig+1-1
......@@ -753,7 +753,7 @@ pub fn default_panic(msg: []const u8, error_return_trace: ?*StackTrace) noreturn
753753 @setCold(true);
754754 // Until self-hosted catches up with stage1 language features, we have a simpler
755755 // default panic function:
756 if (builtin.zig_is_stage2) {
756 if (builtin.zig_backend != .stage1) {
757757 while (true) {
758758 @breakpoint();
759759 }
lib/std/os.zig+1-1
......@@ -4973,7 +4973,7 @@ pub fn toPosixPath(file_path: []const u8) ![MAX_PATH_BYTES - 1:0]u8 {
49734973/// Until then, unexpected error tracing is disabled for the self-hosted compiler.
49744974/// TODO remove this once self-hosted is capable enough to handle printing and
49754975/// stack trace dumping.
4976pub const unexpected_error_tracing = !builtin.zig_is_stage2 and builtin.mode == .Debug;
4976pub const unexpected_error_tracing = builtin.zig_backend == .stage1 and builtin.mode == .Debug;
49774977
49784978pub const UnexpectedError = error{
49794979 /// The Operating System returned an undocumented error code.
lib/std/special/c.zig+2-2
......@@ -12,7 +12,7 @@ comptime {
1212 // When the self-hosted compiler is further along, all the logic from c_stage1.zig will
1313 // be migrated to this file and then c_stage1.zig will be deleted. Until then we have a
1414 // simpler implementation of c.zig that only uses features already implemented in self-hosted.
15 if (builtin.zig_is_stage2) {
15 if (builtin.zig_backend != .stage1) {
1616 @export(memset, .{ .name = "memset", .linkage = .Strong });
1717 @export(memcpy, .{ .name = "memcpy", .linkage = .Strong });
1818 } else {
......@@ -25,7 +25,7 @@ comptime {
2525pub fn panic(msg: []const u8, error_return_trace: ?*std.builtin.StackTrace) noreturn {
2626 @setCold(true);
2727 _ = error_return_trace;
28 if (builtin.zig_is_stage2) {
28 if (builtin.zig_backend != .stage1) {
2929 while (true) {
3030 @breakpoint();
3131 }
lib/std/special/compiler_rt.zig+4-4
......@@ -23,7 +23,7 @@ const long_double_is_f128 = builtin.target.longDoubleIsF128();
2323
2424comptime {
2525 // These files do their own comptime exporting logic.
26 if (!builtin.zig_is_stage2) {
26 if (builtin.zig_backend == .stage1) {
2727 _ = @import("compiler_rt/atomics.zig");
2828 }
2929 _ = @import("compiler_rt/clear_cache.zig").clear_cache;
......@@ -186,7 +186,7 @@ comptime {
186186 //@export(__trunctfxf2, .{ .name = "__trunctfxf2", .linkage = linkage });
187187 }
188188
189 if (!builtin.zig_is_stage2) {
189 if (builtin.zig_backend == .stage1) {
190190 switch (arch) {
191191 .i386,
192192 .x86_64,
......@@ -301,7 +301,7 @@ comptime {
301301
302302 const __floatunsisf = @import("compiler_rt/floatunsisf.zig").__floatunsisf;
303303 @export(__floatunsisf, .{ .name = "__floatunsisf", .linkage = linkage });
304 if (!builtin.zig_is_stage2) {
304 if (builtin.zig_backend == .stage1) {
305305 const __floatundisf = @import("compiler_rt/floatundisf.zig").__floatundisf;
306306 @export(__floatundisf, .{ .name = "__floatundisf", .linkage = linkage });
307307 }
......@@ -752,7 +752,7 @@ fn floorl(x: c_longdouble) callconv(.C) c_longdouble {
752752pub fn panic(msg: []const u8, error_return_trace: ?*std.builtin.StackTrace) noreturn {
753753 _ = error_return_trace;
754754 @setCold(true);
755 if (builtin.zig_is_stage2) {
755 if (builtin.zig_backend != .stage1) {
756756 while (true) {
757757 @breakpoint();
758758 }
lib/std/special/test_runner.zig+1-1
......@@ -23,7 +23,7 @@ fn processArgs() void {
2323}
2424
2525pub fn main() void {
26 if (builtin.zig_is_stage2) {
26 if (builtin.zig_backend != .stage1) {
2727 return main2() catch @panic("test failure");
2828 }
2929 processArgs();
lib/std/start.zig+1-1
......@@ -22,7 +22,7 @@ comptime {
2222 // The self-hosted compiler is not fully capable of handling all of this start.zig file.
2323 // Until then, we have simplified logic here for self-hosted. TODO remove this once
2424 // self-hosted is capable enough to handle all of the real start.zig logic.
25 if (builtin.zig_is_stage2) {
25 if (builtin.zig_backend != .stage1) {
2626 if (builtin.output_mode == .Exe) {
2727 if ((builtin.link_libc or builtin.object_format == .c) and @hasDecl(root, "main")) {
2828 if (@typeInfo(@TypeOf(root.main)).Fn.calling_convention != .C) {
src/Compilation.zig-3
......@@ -4579,8 +4579,6 @@ pub fn generateBuiltinZigSource(comp: *Compilation, allocator: Allocator) Alloca
45794579 \\/// feature detection (i.e. with `@hasDecl` or `@hasField`) over version checks.
45804580 \\pub const zig_version = std.SemanticVersion.parse("{s}") catch unreachable;
45814581 \\pub const zig_backend = std.builtin.CompilerBackend.{};
4582 \\/// Temporary until self-hosted is feature complete.
4583 \\pub const zig_is_stage2 = {};
45844582 \\/// Temporary until self-hosted supports the `cpu.arch` value.
45854583 \\pub const stage2_arch: std.Target.Cpu.Arch = .{};
45864584 \\/// Temporary until self-hosted can call `std.Target.x86.featureSetHas` at comptime.
......@@ -4599,7 +4597,6 @@ pub fn generateBuiltinZigSource(comp: *Compilation, allocator: Allocator) Alloca
45994597 , .{
46004598 build_options.version,
46014599 std.zig.fmtId(@tagName(zig_backend)),
4602 !use_stage1,
46034600 std.zig.fmtId(@tagName(target.cpu.arch)),
46044601 stage2_x86_cx16,
46054602 std.zig.fmtId(@tagName(comp.bin_file.options.output_mode)),
src/stage1/codegen.cpp+1-1
......@@ -9392,7 +9392,7 @@ Buf *codegen_generate_builtin_source(CodeGen *g) {
93929392 buf_appendf(contents, "pub const position_independent_executable = %s;\n", bool_to_str(g->have_pie));
93939393 buf_appendf(contents, "pub const strip_debug_info = %s;\n", bool_to_str(g->strip_debug_symbols));
93949394 buf_appendf(contents, "pub const code_model = std.builtin.CodeModel.default;\n");
9395 buf_appendf(contents, "pub const zig_is_stage2 = false;\n");
9395 buf_appendf(contents, "pub const zig_backend = std.builtin.CompilerBackend.stage1;\n");
93969396
93979397 {
93989398 TargetSubsystem detected_subsystem = detect_subsystem(g);
test/behavior/array.zig+1-1
......@@ -111,7 +111,7 @@ test "array with sentinels" {
111111
112112 const S = struct {
113113 fn doTheTest(is_ct: bool) !void {
114 if (is_ct or builtin.zig_is_stage2) {
114 if (is_ct or builtin.zig_backend != .stage1) {
115115 var zero_sized: [0:0xde]u8 = [_:0xde]u8{};
116116 // Stage1 test coverage disabled at runtime because of
117117 // https://github.com/ziglang/zig/issues/4372
test/behavior/atomics.zig+1-1
......@@ -88,7 +88,7 @@ test "128-bit cmpxchg" {
8888}
8989
9090fn test_u128_cmpxchg() !void {
91 if (builtin.zig_is_stage2) {
91 if (builtin.zig_backend != .stage1) {
9292 if (builtin.cpu.arch != .x86_64) return error.SkipZigTest;
9393 if (!builtin.stage2_x86_cx16) return error.SkipZigTest;
9494 } else {
test/behavior/basic.zig+1-1
......@@ -180,7 +180,7 @@ const OpaqueB = opaque {};
180180
181181test "opaque types" {
182182 try expect(*OpaqueA != *OpaqueB);
183 if (!builtin.zig_is_stage2) {
183 if (builtin.zig_backend == .stage1) { // TODO make this pass for stage2
184184 try expect(mem.eql(u8, @typeName(OpaqueA), "OpaqueA"));
185185 try expect(mem.eql(u8, @typeName(OpaqueB), "OpaqueB"));
186186 }
test/behavior/bugs/2006.zig+1-1
......@@ -8,7 +8,7 @@ test "bug 2006" {
88 var a: S = undefined;
99 a = S{ .p = undefined };
1010 try expect(@sizeOf(S) != 0);
11 if (@import("builtin").zig_is_stage2) {
11 if (@import("builtin").zig_backend != .stage1) {
1212 // It is an accepted proposal to make `@sizeOf` for pointers independent
1313 // of whether the element type is zero bits.
1414 // This language change has not been implemented in stage1.
test/behavior/bugs/6850.zig+1-1
......@@ -8,7 +8,7 @@ test "lazy sizeof comparison with zero" {
88}
99
1010fn hasNoBits(comptime T: type) bool {
11 if (@import("builtin").zig_is_stage2) {
11 if (@import("builtin").zig_backend != .stage1) {
1212 // It is an accepted proposal to make `@sizeOf` for pointers independent
1313 // of whether the element type is zero bits.
1414 // This language change has not been implemented in stage1.
test/behavior/cast.zig+1-1
......@@ -246,7 +246,7 @@ test "array coersion to undefined at runtime" {
246246 @setRuntimeSafety(true);
247247
248248 // TODO implement @setRuntimeSafety in stage2
249 if (builtin.zig_is_stage2 and builtin.mode != .Debug and builtin.mode != .ReleaseSafe) {
249 if (builtin.zig_backend != .stage1 and builtin.mode != .Debug and builtin.mode != .ReleaseSafe) {
250250 return error.SkipZigTest;
251251 }
252252
test/behavior/generics.zig+1-1
......@@ -19,7 +19,7 @@ fn checkSize(comptime T: type) usize {
1919test "simple generic fn" {
2020 try expect(max(i32, 3, -1) == 3);
2121 try expect(max(u8, 1, 100) == 100);
22 if (!builtin.zig_is_stage2) {
22 if (builtin.zig_backend == .stage1) {
2323 // TODO: stage2 is incorrectly emitting the following:
2424 // error: cast of value 1.23e-01 to type 'f32' loses information
2525 try expect(max(f32, 0.123, 0.456) == 0.456);
test/behavior/int128.zig+1-1
......@@ -22,7 +22,7 @@ test "undefined 128 bit int" {
2222 @setRuntimeSafety(true);
2323
2424 // TODO implement @setRuntimeSafety in stage2
25 if (builtin.zig_is_stage2 and builtin.mode != .Debug and builtin.mode != .ReleaseSafe) {
25 if (builtin.zig_backend != .stage1 and builtin.mode != .Debug and builtin.mode != .ReleaseSafe) {
2626 return error.SkipZigTest;
2727 }
2828
test/behavior/struct.zig+1-1
......@@ -213,7 +213,7 @@ test "packed struct field alignment" {
213213 b: u32 align(1),
214214 } = undefined;
215215 };
216 const S = if (builtin.zig_is_stage2) Stage2 else Stage1;
216 const S = if (builtin.zig_backend != .stage1) Stage2 else Stage1;
217217 try expect(@TypeOf(&S.baz.b) == *align(1) u32);
218218}
219219