authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-03-12 14:18:58-05:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2022-03-12 14:18:58-05:00
log5ff7b04a6ad72eb86b6d467dfdc25bea1a9ecf63
treea4bffd48c7c31b64af53425464e0c0c048156abf
parent01081ce5a59f4e2e57a9ff6e5885269ed3014279
parentd532c21d890e1aa22cd4c57d6a3f749890256254
signaturebadge-question-mark Signed by PGP key 4AEE18F83AFDEB23

Merge pull request #11133 from Vexu/stage2

stage2: misc fixes on the way to `std.debug.dumpCurrentStackTrace`

7 files changed, 44 insertions(+), 12 deletions(-)

lib/std/debug.zig-1
......@@ -1630,7 +1630,6 @@ fn getSymbolFromDwarf(address: u64, di: *DW.DwarfInfo) !SymbolInfo {
16301630 .symbol_name = nosuspend di.getSymbolName(address) orelse "???",
16311631 .compile_unit_name = compile_unit.die.getAttrString(di, DW.AT.name) catch |err| switch (err) {
16321632 error.MissingDebugInfo, error.InvalidDebugInfo => "???",
1633 else => return err,
16341633 },
16351634 .line_info = nosuspend di.getLineNumberInfo(compile_unit.*, address) catch |err| switch (err) {
16361635 error.MissingDebugInfo, error.InvalidDebugInfo => null,
lib/std/dwarf.zig+1-1
......@@ -822,7 +822,7 @@ pub const DwarfInfo = struct {
822822 // in the list itself.
823823 // If no starting value is specified use zero.
824824 var base_address = compile_unit.die.getAttrAddr(AT.low_pc) catch |err| switch (err) {
825 error.MissingDebugInfo => 0,
825 error.MissingDebugInfo => @as(u64, 0), // TODO https://github.com/ziglang/zig/issues/11135
826826 else => return err,
827827 };
828828
src/AstGen.zig+2-3
......@@ -1035,9 +1035,8 @@ fn nosuspendExpr(
10351035 });
10361036 }
10371037 gz.nosuspend_node = node;
1038 const result = try expr(gz, scope, rl, body_node);
1039 gz.nosuspend_node = 0;
1040 return rvalue(gz, rl, result, node);
1038 defer gz.nosuspend_node = 0;
1039 return expr(gz, scope, rl, body_node);
10411040}
10421041
10431042fn suspendExpr(
src/Sema.zig+9-2
......@@ -6972,7 +6972,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
69726972 return sema.failWithOwnedErrorMsg(block, msg);
69736973 }
69746974
6975 if (special_prong == .@"else") {
6975 if (special_prong == .@"else" and seen_errors.count() == operand_ty.errorSetNames().len) {
69766976 return sema.fail(
69776977 block,
69786978 special_prong_src,
......@@ -16692,6 +16692,13 @@ fn coerceInMemoryAllowedErrorSets(
1669216692 else => unreachable,
1669316693 }
1669416694
16695 if (dst_ies.func == sema.owner_func) {
16696 // We are trying to coerce an error set to the current function's
16697 // inferred error set.
16698 try dst_ies.addErrorSet(sema.gpa, src_ty);
16699 return .ok;
16700 }
16701
1669516702 try sema.resolveInferredErrorSet(block, dest_src, dst_payload.data);
1669616703 // isAnyError might have changed from a false negative to a true positive after resolution.
1669716704 if (dest_ty.isAnyError()) {
......@@ -18910,7 +18917,7 @@ fn resolvePeerTypes(
1891018917 }
1891118918
1891218919 const chosen_set_ty = err_set_ty orelse chosen_ty.errorUnionSet();
18913 const candidate_set_ty = chosen_ty.errorUnionSet();
18920 const candidate_set_ty = candidate_ty.errorUnionSet();
1891418921
1891518922 if (.ok == try sema.coerceInMemoryAllowedErrorSets(block, chosen_set_ty, candidate_set_ty, src, src)) {
1891618923 err_set_ty = chosen_set_ty;
src/codegen/llvm.zig+8-1
......@@ -5347,7 +5347,14 @@ pub const FuncGen = struct {
53475347 if (self.liveness.isUnused(inst)) return null;
53485348
53495349 const llvm_i32 = self.context.intType(32);
5350 const llvm_fn = self.getIntrinsic("llvm.frameaddress", &.{llvm_i32});
5350 const llvm_fn_name = "llvm.frameaddress.p0i8";
5351 const llvm_fn = self.dg.object.llvm_module.getNamedFunction(llvm_fn_name) orelse blk: {
5352 const llvm_p0i8 = self.context.intType(8).pointerType(0);
5353 const param_types = [_]*const llvm.Type{llvm_i32};
5354 const fn_type = llvm.functionType(llvm_p0i8, &param_types, param_types.len, .False);
5355 break :blk self.dg.object.llvm_module.addFunction(llvm_fn_name, fn_type);
5356 };
5357
53515358 const params = [_]*const llvm.Value{llvm_i32.constNull()};
53525359 const ptr_val = self.builder.buildCall(llvm_fn, &params, params.len, .Fast, .Auto, "");
53535360 const llvm_usize = try self.dg.llvmType(Type.usize);
test/behavior/error.zig+23
......@@ -626,3 +626,26 @@ test "inferred error set equality" {
626626 try expect(BarError == BarError);
627627 try expect(BazError == BazError);
628628}
629
630test "peer type resolution of two different error unions" {
631 const a: error{B}!void = {};
632 const b: error{A}!void = {};
633 var cond = true;
634 const err = if (cond) a else b;
635 try err;
636}
637
638test "coerce error set to the current inferred error set" {
639 const S = struct {
640 fn foo() !void {
641 var a = false;
642 if (a) {
643 const b: error{A}!void = error.A;
644 return b;
645 }
646 const b = error.A;
647 return b;
648 }
649 };
650 S.foo() catch {};
651}
test/behavior/switch.zig+1-4
......@@ -610,14 +610,11 @@ test "switch on pointer type" {
610610}
611611
612612test "switch on error set with single else" {
613 if (builtin.zig_backend != .stage1) return error.SkipZigTest; // TODO
614
615613 const S = struct {
616614 fn doTheTest() !void {
617615 var some: error{Foo} = error.Foo;
618616 try expect(switch (some) {
619 else => |a| blk: {
620 a catch {};
617 else => blk: {
621618 break :blk true;
622619 },
623620 });