Re-implement `testPrimeInteger` predicate (#9281)

This also adds `testPrimeWord#` and `testPrimeBigNat` predicates.

`testPrimeInteger` has been available since `integer-gmp-0.5.1`
(added via f49735486533842cc84df70cafc8d565dffd75db).
The `nextPrimeInteger` function is still missing though.
Make the linker API thread-safe

We used to be able to rely on the client to use the API in a
single-threaded way, but now that the GC calls into the linker to
unload objects this isn't a safe assumption.
Add purgeObj() to remove the symbol table entries for an object

This allows us to replace an object without actually unloading the old
object, which is necessary when we know we have references to the old
object so it can't be completely unloaded.  Using unloadObj() would
cause the GC (CheckUnload) to repeatedly and fruitlessly try to unload
the old object.
Re-implement `nextPrimeInteger` predicate (#9281)

This also adds `nextPrimeWord#` and `nextPrimeBigNat` predicates.

`nextPrimeInteger` has been available since `integer-gmp-0.5.1`
(added via f49735486533842cc84df70cafc8d565dffd75db).
Re-activate `integerGmpInternals` test (#9281)

The `integerGmpInternals` test was disabled in
c774b28f76ee4c220f7c1c9fd81585e0e3af0e8a as many of the primitives
tested in that test weren't available yet w/ `integer-gmp2`.

However, most operations have been reimplemented by now, with the
exception of

    recipModInteger  :: Integer -> Integer -> Integer
    gcdExtInteger    :: Integer -> Integer -> (Integer, Integer)
    powModSecInteger :: Integer -> Integer -> Integer -> Integer
    powModInteger    :: Integer -> Integer -> Integer -> Integer
    powInteger       :: Integer -> Word -> Integer

which are still missing, and will (time permitting) be reimplemented
over time.
Kind variables in RHS of an associated type instances should be bound on LHS

This patche fixes Trac #9574.

The previous Note [Renaming associated types] in RnTypes appears to me to be wrong;
it confused class and instance declarations.

I have:

 * Treated kind and type variables uniformly. Both must be bound on the LHS
   of an associated type instance.  Eg
       instance C ('KProxy :: KProxy o) where
          type F 'KProxy = NatTr (Proxy :: o -> *)
   is illegal because 'o' is not bound on the LHS of the instance.

 * Moved the Note to RnSource and fixed it up

This improves the error message from T7938. However it made the code in
T6118 incorrect. We had:
  instance SingE (a :: Maybe k) where
    type Demote a = Maybe (Demote (Any :: k))
and that is now rejected, rightly I think.
Rename some of the functions in NameSet, to make the uniform with VarSet etc

For ages NameSet has used different names,
  eg.   addOneToNameSet   rather than    extendNameSet
        nameSetToList     rather than    nameSetElems

etc.  Other set-like modules use uniform naming conventions.
This patch makes NameSet follow suit.

No change in behaviour; this is just renaming.

I'm doing this just before the fork so that merging is easier.
Implement Partial Type Signatures

Summary:
Add support for Partial Type Signatures, i.e. holes in types, see:
https://ghc.haskell.org/trac/ghc/wiki/PartialTypeSignatures

This requires an update to the Haddock submodule.

Test Plan: validate

Reviewers: austin, goldfire, simonpj

Reviewed By: simonpj

Subscribers: thomie, Iceland_jack, dominique.devriese, simonmar, carter, goldfire

Differential Revision: https://phabricator.haskell.org/D168

GHC Trac Issues: #9478
Update submodule 'haddock' to render 'pattern' as a keyword
Minor refactoring of static C initializers
Fix testsuite failures after the PartialTypeSignatures merge

Summary:
Properly detect insoluble wanteds

This used to be correct, but was recently incorrectly refactored.

Reviewers: austin, hvr

Reviewed By: austin, hvr

Subscribers: thomie, carter

Differential Revision: https://phabricator.haskell.org/D531
More static C initializer refactoring

A few instances were missed in 447f592697fef04d1e19a2045ec707cfcd1eb59f

Moreover, be more paranoid when testing for zero values, and try harder
to avoid passing denormalized zero `mpz_t`-values into GMP functions.
Re-implement `powModInteger`  (#9281)

This also exposes the following type-specialised modular exponentiation
variants of `powModInteger` useful for implementing a `powModNatural`
operation.

  powModBigNat     :: BigNat -> BigNat -> BigNat -> BigNat
  powModBigNatWord :: BigNat -> BigNat -> Word#  -> Word#
  powModWord       :: Word#  -> Word#  -> Word#  -> Word#

`powModInteger` has been available since `integer-gmp-0.5.1`
(added via 4d516855241b70eb687d95e3c121428de885e83e)
Implement `GHC.Natural.powModNatural` (#9818)

This makes use of the `powMod*` primitives provided by
`integer-gmp-1.0.0`. This is the `Natural`-version of the related
`GHC.Integer.GMP.Internals.powModInteger` operation.

The fallback implementation uses a square and multiply algorithm,
compared to which the optimized GMP-based implementation needs much less
allocations due to in-place mutation during the computation.
Re-implement `recipModInteger` (#9281)

This also exposes the following two type-specialised modular
exponentiation variants of `recipModInteger` useful for implementing a
`recipModNatural` operation.

  recipModBigNat :: BigNat -> BigNat -> BigNat
  recipModWord   :: Word#  -> Word#  -> Word#

`recipModInteger` has been available since `integer-gmp-0.5.1`
(added via 4d516855241b70eb687d95e3c121428de885e83e)
Reimplement `gcdExtInteger` (#9281)

`gcdExtInteger` has been available since `integer-gmp-0.5.1`
(added via 71e29584603cff38e7b83d3eb28b248362569d61)
Special case interactive package key for mkQualPackage.

Signed-off-by: Edward Z. Yang <ezyang@cs.stanford.edu>
Filter instance visibility based on set of visible orphans, fixes #2182.

Summary:
Amazingly, the fix for this very old bug is quite simple: when type-checking,
maintain a set of "visible orphan modules" based on the orphans list of
modules which we explicitly imported.  When we import an instance and it
is an orphan, we check if it is in the visible modules set, and if not,
ignore it.  A little bit of refactoring for when orphan-hood is calculated
happens so that we always know if an instance is an orphan or not.

For GHCi, we preinitialize the visible modules set based on the list of
interactive imports which are active.

Future work: Cache the visible orphan modules set for GHCi, rather than
recomputing it every type-checking round.  (But it's tricky what to do when you
/remove/ a module: you need a data structure a little more complicated than
just a set of modules.)

Signed-off-by: Edward Z. Yang <ezyang@cs.stanford.edu>

Test Plan: new tests and validate

Reviewers: simonpj, austin

Subscribers: thomie, carter

Differential Revision: https://phabricator.haskell.org/D488

GHC Trac Issues: #2182
Shorten long lines in DynFlags, add details to ghci usage guide.

Summary:
Shorten long lines in DynFlags.
Describe --show-options in ghci usage guide.

Reviewers: jstolarek, austin

Reviewed By: jstolarek, austin

Subscribers: thomie, carter

Differential Revision: https://phabricator.haskell.org/D532

GHC Trac Issues: #9259
More Tweaks for API Anotations

Summary: Attaching semis to preceding AST element, not following

Test Plan: sh ./validate

Reviewers: hvr, austin

Reviewed By: austin

Subscribers: cactus, thomie, carter

Differential Revision: https://phabricator.haskell.org/D529