authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-10-31 20:29:55-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-12-06 12:15:04-07:00
log28514476ef8c824c3d189d98f23d0f8d23e496ea
tree537631080e7c99fb582738d3be96ac48c5941bb7
parentbf316e550671cc71eb498b3cf799493627bb0fdc

remove `-fstage1` option

After this commit, the self-hosted compiler does not offer the option to use stage1 as a backend anymore.

25 files changed, 95 insertions(+), 461 deletions(-)

CMakeLists.txt-1
......@@ -1084,7 +1084,6 @@ set(ZIG_BUILD_ARGS
10841084 --zig-lib-dir "${CMAKE_SOURCE_DIR}/lib"
10851085 "-Dconfig_h=${ZIG_CONFIG_H_OUT}"
10861086 "-Denable-llvm"
1087 "-Denable-stage1"
10881087 ${ZIG_RELEASE_ARG}
10891088 ${ZIG_STATIC_ARG}
10901089 ${ZIG_NO_LIB_ARG}
build.zig+2-121
......@@ -69,9 +69,8 @@ pub fn build(b: *Builder) !void {
6969
7070 const only_install_lib_files = b.option(bool, "lib-files-only", "Only install library files") orelse false;
7171
72 const have_stage1 = b.option(bool, "enable-stage1", "Include the stage1 compiler behind a feature flag") orelse false;
7372 const static_llvm = b.option(bool, "static-llvm", "Disable integration with system-installed LLVM, Clang, LLD, and libc++") orelse false;
74 const enable_llvm = b.option(bool, "enable-llvm", "Build self-hosted compiler with LLVM backend enabled") orelse (have_stage1 or static_llvm);
73 const enable_llvm = b.option(bool, "enable-llvm", "Build self-hosted compiler with LLVM backend enabled") orelse static_llvm;
7574 const llvm_has_m68k = b.option(
7675 bool,
7776 "llvm-has-m68k",
......@@ -133,7 +132,6 @@ pub fn build(b: *Builder) !void {
133132 const link_libc = b.option(bool, "force-link-libc", "Force self-hosted compiler to link libc") orelse (enable_llvm or only_c);
134133 const sanitize_thread = b.option(bool, "sanitize-thread", "Enable thread-sanitization") orelse false;
135134 const strip = b.option(bool, "strip", "Omit debug information") orelse false;
136 const use_zig0 = b.option(bool, "zig0", "Bootstrap using zig0") orelse false;
137135 const value_tracing = b.option(bool, "value-tracing", "Enable extra state tracking to help troubleshoot bugs in the compiler (using the std.debug.Trace API)") orelse false;
138136
139137 const mem_leak_frames: u32 = b.option(u32, "mem-leak-frames", "How many stack frames to print when a memory leak occurs. Tests get 2x this amount.") orelse blk: {
......@@ -146,11 +144,7 @@ pub fn build(b: *Builder) !void {
146144 target.ofmt = .c;
147145 }
148146
149 const main_file: ?[]const u8 = mf: {
150 if (!have_stage1) break :mf "src/main.zig";
151 if (use_zig0) break :mf null;
152 break :mf "src/stage1.zig";
153 };
147 const main_file: ?[]const u8 = "src/main.zig";
154148
155149 const exe = b.addExecutable("zig", main_file);
156150
......@@ -264,92 +258,6 @@ pub fn build(b: *Builder) !void {
264258 }
265259 };
266260
267 if (have_stage1) {
268 const softfloat = b.addStaticLibrary("softfloat", null);
269 softfloat.setBuildMode(.ReleaseFast);
270 softfloat.setTarget(target);
271 softfloat.addIncludePath("deps/SoftFloat-3e-prebuilt");
272 softfloat.addIncludePath("deps/SoftFloat-3e/source/8086");
273 softfloat.addIncludePath("deps/SoftFloat-3e/source/include");
274 softfloat.addCSourceFiles(&softfloat_sources, &[_][]const u8{ "-std=c99", "-O3" });
275 softfloat.single_threaded = single_threaded;
276
277 const zig0 = b.addExecutable("zig0", null);
278 zig0.addCSourceFiles(&.{"src/stage1/zig0.cpp"}, &exe_cflags);
279 zig0.addIncludePath("zig-cache/tmp"); // for config.h
280 zig0.defineCMacro("ZIG_VERSION_MAJOR", b.fmt("{d}", .{zig_version.major}));
281 zig0.defineCMacro("ZIG_VERSION_MINOR", b.fmt("{d}", .{zig_version.minor}));
282 zig0.defineCMacro("ZIG_VERSION_PATCH", b.fmt("{d}", .{zig_version.patch}));
283 zig0.defineCMacro("ZIG_VERSION_STRING", b.fmt("\"{s}\"", .{version}));
284
285 for ([_]*std.build.LibExeObjStep{ zig0, exe, test_cases }) |artifact| {
286 artifact.addIncludePath("src");
287 artifact.addIncludePath("deps/SoftFloat-3e/source/include");
288 artifact.addIncludePath("deps/SoftFloat-3e-prebuilt");
289
290 artifact.defineCMacro("ZIG_LINK_MODE", "Static");
291
292 artifact.addCSourceFiles(&stage1_sources, &exe_cflags);
293 artifact.addCSourceFiles(&optimized_c_sources, &[_][]const u8{ "-std=c99", "-O3" });
294
295 artifact.linkLibrary(softfloat);
296 artifact.linkLibCpp();
297 }
298
299 try addStaticLlvmOptionsToExe(zig0);
300
301 const zig1_obj_ext = target.getObjectFormat().fileExt(target.getCpuArch());
302 const zig1_obj_path = b.pathJoin(&.{ "zig-cache", "tmp", b.fmt("zig1{s}", .{zig1_obj_ext}) });
303 const zig1_compiler_rt_path = b.pathJoin(&.{ b.pathFromRoot("lib"), "std", "special", "compiler_rt.zig" });
304
305 const zig1_obj = zig0.run();
306 zig1_obj.addArgs(&.{
307 "src/stage1.zig",
308 "-target",
309 try target.zigTriple(b.allocator),
310 "-mcpu=baseline",
311 "--name",
312 "zig1",
313 "--zig-lib-dir",
314 b.pathFromRoot("lib"),
315 b.fmt("-femit-bin={s}", .{b.pathFromRoot(zig1_obj_path)}),
316 "-fcompiler-rt",
317 "-lc",
318 });
319 {
320 zig1_obj.addArgs(&.{ "--pkg-begin", "build_options" });
321 zig1_obj.addFileSourceArg(exe_options.getSource());
322 zig1_obj.addArgs(&.{ "--pkg-end", "--pkg-begin", "compiler_rt", zig1_compiler_rt_path, "--pkg-end" });
323 }
324 switch (mode) {
325 .Debug => {},
326 .ReleaseFast => {
327 zig1_obj.addArg("-OReleaseFast");
328 zig1_obj.addArg("-fstrip");
329 },
330 .ReleaseSafe => {
331 zig1_obj.addArg("-OReleaseSafe");
332 zig1_obj.addArg("-fstrip");
333 },
334 .ReleaseSmall => {
335 zig1_obj.addArg("-OReleaseSmall");
336 zig1_obj.addArg("-fstrip");
337 },
338 }
339 if (single_threaded orelse false) {
340 zig1_obj.addArg("-fsingle-threaded");
341 }
342
343 if (use_zig0) {
344 exe.step.dependOn(&zig1_obj.step);
345 exe.addObjectFile(zig1_obj_path);
346 }
347
348 // This is intentionally a dummy path. stage1.zig tries to @import("compiler_rt") in case
349 // of being built by cmake. But when built by zig it's gonna get a compiler_rt so that
350 // is pointless.
351 exe.addPackagePath("compiler_rt", "src/empty.zig");
352 }
353261 if (cmake_cfg) |cfg| {
354262 // Inside this code path, we have to coordinate with system packaged LLVM, Clang, and LLD.
355263 // That means we also have to rely on stage1 compiled c++ files. We parse config.h to find
......@@ -379,7 +287,6 @@ pub fn build(b: *Builder) !void {
379287 exe_options.addOption(bool, "enable_tracy_callstack", tracy_callstack);
380288 exe_options.addOption(bool, "enable_tracy_allocation", tracy_allocation);
381289 exe_options.addOption(bool, "value_tracing", value_tracing);
382 exe_options.addOption(bool, "have_stage1", have_stage1);
383290 if (tracy) |tracy_path| {
384291 const client_cpp = fs.path.join(
385292 b.allocator,
......@@ -414,7 +321,6 @@ pub fn build(b: *Builder) !void {
414321 test_cases_options.addOption(bool, "enable_link_snapshots", enable_link_snapshots);
415322 test_cases_options.addOption(bool, "skip_non_native", skip_non_native);
416323 test_cases_options.addOption(bool, "skip_stage1", skip_stage1);
417 test_cases_options.addOption(bool, "have_stage1", have_stage1);
418324 test_cases_options.addOption(bool, "have_llvm", enable_llvm);
419325 test_cases_options.addOption(bool, "llvm_has_m68k", llvm_has_m68k);
420326 test_cases_options.addOption(bool, "llvm_has_csky", llvm_has_csky);
......@@ -1010,31 +916,6 @@ const softfloat_sources = [_][]const u8{
1010916 "deps/SoftFloat-3e/source/ui64_to_extF80M.c",
1011917};
1012918
1013const stage1_sources = [_][]const u8{
1014 "src/stage1/analyze.cpp",
1015 "src/stage1/astgen.cpp",
1016 "src/stage1/bigfloat.cpp",
1017 "src/stage1/bigint.cpp",
1018 "src/stage1/buffer.cpp",
1019 "src/stage1/codegen.cpp",
1020 "src/stage1/errmsg.cpp",
1021 "src/stage1/error.cpp",
1022 "src/stage1/heap.cpp",
1023 "src/stage1/ir.cpp",
1024 "src/stage1/ir_print.cpp",
1025 "src/stage1/mem.cpp",
1026 "src/stage1/os.cpp",
1027 "src/stage1/parser.cpp",
1028 "src/stage1/range_set.cpp",
1029 "src/stage1/stage1.cpp",
1030 "src/stage1/target.cpp",
1031 "src/stage1/tokenizer.cpp",
1032 "src/stage1/util.cpp",
1033 "src/stage1/softfloat_ext.cpp",
1034};
1035const optimized_c_sources = [_][]const u8{
1036 "src/stage1/parse_f128.c",
1037};
1038919const zig_cpp_sources = [_][]const u8{
1039920 // These are planned to stay even when we are self-hosted.
1040921 "src/zig_llvm.cpp",
lib/build_runner.zig-6
......@@ -183,10 +183,6 @@ pub fn main() !void {
183183 builder.enable_darling = true;
184184 } else if (mem.eql(u8, arg, "-fno-darling")) {
185185 builder.enable_darling = false;
186 } else if (mem.eql(u8, arg, "-fstage1")) {
187 builder.use_stage1 = true;
188 } else if (mem.eql(u8, arg, "-fno-stage1")) {
189 builder.use_stage1 = false;
190186 } else if (mem.eql(u8, arg, "-freference-trace")) {
191187 builder.reference_trace = 256;
192188 } else if (mem.startsWith(u8, arg, "-freference-trace=")) {
......@@ -318,8 +314,6 @@ fn usage(builder: *Builder, already_ran_build: bool, out_stream: anytype) !void
318314 try out_stream.writeAll(
319315 \\
320316 \\Advanced Options:
321 \\ -fstage1 Force using bootstrap compiler as the codegen backend
322 \\ -fno-stage1 Prevent using bootstrap compiler as the codegen backend
323317 \\ -freference-trace[=num] How many lines of reference trace should be shown per compile error
324318 \\ -fno-reference-trace Disable reference trace
325319 \\ --build-file [file] Override path to build.zig
lib/std/build.zig-16
......@@ -46,7 +46,6 @@ pub const Builder = struct {
4646 prominent_compile_errors: bool,
4747 color: enum { auto, on, off } = .auto,
4848 reference_trace: ?u32 = null,
49 use_stage1: ?bool = null,
5049 invalid_user_input: bool,
5150 zig_exe: []const u8,
5251 default_step: *Step,
......@@ -1621,7 +1620,6 @@ pub const LibExeObjStep = struct {
16211620 stack_size: ?u64 = null,
16221621
16231622 want_lto: ?bool = null,
1624 use_stage1: ?bool = null,
16251623 use_llvm: ?bool = null,
16261624 use_lld: ?bool = null,
16271625
......@@ -2467,20 +2465,6 @@ pub const LibExeObjStep = struct {
24672465 try zig_args.append(try std.fmt.allocPrint(builder.allocator, "-freference-trace={d}", .{some}));
24682466 }
24692467
2470 if (self.use_stage1) |stage1| {
2471 if (stage1) {
2472 try zig_args.append("-fstage1");
2473 } else {
2474 try zig_args.append("-fno-stage1");
2475 }
2476 } else if (builder.use_stage1) |stage1| {
2477 if (stage1) {
2478 try zig_args.append("-fstage1");
2479 } else {
2480 try zig_args.append("-fno-stage1");
2481 }
2482 }
2483
24842468 if (self.use_llvm) |use_llvm| {
24852469 if (use_llvm) {
24862470 try zig_args.append("-fLLVM");
lib/std/build/TranslateCStep.zig-14
......@@ -21,7 +21,6 @@ output_dir: ?[]const u8,
2121out_basename: []const u8,
2222target: CrossTarget = CrossTarget{},
2323output_file: build.GeneratedFile,
24use_stage1: ?bool = null,
2524
2625pub fn create(builder: *Builder, source: build.FileSource) *TranslateCStep {
2726 const self = builder.allocator.create(TranslateCStep) catch unreachable;
......@@ -92,19 +91,6 @@ fn make(step: *Step) !void {
9291 try argv_list.append("-D");
9392 try argv_list.append(c_macro);
9493 }
95 if (self.use_stage1) |stage1| {
96 if (stage1) {
97 try argv_list.append("-fstage1");
98 } else {
99 try argv_list.append("-fno-stage1");
100 }
101 } else if (self.builder.use_stage1) |stage1| {
102 if (stage1) {
103 try argv_list.append("-fstage1");
104 } else {
105 try argv_list.append("-fno-stage1");
106 }
107 }
10894
10995 try argv_list.append(self.source.getPath(self.builder));
11096
src/Compilation.zig+44-83
......@@ -935,7 +935,6 @@ pub const InitOptions = struct {
935935 use_llvm: ?bool = null,
936936 use_lld: ?bool = null,
937937 use_clang: ?bool = null,
938 use_stage1: ?bool = null,
939938 single_threaded: ?bool = null,
940939 strip: ?bool = null,
941940 formatted_panics: ?bool = null,
......@@ -1133,9 +1132,6 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation {
11331132 const comp = try arena.create(Compilation);
11341133 const root_name = try arena.dupeZ(u8, options.root_name);
11351134
1136 const use_stage1 = options.use_stage1 orelse false;
1137 if (use_stage1 and !build_options.have_stage1) return error.ZigCompilerBuiltWithoutStage1;
1138
11391135 // Make a decision on whether to use LLVM or our own backend.
11401136 const use_llvm = build_options.have_llvm and blk: {
11411137 if (options.use_llvm) |explicit|
......@@ -1149,11 +1145,6 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation {
11491145 if (options.main_pkg == null)
11501146 break :blk false;
11511147
1152 // The stage1 compiler depends on the stage1 C++ LLVM backend
1153 // to compile zig code.
1154 if (use_stage1)
1155 break :blk true;
1156
11571148 // If LLVM does not support the target, then we can't use it.
11581149 if (!target_util.hasLlvmSupport(options.target, options.target.ofmt))
11591150 break :blk false;
......@@ -1181,8 +1172,10 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation {
11811172 // compiler state, the second clause here can be removed so that incremental
11821173 // cache mode is used for LLVM backend too. We need some fuzz testing before
11831174 // that can be enabled.
1184 const cache_mode = if ((use_stage1 and !options.disable_lld_caching) or
1185 (use_llvm and !options.disable_lld_caching)) CacheMode.whole else options.cache_mode;
1175 const cache_mode = if (use_llvm and !options.disable_lld_caching)
1176 CacheMode.whole
1177 else
1178 options.cache_mode;
11861179
11871180 const tsan = options.want_tsan orelse false;
11881181 // TSAN is implemented in C++ so it requires linking libc++.
......@@ -1545,7 +1538,6 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation {
15451538 // Synchronize with other matching comments: ZigOnlyHashStuff
15461539 hash.add(valgrind);
15471540 hash.add(single_threaded);
1548 hash.add(use_stage1);
15491541 hash.add(use_llvm);
15501542 hash.add(dll_export_fns);
15511543 hash.add(options.is_test);
......@@ -1587,9 +1579,6 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation {
15871579 .handle = artifact_dir,
15881580 .path = try options.local_cache_directory.join(arena, &[_][]const u8{artifact_sub_dir}),
15891581 };
1590 log.debug("zig_cache_artifact_directory='{?s}' use_stage1={}", .{
1591 zig_cache_artifact_directory.path, use_stage1,
1592 });
15931582
15941583 const builtin_pkg = try Package.createWithDir(
15951584 gpa,
......@@ -1907,7 +1896,6 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation {
19071896 .subsystem = options.subsystem,
19081897 .is_test = options.is_test,
19091898 .wasi_exec_model = wasi_exec_model,
1910 .use_stage1 = use_stage1,
19111899 .hash_style = options.hash_style,
19121900 .enable_link_snapshots = options.enable_link_snapshots,
19131901 .native_darwin_sdk = options.native_darwin_sdk,
......@@ -2344,7 +2332,6 @@ pub fn update(comp: *Compilation) !void {
23442332 comp.c_object_work_queue.writeItemAssumeCapacity(key);
23452333 }
23462334
2347 const use_stage1 = build_options.have_stage1 and comp.bin_file.options.use_stage1;
23482335 if (comp.bin_file.options.module) |module| {
23492336 module.compile_log_text.shrinkAndFree(module.gpa, 0);
23502337 module.generation += 1;
......@@ -2360,7 +2347,7 @@ pub fn update(comp: *Compilation) !void {
23602347 // import_table here.
23612348 // Likewise, in the case of `zig test`, the test runner is the root source file,
23622349 // and so there is nothing to import the main file.
2363 if (use_stage1 or comp.bin_file.options.is_test) {
2350 if (comp.bin_file.options.is_test) {
23642351 _ = try module.importPkg(module.main_pkg);
23652352 }
23662353
......@@ -2374,21 +2361,19 @@ pub fn update(comp: *Compilation) !void {
23742361 comp.astgen_work_queue.writeItemAssumeCapacity(value);
23752362 }
23762363
2377 if (!use_stage1) {
2378 // Put a work item in for checking if any files used with `@embedFile` changed.
2379 {
2380 try comp.embed_file_work_queue.ensureUnusedCapacity(module.embed_table.count());
2381 var it = module.embed_table.iterator();
2382 while (it.next()) |entry| {
2383 const embed_file = entry.value_ptr.*;
2384 comp.embed_file_work_queue.writeItemAssumeCapacity(embed_file);
2385 }
2364 // Put a work item in for checking if any files used with `@embedFile` changed.
2365 {
2366 try comp.embed_file_work_queue.ensureUnusedCapacity(module.embed_table.count());
2367 var it = module.embed_table.iterator();
2368 while (it.next()) |entry| {
2369 const embed_file = entry.value_ptr.*;
2370 comp.embed_file_work_queue.writeItemAssumeCapacity(embed_file);
23862371 }
2372 }
23872373
2388 try comp.work_queue.writeItem(.{ .analyze_pkg = std_pkg });
2389 if (comp.bin_file.options.is_test) {
2390 try comp.work_queue.writeItem(.{ .analyze_pkg = module.main_pkg });
2391 }
2374 try comp.work_queue.writeItem(.{ .analyze_pkg = std_pkg });
2375 if (comp.bin_file.options.is_test) {
2376 try comp.work_queue.writeItem(.{ .analyze_pkg = module.main_pkg });
23922377 }
23932378 }
23942379
......@@ -2400,36 +2385,34 @@ pub fn update(comp: *Compilation) !void {
24002385
24012386 try comp.performAllTheWork(main_progress_node);
24022387
2403 if (!use_stage1) {
2404 if (comp.bin_file.options.module) |module| {
2405 if (comp.bin_file.options.is_test and comp.totalErrorCount() == 0) {
2406 // The `test_functions` decl has been intentionally postponed until now,
2407 // at which point we must populate it with the list of test functions that
2408 // have been discovered and not filtered out.
2409 try module.populateTestFunctions(main_progress_node);
2410 }
2388 if (comp.bin_file.options.module) |module| {
2389 if (comp.bin_file.options.is_test and comp.totalErrorCount() == 0) {
2390 // The `test_functions` decl has been intentionally postponed until now,
2391 // at which point we must populate it with the list of test functions that
2392 // have been discovered and not filtered out.
2393 try module.populateTestFunctions(main_progress_node);
2394 }
24112395
2412 // Process the deletion set. We use a while loop here because the
2413 // deletion set may grow as we call `clearDecl` within this loop,
2414 // and more unreferenced Decls are revealed.
2415 while (module.deletion_set.count() != 0) {
2416 const decl_index = module.deletion_set.keys()[0];
2417 const decl = module.declPtr(decl_index);
2418 assert(decl.deletion_flag);
2419 assert(decl.dependants.count() == 0);
2420 const is_anon = if (decl.zir_decl_index == 0) blk: {
2421 break :blk decl.src_namespace.anon_decls.swapRemove(decl_index);
2422 } else false;
2423
2424 try module.clearDecl(decl_index, null);
2425
2426 if (is_anon) {
2427 module.destroyDecl(decl_index);
2428 }
2429 }
2396 // Process the deletion set. We use a while loop here because the
2397 // deletion set may grow as we call `clearDecl` within this loop,
2398 // and more unreferenced Decls are revealed.
2399 while (module.deletion_set.count() != 0) {
2400 const decl_index = module.deletion_set.keys()[0];
2401 const decl = module.declPtr(decl_index);
2402 assert(decl.deletion_flag);
2403 assert(decl.dependants.count() == 0);
2404 const is_anon = if (decl.zir_decl_index == 0) blk: {
2405 break :blk decl.src_namespace.anon_decls.swapRemove(decl_index);
2406 } else false;
2407
2408 try module.clearDecl(decl_index, null);
24302409
2431 try module.processExports();
2410 if (is_anon) {
2411 module.destroyDecl(decl_index);
2412 }
24322413 }
2414
2415 try module.processExports();
24332416 }
24342417
24352418 if (comp.totalErrorCount() != 0) {
......@@ -2536,11 +2519,8 @@ fn flush(comp: *Compilation, prog_node: *std.Progress.Node) !void {
25362519 };
25372520 comp.link_error_flags = comp.bin_file.errorFlags();
25382521
2539 const use_stage1 = build_options.have_stage1 and comp.bin_file.options.use_stage1;
2540 if (!use_stage1) {
2541 if (comp.bin_file.options.module) |module| {
2542 try link.File.C.flushEmitH(module);
2543 }
2522 if (comp.bin_file.options.module) |module| {
2523 try link.File.C.flushEmitH(module);
25442524 }
25452525}
25462526
......@@ -2610,7 +2590,6 @@ fn addNonIncrementalStuffToCacheManifest(comp: *Compilation, man: *Cache.Manifes
26102590 // Synchronize with other matching comments: ZigOnlyHashStuff
26112591 man.hash.add(comp.bin_file.options.valgrind);
26122592 man.hash.add(comp.bin_file.options.single_threaded);
2613 man.hash.add(comp.bin_file.options.use_stage1);
26142593 man.hash.add(comp.bin_file.options.use_llvm);
26152594 man.hash.add(comp.bin_file.options.dll_export_fns);
26162595 man.hash.add(comp.bin_file.options.is_test);
......@@ -3010,8 +2989,6 @@ pub fn performAllTheWork(
30102989 comp.work_queue_wait_group.reset();
30112990 defer comp.work_queue_wait_group.wait();
30122991
3013 const use_stage1 = build_options.have_stage1 and comp.bin_file.options.use_stage1;
3014
30152992 {
30162993 const astgen_frame = tracy.namedFrame("astgen");
30172994 defer astgen_frame.end();
......@@ -3056,7 +3033,7 @@ pub fn performAllTheWork(
30563033 }
30573034 }
30583035
3059 if (!use_stage1) {
3036 {
30603037 const outdated_and_deleted_decls_frame = tracy.namedFrame("outdated_and_deleted_decls");
30613038 defer outdated_and_deleted_decls_frame.end();
30623039
......@@ -3064,15 +3041,6 @@ pub fn performAllTheWork(
30643041 if (comp.bin_file.options.module) |mod| {
30653042 try mod.processOutdatedAndDeletedDecls();
30663043 }
3067 } else if (comp.bin_file.options.module) |mod| {
3068 // If there are any AstGen compile errors, report them now to avoid
3069 // hitting stage1 bugs.
3070 if (mod.failed_files.count() != 0) {
3071 return;
3072 }
3073 comp.updateStage1Module(main_progress_node) catch |err| {
3074 fatal("unable to build stage1 zig object: {s}", .{@errorName(err)});
3075 };
30763044 }
30773045
30783046 if (comp.bin_file.options.module) |mod| {
......@@ -3598,10 +3566,7 @@ pub fn cImport(comp: *Compilation, c_src: []const u8) !CImportResult {
35983566 var man = comp.obtainCObjectCacheManifest();
35993567 defer man.deinit();
36003568
3601 const use_stage1 = build_options.have_stage1 and comp.bin_file.options.use_stage1;
3602
36033569 man.hash.add(@as(u16, 0xb945)); // Random number to distinguish translate-c from compiling C objects
3604 man.hash.add(use_stage1);
36053570 man.hash.addBytes(c_src);
36063571
36073572 // If the previous invocation resulted in clang errors, we will see a hit
......@@ -3665,7 +3630,6 @@ pub fn cImport(comp: *Compilation, c_src: []const u8) !CImportResult {
36653630 new_argv.ptr + new_argv.len,
36663631 &clang_errors,
36673632 c_headers_dir_path_z,
3668 use_stage1,
36693633 ) catch |err| switch (err) {
36703634 error.OutOfMemory => return error.OutOfMemory,
36713635 error.ASTUnitFailure => {
......@@ -5097,8 +5061,6 @@ pub fn dump_argv(argv: []const []const u8) void {
50975061}
50985062
50995063pub fn getZigBackend(comp: Compilation) std.builtin.CompilerBackend {
5100 const use_stage1 = build_options.have_stage1 and comp.bin_file.options.use_stage1;
5101 if (use_stage1) return .stage1;
51025064 if (build_options.have_llvm and comp.bin_file.options.use_llvm) return .stage2_llvm;
51035065 const target = comp.bin_file.options.target;
51045066 if (target.ofmt == .c) return .stage2_c;
......@@ -5394,7 +5356,6 @@ fn buildOutputFromZig(
53945356 .link_mode = .Static,
53955357 .function_sections = true,
53965358 .no_builtin = true,
5397 .use_stage1 = build_options.have_stage1 and comp.bin_file.options.use_stage1,
53985359 .want_sanitize_c = false,
53995360 .want_stack_check = false,
54005361 .want_stack_protector = 0,
src/Sema.zig-2
......@@ -2121,8 +2121,6 @@ fn failWithUseOfAsync(sema: *Sema, block: *Block, src: LazySrcLoc) CompileError
21212121 const msg = msg: {
21222122 const msg = try sema.errMsg(block, src, "async has not been implemented in the self-hosted compiler yet", .{});
21232123 errdefer msg.destroy(sema.gpa);
2124
2125 try sema.errNote(block, src, msg, "to use async enable the stage1 compiler with either '-fstage1' or by setting '.use_stage1 = true` in your 'build.zig' script", .{});
21262124 break :msg msg;
21272125 };
21282126 return sema.failWithOwnedErrorMsg(msg);
src/link.zig+2-21
......@@ -155,7 +155,6 @@ pub const Options = struct {
155155 build_id: bool,
156156 disable_lld_caching: bool,
157157 is_test: bool,
158 use_stage1: bool,
159158 hash_style: HashStyle,
160159 major_subsystem_version: ?u32,
161160 minor_subsystem_version: ?u32,
......@@ -293,8 +292,7 @@ pub const File = struct {
293292 return &(try MachO.openPath(allocator, options)).base;
294293 }
295294
296 const use_stage1 = build_options.have_stage1 and options.use_stage1;
297 if (use_stage1 or options.emit == null) {
295 if (options.emit == null) {
298296 return switch (options.target.ofmt) {
299297 .coff => &(try Coff.createEmpty(allocator, options)).base,
300298 .elf => &(try Elf.createEmpty(allocator, options)).base,
......@@ -983,24 +981,7 @@ pub const File = struct {
983981
984982 // If there is no Zig code to compile, then we should skip flushing the output file
985983 // because it will not be part of the linker line anyway.
986 const module_obj_path: ?[]const u8 = if (base.options.module) |module| blk: {
987 const use_stage1 = build_options.have_stage1 and base.options.use_stage1;
988 if (use_stage1) {
989 const obj_basename = try std.zig.binNameAlloc(arena, .{
990 .root_name = base.options.root_name,
991 .target = base.options.target,
992 .output_mode = .Obj,
993 });
994 switch (base.options.cache_mode) {
995 .incremental => break :blk try module.zig_cache_artifact_directory.join(
996 arena,
997 &[_][]const u8{obj_basename},
998 ),
999 .whole => break :blk try fs.path.join(arena, &.{
1000 fs.path.dirname(full_out_path_z).?, obj_basename,
1001 }),
1002 }
1003 }
984 const module_obj_path: ?[]const u8 = if (base.options.module != null) blk: {
1004985 try base.flushModule(comp, prog_node);
1005986
1006987 const dirname = fs.path.dirname(full_out_path_z) orelse ".";
src/link/Coff.zig+1-2
......@@ -248,8 +248,7 @@ pub fn createEmpty(gpa: Allocator, options: link.Options) !*Coff {
248248 };
249249
250250 const use_llvm = build_options.have_llvm and options.use_llvm;
251 const use_stage1 = build_options.have_stage1 and options.use_stage1;
252 if (use_llvm and !use_stage1) {
251 if (use_llvm) {
253252 self.llvm_object = try LlvmObject.create(gpa, options);
254253 }
255254 return self;
src/link/Coff/lld.zig+1-19
......@@ -30,25 +30,7 @@ pub fn linkWithLLD(self: *Coff, comp: *Compilation, prog_node: *std.Progress.Nod
3030
3131 // If there is no Zig code to compile, then we should skip flushing the output file because it
3232 // will not be part of the linker line anyway.
33 const module_obj_path: ?[]const u8 = if (self.base.options.module) |module| blk: {
34 const use_stage1 = build_options.have_stage1 and self.base.options.use_stage1;
35 if (use_stage1) {
36 const obj_basename = try std.zig.binNameAlloc(arena, .{
37 .root_name = self.base.options.root_name,
38 .target = self.base.options.target,
39 .output_mode = .Obj,
40 });
41 switch (self.base.options.cache_mode) {
42 .incremental => break :blk try module.zig_cache_artifact_directory.join(
43 arena,
44 &[_][]const u8{obj_basename},
45 ),
46 .whole => break :blk try fs.path.join(arena, &.{
47 fs.path.dirname(full_out_path).?, obj_basename,
48 }),
49 }
50 }
51
33 const module_obj_path: ?[]const u8 = if (self.base.options.module != null) blk: {
5234 try self.flushModule(comp, prog_node);
5335
5436 if (fs.path.dirname(full_out_path)) |dirname| {
src/link/Elf.zig+2-21
......@@ -328,8 +328,7 @@ pub fn createEmpty(gpa: Allocator, options: link.Options) !*Elf {
328328 .page_size = page_size,
329329 };
330330 const use_llvm = build_options.have_llvm and options.use_llvm;
331 const use_stage1 = build_options.have_stage1 and options.use_stage1;
332 if (use_llvm and !use_stage1) {
331 if (use_llvm) {
333332 self.llvm_object = try LlvmObject.create(gpa, options);
334333 }
335334 return self;
......@@ -1228,25 +1227,7 @@ fn linkWithLLD(self: *Elf, comp: *Compilation, prog_node: *std.Progress.Node) !v
12281227
12291228 // If there is no Zig code to compile, then we should skip flushing the output file because it
12301229 // will not be part of the linker line anyway.
1231 const module_obj_path: ?[]const u8 = if (self.base.options.module) |module| blk: {
1232 // stage1 puts the object file in the cache directory.
1233 if (self.base.options.use_stage1) {
1234 const obj_basename = try std.zig.binNameAlloc(arena, .{
1235 .root_name = self.base.options.root_name,
1236 .target = self.base.options.target,
1237 .output_mode = .Obj,
1238 });
1239 switch (self.base.options.cache_mode) {
1240 .incremental => break :blk try module.zig_cache_artifact_directory.join(
1241 arena,
1242 &[_][]const u8{obj_basename},
1243 ),
1244 .whole => break :blk try fs.path.join(arena, &.{
1245 fs.path.dirname(full_out_path).?, obj_basename,
1246 }),
1247 }
1248 }
1249
1230 const module_obj_path: ?[]const u8 = if (self.base.options.module != null) blk: {
12501231 try self.flushModule(comp, prog_node);
12511232
12521233 if (fs.path.dirname(full_out_path)) |dirname| {
src/link/MachO.zig+3-5
......@@ -290,8 +290,7 @@ pub const Export = struct {
290290pub fn openPath(allocator: Allocator, options: link.Options) !*MachO {
291291 assert(options.target.ofmt == .macho);
292292
293 const use_stage1 = build_options.have_stage1 and options.use_stage1;
294 if (use_stage1 or options.emit == null or options.module == null) {
293 if (options.emit == null or options.module == null) {
295294 return createEmpty(allocator, options);
296295 }
297296
......@@ -377,7 +376,6 @@ pub fn createEmpty(gpa: Allocator, options: link.Options) !*MachO {
377376 const cpu_arch = options.target.cpu.arch;
378377 const page_size: u16 = if (cpu_arch == .aarch64) 0x4000 else 0x1000;
379378 const use_llvm = build_options.have_llvm and options.use_llvm;
380 const use_stage1 = build_options.have_stage1 and options.use_stage1;
381379
382380 const self = try gpa.create(MachO);
383381 errdefer gpa.destroy(self);
......@@ -390,13 +388,13 @@ pub fn createEmpty(gpa: Allocator, options: link.Options) !*MachO {
390388 .file = null,
391389 },
392390 .page_size = page_size,
393 .mode = if (use_stage1 or use_llvm or options.module == null or options.cache_mode == .whole)
391 .mode = if (use_llvm or options.module == null or options.cache_mode == .whole)
394392 .one_shot
395393 else
396394 .incremental,
397395 };
398396
399 if (use_llvm and !use_stage1) {
397 if (use_llvm) {
400398 self.llvm_object = try LlvmObject.create(gpa, options);
401399 }
402400
src/link/MachO/zld.zig+1-18
......@@ -3746,24 +3746,7 @@ pub fn linkWithZld(macho_file: *MachO, comp: *Compilation, prog_node: *std.Progr
37463746
37473747 // If there is no Zig code to compile, then we should skip flushing the output file because it
37483748 // will not be part of the linker line anyway.
3749 const module_obj_path: ?[]const u8 = if (options.module) |module| blk: {
3750 if (options.use_stage1) {
3751 const obj_basename = try std.zig.binNameAlloc(arena, .{
3752 .root_name = options.root_name,
3753 .target = target,
3754 .output_mode = .Obj,
3755 });
3756 switch (options.cache_mode) {
3757 .incremental => break :blk try module.zig_cache_artifact_directory.join(
3758 arena,
3759 &[_][]const u8{obj_basename},
3760 ),
3761 .whole => break :blk try fs.path.join(arena, &.{
3762 fs.path.dirname(full_out_path).?, obj_basename,
3763 }),
3764 }
3765 }
3766
3749 const module_obj_path: ?[]const u8 = if (options.module != null) blk: {
37673750 try macho_file.flushModule(comp, prog_node);
37683751
37693752 if (fs.path.dirname(full_out_path)) |dirname| {
src/link/Wasm.zig+14-40
......@@ -382,8 +382,7 @@ pub fn createEmpty(gpa: Allocator, options: link.Options) !*Wasm {
382382 };
383383
384384 const use_llvm = build_options.have_llvm and options.use_llvm;
385 const use_stage1 = build_options.have_stage1 and options.use_stage1;
386 if (use_llvm and !use_stage1) {
385 if (use_llvm) {
387386 wasm.llvm_object = try LlvmObject.create(gpa, options);
388387 }
389388 return wasm;
......@@ -2986,25 +2985,7 @@ fn linkWithLLD(wasm: *Wasm, comp: *Compilation, prog_node: *std.Progress.Node) !
29862985
29872986 // If there is no Zig code to compile, then we should skip flushing the output file because it
29882987 // will not be part of the linker line anyway.
2989 const module_obj_path: ?[]const u8 = if (wasm.base.options.module) |mod| blk: {
2990 const use_stage1 = build_options.have_stage1 and wasm.base.options.use_stage1;
2991 if (use_stage1) {
2992 const obj_basename = try std.zig.binNameAlloc(arena, .{
2993 .root_name = wasm.base.options.root_name,
2994 .target = wasm.base.options.target,
2995 .output_mode = .Obj,
2996 });
2997 switch (wasm.base.options.cache_mode) {
2998 .incremental => break :blk try mod.zig_cache_artifact_directory.join(
2999 arena,
3000 &[_][]const u8{obj_basename},
3001 ),
3002 .whole => break :blk try fs.path.join(arena, &.{
3003 fs.path.dirname(full_out_path).?, obj_basename,
3004 }),
3005 }
3006 }
3007
2988 const module_obj_path: ?[]const u8 = if (wasm.base.options.module != null) blk: {
30082989 try wasm.flushModule(comp, prog_node);
30092990
30102991 if (fs.path.dirname(full_out_path)) |dirname| {
......@@ -3198,26 +3179,19 @@ fn linkWithLLD(wasm: *Wasm, comp: *Compilation, prog_node: *std.Progress.Node) !
31983179 if (wasm.base.options.module) |mod| {
31993180 // when we use stage1, we use the exports that stage1 provided us.
32003181 // For stage2, we can directly retrieve them from the module.
3201 const use_stage1 = build_options.have_stage1 and wasm.base.options.use_stage1;
3202 if (use_stage1) {
3203 for (comp.export_symbol_names.items) |symbol_name| {
3204 try argv.append(try std.fmt.allocPrint(arena, "--export={s}", .{symbol_name}));
3205 }
3206 } else {
3207 const skip_export_non_fn = target.os.tag == .wasi and
3208 wasm.base.options.wasi_exec_model == .command;
3209 for (mod.decl_exports.values()) |exports| {
3210 for (exports.items) |exprt| {
3211 const exported_decl = mod.declPtr(exprt.exported_decl);
3212 if (skip_export_non_fn and exported_decl.ty.zigTypeTag() != .Fn) {
3213 // skip exporting symbols when we're building a WASI command
3214 // and the symbol is not a function
3215 continue;
3216 }
3217 const symbol_name = exported_decl.name;
3218 const arg = try std.fmt.allocPrint(arena, "--export={s}", .{symbol_name});
3219 try argv.append(arg);
3182 const skip_export_non_fn = target.os.tag == .wasi and
3183 wasm.base.options.wasi_exec_model == .command;
3184 for (mod.decl_exports.values()) |exports| {
3185 for (exports.items) |exprt| {
3186 const exported_decl = mod.declPtr(exprt.exported_decl);
3187 if (skip_export_non_fn and exported_decl.ty.zigTypeTag() != .Fn) {
3188 // skip exporting symbols when we're building a WASI command
3189 // and the symbol is not a function
3190 continue;
32203191 }
3192 const symbol_name = exported_decl.name;
3193 const arg = try std.fmt.allocPrint(arena, "--export={s}", .{symbol_name});
3194 try argv.append(arg);
32213195 }
32223196 }
32233197 }
src/main.zig+2-23
......@@ -394,8 +394,6 @@ const usage_build_generic =
394394 \\ -fno-LLVM Prevent using LLVM as the codegen backend
395395 \\ -fClang Force using Clang as the C/C++ compilation backend
396396 \\ -fno-Clang Prevent using Clang as the C/C++ compilation backend
397 \\ -fstage1 Force using bootstrap compiler as the codegen backend
398 \\ -fno-stage1 Prevent using bootstrap compiler as the codegen backend
399397 \\ -freference-trace[=num] How many lines of reference trace should be shown per compile error
400398 \\ -fno-reference-trace Disable reference trace
401399 \\ -fsingle-threaded Code assumes there is only one thread
......@@ -719,7 +717,6 @@ fn buildOutputType(
719717 var use_llvm: ?bool = null;
720718 var use_lld: ?bool = null;
721719 var use_clang: ?bool = null;
722 var use_stage1: ?bool = null;
723720 var link_eh_frame_hdr = false;
724721 var link_emit_relocs = false;
725722 var each_lib_rpath: ?bool = null;
......@@ -1158,10 +1155,6 @@ fn buildOutputType(
11581155 use_clang = true;
11591156 } else if (mem.eql(u8, arg, "-fno-Clang")) {
11601157 use_clang = false;
1161 } else if (mem.eql(u8, arg, "-fstage1")) {
1162 use_stage1 = true;
1163 } else if (mem.eql(u8, arg, "-fno-stage1")) {
1164 use_stage1 = false;
11651158 } else if (mem.eql(u8, arg, "-freference-trace")) {
11661159 reference_trace = 256;
11671160 } else if (mem.startsWith(u8, arg, "-freference-trace=")) {
......@@ -2909,7 +2902,6 @@ fn buildOutputType(
29092902 .use_llvm = use_llvm,
29102903 .use_lld = use_lld,
29112904 .use_clang = use_clang,
2912 .use_stage1 = use_stage1,
29132905 .hash_style = hash_style,
29142906 .rdynamic = rdynamic,
29152907 .linker_script = linker_script,
......@@ -3024,8 +3016,7 @@ fn buildOutputType(
30243016 return std.io.getStdOut().writeAll(try comp.generateBuiltinZigSource(arena));
30253017 }
30263018 if (arg_mode == .translate_c) {
3027 const stage1_mode = use_stage1 orelse false;
3028 return cmdTranslateC(comp, arena, have_enable_cache, stage1_mode);
3019 return cmdTranslateC(comp, arena, have_enable_cache);
30293020 }
30303021
30313022 const hook: AfterUpdateHook = blk: {
......@@ -3444,7 +3435,7 @@ fn freePkgTree(gpa: Allocator, pkg: *Package, free_parent: bool) void {
34443435 }
34453436}
34463437
3447fn cmdTranslateC(comp: *Compilation, arena: Allocator, enable_cache: bool, stage1_mode: bool) !void {
3438fn cmdTranslateC(comp: *Compilation, arena: Allocator, enable_cache: bool) !void {
34483439 if (!build_options.have_llvm)
34493440 fatal("cannot translate-c: compiler built without LLVM extensions", .{});
34503441
......@@ -3457,7 +3448,6 @@ fn cmdTranslateC(comp: *Compilation, arena: Allocator, enable_cache: bool, stage
34573448 defer if (enable_cache) man.deinit();
34583449
34593450 man.hash.add(@as(u16, 0xb945)); // Random number to distinguish translate-c from compiling C objects
3460 man.hash.add(stage1_mode);
34613451 man.hashCSource(c_source_file) catch |err| {
34623452 fatal("unable to process '{s}': {s}", .{ c_source_file.src_path, @errorName(err) });
34633453 };
......@@ -3509,7 +3499,6 @@ fn cmdTranslateC(comp: *Compilation, arena: Allocator, enable_cache: bool, stage
35093499 new_argv.ptr + new_argv.len,
35103500 &clang_errors,
35113501 c_headers_dir_path_z,
3512 stage1_mode,
35133502 ) catch |err| switch (err) {
35143503 error.OutOfMemory => return error.OutOfMemory,
35153504 error.ASTUnitFailure => fatal("clang API returned errors but due to a clang bug, it is not exposing the errors for zig to see. For more details: https://github.com/ziglang/zig/issues/4455", .{}),
......@@ -3755,8 +3744,6 @@ pub const usage_build =
37553744 \\ Build a project from build.zig.
37563745 \\
37573746 \\Options:
3758 \\ -fstage1 Force using bootstrap compiler as the codegen backend
3759 \\ -fno-stage1 Prevent using bootstrap compiler as the codegen backend
37603747 \\ -freference-trace[=num] How many lines of reference trace should be shown per compile error
37613748 \\ -fno-reference-trace Disable reference trace
37623749 \\ --build-file [file] Override path to build.zig
......@@ -3770,7 +3757,6 @@ pub const usage_build =
37703757
37713758pub fn cmdBuild(gpa: Allocator, arena: Allocator, args: []const []const u8) !void {
37723759 var prominent_compile_errors: bool = false;
3773 var use_stage1: ?bool = null;
37743760
37753761 // We want to release all the locks before executing the child process, so we make a nice
37763762 // big block here to ensure the cleanup gets run when we extract out our argv.
......@@ -3827,12 +3813,6 @@ pub fn cmdBuild(gpa: Allocator, arena: Allocator, args: []const []const u8) !voi
38273813 continue;
38283814 } else if (mem.eql(u8, arg, "--prominent-compile-errors")) {
38293815 prominent_compile_errors = true;
3830 } else if (mem.eql(u8, arg, "-fstage1")) {
3831 use_stage1 = true;
3832 try child_argv.append(arg);
3833 } else if (mem.eql(u8, arg, "-fno-stage1")) {
3834 use_stage1 = false;
3835 try child_argv.append(arg);
38363816 } else if (mem.eql(u8, arg, "-freference-trace")) {
38373817 try child_argv.append(arg);
38383818 reference_trace = 256;
......@@ -3979,7 +3959,6 @@ pub fn cmdBuild(gpa: Allocator, arena: Allocator, args: []const []const u8) !voi
39793959 .optimize_mode = .Debug,
39803960 .self_exe_path = self_exe_path,
39813961 .thread_pool = &thread_pool,
3982 .use_stage1 = use_stage1,
39833962 .cache_mode = .whole,
39843963 .reference_trace = reference_trace,
39853964 .debug_compile_errors = debug_compile_errors,
src/test.zig-1
......@@ -1548,7 +1548,6 @@ pub const TestContext = struct {
15481548 .dynamic_linker = target_info.dynamic_linker.get(),
15491549 .link_libc = case.link_libc,
15501550 .use_llvm = use_llvm,
1551 .use_stage1 = null, // We already handled stage1 tests
15521551 .self_exe_path = zig_exe_path,
15531552 // TODO instead of turning off color, pass in a std.Progress.Node
15541553 .color = .off,
src/translate_c.zig+3-24
......@@ -327,16 +327,6 @@ pub const Context = struct {
327327
328328 pattern_list: PatternList,
329329
330 /// This is used to emit different code depending on whether
331 /// the output zig source code is intended to be compiled with stage1 or stage2.
332 /// Ideally we will have stage1 and stage2 support the exact same Zig language,
333 /// but for now they diverge because I would rather focus on finishing and shipping
334 /// stage2 than implementing the features in stage1.
335 /// The list of differences are currently:
336 /// * function pointers in stage1 are e.g. `fn()void`
337 /// but in stage2 they are `*const fn()void`.
338 zig_is_stage1: bool,
339
340330 fn getMangle(c: *Context) u32 {
341331 c.mangle_count += 1;
342332 return c.mangle_count;
......@@ -365,7 +355,6 @@ pub fn translate(
365355 args_end: [*]?[*]const u8,
366356 errors: *[]ClangErrMsg,
367357 resources_path: [*:0]const u8,
368 zig_is_stage1: bool,
369358) !std.zig.Ast {
370359 // TODO stage2 bug
371360 var tmp = errors;
......@@ -395,7 +384,6 @@ pub fn translate(
395384 .global_scope = try arena.create(Scope.Root),
396385 .clang_context = ast_unit.getASTContext(),
397386 .pattern_list = try PatternList.init(gpa),
398 .zig_is_stage1 = zig_is_stage1,
399387 };
400388 context.global_scope.* = Scope.Root.init(&context);
401389 defer {
......@@ -435,7 +423,7 @@ pub fn translate(
435423 }
436424 }
437425
438 return ast.render(gpa, zig_is_stage1, context.global_scope.nodes.items);
426 return ast.render(gpa, context.global_scope.nodes.items);
439427}
440428
441429/// Determines whether macro is of the form: `#define FOO FOO` (Possibly with trailing tokens)
......@@ -4747,9 +4735,6 @@ fn transType(c: *Context, scope: *Scope, ty: *const clang.Type, source_loc: clan
47474735 .Pointer => {
47484736 const child_qt = ty.getPointeeType();
47494737 const is_fn_proto = qualTypeChildIsFnProto(child_qt);
4750 if (c.zig_is_stage1 and is_fn_proto) {
4751 return Tag.optional_type.create(c.arena, try transQualType(c, scope, child_qt, source_loc));
4752 }
47534738 const is_const = is_fn_proto or child_qt.isConstQualified();
47544739 const is_volatile = child_qt.isVolatileQualified();
47554740 const elem_type = try transQualType(c, scope, child_qt, source_loc);
......@@ -6681,16 +6666,10 @@ fn getFnProto(c: *Context, ref: Node) ?*ast.Payload.Func {
66816666 return null;
66826667 if (getContainerTypeOf(c, init)) |ty_node| {
66836668 if (ty_node.castTag(.optional_type)) |prefix| {
6684 if (c.zig_is_stage1) {
6685 if (prefix.data.castTag(.func)) |fn_proto| {
6669 if (prefix.data.castTag(.single_pointer)) |sp| {
6670 if (sp.data.elem_type.castTag(.func)) |fn_proto| {
66866671 return fn_proto;
66876672 }
6688 } else {
6689 if (prefix.data.castTag(.single_pointer)) |sp| {
6690 if (sp.data.elem_type.castTag(.func)) |fn_proto| {
6691 return fn_proto;
6692 }
6693 }
66946673 }
66956674 }
66966675 }
src/translate_c/ast.zig+17-31
......@@ -732,11 +732,10 @@ pub const Payload = struct {
732732
733733/// Converts the nodes into a Zig Ast.
734734/// Caller must free the source slice.
735pub fn render(gpa: Allocator, zig_is_stage1: bool, nodes: []const Node) !std.zig.Ast {
735pub fn render(gpa: Allocator, nodes: []const Node) !std.zig.Ast {
736736 var ctx = Context{
737737 .gpa = gpa,
738738 .buf = std.ArrayList(u8).init(gpa),
739 .zig_is_stage1 = zig_is_stage1,
740739 };
741740 defer ctx.buf.deinit();
742741 defer ctx.nodes.deinit(gpa);
......@@ -805,11 +804,6 @@ const Context = struct {
805804 extra_data: std.ArrayListUnmanaged(std.zig.Ast.Node.Index) = .{},
806805 tokens: std.zig.Ast.TokenList = .{},
807806
808 /// This is used to emit different code depending on whether
809 /// the output zig source code is intended to be compiled with stage1 or stage2.
810 /// Refer to the Context in translate_c.zig.
811 zig_is_stage1: bool,
812
813807 fn addTokenFmt(c: *Context, tag: TokenTag, comptime format: []const u8, args: anytype) Allocator.Error!TokenIndex {
814808 const start_index = c.buf.items.len;
815809 try c.buf.writer().print(format ++ " ", args);
......@@ -932,7 +926,7 @@ fn renderNode(c: *Context, node: Node) Allocator.Error!NodeIndex {
932926 .call => {
933927 const payload = node.castTag(.call).?.data;
934928 // Cosmetic: avoids an unnecesary address_of on most function calls.
935 const lhs = if (!c.zig_is_stage1 and payload.lhs.tag() == .fn_identifier)
929 const lhs = if (payload.lhs.tag() == .fn_identifier)
936930 try c.addNode(.{
937931 .tag = .identifier,
938932 .main_token = try c.addIdentifier(payload.lhs.castTag(.fn_identifier).?.data),
......@@ -1097,28 +1091,20 @@ fn renderNode(c: *Context, node: Node) Allocator.Error!NodeIndex {
10971091 // value (implicit in stage1, explicit in stage2), except in
10981092 // the context of an address_of, which is handled there.
10991093 const payload = node.castTag(.fn_identifier).?.data;
1100 if (c.zig_is_stage1) {
1101 return try c.addNode(.{
1102 .tag = .identifier,
1103 .main_token = try c.addIdentifier(payload),
1104 .data = undefined,
1105 });
1106 } else {
1107 const tok = try c.addToken(.ampersand, "&");
1108 const arg = try c.addNode(.{
1109 .tag = .identifier,
1110 .main_token = try c.addIdentifier(payload),
1111 .data = undefined,
1112 });
1113 return c.addNode(.{
1114 .tag = .address_of,
1115 .main_token = tok,
1116 .data = .{
1117 .lhs = arg,
1118 .rhs = undefined,
1119 },
1120 });
1121 }
1094 const tok = try c.addToken(.ampersand, "&");
1095 const arg = try c.addNode(.{
1096 .tag = .identifier,
1097 .main_token = try c.addIdentifier(payload),
1098 .data = undefined,
1099 });
1100 return c.addNode(.{
1101 .tag = .address_of,
1102 .main_token = tok,
1103 .data = .{
1104 .lhs = arg,
1105 .rhs = undefined,
1106 },
1107 });
11221108 },
11231109 .float_literal => {
11241110 const payload = node.castTag(.float_literal).?.data;
......@@ -1448,7 +1434,7 @@ fn renderNode(c: *Context, node: Node) Allocator.Error!NodeIndex {
14481434 .optional_type => return renderPrefixOp(c, node, .optional_type, .question_mark, "?"),
14491435 .address_of => {
14501436 const payload = node.castTag(.address_of).?.data;
1451 if (c.zig_is_stage1 and payload.tag() == .fn_identifier)
1437 if (payload.tag() == .fn_identifier)
14521438 return try c.addNode(.{
14531439 .tag = .identifier,
14541440 .main_token = try c.addIdentifier(payload.castTag(.fn_identifier).?.data),
test/link/wasm/archive/build.zig-1
......@@ -13,7 +13,6 @@ pub fn build(b: *Builder) void {
1313 lib.setBuildMode(mode);
1414 lib.setTarget(.{ .cpu_arch = .wasm32, .os_tag = .freestanding });
1515 lib.use_llvm = false;
16 lib.use_stage1 = false;
1716 lib.use_lld = false;
1817 lib.strip = false;
1918
test/link/wasm/bss/build.zig-1
......@@ -11,7 +11,6 @@ pub fn build(b: *Builder) void {
1111 lib.setBuildMode(mode);
1212 lib.setTarget(.{ .cpu_arch = .wasm32, .os_tag = .freestanding });
1313 lib.use_llvm = false;
14 lib.use_stage1 = false;
1514 lib.use_lld = false;
1615 lib.strip = false;
1716 // to make sure the bss segment is emitted, we must import memory
test/link/wasm/producers/build.zig-1
......@@ -12,7 +12,6 @@ pub fn build(b: *Builder) void {
1212 lib.setBuildMode(mode);
1313 lib.setTarget(.{ .cpu_arch = .wasm32, .os_tag = .freestanding });
1414 lib.use_llvm = false;
15 lib.use_stage1 = false;
1615 lib.use_lld = false;
1716 lib.strip = false;
1817 lib.install();
test/link/wasm/segments/build.zig-1
......@@ -11,7 +11,6 @@ pub fn build(b: *Builder) void {
1111 lib.setBuildMode(mode);
1212 lib.setTarget(.{ .cpu_arch = .wasm32, .os_tag = .freestanding });
1313 lib.use_llvm = false;
14 lib.use_stage1 = false;
1514 lib.use_lld = false;
1615 lib.strip = false;
1716 lib.install();
test/link/wasm/stack_pointer/build.zig-1
......@@ -11,7 +11,6 @@ pub fn build(b: *Builder) void {
1111 lib.setBuildMode(mode);
1212 lib.setTarget(.{ .cpu_arch = .wasm32, .os_tag = .freestanding });
1313 lib.use_llvm = false;
14 lib.use_stage1 = false;
1514 lib.use_lld = false;
1615 lib.strip = false;
1716 lib.stack_size = std.wasm.page_size * 2; // set an explicit stack size
test/link/wasm/type/build.zig-1
......@@ -11,7 +11,6 @@ pub fn build(b: *Builder) void {
1111 lib.setBuildMode(mode);
1212 lib.setTarget(.{ .cpu_arch = .wasm32, .os_tag = .freestanding });
1313 lib.use_llvm = false;
14 lib.use_stage1 = false;
1514 lib.use_lld = false;
1615 lib.strip = false;
1716 lib.install();
test/tests.zig+3-7
......@@ -720,20 +720,18 @@ pub fn addPkgTests(
720720 these_tests.addIncludePath("test");
721721 if (test_target.backend) |backend| switch (backend) {
722722 .stage1 => {
723 these_tests.use_stage1 = true;
723 @panic("stage1 testing requested");
724724 },
725725 .stage2_llvm => {
726 these_tests.use_stage1 = false;
727726 these_tests.use_llvm = true;
728727 },
729728 .stage2_c => {
730 these_tests.use_stage1 = false;
731729 these_tests.use_llvm = false;
732730 },
733731 else => {
734 these_tests.use_stage1 = false;
735732 these_tests.use_llvm = false;
736 // TODO: force self-hosted linkers to avoid LLD creeping in until the auto-select mechanism deems them worthy
733 // TODO: force self-hosted linkers to avoid LLD creeping in
734 // until the auto-select mechanism deems them worthy
737735 these_tests.use_lld = false;
738736 },
739737 };
......@@ -1355,8 +1353,6 @@ pub fn addCAbiTests(b: *build.Builder, skip_non_native: bool) *build.Step {
13551353 triple_prefix,
13561354 }));
13571355
1358 test_step.use_stage1 = false;
1359
13601356 step.dependOn(&test_step.step);
13611357 }
13621358 return step;