Merge pull request #11133 from Vexu/stage2

stage2: misc fixes on the way to `std.debug.dumpCurrentStackTrace`
This commit is contained in:
Andrew Kelley 2022-03-12 14:18:58 -05:00 committed by GitHub
commit 5ff7b04a6a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 44 additions and 12 deletions

View File

@ -1630,7 +1630,6 @@ fn getSymbolFromDwarf(address: u64, di: *DW.DwarfInfo) !SymbolInfo {
.symbol_name = nosuspend di.getSymbolName(address) orelse "???",
.compile_unit_name = compile_unit.die.getAttrString(di, DW.AT.name) catch |err| switch (err) {
error.MissingDebugInfo, error.InvalidDebugInfo => "???",
else => return err,
},
.line_info = nosuspend di.getLineNumberInfo(compile_unit.*, address) catch |err| switch (err) {
error.MissingDebugInfo, error.InvalidDebugInfo => null,

View File

@ -822,7 +822,7 @@ pub const DwarfInfo = struct {
// in the list itself.
// If no starting value is specified use zero.
var base_address = compile_unit.die.getAttrAddr(AT.low_pc) catch |err| switch (err) {
error.MissingDebugInfo => 0,
error.MissingDebugInfo => @as(u64, 0), // TODO https://github.com/ziglang/zig/issues/11135
else => return err,
};

View File

@ -1035,9 +1035,8 @@ fn nosuspendExpr(
});
}
gz.nosuspend_node = node;
const result = try expr(gz, scope, rl, body_node);
gz.nosuspend_node = 0;
return rvalue(gz, rl, result, node);
defer gz.nosuspend_node = 0;
return expr(gz, scope, rl, body_node);
}
fn suspendExpr(

View File

@ -6972,7 +6972,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
return sema.failWithOwnedErrorMsg(block, msg);
}
if (special_prong == .@"else") {
if (special_prong == .@"else" and seen_errors.count() == operand_ty.errorSetNames().len) {
return sema.fail(
block,
special_prong_src,
@ -16692,6 +16692,13 @@ fn coerceInMemoryAllowedErrorSets(
else => unreachable,
}
if (dst_ies.func == sema.owner_func) {
// We are trying to coerce an error set to the current function's
// inferred error set.
try dst_ies.addErrorSet(sema.gpa, src_ty);
return .ok;
}
try sema.resolveInferredErrorSet(block, dest_src, dst_payload.data);
// isAnyError might have changed from a false negative to a true positive after resolution.
if (dest_ty.isAnyError()) {
@ -18910,7 +18917,7 @@ fn resolvePeerTypes(
}
const chosen_set_ty = err_set_ty orelse chosen_ty.errorUnionSet();
const candidate_set_ty = chosen_ty.errorUnionSet();
const candidate_set_ty = candidate_ty.errorUnionSet();
if (.ok == try sema.coerceInMemoryAllowedErrorSets(block, chosen_set_ty, candidate_set_ty, src, src)) {
err_set_ty = chosen_set_ty;

View File

@ -5347,7 +5347,14 @@ pub const FuncGen = struct {
if (self.liveness.isUnused(inst)) return null;
const llvm_i32 = self.context.intType(32);
const llvm_fn = self.getIntrinsic("llvm.frameaddress", &.{llvm_i32});
const llvm_fn_name = "llvm.frameaddress.p0i8";
const llvm_fn = self.dg.object.llvm_module.getNamedFunction(llvm_fn_name) orelse blk: {
const llvm_p0i8 = self.context.intType(8).pointerType(0);
const param_types = [_]*const llvm.Type{llvm_i32};
const fn_type = llvm.functionType(llvm_p0i8, &param_types, param_types.len, .False);
break :blk self.dg.object.llvm_module.addFunction(llvm_fn_name, fn_type);
};
const params = [_]*const llvm.Value{llvm_i32.constNull()};
const ptr_val = self.builder.buildCall(llvm_fn, &params, params.len, .Fast, .Auto, "");
const llvm_usize = try self.dg.llvmType(Type.usize);

View File

@ -626,3 +626,26 @@ test "inferred error set equality" {
try expect(BarError == BarError);
try expect(BazError == BazError);
}
test "peer type resolution of two different error unions" {
const a: error{B}!void = {};
const b: error{A}!void = {};
var cond = true;
const err = if (cond) a else b;
try err;
}
test "coerce error set to the current inferred error set" {
const S = struct {
fn foo() !void {
var a = false;
if (a) {
const b: error{A}!void = error.A;
return b;
}
const b = error.A;
return b;
}
};
S.foo() catch {};
}

View File

@ -610,14 +610,11 @@ test "switch on pointer type" {
}
test "switch on error set with single else" {
if (builtin.zig_backend != .stage1) return error.SkipZigTest; // TODO
const S = struct {
fn doTheTest() !void {
var some: error{Foo} = error.Foo;
try expect(switch (some) {
else => |a| blk: {
a catch {};
else => blk: {
break :blk true;
},
});