Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Accumulate rules in reverse and reverse them before they go into the …

…env to fix the rule choice bug
  • Loading branch information...
commit 0d42c78bc65a500dd77489535bb53bfc34845941 1 parent ee61f2c
Max Bolingbroke authored March 05, 2011

Showing 1 changed file with 5 additions and 6 deletions. Show diff stats Hide diff stats

  1. 11  Development/Shake/Core.hs
11  Development/Shake/Core.hs
@@ -193,11 +193,11 @@ defaultShakeOptions = ShakeOptions {
193 193
 
194 194
 
195 195
 newtype ShakeEnv n = SE {
196  
-    se_available_rules :: [[RuleClosure n]]
  196
+    se_available_rules :: [[RuleClosure n]]    -- ^ Presented in corect (non-reversed) order
197 197
   }
198 198
 
199 199
 data ShakeState n = SS {
200  
-    ss_rules :: [RuleClosure n],
  200
+    ss_rules :: [RuleClosure n],               -- ^ Accumulated in reverse order
201 201
     ss_acts :: [([[RuleClosure n]], Act n ())]
202 202
   }
203 203
 
@@ -228,7 +228,7 @@ modifyShakeState f = Shake (State.modify f)
228 228
 -- helpful if you want to override particular 'need' calls with specialised actions.
229 229
 privateTo :: Shake n a -> (a -> Shake n b) -> Shake n b
230 230
 privateTo privates private_to = Shake $ State.StateT $ \s -> Reader.reader $ \e -> let (a, s') = Reader.runReader (State.runStateT (unShake privates) (s { ss_rules = [] })) e_private
231  
-                                                                                       e_private = e { se_available_rules = ss_rules s' : se_available_rules e }
  231
+                                                                                       e_private = e { se_available_rules = reverse (ss_rules s') : se_available_rules e }
232 232
                                                                                    in Reader.runReader (State.runStateT (unShake (private_to a)) (s' { ss_rules = ss_rules s })) e_private
233 233
 
234 234
 -- | Version of 'privateTo' where the two nested actions don't return anything
@@ -385,7 +385,7 @@ shakeWithOptions opts mx = Parallel.withPool (shakeThreads opts) $ \pool -> do
385 385
     report_mvar <- emptyReportDatabase >>= newMVar
386 386
 
387 387
     -- Collect rules and wants, then execute the collected Act actions (in any order)
388  
-    let ((), complete_s) = runShake (SE { se_available_rules = [ss_rules complete_s] }) (SS { ss_rules = [], ss_acts = [] }) mx
  388
+    let ((), complete_s) = runShake (SE { se_available_rules = [reverse (ss_rules complete_s)] }) (SS { ss_rules = [], ss_acts = [] }) mx
389 389
 
390 390
         -- You might think that we could lose the type signature here, and then inline mk_e into its sole use site.
391 391
         -- Unfortunately, that doesn't type check properly on GHC 7.0.1.20101215 (i.e. RC2), and I have no idea why.
@@ -838,8 +838,7 @@ findRule verbosity ruless fp = do
838 838
     possibilities <- flip mapMaybeM ruless $ \rules -> do
839 839
         generators <- mapMaybeM (\rc -> liftM (fmap ((,) (rc_closure rc))) $ rc_rule rc fp) rules
840 840
         return (guard (not (null generators)) >> Just generators)
841  
-    -- To make sure we choose the first rule, we need to reverse the list of matches (we add them in reverse order)
842  
-    (clo_rules, (creates_fps, action)) <- case reverse possibilities of
  841
+    (clo_rules, (creates_fps, action)) <- case possibilities of
843 842
       (generator:other_matches):_next_level -> do
844 843
           unless (null other_matches) $
845 844
             when (verbosity > NormalVerbosity) $

0 notes on commit 0d42c78

Please sign in to comment.
Something went wrong with that request. Please try again.