| author | |
| committer | |
| log | b60fc16b4f6b973ce2207fb28b77606d45961972 |
| tree | eb90eb7d6cfcfa8d90f821b34c4e6d17e7159e1a |
| parent | 155f5274ff4db3bc6e75ae5660cabab5bab22f42 |
* Introduce `-Ddebug-extensions` for enabling compiler debug helpers
* Replace safety mode checks with `std.debug.runtime_safety`
* Replace debugger helper checks with `!builtin.strip_debug_info`
Sometimes, you just have to debug optimized compilers...19 files changed, 70 insertions(+), 81 deletions(-)
bootstrap.c+4-4| ... | @@ -131,15 +131,15 @@ int main(int argc, char **argv) { | ... | @@ -131,15 +131,15 @@ int main(int argc, char **argv) { |
| 131 | "pub const llvm_has_xtensa = false;\n" | 131 | "pub const llvm_has_xtensa = false;\n" |
| 132 | "pub const version: [:0]const u8 = \"%s\";\n" | 132 | "pub const version: [:0]const u8 = \"%s\";\n" |
| 133 | "pub const semver = @import(\"std\").SemanticVersion.parse(version) catch unreachable;\n" | 133 | "pub const semver = @import(\"std\").SemanticVersion.parse(version) catch unreachable;\n" |
| 134 | "pub const enable_logging: bool = false;\n" | 134 | "pub const enable_debug_extensions = false;\n" |
| 135 | "pub const enable_link_snapshots: bool = false;\n" | 135 | "pub const enable_logging = false;\n" |
| 136 | "pub const enable_link_snapshots = false;\n" | ||
| 136 | "pub const enable_tracy = false;\n" | 137 | "pub const enable_tracy = false;\n" |
| 137 | "pub const value_tracing = false;\n" | 138 | "pub const value_tracing = false;\n" |
| 138 | "pub const skip_non_native = false;\n" | 139 | "pub const skip_non_native = false;\n" |
| 139 | "pub const only_c = false;\n" | ||
| 140 | "pub const force_gpa = false;\n" | 140 | "pub const force_gpa = false;\n" |
| 141 | "pub const only_c = false;\n" | ||
| 141 | "pub const only_core_functionality = true;\n" | 142 | "pub const only_core_functionality = true;\n" |
| 142 | "pub const only_reduce = false;\n" | ||
| 143 | , zig_version); | 143 | , zig_version); |
| 144 | if (written < 100) | 144 | if (written < 100) |
| 145 | panic("unable to write to config.zig file"); | 145 | panic("unable to write to config.zig file"); |
build.zig+4| ... | @@ -250,6 +250,7 @@ pub fn build(b: *std.Build) !void { | ... | @@ -250,6 +250,7 @@ pub fn build(b: *std.Build) !void { |
| 250 | } | 250 | } |
| 251 | 251 | ||
| 252 | const is_debug = optimize == .Debug; | 252 | const is_debug = optimize == .Debug; |
| 253 | const enable_debug_extensions = b.option(bool, "debug-extensions", "Enable commands and options useful for debugging the compiler") orelse is_debug; | ||
| 253 | const enable_logging = b.option(bool, "log", "Enable debug logging with --debug-log") orelse is_debug; | 254 | const enable_logging = b.option(bool, "log", "Enable debug logging with --debug-log") orelse is_debug; |
| 254 | const enable_link_snapshots = b.option(bool, "link-snapshot", "Whether to enable linker state snapshots") orelse false; | 255 | const enable_link_snapshots = b.option(bool, "link-snapshot", "Whether to enable linker state snapshots") orelse false; |
| 255 | 256 | ||
| ... | @@ -357,6 +358,7 @@ pub fn build(b: *std.Build) !void { | ... | @@ -357,6 +358,7 @@ pub fn build(b: *std.Build) !void { |
| 357 | const semver = try std.SemanticVersion.parse(version); | 358 | const semver = try std.SemanticVersion.parse(version); |
| 358 | exe_options.addOption(std.SemanticVersion, "semver", semver); | 359 | exe_options.addOption(std.SemanticVersion, "semver", semver); |
| 359 | 360 | ||
| 361 | exe_options.addOption(bool, "enable_debug_extensions", enable_debug_extensions); | ||
| 360 | exe_options.addOption(bool, "enable_logging", enable_logging); | 362 | exe_options.addOption(bool, "enable_logging", enable_logging); |
| 361 | exe_options.addOption(bool, "enable_link_snapshots", enable_link_snapshots); | 363 | exe_options.addOption(bool, "enable_link_snapshots", enable_link_snapshots); |
| 362 | exe_options.addOption(bool, "enable_tracy", tracy != null); | 364 | exe_options.addOption(bool, "enable_tracy", tracy != null); |
| ... | @@ -393,6 +395,7 @@ pub fn build(b: *std.Build) !void { | ... | @@ -393,6 +395,7 @@ pub fn build(b: *std.Build) !void { |
| 393 | check_case_exe.root_module.addOptions("build_options", test_cases_options); | 395 | check_case_exe.root_module.addOptions("build_options", test_cases_options); |
| 394 | 396 | ||
| 395 | test_cases_options.addOption(bool, "enable_tracy", false); | 397 | test_cases_options.addOption(bool, "enable_tracy", false); |
| 398 | test_cases_options.addOption(bool, "enable_debug_extensions", enable_debug_extensions); | ||
| 396 | test_cases_options.addOption(bool, "enable_logging", enable_logging); | 399 | test_cases_options.addOption(bool, "enable_logging", enable_logging); |
| 397 | test_cases_options.addOption(bool, "enable_link_snapshots", enable_link_snapshots); | 400 | test_cases_options.addOption(bool, "enable_link_snapshots", enable_link_snapshots); |
| 398 | test_cases_options.addOption(bool, "skip_non_native", skip_non_native); | 401 | test_cases_options.addOption(bool, "skip_non_native", skip_non_native); |
| ... | @@ -588,6 +591,7 @@ fn addWasiUpdateStep(b: *std.Build, version: [:0]const u8) !void { | ... | @@ -588,6 +591,7 @@ fn addWasiUpdateStep(b: *std.Build, version: [:0]const u8) !void { |
| 588 | exe_options.addOption(bool, "only_c", true); | 591 | exe_options.addOption(bool, "only_c", true); |
| 589 | exe_options.addOption([:0]const u8, "version", version); | 592 | exe_options.addOption([:0]const u8, "version", version); |
| 590 | exe_options.addOption(std.SemanticVersion, "semver", semver); | 593 | exe_options.addOption(std.SemanticVersion, "semver", semver); |
| 594 | exe_options.addOption(bool, "enable_debug_extensions", false); | ||
| 591 | exe_options.addOption(bool, "enable_logging", false); | 595 | exe_options.addOption(bool, "enable_logging", false); |
| 592 | exe_options.addOption(bool, "enable_link_snapshots", false); | 596 | exe_options.addOption(bool, "enable_link_snapshots", false); |
| 593 | exe_options.addOption(bool, "enable_tracy", false); | 597 | exe_options.addOption(bool, "enable_tracy", false); |
lib/std/hash_map.zig+1-1| ... | @@ -1601,7 +1601,7 @@ pub fn HashMapUnmanaged( | ... | @@ -1601,7 +1601,7 @@ pub fn HashMapUnmanaged( |
| 1601 | } | 1601 | } |
| 1602 | 1602 | ||
| 1603 | comptime { | 1603 | comptime { |
| 1604 | if (builtin.mode == .Debug) { | 1604 | if (!builtin.strip_debug_info) { |
| 1605 | _ = &dbHelper; | 1605 | _ = &dbHelper; |
| 1606 | } | 1606 | } |
| 1607 | } | 1607 | } |
lib/std/multi_array_list.zig+1-1| ... | @@ -574,7 +574,7 @@ pub fn MultiArrayList(comptime T: type) type { | ... | @@ -574,7 +574,7 @@ pub fn MultiArrayList(comptime T: type) type { |
| 574 | } | 574 | } |
| 575 | 575 | ||
| 576 | comptime { | 576 | comptime { |
| 577 | if (builtin.mode == .Debug) { | 577 | if (!builtin.strip_debug_info) { |
| 578 | _ = &dbHelper; | 578 | _ = &dbHelper; |
| 579 | _ = &Slice.dbHelper; | 579 | _ = &Slice.dbHelper; |
| 580 | } | 580 | } |
src/Air.zig+2-2| ... | @@ -1102,10 +1102,10 @@ pub const Inst = struct { | ... | @@ -1102,10 +1102,10 @@ pub const Inst = struct { |
| 1102 | }; | 1102 | }; |
| 1103 | 1103 | ||
| 1104 | // Make sure we don't accidentally add a field to make this union | 1104 | // Make sure we don't accidentally add a field to make this union |
| 1105 | // bigger than expected. Note that in Debug builds, Zig is allowed | 1105 | // bigger than expected. Note that in safety builds, Zig is allowed |
| 1106 | // to insert a secret field for safety checks. | 1106 | // to insert a secret field for safety checks. |
| 1107 | comptime { | 1107 | comptime { |
| 1108 | if (builtin.mode != .Debug and builtin.mode != .ReleaseSafe) { | 1108 | if (!std.debug.runtime_safety) { |
| 1109 | assert(@sizeOf(Data) == 8); | 1109 | assert(@sizeOf(Data) == 8); |
| 1110 | } | 1110 | } |
| 1111 | } | 1111 | } |
src/Compilation.zig+2-2| ... | @@ -2191,14 +2191,14 @@ pub fn update(comp: *Compilation, main_progress_node: *std.Progress.Node) !void | ... | @@ -2191,14 +2191,14 @@ pub fn update(comp: *Compilation, main_progress_node: *std.Progress.Node) !void |
| 2191 | try comp.performAllTheWork(main_progress_node); | 2191 | try comp.performAllTheWork(main_progress_node); |
| 2192 | 2192 | ||
| 2193 | if (comp.module) |module| { | 2193 | if (comp.module) |module| { |
| 2194 | if (builtin.mode == .Debug and comp.verbose_intern_pool) { | 2194 | if (build_options.enable_debug_extensions and comp.verbose_intern_pool) { |
| 2195 | std.debug.print("intern pool stats for '{s}':\n", .{ | 2195 | std.debug.print("intern pool stats for '{s}':\n", .{ |
| 2196 | comp.root_name, | 2196 | comp.root_name, |
| 2197 | }); | 2197 | }); |
| 2198 | module.intern_pool.dump(); | 2198 | module.intern_pool.dump(); |
| 2199 | } | 2199 | } |
| 2200 | 2200 | ||
| 2201 | if (builtin.mode == .Debug and comp.verbose_generic_instances) { | 2201 | if (build_options.enable_debug_extensions and comp.verbose_generic_instances) { |
| 2202 | std.debug.print("generic instances for '{s}:0x{x}':\n", .{ | 2202 | std.debug.print("generic instances for '{s}:0x{x}':\n", .{ |
| 2203 | comp.root_name, | 2203 | comp.root_name, |
| 2204 | @as(usize, @intFromPtr(module)), | 2204 | @as(usize, @intFromPtr(module)), |
src/InternPool.zig+1-1| ... | @@ -2593,7 +2593,7 @@ pub const Index = enum(u32) { | ... | @@ -2593,7 +2593,7 @@ pub const Index = enum(u32) { |
| 2593 | } | 2593 | } |
| 2594 | 2594 | ||
| 2595 | comptime { | 2595 | comptime { |
| 2596 | if (builtin.mode == .Debug) { | 2596 | if (!builtin.strip_debug_info) { |
| 2597 | _ = &dbHelper; | 2597 | _ = &dbHelper; |
| 2598 | } | 2598 | } |
| 2599 | } | 2599 | } |
src/Module.zig+2-2| ... | @@ -3203,8 +3203,8 @@ pub fn ensureFuncBodyAnalyzed(zcu: *Zcu, func_index: InternPool.Index) SemaError | ... | @@ -3203,8 +3203,8 @@ pub fn ensureFuncBodyAnalyzed(zcu: *Zcu, func_index: InternPool.Index) SemaError |
| 3203 | 3203 | ||
| 3204 | const comp = zcu.comp; | 3204 | const comp = zcu.comp; |
| 3205 | 3205 | ||
| 3206 | const dump_air = builtin.mode == .Debug and comp.verbose_air; | 3206 | const dump_air = build_options.enable_debug_extensions and comp.verbose_air; |
| 3207 | const dump_llvm_ir = builtin.mode == .Debug and (comp.verbose_llvm_ir != null or comp.verbose_llvm_bc != null); | 3207 | const dump_llvm_ir = build_options.enable_debug_extensions and (comp.verbose_llvm_ir != null or comp.verbose_llvm_bc != null); |
| 3208 | 3208 | ||
| 3209 | if (comp.bin_file == null and zcu.llvm_object == null and !dump_air and !dump_llvm_ir) { | 3209 | if (comp.bin_file == null and zcu.llvm_object == null and !dump_air and !dump_llvm_ir) { |
| 3210 | return; | 3210 | return; |
src/Sema.zig+2-2| ... | @@ -2505,7 +2505,7 @@ fn failWithOwnedErrorMsg(sema: *Sema, block: ?*Block, err_msg: *Module.ErrorMsg) | ... | @@ -2505,7 +2505,7 @@ fn failWithOwnedErrorMsg(sema: *Sema, block: ?*Block, err_msg: *Module.ErrorMsg) |
| 2505 | ref: { | 2505 | ref: { |
| 2506 | errdefer err_msg.destroy(gpa); | 2506 | errdefer err_msg.destroy(gpa); |
| 2507 | 2507 | ||
| 2508 | if (crash_report.is_enabled and mod.comp.debug_compile_errors) { | 2508 | if (build_options.enable_debug_extensions and mod.comp.debug_compile_errors) { |
| 2509 | var wip_errors: std.zig.ErrorBundle.Wip = undefined; | 2509 | var wip_errors: std.zig.ErrorBundle.Wip = undefined; |
| 2510 | wip_errors.init(gpa) catch unreachable; | 2510 | wip_errors.init(gpa) catch unreachable; |
| 2511 | Compilation.addModuleErrorMsg(mod, &wip_errors, err_msg.*) catch unreachable; | 2511 | Compilation.addModuleErrorMsg(mod, &wip_errors, err_msg.*) catch unreachable; |
| ... | @@ -5758,7 +5758,7 @@ fn zirCImport(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileEr | ... | @@ -5758,7 +5758,7 @@ fn zirCImport(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileEr |
| 5758 | const body = sema.code.bodySlice(extra.end, extra.data.body_len); | 5758 | const body = sema.code.bodySlice(extra.end, extra.data.body_len); |
| 5759 | 5759 | ||
| 5760 | // we check this here to avoid undefined symbols | 5760 | // we check this here to avoid undefined symbols |
| 5761 | if (!@import("build_options").have_llvm) | 5761 | if (!build_options.have_llvm) |
| 5762 | return sema.fail(parent_block, src, "C import unavailable; Zig compiler built without LLVM extensions", .{}); | 5762 | return sema.fail(parent_block, src, "C import unavailable; Zig compiler built without LLVM extensions", .{}); |
| 5763 | 5763 | ||
| 5764 | var c_import_buf = std.ArrayList(u8).init(gpa); | 5764 | var c_import_buf = std.ArrayList(u8).init(gpa); |
src/Value.zig+1-1| ... | @@ -4069,7 +4069,7 @@ fn dbHelper(self: *Value, tag_to_payload_map: *map: { | ... | @@ -4069,7 +4069,7 @@ fn dbHelper(self: *Value, tag_to_payload_map: *map: { |
| 4069 | } | 4069 | } |
| 4070 | 4070 | ||
| 4071 | comptime { | 4071 | comptime { |
| 4072 | if (builtin.mode == .Debug) { | 4072 | if (!builtin.strip_debug_info) { |
| 4073 | _ = &dbHelper; | 4073 | _ = &dbHelper; |
| 4074 | } | 4074 | } |
| 4075 | } | 4075 | } |
src/arch/aarch64/Mir.zig+2-2| ... | @@ -484,9 +484,9 @@ pub const Inst = struct { | ... | @@ -484,9 +484,9 @@ pub const Inst = struct { |
| 484 | }; | 484 | }; |
| 485 | 485 | ||
| 486 | // Make sure we don't accidentally make instructions bigger than expected. | 486 | // Make sure we don't accidentally make instructions bigger than expected. |
| 487 | // Note that in Debug builds, Zig is allowed to insert a secret field for safety checks. | 487 | // Note that in safety builds, Zig is allowed to insert a secret field for safety checks. |
| 488 | comptime { | 488 | comptime { |
| 489 | if (builtin.mode != .Debug and builtin.mode != .ReleaseSafe) { | 489 | if (!std.debug.runtime_safety) { |
| 490 | assert(@sizeOf(Data) == 8); | 490 | assert(@sizeOf(Data) == 8); |
| 491 | } | 491 | } |
| 492 | } | 492 | } |
src/arch/arm/Mir.zig+2-2| ... | @@ -264,9 +264,9 @@ pub const Inst = struct { | ... | @@ -264,9 +264,9 @@ pub const Inst = struct { |
| 264 | }; | 264 | }; |
| 265 | 265 | ||
| 266 | // Make sure we don't accidentally make instructions bigger than expected. | 266 | // Make sure we don't accidentally make instructions bigger than expected. |
| 267 | // Note that in Debug builds, Zig is allowed to insert a secret field for safety checks. | 267 | // Note that in safety builds, Zig is allowed to insert a secret field for safety checks. |
| 268 | comptime { | 268 | comptime { |
| 269 | if (builtin.mode != .Debug and builtin.mode != .ReleaseSafe) { | 269 | if (!std.debug.runtime_safety) { |
| 270 | assert(@sizeOf(Data) == 8); | 270 | assert(@sizeOf(Data) == 8); |
| 271 | } | 271 | } |
| 272 | } | 272 | } |
src/arch/riscv64/Mir.zig+2-2| ... | @@ -112,9 +112,9 @@ pub const Inst = struct { | ... | @@ -112,9 +112,9 @@ pub const Inst = struct { |
| 112 | }; | 112 | }; |
| 113 | 113 | ||
| 114 | // Make sure we don't accidentally make instructions bigger than expected. | 114 | // Make sure we don't accidentally make instructions bigger than expected. |
| 115 | // Note that in Debug builds, Zig is allowed to insert a secret field for safety checks. | 115 | // Note that in safety builds, Zig is allowed to insert a secret field for safety checks. |
| 116 | // comptime { | 116 | // comptime { |
| 117 | // if (builtin.mode != .Debug) { | 117 | // if (!std.debug.runtime_safety) { |
| 118 | // assert(@sizeOf(Inst) == 8); | 118 | // assert(@sizeOf(Inst) == 8); |
| 119 | // } | 119 | // } |
| 120 | // } | 120 | // } |
src/arch/sparc64/Mir.zig+2-2| ... | @@ -356,9 +356,9 @@ pub const Inst = struct { | ... | @@ -356,9 +356,9 @@ pub const Inst = struct { |
| 356 | }; | 356 | }; |
| 357 | 357 | ||
| 358 | // Make sure we don't accidentally make instructions bigger than expected. | 358 | // Make sure we don't accidentally make instructions bigger than expected. |
| 359 | // Note that in Debug builds, Zig is allowed to insert a secret field for safety checks. | 359 | // Note that in safety builds, Zig is allowed to insert a secret field for safety checks. |
| 360 | comptime { | 360 | comptime { |
| 361 | if (builtin.mode != .Debug and builtin.mode != .ReleaseSafe) { | 361 | if (!std.debug.runtime_safety) { |
| 362 | assert(@sizeOf(Data) == 8); | 362 | assert(@sizeOf(Data) == 8); |
| 363 | } | 363 | } |
| 364 | } | 364 | } |
src/arch/wasm/CodeGen.zig+4-4| ... | @@ -735,7 +735,7 @@ free_locals_v128: std.ArrayListUnmanaged(u32) = .{}, | ... | @@ -735,7 +735,7 @@ free_locals_v128: std.ArrayListUnmanaged(u32) = .{}, |
| 735 | /// stored in our `values` map and therefore cause bugs. | 735 | /// stored in our `values` map and therefore cause bugs. |
| 736 | air_bookkeeping: @TypeOf(bookkeeping_init) = bookkeeping_init, | 736 | air_bookkeeping: @TypeOf(bookkeeping_init) = bookkeeping_init, |
| 737 | 737 | ||
| 738 | const bookkeeping_init = if (builtin.mode == .Debug) @as(usize, 0) else {}; | 738 | const bookkeeping_init = if (std.debug.runtime_safety) @as(usize, 0) else {}; |
| 739 | 739 | ||
| 740 | const InnerError = error{ | 740 | const InnerError = error{ |
| 741 | OutOfMemory, | 741 | OutOfMemory, |
| ... | @@ -830,7 +830,7 @@ fn finishAir(func: *CodeGen, inst: Air.Inst.Index, result: WValue, operands: []c | ... | @@ -830,7 +830,7 @@ fn finishAir(func: *CodeGen, inst: Air.Inst.Index, result: WValue, operands: []c |
| 830 | branch.values.putAssumeCapacityNoClobber(inst.toRef(), result); | 830 | branch.values.putAssumeCapacityNoClobber(inst.toRef(), result); |
| 831 | } | 831 | } |
| 832 | 832 | ||
| 833 | if (builtin.mode == .Debug) { | 833 | if (std.debug.runtime_safety) { |
| 834 | func.air_bookkeeping += 1; | 834 | func.air_bookkeeping += 1; |
| 835 | } | 835 | } |
| 836 | } | 836 | } |
| ... | @@ -866,7 +866,7 @@ const BigTomb = struct { | ... | @@ -866,7 +866,7 @@ const BigTomb = struct { |
| 866 | bt.gen.currentBranch().values.putAssumeCapacityNoClobber(bt.inst.toRef(), result); | 866 | bt.gen.currentBranch().values.putAssumeCapacityNoClobber(bt.inst.toRef(), result); |
| 867 | } | 867 | } |
| 868 | 868 | ||
| 869 | if (builtin.mode == .Debug) { | 869 | if (std.debug.runtime_safety) { |
| 870 | bt.gen.air_bookkeeping += 1; | 870 | bt.gen.air_bookkeeping += 1; |
| 871 | } | 871 | } |
| 872 | } | 872 | } |
| ... | @@ -2079,7 +2079,7 @@ fn genBody(func: *CodeGen, body: []const Air.Inst.Index) InnerError!void { | ... | @@ -2079,7 +2079,7 @@ fn genBody(func: *CodeGen, body: []const Air.Inst.Index) InnerError!void { |
| 2079 | try func.currentBranch().values.ensureUnusedCapacity(func.gpa, Liveness.bpi); | 2079 | try func.currentBranch().values.ensureUnusedCapacity(func.gpa, Liveness.bpi); |
| 2080 | try func.genInst(inst); | 2080 | try func.genInst(inst); |
| 2081 | 2081 | ||
| 2082 | if (builtin.mode == .Debug and func.air_bookkeeping < old_bookkeeping_value + 1) { | 2082 | if (std.debug.runtime_safety and func.air_bookkeeping < old_bookkeeping_value + 1) { |
| 2083 | std.debug.panic("Missing call to `finishAir` in AIR instruction %{d} ('{}')", .{ | 2083 | std.debug.panic("Missing call to `finishAir` in AIR instruction %{d} ('{}')", .{ |
| 2084 | inst, | 2084 | inst, |
| 2085 | func.air.instructions.items(.tag)[@intFromEnum(inst)], | 2085 | func.air.instructions.items(.tag)[@intFromEnum(inst)], |
src/arch/x86_64/Mir.zig+2-2| ... | @@ -1012,9 +1012,9 @@ pub const Inst = struct { | ... | @@ -1012,9 +1012,9 @@ pub const Inst = struct { |
| 1012 | }; | 1012 | }; |
| 1013 | 1013 | ||
| 1014 | // Make sure we don't accidentally make instructions bigger than expected. | 1014 | // Make sure we don't accidentally make instructions bigger than expected. |
| 1015 | // Note that in Debug builds, Zig is allowed to insert a secret field for safety checks. | 1015 | // Note that in safety builds, Zig is allowed to insert a secret field for safety checks. |
| 1016 | comptime { | 1016 | comptime { |
| 1017 | if (builtin.mode != .Debug and builtin.mode != .ReleaseSafe) { | 1017 | if (!std.debug.runtime_safety) { |
| 1018 | assert(@sizeOf(Data) == 8); | 1018 | assert(@sizeOf(Data) == 8); |
| 1019 | } | 1019 | } |
| 1020 | } | 1020 | } |
src/crash_report.zig+21-35| ... | @@ -1,5 +1,6 @@ | ... | @@ -1,5 +1,6 @@ |
| 1 | const std = @import("std"); | 1 | const std = @import("std"); |
| 2 | const builtin = @import("builtin"); | 2 | const builtin = @import("builtin"); |
| 3 | const build_options = @import("build_options"); | ||
| 3 | const debug = std.debug; | 4 | const debug = std.debug; |
| 4 | const os = std.os; | 5 | const os = std.os; |
| 5 | const io = std.io; | 6 | const io = std.io; |
| ... | @@ -11,37 +12,26 @@ const Sema = @import("Sema.zig"); | ... | @@ -11,37 +12,26 @@ const Sema = @import("Sema.zig"); |
| 11 | const Zir = std.zig.Zir; | 12 | const Zir = std.zig.Zir; |
| 12 | const Decl = Module.Decl; | 13 | const Decl = Module.Decl; |
| 13 | 14 | ||
| 14 | pub const is_enabled = builtin.mode == .Debug; | ||
| 15 | |||
| 16 | /// To use these crash report diagnostics, publish this panic in your main file | 15 | /// To use these crash report diagnostics, publish this panic in your main file |
| 17 | /// and add `pub const enable_segfault_handler = false;` to your `std_options`. | 16 | /// and add `pub const enable_segfault_handler = false;` to your `std_options`. |
| 18 | /// You will also need to call initialize() on startup, preferably as the very first operation in your program. | 17 | /// You will also need to call initialize() on startup, preferably as the very first operation in your program. |
| 19 | pub const panic = if (is_enabled) compilerPanic else std.builtin.default_panic; | 18 | pub const panic = if (build_options.enable_debug_extensions) compilerPanic else std.builtin.default_panic; |
| 20 | 19 | ||
| 21 | /// Install signal handlers to identify crashes and report diagnostics. | 20 | /// Install signal handlers to identify crashes and report diagnostics. |
| 22 | pub fn initialize() void { | 21 | pub fn initialize() void { |
| 23 | if (is_enabled and debug.have_segfault_handling_support) { | 22 | if (build_options.enable_debug_extensions and debug.have_segfault_handling_support) { |
| 24 | attachSegfaultHandler(); | 23 | attachSegfaultHandler(); |
| 25 | } | 24 | } |
| 26 | } | 25 | } |
| 27 | 26 | ||
| 28 | fn En(comptime T: type) type { | 27 | pub const AnalyzeBody = if (build_options.enable_debug_extensions) struct { |
| 29 | return if (is_enabled) T else void; | 28 | parent: ?*AnalyzeBody, |
| 30 | } | 29 | sema: *Sema, |
| 31 | 30 | block: *Sema.Block, | |
| 32 | fn en(val: anytype) En(@TypeOf(val)) { | 31 | body: []const Zir.Inst.Index, |
| 33 | return if (is_enabled) val else {}; | 32 | body_index: usize, |
| 34 | } | ||
| 35 | |||
| 36 | pub const AnalyzeBody = struct { | ||
| 37 | parent: if (is_enabled) ?*AnalyzeBody else void, | ||
| 38 | sema: En(*Sema), | ||
| 39 | block: En(*Sema.Block), | ||
| 40 | body: En([]const Zir.Inst.Index), | ||
| 41 | body_index: En(usize), | ||
| 42 | 33 | ||
| 43 | pub fn push(self: *@This()) void { | 34 | pub fn push(self: *@This()) void { |
| 44 | if (!is_enabled) return; | ||
| 45 | const head = &zir_state; | 35 | const head = &zir_state; |
| 46 | debug.assert(self.parent == null); | 36 | debug.assert(self.parent == null); |
| 47 | self.parent = head.*; | 37 | self.parent = head.*; |
| ... | @@ -49,7 +39,6 @@ pub const AnalyzeBody = struct { | ... | @@ -49,7 +39,6 @@ pub const AnalyzeBody = struct { |
| 49 | } | 39 | } |
| 50 | 40 | ||
| 51 | pub fn pop(self: *@This()) void { | 41 | pub fn pop(self: *@This()) void { |
| 52 | if (!is_enabled) return; | ||
| 53 | const head = &zir_state; | 42 | const head = &zir_state; |
| 54 | const old = head.*.?; | 43 | const old = head.*.?; |
| 55 | debug.assert(old == self); | 44 | debug.assert(old == self); |
| ... | @@ -57,27 +46,24 @@ pub const AnalyzeBody = struct { | ... | @@ -57,27 +46,24 @@ pub const AnalyzeBody = struct { |
| 57 | } | 46 | } |
| 58 | 47 | ||
| 59 | pub fn setBodyIndex(self: *@This(), index: usize) void { | 48 | pub fn setBodyIndex(self: *@This(), index: usize) void { |
| 60 | if (!is_enabled) return; | ||
| 61 | self.body_index = index; | 49 | self.body_index = index; |
| 62 | } | 50 | } |
| 51 | } else struct { | ||
| 52 | pub inline fn push(_: @This()) void {} | ||
| 53 | pub inline fn pop(_: @This()) void {} | ||
| 54 | pub inline fn setBodyIndex(_: @This(), _: usize) void {} | ||
| 63 | }; | 55 | }; |
| 64 | 56 | ||
| 65 | threadlocal var zir_state: ?*AnalyzeBody = if (is_enabled) null else @compileError("Cannot use zir_state if crash_report is disabled."); | 57 | threadlocal var zir_state: ?*AnalyzeBody = if (build_options.enable_debug_extensions) null else @compileError("Cannot use zir_state without debug extensions."); |
| 66 | 58 | ||
| 67 | pub fn prepAnalyzeBody(sema: *Sema, block: *Sema.Block, body: []const Zir.Inst.Index) AnalyzeBody { | 59 | pub fn prepAnalyzeBody(sema: *Sema, block: *Sema.Block, body: []const Zir.Inst.Index) AnalyzeBody { |
| 68 | if (is_enabled) { | 60 | return if (build_options.enable_debug_extensions) .{ |
| 69 | return .{ | 61 | .parent = null, |
| 70 | .parent = null, | 62 | .sema = sema, |
| 71 | .sema = sema, | 63 | .block = block, |
| 72 | .block = block, | 64 | .body = body, |
| 73 | .body = body, | 65 | .body_index = 0, |
| 74 | .body_index = 0, | 66 | } else .{}; |
| 75 | }; | ||
| 76 | } else { | ||
| 77 | if (@sizeOf(AnalyzeBody) != 0) | ||
| 78 | @compileError("AnalyzeBody must have zero size when crash reports are disabled"); | ||
| 79 | return undefined; | ||
| 80 | } | ||
| 81 | } | 67 | } |
| 82 | 68 | ||
| 83 | fn dumpStatusReport() !void { | 69 | fn dumpStatusReport() !void { |
src/main.zig+11-13| ... | @@ -67,8 +67,6 @@ pub fn fatal(comptime format: []const u8, args: anytype) noreturn { | ... | @@ -67,8 +67,6 @@ pub fn fatal(comptime format: []const u8, args: anytype) noreturn { |
| 67 | process.exit(1); | 67 | process.exit(1); |
| 68 | } | 68 | } |
| 69 | 69 | ||
| 70 | const debug_extensions_enabled = builtin.mode == .Debug; | ||
| 71 | |||
| 72 | const normal_usage = | 70 | const normal_usage = |
| 73 | \\Usage: zig [command] [options] | 71 | \\Usage: zig [command] [options] |
| 74 | \\ | 72 | \\ |
| ... | @@ -120,7 +118,7 @@ const debug_usage = normal_usage ++ | ... | @@ -120,7 +118,7 @@ const debug_usage = normal_usage ++ |
| 120 | \\ | 118 | \\ |
| 121 | ; | 119 | ; |
| 122 | 120 | ||
| 123 | const usage = if (debug_extensions_enabled) debug_usage else normal_usage; | 121 | const usage = if (build_options.enable_debug_extensions) debug_usage else normal_usage; |
| 124 | 122 | ||
| 125 | var log_scopes: std.ArrayListUnmanaged([]const u8) = .{}; | 123 | var log_scopes: std.ArrayListUnmanaged([]const u8) = .{}; |
| 126 | 124 | ||
| ... | @@ -334,9 +332,9 @@ fn mainArgs(gpa: Allocator, arena: Allocator, args: []const []const u8) !void { | ... | @@ -334,9 +332,9 @@ fn mainArgs(gpa: Allocator, arena: Allocator, args: []const []const u8) !void { |
| 334 | return io.getStdOut().writeAll(usage); | 332 | return io.getStdOut().writeAll(usage); |
| 335 | } else if (mem.eql(u8, cmd, "ast-check")) { | 333 | } else if (mem.eql(u8, cmd, "ast-check")) { |
| 336 | return cmdAstCheck(gpa, arena, cmd_args); | 334 | return cmdAstCheck(gpa, arena, cmd_args); |
| 337 | } else if (debug_extensions_enabled and mem.eql(u8, cmd, "changelist")) { | 335 | } else if (build_options.enable_debug_extensions and mem.eql(u8, cmd, "changelist")) { |
| 338 | return cmdChangelist(gpa, arena, cmd_args); | 336 | return cmdChangelist(gpa, arena, cmd_args); |
| 339 | } else if (debug_extensions_enabled and mem.eql(u8, cmd, "dump-zir")) { | 337 | } else if (build_options.enable_debug_extensions and mem.eql(u8, cmd, "dump-zir")) { |
| 340 | return cmdDumpZir(gpa, arena, cmd_args); | 338 | return cmdDumpZir(gpa, arena, cmd_args); |
| 341 | } else { | 339 | } else { |
| 342 | std.log.info("{s}", .{usage}); | 340 | std.log.info("{s}", .{usage}); |
| ... | @@ -1591,10 +1589,10 @@ fn buildOutputType( | ... | @@ -1591,10 +1589,10 @@ fn buildOutputType( |
| 1591 | }); | 1589 | }); |
| 1592 | }; | 1590 | }; |
| 1593 | } else if (mem.eql(u8, arg, "--debug-compile-errors")) { | 1591 | } else if (mem.eql(u8, arg, "--debug-compile-errors")) { |
| 1594 | if (!crash_report.is_enabled) { | 1592 | if (build_options.enable_debug_extensions) { |
| 1595 | warn("Zig was compiled in a release mode. --debug-compile-errors has no effect.", .{}); | ||
| 1596 | } else { | ||
| 1597 | debug_compile_errors = true; | 1593 | debug_compile_errors = true; |
| 1594 | } else { | ||
| 1595 | warn("Zig was compiled without debug extensions. --debug-compile-errors has no effect.", .{}); | ||
| 1598 | } | 1596 | } |
| 1599 | } else if (mem.eql(u8, arg, "--verbose-link")) { | 1597 | } else if (mem.eql(u8, arg, "--verbose-link")) { |
| 1600 | verbose_link = true; | 1598 | verbose_link = true; |
| ... | @@ -5076,10 +5074,10 @@ fn cmdBuild(gpa: Allocator, arena: Allocator, args: []const []const u8) !void { | ... | @@ -5076,10 +5074,10 @@ fn cmdBuild(gpa: Allocator, arena: Allocator, args: []const []const u8) !void { |
| 5076 | } | 5074 | } |
| 5077 | continue; | 5075 | continue; |
| 5078 | } else if (mem.eql(u8, arg, "--debug-compile-errors")) { | 5076 | } else if (mem.eql(u8, arg, "--debug-compile-errors")) { |
| 5079 | if (!crash_report.is_enabled) { | 5077 | if (build_options.enable_debug_extensions) { |
| 5080 | warn("Zig was compiled in a release mode. --debug-compile-errors has no effect.", .{}); | ||
| 5081 | } else { | ||
| 5082 | debug_compile_errors = true; | 5078 | debug_compile_errors = true; |
| 5079 | } else { | ||
| 5080 | warn("Zig was compiled without debug extensions. --debug-compile-errors has no effect.", .{}); | ||
| 5083 | } | 5081 | } |
| 5084 | } else if (mem.eql(u8, arg, "--verbose-link")) { | 5082 | } else if (mem.eql(u8, arg, "--verbose-link")) { |
| 5085 | verbose_link = true; | 5083 | verbose_link = true; |
| ... | @@ -6317,8 +6315,8 @@ fn cmdAstCheck( | ... | @@ -6317,8 +6315,8 @@ fn cmdAstCheck( |
| 6317 | if (!want_output_text) { | 6315 | if (!want_output_text) { |
| 6318 | return cleanExit(); | 6316 | return cleanExit(); |
| 6319 | } | 6317 | } |
| 6320 | if (!debug_extensions_enabled) { | 6318 | if (!build_options.enable_debug_extensions) { |
| 6321 | fatal("-t option only available in debug builds of zig", .{}); | 6319 | fatal("-t option only available in builds of zig with debug extensions", .{}); |
| 6322 | } | 6320 | } |
| 6323 | 6321 | ||
| 6324 | { | 6322 | { |
stage1/config.zig.in+4-3| ... | @@ -5,11 +5,12 @@ pub const llvm_has_arc = false; | ... | @@ -5,11 +5,12 @@ pub const llvm_has_arc = false; |
| 5 | pub const llvm_has_xtensa = false; | 5 | pub const llvm_has_xtensa = false; |
| 6 | pub const version: [:0]const u8 = "@RESOLVED_ZIG_VERSION@"; | 6 | pub const version: [:0]const u8 = "@RESOLVED_ZIG_VERSION@"; |
| 7 | pub const semver = @import("std").SemanticVersion.parse(version) catch unreachable; | 7 | pub const semver = @import("std").SemanticVersion.parse(version) catch unreachable; |
| 8 | pub const enable_logging: bool = false; | 8 | pub const enable_debug_extensions = false; |
| 9 | pub const enable_link_snapshots: bool = false; | 9 | pub const enable_logging = false; |
| 10 | pub const enable_link_snapshots = false; | ||
| 10 | pub const enable_tracy = false; | 11 | pub const enable_tracy = false; |
| 11 | pub const value_tracing = false; | 12 | pub const value_tracing = false; |
| 12 | pub const skip_non_native = false; | 13 | pub const skip_non_native = false; |
| 13 | pub const only_c = false; | ||
| 14 | pub const force_gpa = false; | 14 | pub const force_gpa = false; |
| 15 | pub const only_c = false; | ||
| 15 | pub const only_core_functionality = true; | 16 | pub const only_core_functionality = true; |