Fix environment update for type instance declarations in GHCi (#7117)

Patch by Patrick Palka <patrick@parcs.ath.cx>

MERGED from commit 700d287fb11dadfd1e91875e2008c4002cd883a3
Allow a vew pattern or bang pattern in a record pattern.

e.g.
        data T = MkT { x,y :: Int }

        f (MkT { x = !v, y = negate -> w }) = v + w

MERGED from commit 41c7342e7937dab55d082a0c5612f783e7eaa855
Use TcMType.growThetaTyVars (which works) rather than TcSimplify.growPreds (which doesn't)

I think this got left behind when we simplified and improved TcSimplify.  The effect
was that we had a function like
   class P a b | a -> b
   class Q b c | b -> c

   f :: (P a b, Q b c) => a -> a

and were were failing to quanitfy over 'c', even though it is (indirectly) determined
by 'a'.

This make Programatica fail to compile: Trac #7147

MERGED from commit de07bf2657fc5709331ad933b5563fac97b1a05b
Allocate a fresh META unique in newMetaKindVar

Fixes Trac #7176 on the branch.  HEAD has a better fix
(the big patch to untouchable handling)
    Numerous small changes to the constraint solver

    The main thing is that we now keep unsolved Derived constraints in the
    wc_flats of a WantedConstraints, rather than discarding them each time.
    This actually fixes a poential (admittedly obscure) bug, when we currently
    discard a superclass constraint, and may never re-generate it, and may
    thereby miss a functional dependency.

    Instead, reportErrors filters out Derived constraints that we don't want
    to report.

    The other changes are all small refactorings following our walk-through.

MERGED from commit 9c0a6bbb0194f65cd62e48936c0c00fc4888eef3 on HEAD
OS X: use mmap() instead of malloc for allocating the bss (#7040)

MERGED from commit e590ad77f9596a8389409ae56ea902c97e5dbfb0
Make badImportItem into a warning (#7167)

Also fix a bug where a dodgy import warning was emitted for data
families with a single constructor.

MERGED from commit 3d7c81a4be00a6d72b321b4811ab316ea3301a60
Improve Safe Haskell warn/error output.

MERGED from commit 2b5b178f4880b8034ef8c187e6227cfc09edf0d5
Fix :issafe command (#7172).

MERGED from commit 93e8ae26e42fbe9e600db125182d7823a78e2925
Fix missing case in coVarsOfTcCo

Reported by Ganesh, Trac #7178.  Fix is easy.

MERGED from commit a0788a8b2ba19b7f3205010a71472342a75395f8
Fix for optimizer bug on linux-powerpc (#6156).

MERGED from commit b4b78631890a4cd9cde1551de9a4440e7e750372
Retain ordering of finalizers during GC (#7160)

This came up since the addition of C finalizers, since Haskell
finalizers are already stored in an explicit list.  C finalizers on
the other hand get a WEAK object each, so in order to run them in the
right order we have to make sure that list stays in the correct
order.  I hate adding new invariants, but this is the quickest way to
fix the bug for now.  A better way to fix it would be to have a single
WEAK object with a list of finaliers attached to it, and a primop
for adding finalizers to the list.

MERGED from commit cec899d9fb668d4adccf731a63902e5be49f0660
Don't assume that coercion variables have (~) types

The constraint solver doesn't zonk the types of coercion variables
so we can't assume that a coercion variable will have a (~) type.

Fixes Trac #7090.

MERGED from commit d6918e9072e421178d59cd13ee352337a4090c39
Fix Trac #7092, involving Template Hsakell and name shadowing

All the mechanism was there, but it wasn't being use for the
name-shadowing test.

MERGED from commit b2e8bed817483e80d721cc69720d3d547edab4f5
Don't specialise on implicit-parameter arguments in Specalise

This is a fix for Trac #7101

MERGED from commit 2f08f709cfdace23a4e32d80a57af349f7cc785a
Profiling: open .prof when -hr<cc> is specified

The code for retainer profiling is used with e.g. +RTS -hc -hrfoo -RTS,
as well as with +RTS -hr -RTS.

MERGED from commit 4e0a957758af94bc39ff51814bad54faf96a94b9
Re-jig the reporting of names bound multiple times

Fixes Trac #7164

MERGED from commit 2c6d11fa17ff5cab7d62e6dbea3fc9e501fce7f3
Two small fixes to SpecConstr for functions with equality-proof args

First, make Rules.match_co able to deal wit some modest coercions
Second, make SpecConstr use wild-card for coercion arguments

This is the rest of the fix for Trac #7165

MERGED from commit b04ff2fe83d8a5f9c176739559ac722521a7bdcc
Refactor the way we infer types for functions in a mutually recursive group

See Note [Impedence matching] in TcBinds.
Fixes Trac #7173

MERGED from commit 1a591a0ce0e1b70eb5e6646542d5f110bfefc9af
Fail earlier if there's an error in a type declaration

This change means that we don't recover from erroneous type
declarations, thereby reporting fewer errors.  But trying to
recover confused GHC (leading to a pattern match failure in
the compiler Trac #7175), and it turned out to be tricky
to fix that.

So this patch takes the more conservative path of failing
earlier, perhaps reporting fewer real errors.

MERGED from commit d0ddde58f928a6b156d8061c406226c4fbb7cd22