From 59447e53056d8fb6682b79accccffa176d0b44d1 Mon Sep 17 00:00:00 2001 From: mlugg Date: Sat, 24 Feb 2024 04:29:42 +0000 Subject: compiler: decide dbg_var scoping based on AIR blocks This commit eliminates the `dbg_block_{begin,end}` instructions from both ZIR and AIR. Instead, lexical scoping of `dbg_var_{ptr,val}` instructions is decided based on the AIR block they exist within. This is a much more robust system, and also results in a huge drop in ZIR bytes - around 7% for Sema.zig. This required some enhancements to Sema to prevent elision of blocks when they are required for debug variable scoping. This can be observed by looking at the AIR for the following simple test program with and without `-fstrip`: ```zig export fn f() void { { var a: u32 = 0; _ = &a; } { var a: u32 = 0; _ = &a; } } ``` When `-fstrip` is passed, no AIR blocks are generated. When `-fno-strip` is passed, the ZIR blocks are lowered to true AIR blocks to give correct lexical scoping to the debug vars. The changes here incidentally reolve #19060. A corresponding behavior test has been added. Resolves: #19060 --- src/Air.zig | 8 -------- 1 file changed, 8 deletions(-) (limited to 'src/Air.zig') diff --git a/src/Air.zig b/src/Air.zig index fbd958dece..f316ed04e6 100644 --- a/src/Air.zig +++ b/src/Air.zig @@ -443,10 +443,6 @@ pub const Inst = struct { /// Result type is always void. /// Uses the `dbg_stmt` field. dbg_stmt, - /// Marks the beginning of a semantic scope for debug info variables. - dbg_block_begin, - /// Marks the end of a semantic scope for debug info variables. - dbg_block_end, /// Marks the start of an inline call. /// Uses the `ty_fn` field. dbg_inline_begin, @@ -1454,8 +1450,6 @@ pub fn typeOfIndex(air: *const Air, inst: Air.Inst.Index, ip: *const InternPool) .dbg_stmt, .dbg_inline_begin, .dbg_inline_end, - .dbg_block_begin, - .dbg_block_end, .dbg_var_ptr, .dbg_var_val, .store, @@ -1612,8 +1606,6 @@ pub fn mustLower(air: Air, inst: Air.Inst.Index, ip: *const InternPool) bool { .@"try", .try_ptr, .dbg_stmt, - .dbg_block_begin, - .dbg_block_end, .dbg_inline_begin, .dbg_inline_end, .dbg_var_ptr, -- cgit v1.2.3