@@ -62,41 +62,48 @@ type LinkingState = M.Map (PN, I) [PackagePath]
6262-- We also adjust the map of overall goals, and keep track of the
6363-- reverse dependencies of each of the goals.
6464extendOpen :: QPN -> [FlaggedDep QPN ] -> BuildState -> BuildState
65- extendOpen qpn' gs s @ (BS { rdeps = gs' , open = o' }) = go gs' o' gs
65+ extendOpen qpn deps buildState @ (BS { rdeps = rdeps0 , open = goals0 }) = go rdeps0 goals0 deps
6666 where
6767 go :: RevDepMap -> [OpenGoal ] -> [FlaggedDep QPN ] -> BuildState
68- go g o [] = s { rdeps = g, open = o }
69- go g o ((Flagged fn@ (FN qpn _) fInfo t f) : ngs) =
70- go g (FlagGoal fn fInfo t f (flagGR qpn) : o) ngs
71- -- Note: for 'Flagged' goals, we always insert, so later additions win.
72- -- This is important, because in general, if a goal is inserted twice,
73- -- the later addition will have better dependency information.
74- go g o ((Stanza sn@ (SN qpn _) t) : ngs) =
75- go g (StanzaGoal sn t (flagGR qpn) : o) ngs
76- go g o ((Simple (LDep dr (Dep (PkgComponent qpn _) _)) c) : ngs)
77- | qpn == qpn' =
78- -- We currently only add a self-dependency to the graph if it is
79- -- between a package and its setup script. The edge creates a cycle
80- -- and causes the solver to backtrack and choose a different
81- -- instance for the setup script. We may need to track other
82- -- self-dependencies once we implement component-based solving.
68+ go rdeps goals [] =
69+ buildState { rdeps = rdeps, open = goals }
70+
71+ go rdeps goals ((Flagged fn@ (FN qpn' _) fInfo t f) : fdeps) =
72+ go rdeps (FlagGoal fn fInfo t f (flagGR qpn') : goals) fdeps
73+
74+ -- Note: for 'Flagged' goals, we always insert, so later additions win.
75+ -- This is important, because in general, if a goal is inserted twice,
76+ -- the later addition will have better dependency information.
77+ go rdeps goals ((Stanza sn@ (SN qpn' _) t) : fdeps) =
78+ go rdeps (StanzaGoal sn t (flagGR qpn') : goals) fdeps
79+
80+ go rdeps goals ((Simple (LDep dr (Dep (PkgComponent qpn' _) _)) c) : fdeps)
81+ | qpn' == qpn =
82+ -- We currently only add a self-dependency to the graph if it is
83+ -- between a package and its setup script. The edge creates a cycle
84+ -- and causes the solver to backtrack and choose a different
85+ -- instance for the setup script. We may need to track other
86+ -- self-dependencies once we implement component-based solving.
8387 case c of
84- ComponentSetup -> go (M. adjust (addIfAbsent (ComponentSetup , qpn')) qpn g) o ngs
85- _ -> go g o ngs
86- | qpn `M.member` g = go (M. adjust (addIfAbsent (c, qpn')) qpn g) o ngs
87- | otherwise = go (M. insert qpn [(c, qpn')] g) (PkgGoal qpn (DependencyGoal dr) : o) ngs
88- -- code above is correct; insert/adjust have different arg order
89- go g o ((Simple (LDep _dr (Ext _ext )) _) : ngs) = go g o ngs
90- go g o ((Simple (LDep _dr (Lang _lang))_) : ngs) = go g o ngs
91- go g o ((Simple (LDep _dr (Pkg _pn _vr))_) : ngs) = go g o ngs
88+ ComponentSetup -> go (M. adjust (addIfAbsent (ComponentSetup , qpn)) qpn' rdeps) goals fdeps
89+ _ -> go rdeps goals fdeps
90+ | qpn' `M.member` rdeps =
91+ go (M. adjust (addIfAbsent (c, qpn)) qpn' rdeps) goals fdeps
92+ | otherwise =
93+ -- Note: insert/adjust have different arg order
94+ go (M. insert qpn' [(c, qpn)] rdeps) (PkgGoal qpn' (DependencyGoal dr) : goals) fdeps
95+
96+ go rdeps o ((Simple (LDep _dr (Ext _ext )) _c) : goals) = go rdeps o goals
97+ go rdeps o ((Simple (LDep _dr (Lang _lang)) _c) : goals) = go rdeps o goals
98+ go rdeps o ((Simple (LDep _dr (Pkg _pn _vr)) _c) : goals) = go rdeps o goals
9299
93100 addIfAbsent :: Eq a => a -> [a ] -> [a ]
94101 addIfAbsent x xs = if x `elem` xs then xs else x : xs
95102
96- -- GoalReason for a flag or stanza. Each flag/stanza is introduced only by
97- -- its containing package.
98- flagGR :: qpn -> GoalReason qpn
99- flagGR qpn = DependencyGoal (DependencyReason qpn M. empty S. empty)
103+ -- GoalReason for a flag or stanza. Each flag/stanza is introduced only by
104+ -- its containing package.
105+ flagGR :: qpn -> GoalReason qpn
106+ flagGR qpn = DependencyGoal (DependencyReason qpn M. empty S. empty)
100107
101108-- | Given the current scope, qualify all the package names in the given set of
102109-- dependencies and then extend the set of open goals accordingly.
@@ -127,12 +134,14 @@ build = ana go
127134 go :: Linker BuildState -> TreeF () QGoalReason (Linker BuildState )
128135 go s = addLinking (linkingState s) $ addChildren (buildState s)
129136
137+ -- | Add children to the tree based on the current build state.
130138addChildren :: BuildState -> TreeF () QGoalReason BuildState
131139
132140-- If we have a choice between many goals, we just record the choice in
133141-- the tree. We select each open goal in turn, and before we descend, remove
134142-- it from the queue of open goals.
135143addChildren bs@ (BS { rdeps = rdm, open = gs, next = Goals })
144+ -- No goals left. We have done.
136145 | L. null gs = DoneF rdm ()
137146 | otherwise = GoalChoiceF rdm $ P. fromList
138147 $ L. map (\ (g, gs') -> (close g, bs { next = OneGoal g, open = gs' }))
@@ -254,16 +263,17 @@ buildTree idx igs =
254263 build Linker {
255264 buildState = BS {
256265 index = idx
257- , rdeps = M. fromList ( L. map ( \ qpn -> (qpn , [] )) qpns)
258- , open = L. map topLevelGoal qpns
266+ , rdeps = M. fromList [( qpn, [] ) | qpn <- qpns]
267+ , open = [ PkgGoal qpn UserGoal | qpn <- qpns ]
259268 , next = Goals
260269 }
261270 , linkingState = M. empty
262271 }
263272 where
264- topLevelGoal qpn = PkgGoal qpn UserGoal
273+ -- The package names are interpreted as top-level goals in the host stage.
274+ path = PackagePath Stage. Host QualToplevel
275+ qpns = [ Q path pn | pn <- igs ]
265276
266- qpns = L. map (Q (PackagePath Stage. Host QualToplevel )) igs
267277
268278{- ------------------------------------------------------------------------------
269279 Goals
0 commit comments