# dwarf: pass DeclState around instead of storing a temp global in Dwarf · gitcafe/zig

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

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

Visibility: public

Requested revision: f5d9160f1b9fcf7b459c6746e8256d349f0c6873

Requested commit: f5d9160f1b9fcf7b459c6746e8256d349f0c6873

Commit: f5d9160f1b9fcf7b459c6746e8256d349f0c6873

Tree: 36c800efa12843c80f3544e3ca06f89bc7076954

Author: Jakub Konka

Committer: Andrew Kelley

## Message

```
dwarf: pass DeclState around instead of storing a temp global in Dwarf

Avoids many pitfalls connected with premature/early return in case
there are errors with Decl, etc. This is effectively bringing back
the old design however in a much nicer packaging, where every
mechanism related to tracking Decl's debug info is now nicely
wrapped in a single struct (aka the `DeclState`). This includes
relocation table, type arena, etc. It is now the caller's
responsibility to deinit the state (so that no memory is leaked)
after `Decl` has been analysed (or errored out). The caller here
is typically a linker such as `Elf` or `MachO`.

```

## Parents

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

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