Skip to content

Commit e1fed4a

Browse files
committed
a bunch of debugging stuff
1 parent ec5cf7b commit e1fed4a

File tree

15 files changed

+293
-202
lines changed

15 files changed

+293
-202
lines changed

Cabal-syntax/src/Distribution/Compat/Graph.hs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ module Distribution.Compat.Graph
7070
, revTopSort
7171

7272
-- * Conversions
73+
, graphVertexToNode
74+
, graphKeyToVertex
7375

7476
-- ** Maps
7577
, toMap

Cabal/src/Distribution/Simple/Configure.hs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ import Distribution.Package
7777
import Distribution.PackageDescription
7878
import Distribution.PackageDescription.Check hiding (doesFileExist)
7979
import Distribution.PackageDescription.Configuration
80-
import Distribution.PackageDescription.PrettyPrint
80+
-- import Distribution.PackageDescription.PrettyPrint
8181
import Distribution.Simple.BuildTarget
8282
import Distribution.Simple.BuildToolDepends
8383
import Distribution.Simple.BuildWay
@@ -929,9 +929,9 @@ configurePackage cfg lbc0 pkg_descr00 flags enabled comp platform programDb0 pac
929929
, extraCoverageFor = []
930930
}
931931

932-
debug verbosity $
933-
"Finalized package description:\n"
934-
++ showPackageDescription pkg_descr2
932+
-- debug verbosity $
933+
-- "Finalized package description:\n"
934+
-- ++ showPackageDescription pkg_descr2
935935

936936
return (lbc, pbd)
937937

Cabal/src/Distribution/Simple/Utils.hs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -887,9 +887,9 @@ logCommand verbosity cp = do
887887
"Running: " <> case Process.cmdspec cp of
888888
Process.ShellCommand sh -> sh
889889
Process.RawCommand path args -> Process.showCommandForUser path args
890-
case Process.env cp of
891-
Just env -> debugNoWrap verbosity $ "with environment: " ++ show env
892-
Nothing -> return ()
890+
-- case Process.env cp of
891+
-- Just env -> debugNoWrap verbosity $ "with environment: " ++ show env
892+
-- Nothing -> return ()
893893
case Process.cwd cp of
894894
Just cwd -> debugNoWrap verbosity $ "with working directory: " ++ show cwd
895895
Nothing -> return ()

cabal-install-solver/src/Distribution/Solver/Modular.hs

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import Distribution.Compat.Graph
2222
import Distribution.Compiler
2323
( CompilerInfo )
2424
import Distribution.Solver.Modular.Assignment
25-
( Assignment, toCPs )
25+
( Assignment(..), toCPs )
2626
import Distribution.Solver.Modular.ConfiguredConversion
2727
( convCP )
2828
import qualified Distribution.Solver.Modular.ConflictSet as CS
@@ -34,7 +34,7 @@ import Distribution.Solver.Modular.IndexConversion
3434
import Distribution.Solver.Modular.Log
3535
( SolverFailure(..), displayLogMessages )
3636
import Distribution.Solver.Modular.Package
37-
( PN )
37+
( PN, showI )
3838
import Distribution.Solver.Modular.RetryLog
3939
import Distribution.Solver.Modular.Solver
4040
( SolverConfig(..), PruneAfterFirstSuccess(..), solve )
@@ -60,7 +60,15 @@ import Distribution.Solver.Types.Toolchain
6060
-- solver. Performs the necessary translations before and after.
6161
modularResolver :: SolverConfig -> DependencyResolver loc
6262
modularResolver sc toolchains pkgConfigDbs iidx sidx pprefs pcs pns = do
63-
uncurry postprocess <$> solve' sc cinfo pkgConfigDbs idx pprefs gcs pns
63+
(assignment, revdepmap) <- solve' sc cinfo pkgConfigDbs idx pprefs gcs pns
64+
65+
let A pa _fa _sa = assignment
66+
step (unlines [showQPN qpn ++ " -> " ++ showI i| (qpn, i) <- M.toList pa])
67+
68+
-- Results have to be converted into an install plan. 'convCP' removes
69+
-- package qualifiers, which means that linked packages become duplicates
70+
-- and can be removed.
71+
return $ ordNubBy nodeKey $ map (convCP iidx sidx) (toCPs assignment revdepmap)
6472
where
6573
cinfo = fst <$> toolchains
6674

@@ -71,12 +79,6 @@ modularResolver sc toolchains pkgConfigDbs iidx sidx pprefs pcs pns = do
7179
where
7280
pair lpc = (pcName $ unlabelPackageConstraint lpc, [lpc])
7381

74-
-- Results have to be converted into an install plan. 'convCP' removes
75-
-- package qualifiers, which means that linked packages become duplicates
76-
-- and can be removed.
77-
postprocess a rdm = ordNubBy nodeKey $
78-
map (convCP iidx sidx) (toCPs a rdm)
79-
8082
-- Helper function to extract the PN from a constraint.
8183
pcName :: PackageConstraint -> PN
8284
pcName (PackageConstraint scope _) = scopeToPackageName scope

