# compiler: rework type resolution, fully resolve all types · gitcafe/zig

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

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

Visibility: public

Requested revision: 0e5335aaf5e0ac646fbd46a319710019d10c2971

Requested commit: 0e5335aaf5e0ac646fbd46a319710019d10c2971

Commit: 0e5335aaf5e0ac646fbd46a319710019d10c2971

Tree: bb5a2e4184a64985f8e8788f0d11b867213aaf3b

Author: mlugg

Committer: mlugg

## Message

```
compiler: rework type resolution, fully resolve all types

I'm so sorry.

This commit was just meant to be making all types fully resolve by
queueing resolution at the moment of their creation. Unfortunately, a
lot of dominoes ended up falling. Here's what happened:

* I added a work queue job to fully resolve a type.
* I realised that from here we could eliminate `Sema.types_to_resolve`
  if we made function codegen a separate job. This is desirable for
  simplicity of both spec and implementation.
* This led to a new AIR traversal to detect whether any required type is
  unresolved. If a type in the AIR failed to resolve, then we can't run
  codegen.
* Because full type resolution now occurs by the work queue job, a bug
  was exposed whereby error messages for type resolution were associated
  with the wrong `Decl`, resulting in duplicate error messages when the
  type was also resolved "by" its owner `Decl` (which really *all*
  resolution should be done on).
* A correct fix for this requires using a different `Sema` when
  performing type resolution: we need a `Sema` owned by the type. Also
  note that this fix is necessary for incremental compilation.
* This means a whole bunch of functions no longer need to take `Sema`s.
  * First-order effects: `resolveTypeFields`, `resolveTypeLayout`, etc
  * Second-order effects: `Type.abiAlignmentAdvanced`, `Value.orderAgainstZeroAdvanced`, etc

The end result of this is, in short, a more correct compiler and a
simpler language specification. This regressed a few error notes in the
test cases, but nothing that seems worth blocking this change.

Oh, also, I ripped out the old code in `test/src/Cases.zig` which
introduced a dependency on `Compilation`. This dependency was
problematic at best, and this code has been unused for a while. When we
re-enable incremental test cases, we must rewrite their executor to use
the compiler server protocol.

```

## Parents

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

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