From 0879cbeed262415645fe388e1991c7df866f7064 Mon Sep 17 00:00:00 2001 From: Meghan Denny Date: Sun, 24 Jul 2022 19:05:20 -0700 Subject: [PATCH 1/3] remove 'builtin.stage2_arch', Sema is smart enough now --- lib/std/os/plan9.zig | 2 +- lib/std/start.zig | 4 ++-- src/Compilation.zig | 3 --- src/stage1/codegen.cpp | 1 - test/behavior.zig | 2 +- test/behavior/struct.zig | 2 +- 6 files changed, 5 insertions(+), 9 deletions(-) diff --git a/lib/std/os/plan9.zig b/lib/std/os/plan9.zig index 99e25709b1..6d052a3573 100644 --- a/lib/std/os/plan9.zig +++ b/lib/std/os/plan9.zig @@ -1,7 +1,7 @@ const std = @import("../std.zig"); const builtin = @import("builtin"); -pub const syscall_bits = switch (builtin.stage2_arch) { +pub const syscall_bits = switch (builtin.cpu.arch) { .x86_64 => @import("plan9/x86_64.zig"), else => @compileError("more plan9 syscall implementations (needs more inline asm in stage2"), }; diff --git a/lib/std/start.zig b/lib/std/start.zig index 8ea261be2d..e6a7b7991a 100644 --- a/lib/std/start.zig +++ b/lib/std/start.zig @@ -131,7 +131,7 @@ fn wWinMainCRTStartup2() callconv(.C) noreturn { fn exit2(code: usize) noreturn { switch (native_os) { - .linux => switch (builtin.stage2_arch) { + .linux => switch (builtin.cpu.arch) { .x86_64 => { asm volatile ("syscall" : @@ -175,7 +175,7 @@ fn exit2(code: usize) noreturn { else => @compileError("TODO"), }, // exits(0) - .plan9 => switch (builtin.stage2_arch) { + .plan9 => switch (builtin.cpu.arch) { .x86_64 => { asm volatile ( \\push $0 diff --git a/src/Compilation.zig b/src/Compilation.zig index 17ffe356a3..d3816e542c 100644 --- a/src/Compilation.zig +++ b/src/Compilation.zig @@ -4763,8 +4763,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 supports the `cpu.arch` value. - \\pub const stage2_arch: std.Target.Cpu.Arch = .{}; \\ \\pub const output_mode = std.builtin.OutputMode.{}; \\pub const link_mode = std.builtin.LinkMode.{}; @@ -4779,7 +4777,6 @@ pub fn generateBuiltinZigSource(comp: *Compilation, allocator: Allocator) Alloca , .{ build_options.version, std.zig.fmtId(@tagName(zig_backend)), - std.zig.fmtId(@tagName(target.cpu.arch)), std.zig.fmtId(@tagName(comp.bin_file.options.output_mode)), std.zig.fmtId(@tagName(comp.bin_file.options.link_mode)), comp.bin_file.options.is_test, diff --git a/src/stage1/codegen.cpp b/src/stage1/codegen.cpp index 8b88446295..7010e736dc 100644 --- a/src/stage1/codegen.cpp +++ b/src/stage1/codegen.cpp @@ -10076,7 +10076,6 @@ Buf *codegen_generate_builtin_source(CodeGen *g) { buf_appendf(contents, "pub const single_threaded = %s;\n", bool_to_str(g->is_single_threaded)); buf_appendf(contents, "pub const abi = std.Target.Abi.%s;\n", cur_abi); buf_appendf(contents, "pub const cpu = std.Target.Cpu.baseline(.%s);\n", cur_arch); - buf_appendf(contents, "pub const stage2_arch: std.Target.Cpu.Arch = .%s;\n", cur_arch); buf_appendf(contents, "pub const os = std.Target.Os.Tag.defaultVersionRange(.%s, .%s);\n", cur_os, cur_arch); buf_appendf(contents, "pub const target = std.Target{\n" diff --git a/test/behavior.zig b/test/behavior.zig index 813c410f7b..fee61f5e09 100644 --- a/test/behavior.zig +++ b/test/behavior.zig @@ -159,7 +159,7 @@ test { _ = @import("behavior/while.zig"); _ = @import("behavior/widening.zig"); - if (builtin.stage2_arch == .wasm32) { + if (builtin.cpu.arch == .wasm32) { _ = @import("behavior/wasm.zig"); } diff --git a/test/behavior/struct.zig b/test/behavior/struct.zig index 377cbb56f4..eb29c9038d 100644 --- a/test/behavior/struct.zig +++ b/test/behavior/struct.zig @@ -963,7 +963,7 @@ test "tuple assigned to variable" { test "comptime struct field" { if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO - if (builtin.stage2_arch == .arm) return error.SkipZigTest; // TODO + if (builtin.cpu.arch == .arm) return error.SkipZigTest; // TODO const T = struct { a: i32, From 11c715cd5ad392a322858627a12c288d026d2a06 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Sun, 7 Aug 2022 15:21:15 -0700 Subject: [PATCH 2/3] remove brittle test case see #12358 --- ...or_tagged_union_with_extra_union_field.zig | 35 ------------------- 1 file changed, 35 deletions(-) delete mode 100644 test/cases/compile_errors/reify_type_for_tagged_union_with_extra_union_field.zig diff --git a/test/cases/compile_errors/reify_type_for_tagged_union_with_extra_union_field.zig b/test/cases/compile_errors/reify_type_for_tagged_union_with_extra_union_field.zig deleted file mode 100644 index ee557cd6c2..0000000000 --- a/test/cases/compile_errors/reify_type_for_tagged_union_with_extra_union_field.zig +++ /dev/null @@ -1,35 +0,0 @@ -const Tag = @Type(.{ - .Enum = .{ - .layout = .Auto, - .tag_type = u1, - .fields = &.{ - .{ .name = "signed", .value = 0 }, - .{ .name = "unsigned", .value = 1 }, - }, - .decls = &.{}, - .is_exhaustive = true, - }, -}); -const Tagged = @Type(.{ - .Union = .{ - .layout = .Auto, - .tag_type = Tag, - .fields = &.{ - .{ .name = "signed", .field_type = i32, .alignment = @alignOf(i32) }, - .{ .name = "unsigned", .field_type = u32, .alignment = @alignOf(u32) }, - .{ .name = "arst", .field_type = f32, .alignment = @alignOf(f32) }, - }, - .decls = &.{}, - }, -}); -export fn entry() void { - var tagged = Tagged{ .signed = -1 }; - tagged = .{ .unsigned = 1 }; -} - -// error -// backend=stage2 -// target=native -// -// :13:16: error: no field named 'arst' in enum 'tmp.Tag__enum_266' -// :1:13: note: enum declared here From ec7f7131473a5648703c48422b449c12ed4524aa Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Sun, 7 Aug 2022 16:05:57 -0700 Subject: [PATCH 3/3] delete failing RISC-V test this backend needs to get further along before it deserves test coverage. --- .../hello_world_with_updates.0.zig | 21 --------------- .../hello_world_with_updates.1.zig | 27 ------------------- 2 files changed, 48 deletions(-) delete mode 100644 test/cases/riscv64-linux/hello_world_with_updates.0.zig delete mode 100644 test/cases/riscv64-linux/hello_world_with_updates.1.zig diff --git a/test/cases/riscv64-linux/hello_world_with_updates.0.zig b/test/cases/riscv64-linux/hello_world_with_updates.0.zig deleted file mode 100644 index dd119fd1f4..0000000000 --- a/test/cases/riscv64-linux/hello_world_with_updates.0.zig +++ /dev/null @@ -1,21 +0,0 @@ -pub fn main() void { - print(); -} - -fn print() void { - asm volatile ("ecall" - : - : [number] "{a7}" (64), - [arg1] "{a0}" (1), - [arg2] "{a1}" (@ptrToInt("Hello, World!\n")), - [arg3] "{a2}" ("Hello, World!\n".len), - : "rcx", "r11", "memory" - ); - return; -} - -// run -// target=riscv64-linux -// -// Hello, World! -// diff --git a/test/cases/riscv64-linux/hello_world_with_updates.1.zig b/test/cases/riscv64-linux/hello_world_with_updates.1.zig deleted file mode 100644 index 26718738a9..0000000000 --- a/test/cases/riscv64-linux/hello_world_with_updates.1.zig +++ /dev/null @@ -1,27 +0,0 @@ -pub fn main() void { - print(); - print(); - print(); - print(); -} - -fn print() void { - asm volatile ("ecall" - : - : [number] "{a7}" (64), - [arg1] "{a0}" (1), - [arg2] "{a1}" (@ptrToInt("Hello, World!\n")), - [arg3] "{a2}" ("Hello, World!\n".len), - : "rcx", "r11", "memory" - ); - return; -} - -// run -// target=riscv64-linux -// -// Hello, World! -// Hello, World! -// Hello, World! -// Hello, World! -//