cabal-install-solver/src/Distribution/Solver/Modular/Builder.hs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ data BuildState = BS {
5252
rdeps :: RevDepMap, -- ^ set of all package goals, completed and open, with reverse dependencies
5353
open :: [OpenGoal], -- ^ set of still open goals (flag and package goals)
5454
next :: BuildType -- ^ kind of node to generate next
55-
}
55+
} deriving Show
5656

5757
-- | Map of available linking targets.
5858
type LinkingState = M.Map (PN, I) [PackagePath]
@@ -135,6 +135,7 @@ data BuildType =
135135
Goals -- ^ build a goal choice node
136136
| OneGoal OpenGoal -- ^ build a node for this goal
137137
| Instance QPN PInfo -- ^ build a tree for a concrete instance
138+
deriving Show
138139

139140
build :: Linker BuildState -> Tree () QGoalReason
140141
build = ana addChildren . buildState
@@ -210,16 +211,17 @@ buildTree idx igs =
210211
build Linker {
211212
buildState = BS {
212213
index = idx
213-
, rdeps = M.fromList (L.map (\ qpn -> (qpn, [])) qpns)
214-
, open = L.map topLevelGoal qpns
214+
, rdeps = M.fromList [(qpn, []) | qpn <- qpns]
215+
, open = [ PkgGoal qpn UserGoal | qpn <- qpns ]
215216
, next = Goals
216217
}
217218
, linkingState = M.empty
218219
}
219220
where
220-
topLevelGoal qpn = PkgGoal qpn UserGoal
221+
-- The package names are interpreted as top-level goals in the host stage.
222+
path = PackagePath Stage.Host QualToplevel
223+
qpns = [ Q path pn | pn <- igs ]
221224

222-
qpns = L.map (Q (PackagePath Stage.Host QualToplevel)) igs
223225

