Refactor package state, also fixing a module reexport bug.

Instead of building a multiply indirected data structure and querying
it on every import, we now have two data structures moduleToPkgConf
and moduleToPkgConfAll.  moduleToPkgConf is a single-level UniqFM that
is intended to be used for most valid imports; however, it does not
contain any information useful for error reporting.  If an error is
occurred, we then query moduleToPkgConfAll, which contains a more
comprehensive view of the package database.  This field is lazily
initialized (so this means we're retaining the package database list,
but this should be fine because we're already maintaining the entries
of the list.)  Additionally, the full view doesn't keep track of a boolean
toggle for visibility/exposure anymore, but instead tracks the *provenance*
of how the module binding came to be (the ModuleOrigin data type).

Additionally, we move the logic for determining if a module is exposed
or not from Finder.lhs and put it in Packages.lhs; this information is
communicated via the LookupResult data type.  Unfortunately, we can't
directly return a FindResult, because this data type is defined in
HscTypes which depends on Packages.  This is going to change some more
in the near future when I add thinning/renaming to package flags; the
error messages will need to be more flexible.

I've also slightly changed the semantics of error messages for package
qualified imports.  Previously, if we didn't find any package qualified
imports, but there were hidden modules in a *different* package, the error
message would prefer mentioning those as opposed to providing suggestions.
Now, if a module is hidden but in the wrong package, we won't mention it;
instead, it will get mentioned with the other module suggestions.  I
was too lazy to write a test, but I can add one if people would like.

The module reexport bug was, package q reexported p:P as Conflict,
and package r reexported p:P2 as Conflict, this was *not* reported as
a conflict, because the old logic incorrectly decided that P and P2 were
the same module on account of being from the same package.  The logic here
has been corrected.

Contains haddock submodule update.

Signed-off-by: Edward Z. Yang <ezyang@cs.stanford.edu>
Refactor PackageFlags so that ExposePackage is a single constructor.

You can parametrize over the different selection by using a
different PackageArg.  This helps reduce code duplication.

Signed-off-by: Edward Z. Yang <ezyang@cs.stanford.edu>
Thinning and renaming modules from packages on the command line.

Summary:
This patch set adds support for extra syntax on -package and related
arguments which allow you to thin and rename modules from a package.
For example, this argument:

    -package "base (Data.Bool as Bam, Data.List)"

adds two more modules into scope, Bam and Data.List, without adding
any of base's other modules to scope.

These flags are additive: so, for example, saying:

    -hide-all-packages -package base -package "base (Data.Bool as Bam)"

will provide both the normal bindings for modules in base, as well as
the module Bam.

There is also a new debug flag -ddump-mod-map which prints the state
of the module mapping database.  H = hidden, E = exposed (so for
example EH says the module in question is exported, but in a hidden
package.)

Module suggestions have been minorly overhauled to work better with reexports:
if you have -package "base (Data.Bool as Bam)" and mispell Bam, GHC
will suggest "Did you mean Bam (defined via package flags to be
base:Data.Bool)"; and generally you will get more accurate information.
Also, fix a bug where we suggest the -package flag when we really need
the -package-key flag.

NB: The renaming afforded here does *not* affect what wired in
symbols GHC generates.  (But it does affect implicit prelude!)

ToDo: add 'hiding' functionality, to make it easier to support the alternative
prelude use-case.

ToDo: Cabal support

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

Test Plan: new tests and validate

Reviewers: simonpj, simonmar, hvr, austin

Subscribers: simonmar, relrod, ezyang, carter

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

GHC Trac Issues: #9375
[no-ci] Minor bugfixes in Backpack docs.

Signed-off-by: Edward Z. Yang <ezyang@cs.stanford.edu>
configure.ac: drop unused VOID_INT_SIGNALS

Summary:
Another macro borrowed from hugs, gone aways in
commit 528a7d2cf1c90408d60028bb1fec85124d539476

Signed-off-by: Sergei Trofimovich <slyfox@gentoo.org>

Test Plan: build-tested

Reviewers: simonmar, austin, ezyang

Reviewed By: austin, ezyang

Subscribers: phaskell, simonmar, relrod, ezyang, carter

Differential Revision: https://phabricator.haskell.org/D118
Update Haddock submodule to know about profiling.

Signed-off-by: Edward Z. Yang <ezyang@cs.stanford.edu>
Filter out null bytes from trace, and warn accordingly, fixing #9395.

Summary:
Previously, if you ran trace "foo\0bar", the output was truncated so
that everything after the null byte was omitted.  This was terrible.
Now we filter out null bytes, and emit an extra trace saying that
null bytes were filtered out.

NB: we CANNOT fix debugBelch, because all printf variants *always*
respect null bytes, even if you're using string precision such as
%.*s.  The alternative would have been to introduce a new function
debugRawBelch which did not use format strings and took an explicit
string length, but I decided we generally should avoid putting null
bytes in our trace messages, and warn the user.

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

Test Plan: validate

Reviewers: hvr, austin

Subscribers: simonmar, relrod, ezyang, carter

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

GHC Trac Issues: #9395
Temporarily bump Haddock numbers; I'm going to fix it.

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

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