mirror of
https://github.com/ziglang/zig.git
synced 2026-01-06 13:33:21 +00:00
codegen: handle dbg_var scoping correctly after eliding more ZIR blocks
Since we now elide more ZIR blocks in AstGen, care must be taken in codegen to introduce lexical scopes for every body, not just `block`s. Also, elide a few unnecessary AIR blocks in Sema.
This commit is contained in:
parent
f51d9ab892
commit
321045cf33
@ -11508,6 +11508,7 @@ fn zirSwitchBlockErrUnion(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Comp
|
||||
sub_block.runtime_loop = null;
|
||||
sub_block.runtime_cond = mod.declPtr(child_block.src_decl).toSrcLoc(main_operand_src, mod);
|
||||
sub_block.runtime_index.increment();
|
||||
sub_block.need_debug_scope = null; // this body is emitted regardless
|
||||
defer sub_block.instructions.deinit(gpa);
|
||||
|
||||
try sema.analyzeBodyRuntimeBreak(&sub_block, non_error_case.body);
|
||||
@ -12243,6 +12244,7 @@ fn analyzeSwitchRuntimeBlock(
|
||||
case_block.runtime_loop = null;
|
||||
case_block.runtime_cond = mod.declPtr(child_block.src_decl).toSrcLoc(operand_src, mod);
|
||||
case_block.runtime_index.increment();
|
||||
case_block.need_debug_scope = null; // this body is emitted regardless
|
||||
defer case_block.instructions.deinit(gpa);
|
||||
|
||||
var extra_index: usize = special.end;
|
||||
@ -18967,8 +18969,7 @@ fn zirCondbr(
|
||||
const body = if (cond_val.toBool()) then_body else else_body;
|
||||
|
||||
try sema.maybeErrorUnwrapCondbr(parent_block, body, extra.data.condition, cond_src);
|
||||
// We use `analyzeBodyInner` since we want to propagate any possible
|
||||
// `error.ComptimeBreak` to the caller.
|
||||
// We use `analyzeBodyInner` since we want to propagate any comptime control flow to the caller.
|
||||
return sema.analyzeBodyInner(parent_block, body);
|
||||
}
|
||||
|
||||
@ -18980,6 +18981,7 @@ fn zirCondbr(
|
||||
sub_block.runtime_loop = null;
|
||||
sub_block.runtime_cond = mod.declPtr(parent_block.src_decl).toSrcLoc(cond_src, mod);
|
||||
sub_block.runtime_index.increment();
|
||||
sub_block.need_debug_scope = null; // this body is emitted regardless
|
||||
defer sub_block.instructions.deinit(gpa);
|
||||
|
||||
try sema.analyzeBodyRuntimeBreak(&sub_block, then_body);
|
||||
|
||||
@ -5903,10 +5903,10 @@ pub const FuncGen = struct {
|
||||
_ = try self.wip.brCond(cond, then_block, else_block);
|
||||
|
||||
self.wip.cursor = .{ .block = then_block };
|
||||
try self.genBody(then_body);
|
||||
try self.genBodyDebugScope(then_body);
|
||||
|
||||
self.wip.cursor = .{ .block = else_block };
|
||||
try self.genBody(else_body);
|
||||
try self.genBodyDebugScope(else_body);
|
||||
|
||||
// No need to reset the insert cursor since this instruction is noreturn.
|
||||
return .none;
|
||||
@ -5987,7 +5987,7 @@ pub const FuncGen = struct {
|
||||
_ = try fg.wip.brCond(is_err, return_block, continue_block);
|
||||
|
||||
fg.wip.cursor = .{ .block = return_block };
|
||||
try fg.genBody(body);
|
||||
try fg.genBodyDebugScope(body);
|
||||
|
||||
fg.wip.cursor = .{ .block = continue_block };
|
||||
}
|
||||
@ -6060,13 +6060,13 @@ pub const FuncGen = struct {
|
||||
}
|
||||
|
||||
self.wip.cursor = .{ .block = case_block };
|
||||
try self.genBody(case_body);
|
||||
try self.genBodyDebugScope(case_body);
|
||||
}
|
||||
|
||||
self.wip.cursor = .{ .block = else_block };
|
||||
const else_body: []const Air.Inst.Index = @ptrCast(self.air.extra[extra_index..][0..switch_br.data.else_body_len]);
|
||||
if (else_body.len != 0) {
|
||||
try self.genBody(else_body);
|
||||
try self.genBodyDebugScope(else_body);
|
||||
} else {
|
||||
_ = try self.wip.@"unreachable"();
|
||||
}
|
||||
@ -6085,7 +6085,7 @@ pub const FuncGen = struct {
|
||||
_ = try self.wip.br(loop_block);
|
||||
|
||||
self.wip.cursor = .{ .block = loop_block };
|
||||
try self.genBody(body);
|
||||
try self.genBodyDebugScope(body);
|
||||
|
||||
// TODO instead of this logic, change AIR to have the property that
|
||||
// every block is guaranteed to end with a noreturn instruction.
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user