# compiler: decide dbg_var scoping based on AIR blocks · gitcafe/zig

[View on GitCafe](https://git.cafe/gitcafe/zig/commit/59447e53056d8fb6682b79accccffa176d0b44d1)

Repository: [gitcafe/zig](https://git.cafe/gitcafe/zig)

Visibility: public

Requested revision: 59447e53056d8fb6682b79accccffa176d0b44d1

Requested commit: 59447e53056d8fb6682b79accccffa176d0b44d1

Commit: 59447e53056d8fb6682b79accccffa176d0b44d1

Tree: fef7809520fc67d519150592ea479576c9b289ca

Author: mlugg

Committer: mlugg

## Message

````
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

````

## Parents

- [031f23117dadd84b1e7189ee5b0f712eeb23ca1e](https://git.cafe/gitcafe/zig/commit/031f23117dadd84b1e7189ee5b0f712eeb23ca1e?format=markdown)

[Source at this commit](https://git.cafe/gitcafe/zig/tree/59447e53056d8fb6682b79accccffa176d0b44d1?format=markdown)
