Skip to content

Commit

Permalink
Fix a space leak in package preferences (part of issue haskell#3824).
Browse files Browse the repository at this point in the history
  • Loading branch information
grayjay committed Sep 12, 2016
1 parent 5289f17 commit a9fe3a1
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions cabal-install/Distribution/Solver/Modular/Preference.hs
Original file line number Diff line number Diff line change
Expand Up @@ -51,17 +51,26 @@ import qualified Distribution.Solver.Modular.WeightedPSQ as W
-- | Update the weights of children under 'PChoice' nodes. 'addWeights' takes a
-- list of weight-calculating functions in order to avoid sorting the package
-- choices multiple times. Each function takes the package name, sorted list of
-- siblings' versions, and package option. 'addWeights' prepends the new
-- children's versions, and package option. 'addWeights' prepends the new
-- weights to the existing weights, which gives precedence to preferences that
-- are applied later.
addWeights :: [PN -> [Ver] -> POption -> Weight] -> Tree a -> Tree a
addWeights fs = trav go
where
go :: TreeF a (Tree a) -> TreeF a (Tree a)
go (PChoiceF qpn@(Q _ pn) x cs) =
let sortedVersions = L.sortBy (flip compare) $ L.map version (W.keys cs)
let versions = L.map version (W.keys cs)
sortedVersions = L.sortBy (flip compare) versions
weights k = [f pn sortedVersions k | f <- fs]
in PChoiceF qpn x $
W.mapWeightsWithKey (\k w -> weights k ++ w) cs

elemsToWhnf :: [a] -> ()
elemsToWhnf = foldr seq ()
in PChoiceF qpn x
-- Evaluate the children's versions before evaluating any of the
-- subtrees, so that 'versions' doesn't hold onto all of the
-- subtrees (referenced by cs) and cause a space leak.
(elemsToWhnf versions `seq`
W.mapWeightsWithKey (\k w -> weights k ++ w) cs)
go x = x

addWeight :: (PN -> [Ver] -> POption -> Weight) -> Tree a -> Tree a
Expand Down

0 comments on commit a9fe3a1

Please sign in to comment.