Commit 4d05f2ae5f

Andrew Kelley <andrew@ziglang.org>
2022-01-18 05:55:49
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.
1 parent 84c2c47
lib/std/special/c.zig
@@ -12,7 +12,7 @@ comptime {
     // When the self-hosted compiler is further along, all the logic from c_stage1.zig will
     // be migrated to this file and then c_stage1.zig will be deleted. Until then we have a
     // simpler implementation of c.zig that only uses features already implemented in self-hosted.
-    if (builtin.zig_is_stage2) {
+    if (builtin.zig_backend != .stage1) {
         @export(memset, .{ .name = "memset", .linkage = .Strong });
         @export(memcpy, .{ .name = "memcpy", .linkage = .Strong });
     } else {
@@ -25,7 +25,7 @@ comptime {
 pub fn panic(msg: []const u8, error_return_trace: ?*std.builtin.StackTrace) noreturn {
     @setCold(true);
     _ = error_return_trace;
-    if (builtin.zig_is_stage2) {
+    if (builtin.zig_backend != .stage1) {
         while (true) {
             @breakpoint();
         }
lib/std/special/compiler_rt.zig
@@ -23,7 +23,7 @@ const long_double_is_f128 = builtin.target.longDoubleIsF128();
 
 comptime {
     // These files do their own comptime exporting logic.
-    if (!builtin.zig_is_stage2) {
+    if (builtin.zig_backend == .stage1) {
         _ = @import("compiler_rt/atomics.zig");
     }
     _ = @import("compiler_rt/clear_cache.zig").clear_cache;
@@ -186,7 +186,7 @@ comptime {
         //@export(__trunctfxf2, .{ .name = "__trunctfxf2", .linkage = linkage });
     }
 
-    if (!builtin.zig_is_stage2) {
+    if (builtin.zig_backend == .stage1) {
         switch (arch) {
             .i386,
             .x86_64,
@@ -301,7 +301,7 @@ comptime {
 
     const __floatunsisf = @import("compiler_rt/floatunsisf.zig").__floatunsisf;
     @export(__floatunsisf, .{ .name = "__floatunsisf", .linkage = linkage });
-    if (!builtin.zig_is_stage2) {
+    if (builtin.zig_backend == .stage1) {
         const __floatundisf = @import("compiler_rt/floatundisf.zig").__floatundisf;
         @export(__floatundisf, .{ .name = "__floatundisf", .linkage = linkage });
     }
@@ -752,7 +752,7 @@ fn floorl(x: c_longdouble) callconv(.C) c_longdouble {
 pub fn panic(msg: []const u8, error_return_trace: ?*std.builtin.StackTrace) noreturn {
     _ = error_return_trace;
     @setCold(true);
-    if (builtin.zig_is_stage2) {
+    if (builtin.zig_backend != .stage1) {
         while (true) {
             @breakpoint();
         }
lib/std/special/test_runner.zig
@@ -23,7 +23,7 @@ fn processArgs() void {
 }
 
 pub fn main() void {
-    if (builtin.zig_is_stage2) {
+    if (builtin.zig_backend != .stage1) {
         return main2() catch @panic("test failure");
     }
     processArgs();
lib/std/builtin.zig
@@ -753,7 +753,7 @@ pub fn default_panic(msg: []const u8, error_return_trace: ?*StackTrace) noreturn
     @setCold(true);
     // Until self-hosted catches up with stage1 language features, we have a simpler
     // default panic function:
-    if (builtin.zig_is_stage2) {
+    if (builtin.zig_backend != .stage1) {
         while (true) {
             @breakpoint();
         }
lib/std/os.zig
@@ -4973,7 +4973,7 @@ pub fn toPosixPath(file_path: []const u8) ![MAX_PATH_BYTES - 1:0]u8 {
 /// Until then, unexpected error tracing is disabled for the self-hosted compiler.
 /// TODO remove this once self-hosted is capable enough to handle printing and
 /// stack trace dumping.
-pub const unexpected_error_tracing = !builtin.zig_is_stage2 and builtin.mode == .Debug;
+pub const unexpected_error_tracing = builtin.zig_backend == .stage1 and builtin.mode == .Debug;
 
 pub const UnexpectedError = error{
     /// The Operating System returned an undocumented error code.
lib/std/start.zig
@@ -22,7 +22,7 @@ comptime {
     // The self-hosted compiler is not fully capable of handling all of this start.zig file.
     // Until then, we have simplified logic here for self-hosted. TODO remove this once
     // self-hosted is capable enough to handle all of the real start.zig logic.
-    if (builtin.zig_is_stage2) {
+    if (builtin.zig_backend != .stage1) {
         if (builtin.output_mode == .Exe) {
             if ((builtin.link_libc or builtin.object_format == .c) and @hasDecl(root, "main")) {
                 if (@typeInfo(@TypeOf(root.main)).Fn.calling_convention != .C) {
src/stage1/codegen.cpp
@@ -9392,7 +9392,7 @@ Buf *codegen_generate_builtin_source(CodeGen *g) {
     buf_appendf(contents, "pub const position_independent_executable = %s;\n", bool_to_str(g->have_pie));
     buf_appendf(contents, "pub const strip_debug_info = %s;\n", bool_to_str(g->strip_debug_symbols));
     buf_appendf(contents, "pub const code_model = std.builtin.CodeModel.default;\n");
-    buf_appendf(contents, "pub const zig_is_stage2 = false;\n");
+    buf_appendf(contents, "pub const zig_backend = std.builtin.CompilerBackend.stage1;\n");
 
     {
         TargetSubsystem detected_subsystem = detect_subsystem(g);
src/Compilation.zig
@@ -4579,8 +4579,6 @@ pub fn generateBuiltinZigSource(comp: *Compilation, allocator: Allocator) Alloca
         \\/// feature detection (i.e. with `@hasDecl` or `@hasField`) over version checks.
         \\pub const zig_version = std.SemanticVersion.parse("{s}") catch unreachable;
         \\pub const zig_backend = std.builtin.CompilerBackend.{};
-        \\/// Temporary until self-hosted is feature complete.
-        \\pub const zig_is_stage2 = {};
         \\/// Temporary until self-hosted supports the `cpu.arch` value.
         \\pub const stage2_arch: std.Target.Cpu.Arch = .{};
         \\/// Temporary until self-hosted can call `std.Target.x86.featureSetHas` at comptime.
@@ -4599,7 +4597,6 @@ pub fn generateBuiltinZigSource(comp: *Compilation, allocator: Allocator) Alloca
     , .{
         build_options.version,
         std.zig.fmtId(@tagName(zig_backend)),
-        !use_stage1,
         std.zig.fmtId(@tagName(target.cpu.arch)),
         stage2_x86_cx16,
         std.zig.fmtId(@tagName(comp.bin_file.options.output_mode)),
test/behavior/bugs/2006.zig
@@ -8,7 +8,7 @@ test "bug 2006" {
     var a: S = undefined;
     a = S{ .p = undefined };
     try expect(@sizeOf(S) != 0);
-    if (@import("builtin").zig_is_stage2) {
+    if (@import("builtin").zig_backend != .stage1) {
         // It is an accepted proposal to make `@sizeOf` for pointers independent
         // of whether the element type is zero bits.
         // This language change has not been implemented in stage1.
test/behavior/bugs/6850.zig
@@ -8,7 +8,7 @@ test "lazy sizeof comparison with zero" {
 }
 
 fn hasNoBits(comptime T: type) bool {
-    if (@import("builtin").zig_is_stage2) {
+    if (@import("builtin").zig_backend != .stage1) {
         // It is an accepted proposal to make `@sizeOf` for pointers independent
         // of whether the element type is zero bits.
         // This language change has not been implemented in stage1.
test/behavior/array.zig
@@ -111,7 +111,7 @@ test "array with sentinels" {
 
     const S = struct {
         fn doTheTest(is_ct: bool) !void {
-            if (is_ct or builtin.zig_is_stage2) {
+            if (is_ct or builtin.zig_backend != .stage1) {
                 var zero_sized: [0:0xde]u8 = [_:0xde]u8{};
                 // Stage1 test coverage disabled at runtime because of
                 // https://github.com/ziglang/zig/issues/4372
test/behavior/atomics.zig
@@ -88,7 +88,7 @@ test "128-bit cmpxchg" {
 }
 
 fn test_u128_cmpxchg() !void {
-    if (builtin.zig_is_stage2) {
+    if (builtin.zig_backend != .stage1) {
         if (builtin.cpu.arch != .x86_64) return error.SkipZigTest;
         if (!builtin.stage2_x86_cx16) return error.SkipZigTest;
     } else {
test/behavior/basic.zig
@@ -180,7 +180,7 @@ const OpaqueB = opaque {};
 
 test "opaque types" {
     try expect(*OpaqueA != *OpaqueB);
-    if (!builtin.zig_is_stage2) {
+    if (builtin.zig_backend == .stage1) { // TODO make this pass for stage2
         try expect(mem.eql(u8, @typeName(OpaqueA), "OpaqueA"));
         try expect(mem.eql(u8, @typeName(OpaqueB), "OpaqueB"));
     }
test/behavior/cast.zig
@@ -246,7 +246,7 @@ test "array coersion to undefined at runtime" {
     @setRuntimeSafety(true);
 
     // TODO implement @setRuntimeSafety in stage2
-    if (builtin.zig_is_stage2 and builtin.mode != .Debug and builtin.mode != .ReleaseSafe) {
+    if (builtin.zig_backend != .stage1 and builtin.mode != .Debug and builtin.mode != .ReleaseSafe) {
         return error.SkipZigTest;
     }
 
test/behavior/generics.zig
@@ -19,7 +19,7 @@ fn checkSize(comptime T: type) usize {
 test "simple generic fn" {
     try expect(max(i32, 3, -1) == 3);
     try expect(max(u8, 1, 100) == 100);
-    if (!builtin.zig_is_stage2) {
+    if (builtin.zig_backend == .stage1) {
         // TODO: stage2 is incorrectly emitting the following:
         // error: cast of value 1.23e-01 to type 'f32' loses information
         try expect(max(f32, 0.123, 0.456) == 0.456);
test/behavior/int128.zig
@@ -22,7 +22,7 @@ test "undefined 128 bit int" {
     @setRuntimeSafety(true);
 
     // TODO implement @setRuntimeSafety in stage2
-    if (builtin.zig_is_stage2 and builtin.mode != .Debug and builtin.mode != .ReleaseSafe) {
+    if (builtin.zig_backend != .stage1 and builtin.mode != .Debug and builtin.mode != .ReleaseSafe) {
         return error.SkipZigTest;
     }
 
test/behavior/struct.zig
@@ -213,7 +213,7 @@ test "packed struct field alignment" {
             b: u32 align(1),
         } = undefined;
     };
-    const S = if (builtin.zig_is_stage2) Stage2 else Stage1;
+    const S = if (builtin.zig_backend != .stage1) Stage2 else Stage1;
     try expect(@TypeOf(&S.baz.b) == *align(1) u32);
 }