# Sema: better code generated for struct literals · gitcafe/zig

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

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

Visibility: public

Requested revision: 713d2a9b3883942491b40738245232680877cc66

Requested commit: 713d2a9b3883942491b40738245232680877cc66

Commit: 713d2a9b3883942491b40738245232680877cc66

Tree: 9b28339bd354a4739344197042d26c38315147a0

Author: Andrew Kelley

Committer: Andrew Kelley

## Message

```
Sema: better code generated for struct literals

Add a variant of the `validate_struct_init` ZIR instruction:
`validate_struct_init_comptime` which is the same thing except it
indicates a comptime scope.

Sema code for this instruction now handles default struct field
values and detects when the struct initialization resulted in a
comptime value, replacing the already-emitted AIR instructions
to store each individual field with a single `store` instruction
with a comptime struct value as the operand.

In the case of a comptime scope, there is a simpler path that only
evals the implicit store instructions for default field values, avoiding
the mechanism for detecting comptime values.

This regressed one test case for the wasm backend, but it's just hitting
a different prong of `emitConstant` which currently has "TODO" in there,
so I think it's fine.

```

## Parents

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

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