# sema: analyze field init bodies in a second pass · gitcafe/zig

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

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

Visibility: public

Requested revision: f10499be0a16ec58d98387b49189401f2af2094f

Requested commit: f10499be0a16ec58d98387b49189401f2af2094f

Commit: f10499be0a16ec58d98387b49189401f2af2094f

Tree: 1dee8acd698e9bb489a9926004d4cdf16f7ce72d

Author: kcbanner

Committer: mlugg

## Message

```
sema: analyze field init bodies in a second pass

This change allows struct field inits to use layout information
of their own struct without causing a circular dependency.

`semaStructFields` caches the ranges of the init bodies in the `StructType`
trailing data. The init bodies are then resolved by `resolveStructFieldInits`,
which is called before the inits are actually required.

Within the init bodies, the struct decl's instruction is repurposed to refer
to the field type itself. This is to allow us to easily rebuild the inst_map
mapping required for the init body instructions to refer to the field type.

Thanks to @mlugg for the guidance on this one!

```

## Parents

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

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