# Zir: represent declarations via an instruction · gitcafe/zig

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

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

Visibility: public

Requested revision: ae845a33c04fb287ae5a7445743c2b570e40ca1f

Requested commit: ae845a33c04fb287ae5a7445743c2b570e40ca1f

Commit: ae845a33c04fb287ae5a7445743c2b570e40ca1f

Tree: 65bbaa19d241453a95f7a1561d2815106cf36844

Author: mlugg

Committer: mlugg

## Message

```
Zir: represent declarations via an instruction

This commit changes how declarations (`const`, `fn`, `usingnamespace`,
etc) are represented in ZIR. Previously, these were represented in the
container type's extra data (e.g. as trailing data on a `struct_decl`).
However, this introduced the complexity of the ZIR mapping logic having
to also correlate some ZIR extra data indices. That isn't really a
problem today, but it's tricky for the introduction of `TrackedInst` in
the commit following this one. Instead, these type declarations now
simply contain a trailing list of ZIR indices to `declaration`
instructions, which directly encode all data related to the declaration
(including containing the declaration's body). Additionally, the ZIR for
`align` etc have been split out into their own bodies. This is not
strictly necessary, but it's much simpler to understand for an
insignificant cost in bytes, and will simplify the resolution of #131
(where we may need to evaluate the pointer type, including align etc,
without immediately evaluating the value body).

```

## Parents

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

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