on master help sign in
Fix efficiency problem with module chasing

When seeing if a dependency needs rebuilding, we were exploring bits of the tree multiple times which could be bad if there's lots of dependencies (especially if lots of modules are imported lots of times by lots of things...)

commitd23221bcb3fc07a6b59651b6b790ec7bcf092491 authorEdwin Brady <ecb10@st-andrews.ac.uk> dateTue 2 Jan 2018, 18:48 (9 years ago) parent6f08595
2 files changed+24−16
src/Idris/Chaser.hs+22−14 src/Idris/ModeCommon.hs+2−2
src/Idris/Chaser.hs+22−14
@@ -32,9 +32,17 @@ data ModuleTree = MTree { mod_path :: IFileType,
3232 mod_deps :: [ModuleTree] }
3333 deriving Show
3434
35−latest :: UTCTime -> [ModuleTree] -> UTCTime
36−latest tm [] = tm
37−latest tm (m : ms) = latest (max tm (mod_time m)) (ms ++ mod_deps m)
35+latest :: UTCTime -> [IFileType] -> [ModuleTree] -> UTCTime
36+latest tm done [] = tm
37+latest tm done (m : ms)
38+ | mod_path m `elem` done = latest tm done ms
39+ | otherwise = latest (max tm (mod_time m)) (mod_path m : done)
40+ (ms ++ mod_deps m)
41+
42+modName :: IFileType -> String
43+modName (IDR fp) = fp
44+modName (LIDR fp) = fp
45+modName (IBC fp src) = modName src
3846
3947-- | Given a module tree, return the list of files to be loaded. If
4048-- any module has a descendent which needs reloading, return its
@@ -46,17 +54,17 @@ getModuleFiles ts = nub $ execState (modList ts) [] where
4654 modList (m : ms) = do modTree [] m; modList ms
4755
4856 modTree path (MTree p rechk tm deps)
49− = do let file = chkReload rechk p
50− -- Needs rechecking if 'rechk' is true, or if any of the
51− -- modification times in 'deps' are later than tm
52− let depMod = latest tm deps
53− let needsRechk = rechk || depMod > tm
54−
55− st <- get
56− if needsRechk then put $ nub (getSrc file : updateToSrc path st)
57− else put $ nub (file : st)
58−-- when (not (ibc p) || rechk) $
59− mapM_ (modTree (getSrc p : path)) deps
57+ = do let file = chkReload rechk p
58+ -- Needs rechecking if 'rechk' is true, or if any of the
59+ -- modification times in 'deps' are later than tm
60+ let depMod = latest tm [] deps
61+ let needsRechk = rechk || depMod > tm
62+
63+ st <- get
64+ if needsRechk then put $ nub (getSrc file : updateToSrc path st)
65+ else put $ nub (file : st)
66+ st <- get
67+ mapM_ (modTree (getSrc p : path)) deps
6068
6169 chkReload False p = p
6270 chkReload True (IBC fn src) = chkReload True src
src/Idris/ModeCommon.hs+2−2
@@ -67,8 +67,8 @@ loadInputs inputs toline -- furthest line to read in input source files
6767 importlists
6868 input
6969 let ifiles = getModuleFiles modTree
70− logParser 1 ("MODULE TREE : " ++ show modTree)
71− logParser 1 ("RELOAD: " ++ show ifiles)
70+ logParser 2 ("MODULE TREE : " ++ show modTree)
71+ logParser 2 ("RELOAD: " ++ show ifiles)
7272 when (not (all ibc ifiles) || loadCode) $
7373 tryLoad False IBC_Building (filter (not . ibc) ifiles)
7474 -- return the files that need rechecking