deferSetupChoices :: Tree a -> Tree a
deferSetupChoices = trav go
  where
    go (GoalChoiceF xs) = GoalChoiceF (P.sortByKeys deferSetup xs)
    go x                = x

    deferSetup :: OpenGoal comp -> OpenGoal comp -> Ordering
    deferSetup (OpenGoal (Simple (Dep (Q (Setup _ _) _) _) _) _) _ = GT
    deferSetup _ (OpenGoal (Simple (Dep (Q (Setup _ _) _) _) _) _) = LT
    deferSetup _ _                                                 = EQ

-- | Transformation that tries to avoid making weak flag choices early.
-- Weak flags are trivial flags (not influencing dependencies) or such
-- flags that are explicitly declared to be weak in the index.
deferSetupChoices :: Tree a -> Tree a
deferSetupChoices = trav go
  where
    go (GoalChoiceF xs) = GoalChoiceF (P.sortByKeys deferSetup xs)
    go x                = x

    deferSetup :: OpenGoal comp -> OpenGoal comp -> Ordering
    deferSetup (OpenGoal (Simple (Dep (Q (Setup _ _) _) _) _) _) _ = GT
    deferSetup _ (OpenGoal (Simple (Dep (Q (Setup _ _) _) _) _) _) = LT
    deferSetup _ _                                                 = EQ

-- | Transformation that tries to avoid making weak flag choices early.
-- Weak flags are trivial flags (not influencing dependencies) or such
-- flags that are explicitly declared to be weak in the index.
deferSetupChoices = trav go
  where
    go (GoalChoiceF xs) = GoalChoiceF (P.sortByKeys deferSetup xs)
    go x                = x

    deferSetup :: OpenGoal comp -> OpenGoal comp -> Ordering
    deferSetup (OpenGoal (Simple (Dep (Q (Setup _ _) _) _) _) _) _ = GT
    deferSetup _ (OpenGoal (Simple (Dep (Q (Setup _ _) _) _) _) _) = LT
    deferSetup _ _                                                 = EQ

-- | Transformation that tries to avoid making weak flag choices early.
-- Weak flags are trivial flags (not influencing dependencies) or such
-- flags that are explicitly declared to be weak in the index.