| author | |
| committer | |
| log | 529d01c2baf695c2844b5dd42642a74749bef0d0 |
| tree | d5c54c9a9f9d835ab0a7f0e8789fda1957cb8224 |
| parent | 8944dea23fb554290a4b54ca40b0594f6e3f77a9 |
rather than checking multiple conditions in Sema4 files changed, 34 insertions(+), 20 deletions(-)
src/Compilation/Config.zig+10| ... | ... | @@ -408,9 +408,17 @@ pub fn resolve(options: Options) !Config { |
| 408 | 408 | }; |
| 409 | 409 | }; |
| 410 | 410 | |
| 411 | const backend_supports_error_tracing = target_util.backendSupportsFeature( | |
| 412 | target.cpu.arch, | |
| 413 | target.ofmt, | |
| 414 | use_llvm, | |
| 415 | .error_return_trace, | |
| 416 | ); | |
| 417 | ||
| 411 | 418 | const root_error_tracing = b: { |
| 412 | 419 | if (options.root_error_tracing) |x| break :b x; |
| 413 | 420 | if (root_strip) break :b false; |
| 421 | if (!backend_supports_error_tracing) break :b false; | |
| 414 | 422 | break :b switch (root_optimize_mode) { |
| 415 | 423 | .Debug => true, |
| 416 | 424 | .ReleaseSafe, .ReleaseFast, .ReleaseSmall => false, |
| ... | ... | @@ -418,6 +426,8 @@ pub fn resolve(options: Options) !Config { |
| 418 | 426 | }; |
| 419 | 427 | |
| 420 | 428 | const any_error_tracing = root_error_tracing or options.any_error_tracing; |
| 429 | if (any_error_tracing and !backend_supports_error_tracing) | |
| 430 | return error.BackendLacksErrorTracing; | |
| 421 | 431 | |
| 422 | 432 | const rdynamic = options.rdynamic orelse false; |
| 423 | 433 |
src/Module.zig+1-10| ... | ... | @@ -5589,16 +5589,7 @@ pub fn backendSupportsFeature(zcu: Module, feature: Feature) bool { |
| 5589 | 5589 | const cpu_arch = zcu.root_mod.resolved_target.result.cpu.arch; |
| 5590 | 5590 | const ofmt = zcu.root_mod.resolved_target.result.ofmt; |
| 5591 | 5591 | const use_llvm = zcu.comp.config.use_llvm; |
| 5592 | return switch (feature) { | |
| 5593 | .panic_fn => ofmt == .c or use_llvm or cpu_arch == .x86_64, | |
| 5594 | .panic_unwrap_error => ofmt == .c or use_llvm, | |
| 5595 | .safety_check_formatted => ofmt == .c or use_llvm, | |
| 5596 | .error_return_trace => use_llvm, | |
| 5597 | .is_named_enum_value => use_llvm, | |
| 5598 | .error_set_has_value => use_llvm or cpu_arch.isWasm(), | |
| 5599 | .field_reordering => use_llvm, | |
| 5600 | .safety_checked_instructions => use_llvm, | |
| 5601 | }; | |
| 5592 | return target_util.backendSupportsFeature(cpu_arch, ofmt, use_llvm, feature); | |
| 5602 | 5593 | } |
| 5603 | 5594 | |
| 5604 | 5595 | /// Shortcut for calling `intern_pool.get`. |
src/Sema.zig+4-10| ... | ... | @@ -2045,9 +2045,10 @@ fn analyzeAsType( |
| 2045 | 2045 | |
| 2046 | 2046 | pub fn setupErrorReturnTrace(sema: *Sema, block: *Block, last_arg_index: usize) !void { |
| 2047 | 2047 | const mod = sema.mod; |
| 2048 | const comp = mod.comp; | |
| 2048 | 2049 | const gpa = sema.gpa; |
| 2049 | 2050 | const ip = &mod.intern_pool; |
| 2050 | if (!mod.backendSupportsFeature(.error_return_trace)) return; | |
| 2051 | if (!comp.config.any_error_tracing) return; | |
| 2051 | 2052 | |
| 2052 | 2053 | assert(!block.is_comptime); |
| 2053 | 2054 | var err_trace_block = block.makeSubBlock(); |
| ... | ... | @@ -6543,7 +6544,6 @@ pub fn analyzeSaveErrRetIndex(sema: *Sema, block: *Block) SemaError!Air.Inst.Ref |
| 6543 | 6544 | const gpa = sema.gpa; |
| 6544 | 6545 | const src = sema.src; |
| 6545 | 6546 | |
| 6546 | if (!mod.backendSupportsFeature(.error_return_trace)) return .none; | |
| 6547 | 6547 | if (!block.ownerModule().error_tracing) return .none; |
| 6548 | 6548 | |
| 6549 | 6549 | if (block.is_comptime) |
| ... | ... | @@ -6728,7 +6728,7 @@ fn zirCall( |
| 6728 | 6728 | input_is_error = false; |
| 6729 | 6729 | } |
| 6730 | 6730 | |
| 6731 | if (mod.backendSupportsFeature(.error_return_trace) and block.ownerModule().error_tracing and | |
| 6731 | if (block.ownerModule().error_tracing and | |
| 6732 | 6732 | !block.is_comptime and !block.is_typeof and (input_is_error or pop_error_return_trace)) |
| 6733 | 6733 | { |
| 6734 | 6734 | const return_ty = sema.typeOf(call_inst); |
| ... | ... | @@ -18759,8 +18759,6 @@ fn retWithErrTracing( |
| 18759 | 18759 | |
| 18760 | 18760 | fn wantErrorReturnTracing(sema: *Sema, fn_ret_ty: Type) bool { |
| 18761 | 18761 | const mod = sema.mod; |
| 18762 | if (!mod.backendSupportsFeature(.error_return_trace)) return false; | |
| 18763 | ||
| 18764 | 18762 | return fn_ret_ty.isError(mod) and mod.comp.config.any_error_tracing; |
| 18765 | 18763 | } |
| 18766 | 18764 | |
| ... | ... | @@ -18768,8 +18766,6 @@ fn zirSaveErrRetIndex(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileE |
| 18768 | 18766 | const mod = sema.mod; |
| 18769 | 18767 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].save_err_ret_index; |
| 18770 | 18768 | |
| 18771 | // TODO: replace all of these checks with logic in module creation | |
| 18772 | if (!mod.backendSupportsFeature(.error_return_trace)) return; | |
| 18773 | 18769 | if (!block.ownerModule().error_tracing) return; |
| 18774 | 18770 | |
| 18775 | 18771 | // This is only relevant at runtime. |
| ... | ... | @@ -18795,7 +18791,6 @@ fn zirRestoreErrRetIndex(sema: *Sema, start_block: *Block, inst: Zir.Inst.Index) |
| 18795 | 18791 | const mod = sema.mod; |
| 18796 | 18792 | const ip = &mod.intern_pool; |
| 18797 | 18793 | |
| 18798 | if (!mod.backendSupportsFeature(.error_return_trace)) return; | |
| 18799 | 18794 | if (!ip.funcAnalysis(sema.owner_func_index).calls_or_awaits_errorable_fn) return; |
| 18800 | 18795 | if (!start_block.ownerModule().error_tracing) return; |
| 18801 | 18796 | |
| ... | ... | @@ -20068,8 +20063,7 @@ fn getErrorReturnTrace(sema: *Sema, block: *Block) CompileError!Air.Inst.Ref { |
| 20068 | 20063 | |
| 20069 | 20064 | if (sema.owner_func_index != .none and |
| 20070 | 20065 | ip.funcAnalysis(sema.owner_func_index).calls_or_awaits_errorable_fn and |
| 20071 | block.ownerModule().error_tracing and | |
| 20072 | mod.backendSupportsFeature(.error_return_trace)) | |
| 20066 | block.ownerModule().error_tracing) | |
| 20073 | 20067 | { |
| 20074 | 20068 | return block.addTy(.err_return_trace, opt_ptr_stack_trace_ty); |
| 20075 | 20069 | } |
src/target.zig+19| ... | ... | @@ -2,6 +2,7 @@ const std = @import("std"); |
| 2 | 2 | const Type = @import("type.zig").Type; |
| 3 | 3 | const AddressSpace = std.builtin.AddressSpace; |
| 4 | 4 | const Alignment = @import("InternPool.zig").Alignment; |
| 5 | const Feature = @import("Module.zig").Feature; | |
| 5 | 6 | |
| 6 | 7 | pub const default_stack_protector_buffer_size = 4; |
| 7 | 8 | |
| ... | ... | @@ -665,6 +666,24 @@ pub fn zigBackend(target: std.Target, use_llvm: bool) std.builtin.CompilerBacken |
| 665 | 666 | }; |
| 666 | 667 | } |
| 667 | 668 | |
| 669 | pub fn backendSupportsFeature( | |
| 670 | cpu_arch: std.Target.Cpu.Arch, | |
| 671 | ofmt: std.Target.ObjectFormat, | |
| 672 | use_llvm: bool, | |
| 673 | feature: Feature, | |
| 674 | ) bool { | |
| 675 | return switch (feature) { | |
| 676 | .panic_fn => ofmt == .c or use_llvm or cpu_arch == .x86_64, | |
| 677 | .panic_unwrap_error => ofmt == .c or use_llvm, | |
| 678 | .safety_check_formatted => ofmt == .c or use_llvm, | |
| 679 | .error_return_trace => use_llvm, | |
| 680 | .is_named_enum_value => use_llvm, | |
| 681 | .error_set_has_value => use_llvm or cpu_arch.isWasm(), | |
| 682 | .field_reordering => use_llvm, | |
| 683 | .safety_checked_instructions => use_llvm, | |
| 684 | }; | |
| 685 | } | |
| 686 | ||
| 668 | 687 | pub fn defaultEntrySymbolName( |
| 669 | 688 | target: std.Target, |
| 670 | 689 | /// May be `undefined` when `target` is not WASI. |