# stage2: rework ZIR/TZIR for optionals and error unions · gitcafe/zig

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

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

Visibility: public

Requested revision: ecc246efa2c133aaab73032a18fed5b2c15e08ce

Requested commit: ecc246efa2c133aaab73032a18fed5b2c15e08ce

Commit: ecc246efa2c133aaab73032a18fed5b2c15e08ce

Tree: 660b8f5e027066e728fbd88db5e58385940aa2d7

Author: Andrew Kelley

Committer: Andrew Kelley

## Message

```
stage2: rework ZIR/TZIR for optionals and error unions

 * fix wrong pointer const-ness when unwrapping optionals
 * allow grouped expressions and orelse as lvalues
 * ZIR for unwrapping optionals: no redundant deref
   - add notes to please don't use rlWrapPtr, this function should be
     deleted
 * catch and orelse: better ZIR for non-lvalue: no redundant deref;
   operate entirely on values. lvalue case still works properly.
   - properly propagate the result location into the target expression
 * Test harness: better output when tests fail due to compile errors.
 * TZIR: add instruction variants. These allow fewer TZIR instructions to
   be emitted from zir_sema. See the commit diff for per-instruction
   documentation.
   - is_null
   - is_non_null
   - is_null_ptr
   - is_non_null_ptr
   - is_err
   - is_err_ptr
   - optional_payload
   - optional_payload_ptr
 * TZIR: removed old naming convention instructions:
   - isnonnull
   - isnull
   - iserr
   - unwrap_optional
 * ZIR: add instruction variants. These allow fewer ZIR instructions to
   be emitted from astgen. See the commit diff for per-instruction
   documentation.
   - is_non_null
   - is_null
   - is_non_null_ptr
   - is_null_ptr
   - is_err
   - is_err_ptr
   - optional_payload_safe
   - optional_payload_unsafe
   - optional_payload_safe_ptr
   - optional_payload_unsafe_ptr
   - err_union_payload_safe
   - err_union_payload_unsafe
   - err_union_payload_safe_ptr
   - err_union_payload_unsafe_ptr
   - err_union_code
   - err_union_code_ptr
 * ZIR: removed old naming convention instructions:
   - isnonnull
   - isnull
   - iserr
   - unwrap_optional_safe
   - unwrap_optional_unsafe
   - unwrap_err_safe
   - unwrap_err_unsafe
   - unwrap_err_code

```

## Parents

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

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