| ... | @@ -8107,6 +8107,13 @@ fn funcCommon( | ... | @@ -8107,6 +8107,13 @@ fn funcCommon( |
| 8107 | for (comptime_params) |ct| is_generic = is_generic or ct; | 8107 | for (comptime_params) |ct| is_generic = is_generic or ct; |
| 8108 | is_generic = is_generic or ret_ty_requires_comptime; | 8108 | is_generic = is_generic or ret_ty_requires_comptime; |
| 8109 | | 8109 | |
| | 8110 | if (!is_generic and sema.wantErrorReturnTracing(return_type)) { |
| | 8111 | // Make sure that StackTrace's fields are resolved so that the backend can |
| | 8112 | // lower this fn type. |
| | 8113 | const unresolved_stack_trace_ty = try sema.getBuiltinType(block, ret_ty_src, "StackTrace"); |
| | 8114 | _ = try sema.resolveTypeFields(block, ret_ty_src, unresolved_stack_trace_ty); |
| | 8115 | } |
| | 8116 | |
| 8110 | break :fn_ty try Type.Tag.function.create(sema.arena, .{ | 8117 | break :fn_ty try Type.Tag.function.create(sema.arena, .{ |
| 8111 | .param_types = param_types, | 8118 | .param_types = param_types, |
| 8112 | .comptime_params = comptime_params.ptr, | 8119 | .comptime_params = comptime_params.ptr, |
| ... | @@ -15631,7 +15638,7 @@ fn zirRetLoad(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Zir | ... | @@ -15631,7 +15638,7 @@ fn zirRetLoad(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Zir |
| 15631 | return sema.analyzeRet(block, operand, src); | 15638 | return sema.analyzeRet(block, operand, src); |
| 15632 | } | 15639 | } |
| 15633 | | 15640 | |
| 15634 | if (sema.wantErrorReturnTracing()) { | 15641 | if (sema.wantErrorReturnTracing(sema.fn_ret_ty)) { |
| 15635 | const is_non_err = try sema.analyzePtrIsNonErr(block, src, ret_ptr); | 15642 | const is_non_err = try sema.analyzePtrIsNonErr(block, src, ret_ptr); |
| 15636 | return retWithErrTracing(sema, block, src, is_non_err, .ret_load, ret_ptr); | 15643 | return retWithErrTracing(sema, block, src, is_non_err, .ret_load, ret_ptr); |
| 15637 | } | 15644 | } |
| ... | @@ -15698,11 +15705,11 @@ fn retWithErrTracing( | ... | @@ -15698,11 +15705,11 @@ fn retWithErrTracing( |
| 15698 | return always_noreturn; | 15705 | return always_noreturn; |
| 15699 | } | 15706 | } |
| 15700 | | 15707 | |
| 15701 | fn wantErrorReturnTracing(sema: *Sema) bool { | 15708 | fn wantErrorReturnTracing(sema: *Sema, fn_ret_ty: Type) bool { |
| 15702 | // TODO implement this feature in all the backends and then delete this check. | 15709 | // TODO implement this feature in all the backends and then delete this check. |
| 15703 | const backend_supports_error_return_tracing = sema.mod.comp.bin_file.options.use_llvm; | 15710 | const backend_supports_error_return_tracing = sema.mod.comp.bin_file.options.use_llvm; |
| 15704 | | 15711 | |
| 15705 | return sema.fn_ret_ty.isError() and | 15712 | return fn_ret_ty.isError() and |
| 15706 | sema.mod.comp.bin_file.options.error_return_tracing and | 15713 | sema.mod.comp.bin_file.options.error_return_tracing and |
| 15707 | backend_supports_error_return_tracing; | 15714 | backend_supports_error_return_tracing; |
| 15708 | } | 15715 | } |
| ... | @@ -15754,7 +15761,7 @@ fn analyzeRet( | ... | @@ -15754,7 +15761,7 @@ fn analyzeRet( |
| 15754 | | 15761 | |
| 15755 | try sema.resolveTypeLayout(block, src, sema.fn_ret_ty); | 15762 | try sema.resolveTypeLayout(block, src, sema.fn_ret_ty); |
| 15756 | | 15763 | |
| 15757 | if (sema.wantErrorReturnTracing()) { | 15764 | if (sema.wantErrorReturnTracing(sema.fn_ret_ty)) { |
| 15758 | // Avoid adding a frame to the error return trace in case the value is comptime-known | 15765 | // Avoid adding a frame to the error return trace in case the value is comptime-known |
| 15759 | // to be not an error. | 15766 | // to be not an error. |
| 15760 | const is_non_err = try sema.analyzeIsNonErr(block, src, operand); | 15767 | const is_non_err = try sema.analyzeIsNonErr(block, src, operand); |