summaryrefslogtreecommitdiff
path: root/ghc/GHCi
diff options
context:
space:
mode:
authorRoland Senn <rsx@bluewin.ch>2018-12-07 23:22:40 -0500
committerBen Gamari <ben@smart-cactus.org>2018-12-07 23:22:50 -0500
commit57c9b1ae4cafd0ee763451f2d4bc10220eef9689 (patch)
tree722f03f041237dd4664c724a516fa3222fcadebb /ghc/GHCi
parentc5ced679a6f5421eb53acf1fd1d212088145c971 (diff)
downloadhaskell-57c9b1ae4cafd0ee763451f2d4bc10220eef9689.tar.gz
Fix #15369: GHCi doesn't honor :set +c when loading for a second time
The decision to (re)collect the type info for a (re)loaded module is now taken only by comparing the file timestamps of the .hs file of the module. (Or form the .o file if the .hs file is missing). If the file timestamp changes, we (re)collect the type info. The timestamp of the processing time of the last collect is no longer used. Test Plan: make test TEST=T15369 Reviewers: alanz, hvr, monoidal, osa1, thomie, bgamari, tdammers Reviewed By: tdammers Subscribers: rwbarton, carter GHC Trac Issues: #15369 Differential Revision: https://phabricator.haskell.org/D5376
Diffstat (limited to 'ghc/GHCi')
-rw-r--r--ghc/GHCi/UI/Info.hs22
1 files changed, 16 insertions, 6 deletions
diff --git a/ghc/GHCi/UI/Info.hs b/ghc/GHCi/UI/Info.hs
index d608aadb74..d42f019e5f 100644
--- a/ghc/GHCi/UI/Info.hs
+++ b/ghc/GHCi/UI/Info.hs
@@ -58,6 +58,7 @@ data ModInfo = ModInfo
-- ^ Again, useful from GHC for accessing information
-- (exports, instances, scope) from a module.
, modinfoLastUpdate :: !UTCTime
+ -- ^ The timestamp of the file used to generate this record.
}
-- | Type of some span of source code. Most of these fields are
@@ -277,15 +278,24 @@ collectInfo ms loaded = do
cacheInvalid name = case M.lookup name ms of
Nothing -> return True
Just mi -> do
- let src_fp = ml_hs_file (ms_location (modinfoSummary mi))
- obj_fp = ml_obj_file (ms_location (modinfoSummary mi))
- fp = fromMaybe obj_fp src_fp
+ let fp = srcFilePath (modinfoSummary mi)
last' = modinfoLastUpdate mi
+ current <- getModificationTime fp
exists <- doesFileExist fp
if exists
- then (> last') <$> getModificationTime fp
+ then return $ current /= last'
else return True
+-- | Get the source file path from a ModSummary.
+-- If the .hs file is missing, and the .o file exists,
+-- we return the .o file path.
+srcFilePath :: ModSummary -> FilePath
+srcFilePath modSum = fromMaybe obj_fp src_fp
+ where
+ src_fp = ml_hs_file ms_loc
+ obj_fp = ml_obj_file ms_loc
+ ms_loc = ms_location modSum
+
-- | Get info about the module: summary, types, etc.
getModInfo :: (GhcMonad m) => ModuleName -> m ModInfo
getModInfo name = do
@@ -294,8 +304,8 @@ getModInfo name = do
typechecked <- typecheckModule p
allTypes <- processAllTypeCheckedModule typechecked
let i = tm_checked_module_info typechecked
- now <- liftIO getCurrentTime
- return (ModInfo m allTypes i now)
+ ts <- liftIO $ getModificationTime $ srcFilePath m
+ return (ModInfo m allTypes i ts)
-- | Get ALL source spans in the module.
processAllTypeCheckedModule :: forall m . GhcMonad m => TypecheckedModule