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)
Merge latest upstream changes into ghc-7.8