Refactor iface file generation:

This commit refactors interface file generation to allow information
from the later passed (NCG, STG) to be stored in interface files.

We achieve this by splitting interface file generation into two parts:
* Partial interfaces, built based on the result of the core pipeline
* A fully instantiated interface, which also contains the final
fingerprints and can optionally contain information produced by the backend.

This change is required by !1304 and !1530.

-dynamic-too handling is refactored too: previously when generating code
we'd branch on -dynamic-too *before* code generation, but now we do it
after.

(Original code written by @AndreasK in !1530)

Performance
~~~~~~~~~~~

Before this patch interface files where created and immediately flushed
to disk which made space leaks impossible.
With this change we instead use NFData to force all iface related data
structures to avoid space leaks.

In the process of refactoring it was discovered that the code in the
ToIface Module allocated a lot of thunks which were immediately forced
when writing/forcing the interface file. So we made this module more
strict to avoid creating many of those thunks.

Bottom line is that allocations go down by about ~0.1% compared to
master.
Residency is not meaningfully different after this patch.
Runtime was not benchmarked.

Co-Authored-By: Andreas Klebinger <klebinger.andreas@gmx.at>
Co-Authored-By: Ömer Sinan Ağacan <omer@well-typed.com>
22 jobs for master in 345 minutes and 51 seconds (queued for 10 seconds)
Status Job ID Name Coverage
  Lint
passed #167165
lint
lint-linters

00:00:13

passed #167168
lint
lint-submods-branch

00:00:37

passed #167166
lint
lint-testsuite

00:00:15

passed #167167
lint
typecheck-testsuite

00:00:14

 
  Build
passed #167170
x86_64-linux
hadrian-ghc-in-ghci

00:20:41

failed #167870
x86_64-linux
release-x86_64-linux-deb9-dwarf

02:17:21

passed #167171
x86_64-linux
validate-x86_64-linux-deb9-debug

02:31:03

passed #167169
x86_64-linux
validate-x86_64-linux-deb9-hadrian

03:27:28

failed #167172
x86_64-linux
release-x86_64-linux-deb9-dwarf

00:00:19

 
  Full Build
skipped #167174
aarch64-linux allowed to fail
validate-aarch64-linux-deb9
skipped #167175
x86_64-linux
validate-i386-linux-deb9
skipped #167173
x86_64-darwin
validate-x86_64-darwin
skipped #167176
x86_64-linux
validate-x86_64-linux-deb9-integer-simple
skipped #167177
x86_64-linux
validate-x86_64-linux-deb9-unreg
skipped #167178
x86_64-linux
validate-x86_64-linux-fedora27
skipped #167180
x86_64-windows allowed to fail
validate-x86_64-windows
skipped #167179
x86_64-windows allowed to fail
validate-x86_64-windows-hadrian
 
  Cleanup
passed #167181
x86_64-darwin
cleanup-darwin

00:00:05

 
  Packaging
skipped #167182
x86_64-linux allowed to fail
doc-tarball
 
  Testing
skipped #167183
x86_64-linux allowed to fail manual
hackage
skipped #167184
x86_64-linux
perf-nofib
 
  Deploy
skipped #167185
x86_64-linux allowed to fail
pages
 
Name Stage Failure
failed
release-x86_64-linux-deb9-dwarf Build
$ cp -Rf $HOME/.cabal cabal-cache
Uploading artifacts...
ghc-*.tar.xz: found 1 matching files
junit.xml: found 1 matching files

Uploading artifacts to coordinator... ok
id=167870 responseStatus=201 Created token=4ogEqd-8
Uploading artifacts...
junit.xml: found 1 matching files

Uploading artifacts to coordinator... ok
id=167870 responseStatus=201 Created token=4ogEqd-8
ERROR: Job failed: exit code 1