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
59465946 try zcu.ensureFuncBodyAnalysisQueued(zcu.builtin_decl_values.get(.@"panic.call"));
59475947
59485948 const panic_fn = Air.internedToRef(zcu.builtin_decl_values.get(.@"panic.call"));
5949 const null_stack_trace = Air.internedToRef(zcu.null_stack_trace);
59505949
59515950 const opt_usize_ty = try pt.optionalType(.usize_type);
59525951 const null_ret_addr = Air.internedToRef((try pt.intern(.{ .opt = .{
59535952 .ty = opt_usize_ty.toIntern(),
59545953 .val = .none,
59555954 } })));
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");
59575956}
59585957
59595958fn zirTrap(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void {
......@@ -13805,8 +13804,7 @@ fn maybeErrorUnwrap(
1380513804 const msg_inst = try sema.resolveInst(inst_data.operand);
1380613805
1380713806 const panic_fn = try getBuiltin(sema, operand_src, .@"panic.call");
13808 const err_return_trace = try sema.getErrorReturnTrace(block);
13809 const args: [3]Air.Inst.Ref = .{ msg_inst, err_return_trace, .null_value };
13807 const args: [2]Air.Inst.Ref = .{ msg_inst, .null_value };
1381013808 try sema.callBuiltin(block, operand_src, Air.internedToRef(panic_fn), .auto, &args, .@"safety check");
1381113809 return true;
1381213810 },
......@@ -27242,9 +27240,7 @@ fn safetyPanicUnwrapError(sema: *Sema, block: *Block, src: LazySrcLoc, err: Air.
2724227240 _ = try block.addNoOp(.trap);
2724327241 } else {
2724427242 const panic_fn = try getBuiltin(sema, src, .@"panic.unwrapError");
27245 const err_return_trace = try sema.getErrorReturnTrace(block);
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");
27243 try sema.callBuiltin(block, src, Air.internedToRef(panic_fn), .auto, &.{err}, .@"safety check");
2724827244 }
2724927245}
2725027246
......@@ -38524,7 +38520,7 @@ pub fn analyzeMemoizedState(sema: *Sema, block: *Block, simple_src: LazySrcLoc,
3852438520 break :val uncoerced_val;
3852538521 },
3852638522 .func => val: {
38527 const func_ty = try sema.getExpectedBuiltinFnType(src, builtin_decl);
38523 const func_ty = try sema.getExpectedBuiltinFnType(builtin_decl);
3852838524 const coerced = try sema.coerce(block, func_ty, Air.internedToRef(uncoerced_val.toIntern()), src);
3852938525 break :val .fromInterned(coerced.toInterned().?);
3853038526 },
......@@ -38562,7 +38558,7 @@ pub fn analyzeMemoizedState(sema: *Sema, block: *Block, simple_src: LazySrcLoc,
3856238558}
3856338559
3856438560/// 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 {
3856638562 const pt = sema.pt;
3856738563 return switch (decl) {
3856838564 // `noinline fn () void`
......@@ -38572,15 +38568,10 @@ fn getExpectedBuiltinFnType(sema: *Sema, src: LazySrcLoc, decl: Zcu.BuiltinDecl)
3857238568 .is_noinline = true,
3857338569 }),
3857438570
38575 // `fn ([]const u8, ?*StackTrace, ?usize) noreturn`
38571 // `fn ([]const u8, ?usize) noreturn`
3857638572 .@"panic.call" => try pt.funcType(.{
3857738573 .param_types = &.{
3857838574 .slice_const_u8_type,
38579 (try pt.optionalType(
38580 (try pt.singleMutPtrType(
38581 try sema.getBuiltinType(src, .StackTrace),
38582 )).toIntern(),
38583 )).toIntern(),
3858438575 (try pt.optionalType(.usize_type)).toIntern(),
3858538576 },
3858638577 .return_type = .noreturn_type,
......@@ -38595,16 +38586,9 @@ fn getExpectedBuiltinFnType(sema: *Sema, src: LazySrcLoc, decl: Zcu.BuiltinDecl)
3859538586 .is_generic = true,
3859638587 }),
3859738588
38598 // `fn (?*StackTrace, anyerror) noreturn`
38589 // `fn (anyerror) noreturn`
3859938590 .@"panic.unwrapError" => try pt.funcType(.{
38600 .param_types = &.{
38601 (try pt.optionalType(
38602 (try pt.singleMutPtrType(
38603 try sema.getBuiltinType(src, .StackTrace),
38604 )).toIntern(),
38605 )).toIntern(),
38606 .anyerror_type,
38607 },
38591 .param_types = &.{.anyerror_type},
3860838592 .return_type = .noreturn_type,
3860938593 }),
3861038594