# stage2: improvements towards \`zig test\` · gitcafe/zig

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

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

Visibility: public

Requested revision: 31a59c229cb39b9ffd1ee3397a1ce87c36b91477

Requested commit: 31a59c229cb39b9ffd1ee3397a1ce87c36b91477

Commit: 31a59c229cb39b9ffd1ee3397a1ce87c36b91477

Tree: f4074655750f90c6350a8f3070343da9a724ccfd

Author: Andrew Kelley

Committer: Andrew Kelley

## Message

```
stage2: improvements towards `zig test`

 * Add AIR instruction: struct_field_val
   - This is part of an effort to eliminate the AIR instruction `ref`.
   - It's implemented for C backend and LLVM backend so far.
 * Rename `resolvePossiblyUndefinedValue` to `resolveMaybeUndefVal` just
   to save some columns on long lines.
 * Sema: add `fieldVal` alongside `fieldPtr` (renamed from
   `namedFieldPtr`). This is part of an effort to eliminate the AIR
   instruction `ref`. The idea is to avoid unnecessary loads, stores,
   stack usage, and IR instructions, by paying a DRY cost.

LLVM backend improvements:

 * internal linkage vs exported linkage is implemented, along with
   aliases. There is an issue with incremental updates due to missing
   LLVM API for deleting aliases; see the relevant comment in this commit.
   - `updateDeclExports` is hooked up to the LLVM backend now.
 * Fix usage of `Type.tag() == .noreturn` rather than calling `isNoReturn()`.
 * Properly mark global variables as mutable/constant.
 * Fix llvm type generation of function pointers
 * Fix codegen for calls of function pointers
 * Implement llvm type generation of error unions and error sets.
 * Implement AIR instructions: addwrap, subwrap, mul, mulwrap, div,
   bit_and, bool_and, bit_or, bool_or, xor, struct_field_ptr,
   struct_field_val, unwrap_errunion_err, add for floats, sub for
   floats.

After this commit, `zig test` on a file with `test "example" {}`
correctly generates and executes a test binary. However the
`test_functions` slice is undefined and just happens to be going into
the .bss section, causing the length to be 0. The next step towards
`zig test` will be replacing the `test_functions` Decl Value with the
set of test function pointers, before it is sent to linker/codegen.

```

## Parents

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

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