| author | |
| committer | |
| log | 53a5aee3b3684a03c91236702c9304dce21279e2 |
| tree | b14c0c4d2f017d9423f5f050aa42ea66eaa4ae7a |
| parent | 66c3988e5eebd423844d5dd20c762d6fefe20adf |
3 files changed, 21 insertions(+), 17 deletions(-)
src/Compilation.zig+2-1| ... | @@ -1457,7 +1457,8 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation { | ... | @@ -1457,7 +1457,8 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation { |
| 1457 | errdefer if (module) |zm| zm.deinit(); | 1457 | errdefer if (module) |zm| zm.deinit(); |
| 1458 | 1458 | ||
| 1459 | const error_return_tracing = !strip and switch (options.optimize_mode) { | 1459 | const error_return_tracing = !strip and switch (options.optimize_mode) { |
| 1460 | .Debug, .ReleaseSafe => true, | 1460 | .Debug, .ReleaseSafe => (!options.target.isWasm() or options.target.os.tag == .emscripten) and |
| 1461 | !options.target.cpu.arch.isBpf(), | ||
| 1461 | .ReleaseFast, .ReleaseSmall => false, | 1462 | .ReleaseFast, .ReleaseSmall => false, |
| 1462 | }; | 1463 | }; |
| 1463 | 1464 |
src/Sema.zig+11-11| ... | @@ -1412,7 +1412,8 @@ fn analyzeAsType( | ... | @@ -1412,7 +1412,8 @@ fn analyzeAsType( |
| 1412 | } | 1412 | } |
| 1413 | 1413 | ||
| 1414 | pub fn setupErrorReturnTrace(sema: *Sema, block: *Block, last_arg_index: usize) !void { | 1414 | pub fn setupErrorReturnTrace(sema: *Sema, block: *Block, last_arg_index: usize) !void { |
| 1415 | const backend_supports_error_return_tracing = false; | 1415 | const backend_supports_error_return_tracing = |
| 1416 | sema.mod.comp.bin_file.options.use_llvm; | ||
| 1416 | if (!backend_supports_error_return_tracing) { | 1417 | if (!backend_supports_error_return_tracing) { |
| 1417 | // TODO implement this feature in all the backends and then delete this branch | 1418 | // TODO implement this feature in all the backends and then delete this branch |
| 1418 | return; | 1419 | return; |
| ... | @@ -5275,10 +5276,6 @@ fn analyzeCall( | ... | @@ -5275,10 +5276,6 @@ fn analyzeCall( |
| 5275 | 5276 | ||
| 5276 | try sema.queueFullTypeResolution(func_ty_info.return_type); | 5277 | try sema.queueFullTypeResolution(func_ty_info.return_type); |
| 5277 | if (sema.owner_func != null and func_ty_info.return_type.isError()) { | 5278 | if (sema.owner_func != null and func_ty_info.return_type.isError()) { |
| 5278 | if (!sema.owner_func.?.calls_or_awaits_errorable_fn) { | ||
| 5279 | // Ensure the type exists so that backends can assume that. | ||
| 5280 | _ = try sema.getBuiltinType(block, call_src, "StackTrace"); | ||
| 5281 | } | ||
| 5282 | sema.owner_func.?.calls_or_awaits_errorable_fn = true; | 5279 | sema.owner_func.?.calls_or_awaits_errorable_fn = true; |
| 5283 | } | 5280 | } |
| 5284 | 5281 | ||
| ... | @@ -5692,10 +5689,6 @@ fn instantiateGenericCall( | ... | @@ -5692,10 +5689,6 @@ fn instantiateGenericCall( |
| 5692 | } | 5689 | } |
| 5693 | 5690 | ||
| 5694 | if (sema.owner_func != null and new_fn_info.return_type.isError()) { | 5691 | if (sema.owner_func != null and new_fn_info.return_type.isError()) { |
| 5695 | if (!sema.owner_func.?.calls_or_awaits_errorable_fn) { | ||
| 5696 | // Ensure the type exists so that backends can assume that. | ||
| 5697 | _ = try sema.getBuiltinType(block, call_src, "StackTrace"); | ||
| 5698 | } | ||
| 5699 | sema.owner_func.?.calls_or_awaits_errorable_fn = true; | 5692 | sema.owner_func.?.calls_or_awaits_errorable_fn = true; |
| 5700 | } | 5693 | } |
| 5701 | 5694 | ||
| ... | @@ -12662,7 +12655,8 @@ fn analyzeRet( | ... | @@ -12662,7 +12655,8 @@ fn analyzeRet( |
| 12662 | } | 12655 | } |
| 12663 | 12656 | ||
| 12664 | // TODO implement this feature in all the backends and then delete this check. | 12657 | // TODO implement this feature in all the backends and then delete this check. |
| 12665 | const backend_supports_error_return_tracing = false; | 12658 | const backend_supports_error_return_tracing = |
| 12659 | sema.mod.comp.bin_file.options.use_llvm; | ||
| 12666 | 12660 | ||
| 12667 | if (sema.fn_ret_ty.isError() and sema.mod.comp.bin_file.options.error_return_tracing and | 12661 | if (sema.fn_ret_ty.isError() and sema.mod.comp.bin_file.options.error_return_tracing and |
| 12668 | backend_supports_error_return_tracing) | 12662 | backend_supports_error_return_tracing) |
| ... | @@ -13410,7 +13404,8 @@ fn zirErrorReturnTrace( | ... | @@ -13410,7 +13404,8 @@ fn zirErrorReturnTrace( |
| 13410 | const opt_ptr_stack_trace_ty = try Type.Tag.optional_single_mut_pointer.create(sema.arena, stack_trace_ty); | 13404 | const opt_ptr_stack_trace_ty = try Type.Tag.optional_single_mut_pointer.create(sema.arena, stack_trace_ty); |
| 13411 | 13405 | ||
| 13412 | // TODO implement this feature in all the backends and then delete this check. | 13406 | // TODO implement this feature in all the backends and then delete this check. |
| 13413 | const backend_supports_error_return_tracing = false; | 13407 | const backend_supports_error_return_tracing = |
| 13408 | sema.mod.comp.bin_file.options.use_llvm; | ||
| 13414 | 13409 | ||
| 13415 | if (sema.owner_func != null and | 13410 | if (sema.owner_func != null and |
| 13416 | sema.owner_func.?.calls_or_awaits_errorable_fn and | 13411 | sema.owner_func.?.calls_or_awaits_errorable_fn and |
| ... | @@ -21966,6 +21961,11 @@ pub fn resolveFnTypes( | ... | @@ -21966,6 +21961,11 @@ pub fn resolveFnTypes( |
| 21966 | ) CompileError!void { | 21961 | ) CompileError!void { |
| 21967 | try sema.resolveTypeFully(block, src, fn_info.return_type); | 21962 | try sema.resolveTypeFully(block, src, fn_info.return_type); |
| 21968 | 21963 | ||
| 21964 | if (sema.mod.comp.bin_file.options.error_return_tracing and fn_info.return_type.isError()) { | ||
| 21965 | // Ensure the type exists so that backends can assume that. | ||
| 21966 | _ = try sema.getBuiltinType(block, src, "StackTrace"); | ||
| 21967 | } | ||
| 21968 | |||
| 21969 | for (fn_info.param_types) |param_ty| { | 21969 | for (fn_info.param_types) |param_ty| { |
| 21970 | try sema.resolveTypeFully(block, src, param_ty); | 21970 | try sema.resolveTypeFully(block, src, param_ty); |
| 21971 | } | 21971 | } |
src/codegen/llvm.zig+8-5| ... | @@ -637,7 +637,7 @@ pub const Object = struct { | ... | @@ -637,7 +637,7 @@ pub const Object = struct { |
| 637 | const gpa = dg.gpa; | 637 | const gpa = dg.gpa; |
| 638 | 638 | ||
| 639 | const err_return_tracing = fn_info.return_type.isError() and | 639 | const err_return_tracing = fn_info.return_type.isError() and |
| 640 | dg.module.comp.bin_file.options.error_return_tracing and false; | 640 | dg.module.comp.bin_file.options.error_return_tracing; |
| 641 | 641 | ||
| 642 | const err_ret_trace = if (err_return_tracing) | 642 | const err_ret_trace = if (err_return_tracing) |
| 643 | llvm_func.getParam(@boolToInt(ret_ptr != null)) | 643 | llvm_func.getParam(@boolToInt(ret_ptr != null)) |
| ... | @@ -698,6 +698,9 @@ pub const Object = struct { | ... | @@ -698,6 +698,9 @@ pub const Object = struct { |
| 698 | 698 | ||
| 699 | const lexical_block = dib.createLexicalBlock(subprogram.toScope(), di_file.?, line_number, 1); | 699 | const lexical_block = dib.createLexicalBlock(subprogram.toScope(), di_file.?, line_number, 1); |
| 700 | di_scope = lexical_block.toScope(); | 700 | di_scope = lexical_block.toScope(); |
| 701 | |||
| 702 | // Setup a debug location in case there is a call to `returnError` before a `.dbg_stmt`. | ||
| 703 | builder.setCurrentDebugLocation(line_number + func.lbrace_line, func.lbrace_column, di_scope.?, null); | ||
| 701 | } | 704 | } |
| 702 | 705 | ||
| 703 | var fg: FuncGen = .{ | 706 | var fg: FuncGen = .{ |
| ... | @@ -1765,7 +1768,7 @@ pub const Object = struct { | ... | @@ -1765,7 +1768,7 @@ pub const Object = struct { |
| 1765 | } | 1768 | } |
| 1766 | 1769 | ||
| 1767 | if (fn_info.return_type.isError() and | 1770 | if (fn_info.return_type.isError() and |
| 1768 | o.module.comp.bin_file.options.error_return_tracing and false) | 1771 | o.module.comp.bin_file.options.error_return_tracing) |
| 1769 | { | 1772 | { |
| 1770 | var ptr_ty_payload: Type.Payload.ElemType = .{ | 1773 | var ptr_ty_payload: Type.Payload.ElemType = .{ |
| 1771 | .base = .{ .tag = .single_mut_pointer }, | 1774 | .base = .{ .tag = .single_mut_pointer }, |
| ... | @@ -2018,7 +2021,7 @@ pub const DeclGen = struct { | ... | @@ -2018,7 +2021,7 @@ pub const DeclGen = struct { |
| 2018 | } | 2021 | } |
| 2019 | 2022 | ||
| 2020 | const err_return_tracing = fn_info.return_type.isError() and | 2023 | const err_return_tracing = fn_info.return_type.isError() and |
| 2021 | dg.module.comp.bin_file.options.error_return_tracing and false; | 2024 | dg.module.comp.bin_file.options.error_return_tracing; |
| 2022 | 2025 | ||
| 2023 | if (err_return_tracing) { | 2026 | if (err_return_tracing) { |
| 2024 | dg.addArgAttr(llvm_fn, @boolToInt(sret), "nonnull"); | 2027 | dg.addArgAttr(llvm_fn, @boolToInt(sret), "nonnull"); |
| ... | @@ -2484,7 +2487,7 @@ pub const DeclGen = struct { | ... | @@ -2484,7 +2487,7 @@ pub const DeclGen = struct { |
| 2484 | } | 2487 | } |
| 2485 | 2488 | ||
| 2486 | if (fn_info.return_type.isError() and | 2489 | if (fn_info.return_type.isError() and |
| 2487 | dg.module.comp.bin_file.options.error_return_tracing and false) | 2490 | dg.module.comp.bin_file.options.error_return_tracing) |
| 2488 | { | 2491 | { |
| 2489 | var ptr_ty_payload: Type.Payload.ElemType = .{ | 2492 | var ptr_ty_payload: Type.Payload.ElemType = .{ |
| 2490 | .base = .{ .tag = .single_mut_pointer }, | 2493 | .base = .{ .tag = .single_mut_pointer }, |
| ... | @@ -3796,7 +3799,7 @@ pub const FuncGen = struct { | ... | @@ -3796,7 +3799,7 @@ pub const FuncGen = struct { |
| 3796 | }; | 3799 | }; |
| 3797 | 3800 | ||
| 3798 | if (fn_info.return_type.isError() and | 3801 | if (fn_info.return_type.isError() and |
| 3799 | self.dg.module.comp.bin_file.options.error_return_tracing and false) | 3802 | self.dg.module.comp.bin_file.options.error_return_tracing) |
| 3800 | { | 3803 | { |
| 3801 | try llvm_args.append(self.err_ret_trace.?); | 3804 | try llvm_args.append(self.err_ret_trace.?); |
| 3802 | } | 3805 | } |