authorgravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2025-01-24 04:20:09+00:00
committergravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2025-01-24 20:50:20+00:00
logb0a8931690660da753f9684d65db4b1bdfe29757
tree103bc445a6fd9508e28f91c28f2a1dc3637cddbe
parent83991efe10d92c4b920d7b7fc75be98ed7854ad7
signaturelock-open Commit is signed but in an unrecognized format.

Sema: prepare to remove `?*StackTrace` argument from `unwrapError` and `call`

Now that we propagate the error return trace to all `callconv(.auto)` functions, passing it explicitly to panic handlers is redundant.

1 files changed, 8 insertions(+), 24 deletions(-)

src/Sema.zig+8-24
...@@ -5946,14 +5946,13 @@ fn zirPanic(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void...@@ -5946,14 +5946,13 @@ fn zirPanic(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void
5946 try zcu.ensureFuncBodyAnalysisQueued(zcu.builtin_decl_values.get(.@"panic.call"));5946 try zcu.ensureFuncBodyAnalysisQueued(zcu.builtin_decl_values.get(.@"panic.call"));
59475947
5948 const panic_fn = Air.internedToRef(zcu.builtin_decl_values.get(.@"panic.call"));5948 const panic_fn = Air.internedToRef(zcu.builtin_decl_values.get(.@"panic.call"));
5949 const null_stack_trace = Air.internedToRef(zcu.null_stack_trace);
59505949
5951 const opt_usize_ty = try pt.optionalType(.usize_type);5950 const opt_usize_ty = try pt.optionalType(.usize_type);
5952 const null_ret_addr = Air.internedToRef((try pt.intern(.{ .opt = .{5951 const null_ret_addr = Air.internedToRef((try pt.intern(.{ .opt = .{
5953 .ty = opt_usize_ty.toIntern(),5952 .ty = opt_usize_ty.toIntern(),
5954 .val = .none,5953 .val = .none,
5955 } })));5954 } })));
5956 try sema.callBuiltin(block, src, panic_fn, .auto, &.{ coerced_msg, null_stack_trace, null_ret_addr }, .@"@panic");5955 try sema.callBuiltin(block, src, panic_fn, .auto, &.{ coerced_msg, null_ret_addr }, .@"@panic");
5957}5956}
59585957
5959fn zirTrap(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void {5958fn zirTrap(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void {
...@@ -13805,8 +13804,7 @@ fn maybeErrorUnwrap(...@@ -13805,8 +13804,7 @@ fn maybeErrorUnwrap(
13805 const msg_inst = try sema.resolveInst(inst_data.operand);13804 const msg_inst = try sema.resolveInst(inst_data.operand);
1380613805
13807 const panic_fn = try getBuiltin(sema, operand_src, .@"panic.call");13806 const panic_fn = try getBuiltin(sema, operand_src, .@"panic.call");
13808 const err_return_trace = try sema.getErrorReturnTrace(block);13807 const args: [2]Air.Inst.Ref = .{ msg_inst, .null_value };
13809 const args: [3]Air.Inst.Ref = .{ msg_inst, err_return_trace, .null_value };
13810 try sema.callBuiltin(block, operand_src, Air.internedToRef(panic_fn), .auto, &args, .@"safety check");13808 try sema.callBuiltin(block, operand_src, Air.internedToRef(panic_fn), .auto, &args, .@"safety check");
13811 return true;13809 return true;
13812 },13810 },
...@@ -27242,9 +27240,7 @@ fn safetyPanicUnwrapError(sema: *Sema, block: *Block, src: LazySrcLoc, err: Air....@@ -27242,9 +27240,7 @@ fn safetyPanicUnwrapError(sema: *Sema, block: *Block, src: LazySrcLoc, err: Air.
27242 _ = try block.addNoOp(.trap);27240 _ = try block.addNoOp(.trap);
27243 } else {27241 } else {
27244 const panic_fn = try getBuiltin(sema, src, .@"panic.unwrapError");27242 const panic_fn = try getBuiltin(sema, src, .@"panic.unwrapError");
27245 const err_return_trace = try sema.getErrorReturnTrace(block);27243 try sema.callBuiltin(block, src, Air.internedToRef(panic_fn), .auto, &.{err}, .@"safety check");
27246 const args: [2]Air.Inst.Ref = .{ err_return_trace, err };
27247 try sema.callBuiltin(block, src, Air.internedToRef(panic_fn), .auto, &args, .@"safety check");
27248 }27244 }
27249}27245}
2725027246
...@@ -38524,7 +38520,7 @@ pub fn analyzeMemoizedState(sema: *Sema, block: *Block, simple_src: LazySrcLoc,...@@ -38524,7 +38520,7 @@ pub fn analyzeMemoizedState(sema: *Sema, block: *Block, simple_src: LazySrcLoc,
38524 break :val uncoerced_val;38520 break :val uncoerced_val;
38525 },38521 },
38526 .func => val: {38522 .func => val: {
38527 const func_ty = try sema.getExpectedBuiltinFnType(src, builtin_decl);38523 const func_ty = try sema.getExpectedBuiltinFnType(builtin_decl);
38528 const coerced = try sema.coerce(block, func_ty, Air.internedToRef(uncoerced_val.toIntern()), src);38524 const coerced = try sema.coerce(block, func_ty, Air.internedToRef(uncoerced_val.toIntern()), src);
38529 break :val .fromInterned(coerced.toInterned().?);38525 break :val .fromInterned(coerced.toInterned().?);
38530 },38526 },
...@@ -38562,7 +38558,7 @@ pub fn analyzeMemoizedState(sema: *Sema, block: *Block, simple_src: LazySrcLoc,...@@ -38562,7 +38558,7 @@ pub fn analyzeMemoizedState(sema: *Sema, block: *Block, simple_src: LazySrcLoc,
38562}38558}
3856338559
38564/// Given that `decl.kind() == .func`, get the type expected of the function.38560/// Given that `decl.kind() == .func`, get the type expected of the function.
38565fn getExpectedBuiltinFnType(sema: *Sema, src: LazySrcLoc, decl: Zcu.BuiltinDecl) CompileError!Type {38561fn getExpectedBuiltinFnType(sema: *Sema, decl: Zcu.BuiltinDecl) CompileError!Type {
38566 const pt = sema.pt;38562 const pt = sema.pt;
38567 return switch (decl) {38563 return switch (decl) {
38568 // `noinline fn () void`38564 // `noinline fn () void`
...@@ -38572,15 +38568,10 @@ fn getExpectedBuiltinFnType(sema: *Sema, src: LazySrcLoc, decl: Zcu.BuiltinDecl)...@@ -38572,15 +38568,10 @@ fn getExpectedBuiltinFnType(sema: *Sema, src: LazySrcLoc, decl: Zcu.BuiltinDecl)
38572 .is_noinline = true,38568 .is_noinline = true,
38573 }),38569 }),
3857438570
38575 // `fn ([]const u8, ?*StackTrace, ?usize) noreturn`38571 // `fn ([]const u8, ?usize) noreturn`
38576 .@"panic.call" => try pt.funcType(.{38572 .@"panic.call" => try pt.funcType(.{
38577 .param_types = &.{38573 .param_types = &.{
38578 .slice_const_u8_type,38574 .slice_const_u8_type,
38579 (try pt.optionalType(
38580 (try pt.singleMutPtrType(
38581 try sema.getBuiltinType(src, .StackTrace),
38582 )).toIntern(),
38583 )).toIntern(),
38584 (try pt.optionalType(.usize_type)).toIntern(),38575 (try pt.optionalType(.usize_type)).toIntern(),
38585 },38576 },
38586 .return_type = .noreturn_type,38577 .return_type = .noreturn_type,
...@@ -38595,16 +38586,9 @@ fn getExpectedBuiltinFnType(sema: *Sema, src: LazySrcLoc, decl: Zcu.BuiltinDecl)...@@ -38595,16 +38586,9 @@ fn getExpectedBuiltinFnType(sema: *Sema, src: LazySrcLoc, decl: Zcu.BuiltinDecl)
38595 .is_generic = true,38586 .is_generic = true,
38596 }),38587 }),
3859738588
38598 // `fn (?*StackTrace, anyerror) noreturn`38589 // `fn (anyerror) noreturn`
38599 .@"panic.unwrapError" => try pt.funcType(.{38590 .@"panic.unwrapError" => try pt.funcType(.{
38600 .param_types = &.{38591 .param_types = &.{.anyerror_type},
38601 (try pt.optionalType(
38602 (try pt.singleMutPtrType(
38603 try sema.getBuiltinType(src, .StackTrace),
38604 )).toIntern(),
38605 )).toIntern(),
38606 .anyerror_type,
38607 },
38608 .return_type = .noreturn_type,38592 .return_type = .noreturn_type,
38609 }),38593 }),
3861038594