224226
{-------------------------------------------------------------------------------
225227
Goals
@@ -230,6 +232,7 @@ data OpenGoal
230232
= FlagGoal (FN QPN) FInfo (FlaggedDeps QPN) (FlaggedDeps QPN) QGoalReason
231233
| StanzaGoal (SN QPN) (FlaggedDeps QPN) QGoalReason
232234
| PkgGoal QPN QGoalReason
235+
deriving Show
233236

234237
-- | Closes a goal, i.e., removes all the extraneous information that we
235238
-- need only during the build phase.

cabal-install-solver/src/Distribution/Solver/Modular/Index.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ data PInfo = PInfo
4040
FlagInfo
4141
--
4242
(Maybe FailReason)
43+
deriving Show
4344

4445
-- | Info associated with each library and executable in a package instance.
4546
data ComponentInfo = ComponentInfo {

cabal-install-solver/src/Distribution/Solver/Modular/Message.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ showFR _ (GlobalConstraintSource src) = " (" ++ constraintSource src ++ " re
303303
showFR _ (GlobalConstraintFlag src) = " (" ++ constraintSource src ++ " requires opposite flag selection)"
304304
showFR _ ManualFlag = " (manual flag can only be changed explicitly)"
305305
showFR c Backjump = " (backjumping, conflict set: " ++ showConflictSet c ++ ")"
306-
showFR _ MultipleInstances = " (multiple instances)"
306+
-- showFR _ MultipleInstances = " (multiple instances)"
307307
showFR c (DependenciesNotLinked msg) = " (dependencies not linked: " ++ msg ++ "; conflict set: " ++ showConflictSet c ++ ")"
308308
showFR c CyclicDependencies = " (cyclic dependencies; conflict set: " ++ showConflictSet c ++ ")"
309309
showFR _ (UnsupportedSpecVer ver) = " (unsupported spec-version " ++ prettyShow ver ++ ")"

cabal-install-solver/src/Distribution/Solver/Modular/Preference.hs

Lines changed: 46 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ module Distribution.Solver.Modular.Preference
66
, deferWeakFlagChoices
77
, enforceManualFlags
88
, enforcePackageConstraints
9-
, enforceSingleInstanceRestriction
9+
-- , enforceSingleInstanceRestriction
1010
, firstGoal
1111
, preferBaseGoalChoice
1212
, preferLinked
@@ -22,7 +22,7 @@ import Distribution.Solver.Compat.Prelude
2222

2323
import qualified Data.List as L
2424
import qualified Data.Map as M
25-
import Control.Monad.Trans.Reader (Reader, runReader, ask, local)
25+
-- import Control.Monad.Trans.Reader (Reader, runReader, ask, local)
2626

2727
import Distribution.PackageDescription (lookupFlagAssignment, unFlagAssignment) -- from Cabal
2828

@@ -453,47 +453,47 @@ preferReallyEasyGoalChoices = go
453453
go (GoalChoiceF rdm xs) = GoalChoiceF rdm (P.filterIfAny zeroOrOneChoices xs)
454454
go x = x
455455

456-
-- | Monad used internally in enforceSingleInstanceRestriction
457-
--
458-
-- For each package instance we record the goal for which we picked a concrete
459-
-- instance. The SIR means that for any package instance there can only be one.
460-
type EnforceSIR = Reader (Map (PI PN) QPN)
461-
462-
-- | Enforce ghc's single instance restriction
463-
--
464-
-- From the solver's perspective, this means that for any package instance
465-
-- (that is, package name + package version) there can be at most one qualified
466-
-- goal resolving to that instance (there may be other goals _linking_ to that
467-
-- instance however).
468-
enforceSingleInstanceRestriction :: Tree d c -> Tree d c
469-
enforceSingleInstanceRestriction = (`runReader` M.empty) . go
470-
where
471-
go :: Tree d c -> EnforceSIR (Tree d c)
472-
473-
-- We just verify package choices.
474-
go (PChoice qpn rdm gr cs) =
475-
PChoice qpn rdm gr <$> sequenceA (W.mapWithKey (goP qpn) (fmap go cs))
476-
go (FChoice qfn rdm y t m d ts) =
477-
FChoice qfn rdm y t m d <$> traverse go ts
478-
go (SChoice qsn rdm y t ts) =
479-
SChoice qsn rdm y t <$> traverse go ts
480-
go (GoalChoice rdm ts) =
481-
GoalChoice rdm <$> traverse go ts
482-
go x@(Fail _ _) = return x
483-
go x@(Done _ _) = return x
484-
485-
-- The check proper
486-
goP :: QPN -> POption -> EnforceSIR (Tree d c) -> EnforceSIR (Tree d c)
487-
goP qpn@(Q _ pn) (POption i linkedTo) r = do
488-
let inst = PI pn i
489-
env <- ask
490-
case (linkedTo, M.lookup inst env) of
491-
(Just _, _) ->
492-
-- For linked nodes we don't check anything
493-
r
494-
(Nothing, Nothing) ->
495-
-- Not linked, not already used
496-
local (M.insert inst qpn) r
497-
(Nothing, Just qpn') -> do
498-
-- Not linked, already used. This is an error
499-
return $ Fail (CS.union (varToConflictSet (P qpn)) (varToConflictSet (P qpn'))) MultipleInstances
456+
-- -- | Monad used internally in enforceSingleInstanceRestriction
457+
-- --
458+
-- -- For each package instance we record the goal for which we picked a concrete
459+
-- -- instance. The SIR means that for any package instance there can only be one.
460+
-- type EnforceSIR = Reader (Map (PI PN) QPN)
461+
462+
-- -- | Enforce ghc's single instance restriction
463+
-- --
464+
-- -- From the solver's perspective, this means that for any package instance
465+
-- -- (that is, package name + package version) there can be at most one qualified
466+
-- -- goal resolving to that instance (there may be other goals _linking_ to that
467+
-- -- instance however).
468+
-- enforceSingleInstanceRestriction :: Tree d c -> Tree d c
469+
-- enforceSingleInstanceRestriction = (`runReader` M.empty) . go
470+
-- where
471+
-- go :: Tree d c -> EnforceSIR (Tree d c)
472+
473+
-- -- We just verify package choices.
474+
-- go (PChoice qpn rdm gr cs) =
475+
-- PChoice qpn rdm gr <$> sequenceA (W.mapWithKey (goP qpn) (fmap go cs))
476+
-- go (FChoice qfn rdm y t m d ts) =
477+
-- FChoice qfn rdm y t m d <$> traverse go ts
478+
-- go (SChoice qsn rdm y t ts) =
479+
-- SChoice qsn rdm y t <$> traverse go ts
480+
-- go (GoalChoice rdm ts) =
481+
-- GoalChoice rdm <$> traverse go ts
482+
-- go x@(Fail _ _) = return x
483+
-- go x@(Done _ _) = return x
484+
485+
-- -- The check proper
486+
-- goP :: QPN -> POption -> EnforceSIR (Tree d c) -> EnforceSIR (Tree d c)
487+
-- goP qpn@(Q _ pn) (POption i linkedTo) r = do
488+
-- let inst = PI pn i
489+
-- env <- ask
490+
-- case (linkedTo, M.lookup inst env) of
491+
-- (Just _, _) ->
492+
-- -- For linked nodes we don't check anything
493+
-- r
494+
-- (Nothing, Nothing) ->
495+
-- -- Not linked, not already used
496+
-- local (M.insert inst qpn) r
497+
-- (Nothing, Just qpn') -> do
498+
-- -- Not linked, already used. This is an error
499+
-- return $ Fail (CS.union (varToConflictSet (P qpn)) (varToConflictSet (P qpn'))) MultipleInstances

0 commit comments

Comments
 (0)