# stage2: implement \`@intToError\` with safety · gitcafe/zig

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

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

Visibility: public

Requested revision: 05947ea870f95ab90a75e174079492f546baaf72

Requested commit: 05947ea870f95ab90a75e174079492f546baaf72

Commit: 05947ea870f95ab90a75e174079492f546baaf72

Tree: 10c9a048bb1d55ce553c42c8f8e4f969241925cc

Author: Andrew Kelley

Committer: Andrew Kelley

## Message

```
stage2: implement `@intToError` with safety

This commit introduces a new AIR instruction `cmp_lt_errors_len`. It's
specific to this use case for two reasons:

 * The total number of errors is not stable during semantic analysis; it
   can only be reliably checked when flush() is called. So the backend
   that is lowering the instruction must emit a relocation of some kind
   and then populate it during flush().
 * The fewer AIR instructions in memory, the better for compiler
   performance, so we squish complex meanings into AIR tags without
   hesitation.

The instruction is implemented only in the LLVM backend so far. It does
this by creating a simple function which is gutted and re-populated
with each flush().

AstGen now uses ResultLoc.coerced_ty for `@intToError` and Sema does the
coercion.

```

## Parents

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

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