Simplify handling of the interactive package; fixes Trac #8831

This patch is really a fix to the big commint
   73c08ab10e4077e18e459a1325996bff110360c3
   Re-work the naming story for the GHCi prompt (Trac #8649)
which introduced the 'interactive' package
See Note [The interactive package] in HscTypes

The original commit set both
  (a) The tcg_mod field of TcGblEnv to 'interactive:Ghci4' (say)
  (b) The thisPackage field of DynFlags to 'interactive'

But the second step interacts badly with linking.  :loaded modules are
in the package set by 'thisPackage' (usually 'main'); if you change
that, then we try to link package 'main', but can't find it, and
that is what happened in #8831.

The fix was simple: do (a) but not (b).

I changed Note [The interactive package] in HscTypes to describe this.

(cherry picked from commit 28e8d878b63d06824001ac3a631254679e0f1960)
Trac #8831 is fixed

(cherry picked from commit 1a7709ef9b25175566bc040a34b3d479ea8566ed)

Conflicts:
	testsuite/tests/ghci/scripts/all.T
Fix the treatment of lexically scoped kind variables (Trac #8856)

The issue here is described in Note [Binding scoped type variables] in
TcPat.  When implementing this fix I was able to make things quite a
bit simpler:
 * The type variables in a type signature now never unify
   with each other, and so can be straightfoward skolems.
 * We only need the SigTv stuff for signatures in patterns,
   and for kind variables.

(cherry picked from commit cf1a0f971966af633fbd932ad012ce716680465b)
Test Trac #8856

(cherry picked from commit 062391be4f06aa408187582c4a40f1cea80429c3)
Unflatten the constraints of an inferred types (Trac #8889)

There was even a comment to warn about this possiblity,
and it finally showed up in practice!  This patch fixes
it quite nicely, with commens to explain.

(cherry picked from commit 7a7af1ffc48f605cf365faf8fcef31ef4f13822b)
Test Trac #8889

(cherry picked from commit 0e2155ddb10f4ccf53e50064756cbc3ce7dd8832)
Make sure we occurrence-analyse unfoldings (fixes Trac #8892)

For DFunUnfoldings we were failing to occurrence-analyse the unfolding,
and that meant that a loop breaker wasn't marked as such, which in turn
meant it was inlined away when it still had occurrence sites.  See
Note [Occurrrence analysis of unfoldings] in CoreUnfold.

This is a pretty long-standing bug, happily nailed by John Lato.

(cherry picked from commit 87bbc69c40d36046492d754c8d7ff02c3be6ce43)
Apply the kind subst to the (kinds of the) quanitifed tyvars in deriveTyData

I've elaboated Note [Unify kinds in deriving] to explain
what is going on here.

The change fixes Trac #8893.

(cherry picked from commit ffed708c30f2d1d4b4c5cd08d9c19aeb0bb623ec)
Test Trac #8893

(cherry picked from commit 7973bfb87fdbe6e980e64ed5d7b2a90a469effd4)
Revert "Fix #8745 - GND is now -XSafe compatible."

See #8827 - for now, we're making GND unsafe again.

This also fixes the tests since they were originally not using the new
unicode quote style we're using.

This reverts commit a8a01e742434df11b830ab99af12d9045dfcbc4b.

(cherry picked from commit 8f7303774237a8b0787d98c5ab6f605e3e897f19)
Follow hs_popcntX changes in ghc-prim

(cherry picked from commit 1a63f17f19a6c83980efe453966eac1cf441b277)
Enable popcnt test now when segfault is fixed

The fix was to ghc-prim.

(cherry picked from commit 16d04d902d4720b3137e07a503fbf72c90b9e164)
Revert "change deriveConstants to use nm in a POSIX way (fixes #8781)"

It causes a failure on Windows right now.

This reverts commit 045b28033a33a48d31951240a8cb35f2b78345dc.

(cherry picked from commit 15b1eb7c67e29c4ad6f6859f89d220b33493fd46)
Add missing kind-check for tcEqType on forall-types

This wasn't showing up as a bug, but it was definitely wrong.

(cherry picked from commit 74894e0bc405247092e865b9541f5f18d26aa015)
relnotes: GND is not -XSafe compatible.

Signed-off-by: Austin Seipp <austin@well-typed.com>
(cherry picked from commit 73cab206e0f211b75cb6fd62ab9b6ca8ae0950f2)
Implicit parameters should not be allowed in class and instance declarations

Trac #8912 pointed out that GHC 7.4 and 7.6 have omitted this test, although
7.2 and earlier had it.  This patch puts the test back in, and refactors a
little.

(cherry picked from commit a8b7b28cdb98d14c6fb43d5ad3293fd4a5c1f8b4)

Conflicts:
	testsuite/tests/typecheck/should_fail/all.T
For equalities with incompatible kinds, new IrredCan goes in the inert set, not work list

This change makes the code for canIrred markedly simpler (and more efficient)
See Note [Equalities with incompatible kinds].

I don't think there was really a bug here, but I came across it when
fixing Trac #8913

(cherry picked from commit c89c57e3b72a8f3de9f35e1bd6e0f70d2b18a941)
Flattener preserves synonyms, rewriteEvidence can drop buggy "optimisation"

There was a special case in rewriteEvidence, looking like:
  = return (Just (if ctEvPred old_ev `tcEqType` new_pred
                  then old_ev
                  else old_ev { ctev_pred = new_pred }))

But this was wrong: old_pred and new_pred might differ in the kind
of a TyVar occurrence, in which case tcEqType would not notice,
but we really, really want new_pred.  This caused Trac #8913.

I solved this by dropping the whole test, and instead making
the flattener preserve type synonyms. This was easy because
TcEvidence has TcTyConAppCo which (unlike) Coercion, handles
synonyms.

(cherry picked from commit 6ae678e31a5fdd3b0bd1f8613fe164012bb630f4)
Adding CPP and CPP-Flags to configure step, ghc settings file, and associated dyn flags support
Still not quite right, CPP flags work in progress