Fix a flag-handling bug related to #1855.

This was an innocent-looking but severe bug that was triggered for manual
flags in certain circumstances: if both choices of a manual flag are
already invalidated by other decisions, then the old code was removing
the nodes underneath the flag completely. As a result, there's a node
with no children rather than a node with two failure-children. The
fail-nodes carry important information that is used to compute how far
we can backtrack. If this information is removed, strange things happen.
Fix flag goal generation (and hopefully #1855).

Package flags generate (Boolean) goals. Package flags can be dependent
on one another, in situations such as this one:

  if flag(a)
    ...
  else
    if flag(b)
      ...
    else
      ...

In such a scenario, it's important to record that flag b depends on flag
a. This affects conflict set generation. If something fails due to the
choice of flag b, we should not backjump beyond flag a.

While the code handling the proper insertion of goals with their correct
dependencies was always there, it was accidentally overridden by another
piece of code that created flag goals (without dependencies) for all
flags defined in a package. The reason I add flag goals separately is
because not all paths in the decision tree may contain choices for all
flags of a package. For example, if a is chosen to be True in the
example above, b does not occur at all. But flag choices may still
affect other things that aren't visible to the solver (directory
choices, exposed modules, ...), so all flags declared should always be
chosen explicitly. So we want to keep adding all flags declared in a
package as dummies, but we have to make sure to do so *before* adding
the actual dependency tree. This way, while traversing the dependency
tree, the ones occurring in dependencies will be added again, overriding
the dummies, rather than the other way round (which we used to have
before, where the dummies were overwriting the more informative
versions).
Merge branch 'solver-flag-handling-fixes' of https://github.com/kosmikus/cabal