Refactor CmmToAsm (disentangle DynFlags)

This patch disentangles a bit more DynFlags from the native code
generator (CmmToAsm).

In more details:

- add a new NCGConfig datatype in GHC.CmmToAsm.Config which contains the
  configuration of a native code generation session
- explicitly pass NCGConfig/Platform arguments when necessary
- as a consequence `sdocWithPlatform` is gone and there are only a few
  `sdocWithDynFlags` left
- remove the use of `unsafeGlobalDynFlags` from GHC.CmmToAsm.CFG
- remove `sdocDebugLevel` (now we pass the debug level via NCGConfig)

There are still some places where DynFlags is used, especially because
of pretty-printing (CLabel), because of Cmm helpers (such as
`cmmExprType`) and because of `Outputable` instance for the
instructions. These are left for future refactoring as this patch is
already big.
23 jobs for master in 442 minutes and 25 seconds (queued for 4 seconds)
Status Job ID Name Coverage
  Lint
passed #282144
lint
lint-linters

00:00:13

passed #282147
lint
lint-submods-branch

00:00:15

passed #282145
lint
lint-testsuite

00:00:14

passed #282146
lint
typecheck-testsuite

00:00:14

 
  Quick Build
passed #282148
x86_64-linux
hadrian-ghc-in-ghci

00:08:56

 
  Build
passed #282149
x86_64-linux
validate-x86_64-linux-deb9-hadrian

03:07:30

 
  Full Build
failed #282152
aarch64-linux allowed to fail
validate-aarch64-linux-deb9

03:26:32

passed #282153
armv7-linux
validate-armv7-linux-deb9

03:19:47

passed #282154
x86_64-linux
validate-i386-linux-deb9

00:55:11

failed #282161
new-x86_64-windows test allowed to fail
validate-i386-windows

passed #282151
x86_64-darwin
validate-x86_64-darwin

01:09:19

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

01:06:21

passed #282157
x86_64-linux
validate-x86_64-linux-deb9-dwarf

01:07:01

passed #282156
x86_64-linux
validate-x86_64-linux-deb9-integer-simple

00:58:49

passed #282150
x86_64-linux
validate-x86_64-linux-deb9-unreg-hadrian

02:02:44

passed #282158
x86_64-linux
validate-x86_64-linux-fedora27

01:45:51

failed #282160
new-x86_64-windows test allowed to fail
validate-x86_64-windows

failed #282159
new-x86_64-windows test allowed to fail
validate-x86_64-windows-hadrian

 
  Cleanup
passed #282162
x86_64-darwin
cleanup-darwin

00:00:24

 
  Packaging
failed #282163
x86_64-linux allowed to fail
doc-tarball

00:00:56

 
  Testing
manual #282164
x86_64-linux allowed to fail manual
hackage
passed #282165
x86_64-linux
perf-nofib

00:36:31

 
  Deploy
failed #282166
x86_64-linux allowed to fail
pages

00:00:56

 
Name Stage Failure
failed
validate-x86_64-windows-hadrian Full Build There has been a timeout failure or the job got stuck. Check your timeout limits or try again
No job log
failed
validate-x86_64-windows Full Build There has been a timeout failure or the job got stuck. Check your timeout limits or try again
No job log
failed
validate-i386-windows Full Build There has been a timeout failure or the job got stuck. Check your timeout limits or try again
No job log
failed
validate-aarch64-linux-deb9 Full Build
cd "libraries/ghc-heap/tests/heap_all.run" &&  "/builds/ghc/ghc/inplace/bin/ghc-stage2" -o heap_all heap_all.hs -dcore-lint -dstg-lint -dcmm-lint -no-user-package-db -rtsopts -fno-warn-missed-specialisations -fshow-warning-groups -fdiagnostics-color=never -fno-diagnostics-show-caret -Werror=compat -dno-debug-output  < 
cd "libraries/ghc-compact/tests/compact_bench.run" && ./compact_bench 100<
=====> compact_bench(sanity) 7279 of 7398 [0, 103, 8]
cd "libraries/ghc-compact/tests/compact_bench.run" && "/builds/ghc/ghc/inplace/bin/ghc-stage2" -o compact_bench compact_bench.hs -dcore-lint -dstg-lint -dcmm-lint -no-user-package-db -rtsopts -fno-warn-missed-specialisations -fshow-warning-groups -fdiagnostics-color=never -fno-diagnostics-show-caret -Werror=compat -dno-debug-output -debug <
cd "libraries/ghc-compact/tests/compact_gc.run" && ./compact_gc +RTS -DS -RTS <
cd "libraries/ghc-compact/tests/T17044.run" && ./T17044 <
cd "libraries/ghc-compact/tests/compact_share.run" && ./compact_share +RTS -DS -RTS <
=====> T17044(sanity) 7279 of 7398 [0, 103, 8]
cd "libraries/ghc-compact/tests/T17044.run" && "/builds/ghc/ghc/inplace/bin/ghc-stage2" -o T17044 T17044.hs -dcore-lint -dstg-lint -
Job's log exceeded limit of 16384000 bytes.
failed
doc-tarball Packaging
Entering 'libraries/xhtml'
Entering 'nofib'
Entering 'utils/haddock'
Entering 'utils/hsc2hs'
Downloading artifacts for validate-x86_64-linux-deb9-debug (282155)...
Downloading artifacts from coordinator... ok id=282155 responseStatus=200 OK token=aFQtBAHs
$ if [ ! -f "$LINUX_BINDIST" ]; then # collapsed multi-line command
Error: ghc-x86_64-mingw32.tar.xz does not exist. Did the 64-bit Windows job fail?
ERROR: Job failed: exit code 1
failed
pages Deploy
Entering 'libraries/xhtml'
Entering 'nofib'
Entering 'utils/haddock'
Entering 'utils/hsc2hs'
$ mkdir -p public/doc
$ tar -xf haddock.html.tar.xz -C public/doc
tar: haddock.html.tar.xz: Cannot open: No such file or directory
tar: Error is not recoverable: exiting now
ERROR: Job failed: exit code 1