@@ -1147,30 +1147,32 @@ loadInputs h inputs
11471147 let ninputs = zip [1..] inputs
11481148 ifiles <- mapWhileOK (\(num, input) ->
11491149 do putIState ist
1150− v <- verbose
1151− -- when v $ iputStrLn $ "(" ++ show num ++ "/" ++
1152− -- show (length inputs) ++
1153− -- ") " ++ input
11541150 modTree <- buildTree
11551151 (map snd (take (num-1) ninputs))
11561152 input
11571153 let ifiles = getModuleFiles modTree
11581154 iLOG ("MODULE TREE : " ++ show modTree)
11591155 iLOG ("RELOAD: " ++ show ifiles)
1160− when (not (all ibc ifiles) || loadCode) $ tryLoad ifiles
1156+ when (not (all ibc ifiles) || loadCode) $
1157+ tryLoad False (filter (not . ibc) ifiles)
11611158 -- return the files that need rechecking
1162− return (if (all ibc ifiles) then ifiles else []))
1159+ return ifiles)
11631160 ninputs
11641161 inew <- getIState
1165− -- to check everything worked consistently (in particular, will catch
1166− -- if the ibc version is out of date) if we weren't loading per
1167− -- module
1162+ let tidata = idris_tyinfodata inew
1163+ let lineapps = idris_lineapps inew
1164+ let patdefs = idris_patdefs inew
1165+ -- If it worked, load the whole thing from all the ibcs together
11681166 case errSpan inew of
11691167 Nothing ->
1170− do putIState ist
1171− when (not loadCode) $ tryLoad $ nub (concat ifiles)
1168+ do putIState (ist { idris_tyinfodata = tidata })
1169+ ibcfiles <- mapM findNewIBC (nub (concat ifiles))
1170+ tryLoad True (mapMaybe id ibcfiles)
11721171 _ -> return ()
1173− putIState inew)
1172+ ist <- getIState
1173+ putIState (ist { idris_tyinfodata = tidata,
1174+ idris_lineapps = lineapps,
1175+ idris_patdefs = patdefs }))
11741176 (\e -> do i <- getIState
11751177 case e of
11761178 At f _ -> do setErrSpan f
@@ -1179,15 +1181,43 @@ loadInputs h inputs
11791181 _ -> do setErrSpan emptyFC -- FIXME! Propagate it
11801182 iputStrLn (pshow i e))
11811183 where -- load all files, stop if any fail
1182− tryLoad :: [IFileType] -> Idris ()
1183− tryLoad [] = return ()
1184− tryLoad (f : fs) = do loadFromIFile h f
1185− ok <- noErrors
1186− when ok $ tryLoad fs
1184+ tryLoad :: Bool -> [IFileType] -> Idris ()
1185+ tryLoad keepstate [] = return ()
1186+ tryLoad keepstate (f : fs)
1187+ = do ist <- getIState
1188+ loadFromIFile h f
1189+ inew <- getIState
1190+ -- FIXME: Save these in IBC to avoid this hack! Need to
1191+ -- preserve it all from source inputs
1192+ let tidata = idris_tyinfodata inew
1193+ let lineapps = idris_lineapps inew
1194+ let patdefs = idris_patdefs inew
1195+ ok <- noErrors
1196+ when ok $ do when (not keepstate) $ putIState ist
1197+ ist <- getIState
1198+ putIState (ist { idris_tyinfodata = tidata,
1199+ idris_lineapps = lineapps,
1200+ idris_patdefs = patdefs })
1201+ tryLoad keepstate fs
11871202
11881203 ibc (IBC _ _) = True
11891204 ibc _ = False
11901205
1206+ findNewIBC :: IFileType -> Idris (Maybe IFileType)
1207+ findNewIBC i@(IBC _ _) = return (Just i)
1208+ findNewIBC s@(IDR f) = do ist <- get
1209+ ibcsd <- valIBCSubDir ist
1210+ let ibc = ibcPathNoFallback ibcsd f
1211+ ok <- runIO $ doesFileExist ibc
1212+ if ok then return (Just (IBC ibc s))
1213+ else return Nothing
1214+ findNewIBC s@(LIDR f) = do ist <- get
1215+ ibcsd <- valIBCSubDir ist
1216+ let ibc = ibcPathNoFallback ibcsd f
1217+ ok <- runIO $ doesFileExist ibc
1218+ if ok then return (Just (IBC ibc s))
1219+ else return Nothing
1220+
11911221 -- Like mapM, but give up when there's an error
11921222 mapWhileOK f [] = return []
11931223 mapWhileOK f (x : xs) = do x' <- f x