module Distribution.Solver.Modular.Log
    ( displayLogMessages
    , SolverFailure(..)
    ) where

import Prelude ()
import Distribution.Solver.Compat.Prelude

import Distribution.Solver.Types.Progress

import Distribution.Solver.Modular.Dependency
import Distribution.Solver.Modular.Message
import Distribution.Solver.Modular.RetryLog

-- | Information about a dependency solver failure.
data SolverFailure =
    ExhaustiveSearch ConflictSet ConflictMap
  | BackjumpLimitReached

-- | Postprocesses a log file. This function discards all log messages and
-- avoids calling 'showMessages' if the log isn't needed (specified by
-- 'keepLog'), for efficiency.
displayLogMessages :: Bool
                   -> RetryLog Message SolverFailure a
                   -> RetryLog String SolverFailure a
displayLogMessages :: Bool
-> RetryLog Message SolverFailure a
-> RetryLog String SolverFailure a
displayLogMessages Bool
keepLog RetryLog Message SolverFailure a
lg = Progress String SolverFailure a -> RetryLog String SolverFailure a
forall step fail done.
Progress step fail done -> RetryLog step fail done
fromProgress (Progress String SolverFailure a
 -> RetryLog String SolverFailure a)
-> Progress String SolverFailure a
-> RetryLog String SolverFailure a
forall a b. (a -> b) -> a -> b
$
    if Bool
keepLog
    then Progress Message SolverFailure a -> Progress String SolverFailure a
forall a b. Progress Message a b -> Progress String a b
showMessages Progress Message SolverFailure a
progress
    else (Message
 -> Progress String SolverFailure a
 -> Progress String SolverFailure a)
-> (SolverFailure -> Progress String SolverFailure a)
-> (a -> Progress String SolverFailure a)
-> Progress Message SolverFailure a
-> Progress String SolverFailure a
forall step a fail done.
(step -> a -> a)
-> (fail -> a) -> (done -> a) -> Progress step fail done -> a
foldProgress ((Progress String SolverFailure a
 -> Progress String SolverFailure a)
-> Message
-> Progress String SolverFailure a
-> Progress String SolverFailure a
forall a b. a -> b -> a
const Progress String SolverFailure a -> Progress String SolverFailure a
forall a. a -> a
id) SolverFailure -> Progress String SolverFailure a
forall step fail done. fail -> Progress step fail done
Fail a -> Progress String SolverFailure a
forall step fail done. done -> Progress step fail done
Done Progress Message SolverFailure a
progress
  where
    progress :: Progress Message SolverFailure a
progress = RetryLog Message SolverFailure a
-> Progress Message SolverFailure a
forall step fail done.
RetryLog step fail done -> Progress step fail done
toProgress RetryLog Message SolverFailure a
lg