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 {...@@ -1630,7 +1630,6 @@ fn getSymbolFromDwarf(address: u64, di: *DW.DwarfInfo) !SymbolInfo {
1630 .symbol_name = nosuspend di.getSymbolName(address) orelse "???",1630 .symbol_name = nosuspend di.getSymbolName(address) orelse "???",
1631 .compile_unit_name = compile_unit.die.getAttrString(di, DW.AT.name) catch |err| switch (err) {1631 .compile_unit_name = compile_unit.die.getAttrString(di, DW.AT.name) catch |err| switch (err) {
1632 error.MissingDebugInfo, error.InvalidDebugInfo => "???",1632 error.MissingDebugInfo, error.InvalidDebugInfo => "???",
1633 else => return err,
1634 },1633 },
1635 .line_info = nosuspend di.getLineNumberInfo(compile_unit.*, address) catch |err| switch (err) {1634 .line_info = nosuspend di.getLineNumberInfo(compile_unit.*, address) catch |err| switch (err) {
1636 error.MissingDebugInfo, error.InvalidDebugInfo => null,1635 error.MissingDebugInfo, error.InvalidDebugInfo => null,
lib/std/dwarf.zig+1-1
...@@ -822,7 +822,7 @@ pub const DwarfInfo = struct {...@@ -822,7 +822,7 @@ pub const DwarfInfo = struct {
822 // in the list itself.822 // in the list itself.
823 // If no starting value is specified use zero.823 // If no starting value is specified use zero.
824 var base_address = compile_unit.die.getAttrAddr(AT.low_pc) catch |err| switch (err) {824 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
826 else => return err,826 else => return err,
827 };827 };
828828
src/AstGen.zig+2-3
...@@ -1035,9 +1035,8 @@ fn nosuspendExpr(...@@ -1035,9 +1035,8 @@ fn nosuspendExpr(
1035 });1035 });
1036 }1036 }
1037 gz.nosuspend_node = node;1037 gz.nosuspend_node = node;
1038 const result = try expr(gz, scope, rl, body_node);1038 defer gz.nosuspend_node = 0;
1039 gz.nosuspend_node = 0;1039 return expr(gz, scope, rl, body_node);
1040 return rvalue(gz, rl, result, node);
1041}1040}
10421041
1043fn suspendExpr(1042fn suspendExpr(
src/Sema.zig+9-2
...@@ -6972,7 +6972,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError...@@ -6972,7 +6972,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
6972 return sema.failWithOwnedErrorMsg(block, msg);6972 return sema.failWithOwnedErrorMsg(block, msg);
6973 }6973 }
69746974
6975 if (special_prong == .@"else") {6975 if (special_prong == .@"else" and seen_errors.count() == operand_ty.errorSetNames().len) {
6976 return sema.fail(6976 return sema.fail(
6977 block,6977 block,
6978 special_prong_src,6978 special_prong_src,
...@@ -16692,6 +16692,13 @@ fn coerceInMemoryAllowedErrorSets(...@@ -16692,6 +16692,13 @@ fn coerceInMemoryAllowedErrorSets(
16692 else => unreachable,16692 else => unreachable,
16693 }16693 }
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
16695 try sema.resolveInferredErrorSet(block, dest_src, dst_payload.data);16702 try sema.resolveInferredErrorSet(block, dest_src, dst_payload.data);
16696 // isAnyError might have changed from a false negative to a true positive after resolution.16703 // isAnyError might have changed from a false negative to a true positive after resolution.
16697 if (dest_ty.isAnyError()) {16704 if (dest_ty.isAnyError()) {
...@@ -18910,7 +18917,7 @@ fn resolvePeerTypes(...@@ -18910,7 +18917,7 @@ fn resolvePeerTypes(
18910 }18917 }
1891118918
18912 const chosen_set_ty = err_set_ty orelse chosen_ty.errorUnionSet();18919 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
18915 if (.ok == try sema.coerceInMemoryAllowedErrorSets(block, chosen_set_ty, candidate_set_ty, src, src)) {18922 if (.ok == try sema.coerceInMemoryAllowedErrorSets(block, chosen_set_ty, candidate_set_ty, src, src)) {
18916 err_set_ty = chosen_set_ty;18923 err_set_ty = chosen_set_ty;
src/codegen/llvm.zig+8-1
...@@ -5347,7 +5347,14 @@ pub const FuncGen = struct {...@@ -5347,7 +5347,14 @@ pub const FuncGen = struct {
5347 if (self.liveness.isUnused(inst)) return null;5347 if (self.liveness.isUnused(inst)) return null;
53485348
5349 const llvm_i32 = self.context.intType(32);5349 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
5351 const params = [_]*const llvm.Value{llvm_i32.constNull()};5358 const params = [_]*const llvm.Value{llvm_i32.constNull()};
5352 const ptr_val = self.builder.buildCall(llvm_fn, &params, params.len, .Fast, .Auto, "");5359 const ptr_val = self.builder.buildCall(llvm_fn, &params, params.len, .Fast, .Auto, "");
5353 const llvm_usize = try self.dg.llvmType(Type.usize);5360 const llvm_usize = try self.dg.llvmType(Type.usize);
test/behavior/error.zig+23
...@@ -626,3 +626,26 @@ test "inferred error set equality" {...@@ -626,3 +626,26 @@ test "inferred error set equality" {
626 try expect(BarError == BarError);626 try expect(BarError == BarError);
627 try expect(BazError == BazError);627 try expect(BazError == BazError);
628}628}
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" {...@@ -610,14 +610,11 @@ test "switch on pointer type" {
610}610}
611611
612test "switch on error set with single else" {612test "switch on error set with single else" {
613 if (builtin.zig_backend != .stage1) return error.SkipZigTest; // TODO
614
615 const S = struct {613 const S = struct {
616 fn doTheTest() !void {614 fn doTheTest() !void {
617 var some: error{Foo} = error.Foo;615 var some: error{Foo} = error.Foo;
618 try expect(switch (some) {616 try expect(switch (some) {
619 else => |a| blk: {617 else => blk: {
620 a catch {};
621 break :blk true;618 break :blk true;
622 },619 },
623 });620 });