Unbreak the build on FreeBSD/i386, where the default target arch is i486.

The recent version of ghc-prim assumes a more modern processor as it
exploits built-in atomic operations, and some of them are not yet
present on i486.  Hence the -march flag is explicitly set to i686 for the
C compiler -- just to be in sync with the default of other distributions.
Make last a good consumer

Summary:
Make last a good consumer simply by implementing it as foldl. This fixes Trac: #9339.
Thanks to David Feuer for bringing it up.

Test Plan: perf/should_run/T9339 + general validation

Reviewers: austin

Reviewed By: austin

Subscribers: phaskell, simonmar, relrod, carter

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

Trac Issues: #9339
Rewrite package/module identity section

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

Signed-off-by: Edward Z. Yang <ezyang@cs.stanford.edu>
Definite compilation is a go

Signed-off-by: Edward Z. Yang <ezyang@cs.stanford.edu>
Write up rename on entry

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

Signed-off-by: Edward Z. Yang <ezyang@cs.stanford.edu>
Duplicate word
X86 codegen: make LOCK a real instruction prefix

Before LOCK was a separate instruction and this led to the register
allocator separating it from the instruction it was supposed to be a
prefix of, leading to illegal assembly such as

    lock mov

Fix contributed by PÁLI Gábor János.
Fix test for fetchNandIntArray#

The test was incorrectly testing that NAND is associative, which it
isn't.
Add missing memory fence to atomicWriteIntArray#
Fixed issue with detection of duplicate record fields

Duplicate record fields would not be detected when given a type
with multiple data constructors, and the first data constructor
had a record field r1 and any consecutive data constructors
had multiple fields named r1.

This fixes #9156 and was reviewed in https://phabricator.haskell.org/D87
Use the right kinds on the LHS in 'deriving' clauses

This patch fixes Trac #9359
Check for boxed tau types in the LHS of type family instances

Fixes Trac #9357
[backpack] Rewrite compilation to be cleaner.

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

This patch was provoked by Trac #5610, which I finally got a moment to look at.

In the end I added a new data type ErrUtils.Validity,

  data Validity
    = IsValid            -- Everything is fine
    | NotValid MsgDoc    -- A problem, and some indication of why

with some suitable combinators, and used it where appropriate (which touches
quite a few modules).  The main payoff is that error messages improve for
FFI type validation.
Module reexports, fixing #8407.

The general approach is to add a new field to the package database,
reexported-modules, which considered by the module finder as possible
module declarations.  Unlike declaring stub module files, multiple
reexports of the same physical package at the same name do not
result in an ambiguous import.

NB: When a reexport renames a module, that renaming is *not* accessible
from inside the package.  This is not so much a deliberate design choice
as for implementation expediency (reexport resolution happens only when
a package is in the package database.)

TODO: Error handling when there are duplicate reexports/etc is not very
well tested.

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

Conflicts:
	compiler/main/HscTypes.lhs
	testsuite/.gitignore
	utils/haddock
(WIP) Package keys, plus a raft of error reporting refactoring

Summary:
This patch set makes us no longer assume that a package key is a human
readable string, leaving Cabal free to "do whatever it wants" to allocate
keys; we'll look up the PackageId in the database to display to the user.
This also means we have a new level of qualifier decisions to make at the
package level, and rewriting some Safe Haskell error reporting code to DTRT.

Additionally, we adjust the build system to use a new ghc-cabal output
Make variable PACKAGE_KEY to determine library names and other things,
rather than concatenating PACKAGE/VERSION as before.

Adds a new `-package-key` flag to subsume the old, erroneously named
`-package-name` flag.

RFC: Perhaps the flag should be called -current-package-key (so that we
can use -package-key to load packages by key?

RFC: The md5 hashes are pretty tough on the eye, as far as the file
system is concerned :(

ToDo: Figure out what to do with the funny case of mutual recursion in Packages

ToDo: Fix warnings and validate

ToDo: Fix code duplication for pkg_qual logic.

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

Test Plan: validate

Reviewers: simonpj, simonmar, hvr, austin

Subscribers: simonmar, relrod, carter

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

Conflicts:
	compiler/main/Packages.lhs
IPid but without UI wiring in.

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