shouldInlinePrimOp: Fix Int overflow

There were two overflow issues in shouldInlinePrimOp. The first one is
due to a negative CmmInt literal being created if the array size was
given as larger than 2^63-1 (on a 64-bit platform.) This meant that
large array sizes could compare as being smaller than
maxInlineAllocSize.

The second issue is that we casted the Integer to an Int in the
comparison, which again meant that large array sizes could compare as
being smaller than maxInlineAllocSize.

The attempt to allocate a large array inline then caused a segfault.

Fixes #9416.
Add some Haddocks to SMRep
StgCmmPrim: add note to stop using fixed size signed types for sizes

We use fixed size signed types to e.g. represent array sizes. This
means that the size can overflow.
Have ghc-pkg use an old-style package key when it's not provided.

Summary:
When this occurs, it means that the user is using an old version of Cabal.
In that case, don't barf out: just go ahead and install it as an old-style
package key.  The user won't be able to link multiple versions together,
but that should not be a problem because their Cabal can't handle it anyway.

What happens if old-style are mixed up with new-style?  Well, currently
with Cabal, it's indistinguishable.  However, if at some later point we
add private dependencies, libraries compiled with old style linker names
are incompatible with each other.  We'll cross that road when we come
to it.

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

Test Plan: validate

Reviewers: tibbe, hvr, austin

Subscribers: simonmar, relrod, ezyang, carter

Differential Revision: https://phabricator.haskell.org/D154
Explicitly version test for package key support.

Signed-off-by: Edward Z. Yang <ezyang@cs.stanford.edu>
Remove out of date TODO

Signed-off-by: Edward Z. Yang <ezyang@cs.stanford.edu>
Implement new CLZ and CTZ primops (re #9340)

This implements the new primops

  clz#, clz32#, clz64#,
  ctz#, ctz32#, ctz64#

which provide efficient implementations of the popular
count-leading-zero and count-trailing-zero respectively
(see testcase for a pure Haskell reference implementation).

On x86, NCG as well as LLVM generates code based on the BSF/BSR
instructions (which need extra logic to make the 0-case well-defined).

Test Plan: validate and succesful tests on i686 and amd64

Reviewers: rwbarton, simonmar, ezyang, austin

Subscribers: simonmar, relrod, ezyang, carter

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

GHC Trac Issues: #9340
Declare `ghc-head` to be haddock's upstream branch

This will affect commands such as

   git submodule update --remote utils/haddock

to use `ghc-head` instead of the default `master` branch
LlvmMangler: Be more selective when mangling object types

Summary:
We previously did a wholesale replace of `%function` to `%object` to
mangle object `.type` annotations. This is bad as it can end up
replacing appearances of `"%function"` in the user's code. We now look
for a proper `.type` keyword before performing the replacement.

Thanks to @rwbarton for pointing out the bug.

Test Plan:
Previously,

    $ echo 'main = putStrLn "@function"' > test.hs
    $ ghc -fllvm test.hs
    $ ./test
    @object

Now,
    $ echo 'main = putStrLn "@function"' > test.hs
    $ ghc -fllvm test.hs
    $ ./test
    @function

Reviewers: rwbarton, austin

Reviewed By: rwbarton, austin

Subscribers: phaskell, simonmar, relrod, ezyang, carter

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

GHC Trac Issues: #9439
Make configure's sed(1) expression for GHC_LDFLAGS more BSD-friendly.
Implement {resize,shrink}MutableByteArray# primops

The two new primops with the type-signatures

  resizeMutableByteArray# :: MutableByteArray# s -> Int#
                          -> State# s -> (# State# s, MutableByteArray# s #)

  shrinkMutableByteArray# :: MutableByteArray# s -> Int#
                          -> State# s -> State# s

allow to resize MutableByteArray#s in-place (when possible), and are useful
for algorithms where memory is temporarily over-allocated. The motivating
use-case is for implementing integer backends, where the final target size of
the result is either N or N+1, and only known after the operation has been
performed.

A future commit will implement a stateful variant of the
`sizeofMutableByteArray#` operation (see #9447 for details), since now the
size of a `MutableByteArray#` may change over its lifetime (i.e before
it gets frozen or GCed).

Test Plan: ./validate --slow

Reviewers: ezyang, austin, simonmar

Reviewed By: austin, simonmar

Differential Revision: https://phabricator.haskell.org/D133
Fix typos 'resizze'
Revert "Fix typos 'resizze'"
this is z-encoding (as hvr tells me)

This reverts commit 425d5178af55620efa00e6e16426f491c63ad533.
Workaround GCC `__ctzdi2` intrinsic linker errors

On Linux/i386 the 64bit `__builtin_ctzll()` instrinsic doesn't get
inlined by GCC but rather a short `__ctzdi2` runtime function is
inserted when needed into compiled object files.

This causes failures for the four test-cases

  TEST="T8639_api T8628 dynCompileExpr T5313"

with error messages of the kind

  dynCompileExpr: .../libraries/ghc-prim/dist-install/build/libHSghcpr_BE58KUgBe9ELCsPXiJ1Q2r.a: unknown symbol `__ctzdi2'
  dynCompileExpr: dynCompileExpr: unable to load package `ghc-prim'

This workaround forces GCC on 32bit x86 to to express `hs_ctz64` in
terms of the 32bit `__builtin_ctz()` (this is no loss, as there's no
64bit BSF instruction on i686 anyway) and thus avoid the problematic
out-of-line runtime function.

Note: `__builtin_ctzll()` is used since
      e0c1767d0ea8d12e0a4badf43682a08784e379c6 (re #9340)
Remove obsolete `digitsTyConKey :: Unique`

This became dead with 1e87c0a6e485e1dbef8e9ed19191e54f6cdc54e0
and was probably just missed.

I plan to re-use the freed up `mkPreludeTyConUnique 23` slot soon
for a new `bigNatTyConKey` (as part of the #9281 effort)
workaround Solaris 11 GNU C CPP issue by using GNU C 3.4 as CPP

Summary:
Solaris 11 distributed GNU C 4.5.x is configured in a way that its
CPP is not working well while invoked from GHC. GHC runs it with
-x assembler-with-cpp and in this particular configuration GNU C CPP
does not provide any line-markers so GHC's output of errors or warnings
is confusing since it points to preprocessed file in /tmp and not
to the original Haskell file. Fortunately old GNU C 3.4.x is still
provided by the OS and when installed it'll be used automatically
as GHC CPP which is whole logic of this patch. So although we use modern
GCC as a C compiler and assembler we use old GCC as a C preprocessor.

Test Plan: validate

Reviewers: austin

Reviewed By: austin

Subscribers: phaskell, simonmar, relrod, ezyang, carter

Differential Revision: https://phabricator.haskell.org/D151
Fix quasi-quoter documentation (#9448)
Fix broken link in Data.Data to SYB home page (Trac #9455)

Ralf Laemmel's page has disappeared, so I made it point to the Haskell
Wiki page instead.
Update list of flags implied by -XGADTs in User's Guide section on GADTs
Make T8832 operative on 32-bit systems (#8832)

(Also, the 'extra_clean' was unnecessary.)