Matthew Pickering pushed to branch wip/gbc-files at Glasgow Haskell Compiler / GHC

Commits:

8 changed files:

Changes:

  • compiler/GHC/ByteCode/Serialize.hs
    ... ... @@ -34,6 +34,7 @@ import qualified Data.ByteString as BS
    34 34
     import Data.Traversable
    
    35 35
     import GHC.Utils.Logger
    
    36 36
     import GHC.Linker.Types
    
    37
    +import System.IO.Unsafe (unsafeInterleaveIO)
    
    37 38
     
    
    38 39
     -- | The on-disk representation of a bytecode object
    
    39 40
     data OnDiskByteCodeObject = OnDiskByteCodeObject { odbco_module :: Module
    
    ... ... @@ -242,12 +243,15 @@ addBinNameReader HscEnv {..} bh' = do
    242 243
             pure $ BinName nm
    
    243 244
           1 -> do
    
    244 245
             occ <- mkVarOccFS <$> get bh
    
    245
    -        u <- takeUniqFromNameCache hsc_NC
    
    246
    -        nm' <- evaluate $ mkInternalName u occ noSrcSpan
    
    246
    +        -- We don't want to get a new unique from the NameCache each time we
    
    247
    +        -- see a name.
    
    248
    +        nm' <- unsafeInterleaveIO $ do
    
    249
    +          u <- takeUniqFromNameCache hsc_NC
    
    250
    +          evaluate $ mkInternalName u occ noSrcSpan
    
    247 251
             fmap BinName $ atomicModifyIORef' env_ref $ \env ->
    
    248 252
               case lookupOccEnv env occ of
    
    249 253
                 Just nm -> (env, nm)
    
    250
    -            _ -> (extendOccEnv env occ nm', nm')
    
    254
    +            _ -> nm' `seq` (extendOccEnv env occ nm', nm')
    
    251 255
           _ -> panic "Binary BinName: invalid byte"
    
    252 256
     
    
    253 257
     -- Note [Serializing Names in bytecode]
    

  • compiler/GHC/Driver/Backpack.hs
    ... ... @@ -786,8 +786,8 @@ summariseRequirement pn mod_name = do
    786 786
     
    
    787 787
         env <- getBkpEnv
    
    788 788
         src_hash <- liftIO $ getFileHash (bkp_filename env)
    
    789
    -    hi_timestamp <- liftIO $ modificationTimeIfExists (ml_hi_file location)
    
    790
    -    hie_timestamp <- liftIO $ modificationTimeIfExists (ml_hie_file location)
    
    789
    +    hi_timestamp <- liftIO $ modificationTimeIfExists (ml_hi_file_ospath location)
    
    790
    +    hie_timestamp <- liftIO $ modificationTimeIfExists (ml_hie_file_ospath location)
    
    791 791
         let loc = srcLocSpan (mkSrcLoc (mkFastString (bkp_filename env)) 1 1)
    
    792 792
     
    
    793 793
         let fc = hsc_FC hsc_env
    
    ... ... @@ -872,8 +872,8 @@ hsModuleToModSummary home_keys pn hsc_src modname
    872 872
                                     HsSrcFile  -> os "hs")
    
    873 873
                                  hsc_src
    
    874 874
         -- This duplicates a pile of logic in GHC.Driver.Make
    
    875
    -    hi_timestamp <- liftIO $ modificationTimeIfExists (ml_hi_file location)
    
    876
    -    hie_timestamp <- liftIO $ modificationTimeIfExists (ml_hie_file location)
    
    875
    +    hi_timestamp <- liftIO $ modificationTimeIfExists (ml_hi_file_ospath location)
    
    876
    +    hie_timestamp <- liftIO $ modificationTimeIfExists (ml_hie_file_ospath location)
    
    877 877
     
    
    878 878
         -- Also copied from 'getImports'
    
    879 879
         let (src_idecls, ord_idecls) = partition ((== IsBoot) . ideclSource . unLoc) imps
    

  • compiler/GHC/Driver/Downsweep.hs
    ... ... @@ -1264,7 +1264,7 @@ checkSummaryHash
    1264 1264
       | ms_hs_hash old_summary == src_hash &&
    
    1265 1265
           not (gopt Opt_ForceRecomp (hsc_dflags hsc_env)) = do
    
    1266 1266
                -- update the object-file timestamp
    
    1267
    -           obj_timestamp <- modificationTimeIfExists (ml_obj_file location)
    
    1267
    +           obj_timestamp <- modificationTimeIfExists (ml_obj_file_ospath location)
    
    1268 1268
     
    
    1269 1269
                -- We have to repopulate the Finder's cache for file targets
    
    1270 1270
                -- because the file might not even be on the regular search path
    
    ... ... @@ -1276,8 +1276,8 @@ checkSummaryHash
    1276 1276
                    hsc_src = ms_hsc_src old_summary
    
    1277 1277
                addModuleToFinder fc mod location hsc_src
    
    1278 1278
     
    
    1279
    -           hi_timestamp <- modificationTimeIfExists (ml_hi_file location)
    
    1280
    -           hie_timestamp <- modificationTimeIfExists (ml_hie_file location)
    
    1279
    +           hi_timestamp <- modificationTimeIfExists (ml_hi_file_ospath location)
    
    1280
    +           hie_timestamp <- modificationTimeIfExists (ml_hie_file_ospath location)
    
    1281 1281
     
    
    1282 1282
                return $ Right
    
    1283 1283
                  ( old_summary
    
    ... ... @@ -1481,11 +1481,11 @@ data MakeNewModSummary
    1481 1481
     makeNewModSummary :: HscEnv -> MakeNewModSummary -> IO ModSummary
    
    1482 1482
     makeNewModSummary hsc_env MakeNewModSummary{..} = do
    
    1483 1483
       let PreprocessedImports{..} = nms_preimps
    
    1484
    -  obj_timestamp <- modificationTimeIfExists (ml_obj_file nms_location)
    
    1485
    -  dyn_obj_timestamp <- modificationTimeIfExists (ml_dyn_obj_file nms_location)
    
    1486
    -  hi_timestamp <- modificationTimeIfExists (ml_hi_file nms_location)
    
    1487
    -  hie_timestamp <- modificationTimeIfExists (ml_hie_file nms_location)
    
    1488
    -  bytecode_timestamp <- modificationTimeIfExists (ml_bytecode_file nms_location)
    
    1484
    +  obj_timestamp <- modificationTimeIfExists (ml_obj_file_ospath nms_location)
    
    1485
    +  dyn_obj_timestamp <- modificationTimeIfExists (ml_dyn_obj_file_ospath nms_location)
    
    1486
    +  hi_timestamp <- modificationTimeIfExists (ml_hi_file_ospath nms_location)
    
    1487
    +  hie_timestamp <- modificationTimeIfExists (ml_hie_file_ospath nms_location)
    
    1488
    +  bytecode_timestamp <- modificationTimeIfExists (ml_bytecode_file_ospath nms_location)
    
    1489 1489
       extra_sig_imports <- findExtraSigImports hsc_env nms_hsc_src pi_mod_name
    
    1490 1490
       (implicit_sigs, _inst_deps) <- implicitRequirementsShallow (hscSetActiveUnitId (moduleUnitId nms_mod) hsc_env) pi_theimps
    
    1491 1491
     
    

  • compiler/GHC/Driver/Main.hs
    ... ... @@ -1088,7 +1088,7 @@ loadIfaceByteCode hsc_env iface location type_env =
    1088 1088
           linkable $ pure $ BCOs $ (ByteCodeObject (mi_module iface) bcos fos)
    
    1089 1089
     
    
    1090 1090
         linkable parts = do
    
    1091
    -      if_time <- modificationTimeIfExists (ml_hi_file location)
    
    1091
    +      if_time <- modificationTimeIfExists (ml_hi_file_ospath location)
    
    1092 1092
           time <- maybe getCurrentTime pure if_time
    
    1093 1093
           return $! Linkable time (mi_module iface) parts
    
    1094 1094
     
    
    ... ... @@ -1109,7 +1109,7 @@ loadIfaceByteCodeLazy hsc_env iface location type_env =
    1109 1109
           linkable $ NE.singleton (BCOs (ByteCodeObject (mi_module iface) bcos fos))
    
    1110 1110
     
    
    1111 1111
         linkable parts = do
    
    1112
    -      if_time <- modificationTimeIfExists (ml_hi_file location)
    
    1112
    +      if_time <- modificationTimeIfExists (ml_hi_file_ospath location)
    
    1113 1113
           time <- maybe getCurrentTime pure if_time
    
    1114 1114
           return $!Linkable time (mi_module iface) parts
    
    1115 1115
     
    
    ... ... @@ -2230,7 +2230,7 @@ generateAndWriteByteCodeLinkable hsc_env cgguts mod_location = do
    2230 2230
       -- Either, get the same time as the .gbc file if it exists, or just the current time.
    
    2231 2231
       -- It's important the time of the linkable matches the time of the .gbc file for recompilation
    
    2232 2232
       -- checking.
    
    2233
    -  bco_time <- maybe getCurrentTime pure =<< modificationTimeIfExists (ml_bytecode_file mod_location)
    
    2233
    +  bco_time <- maybe getCurrentTime pure =<< modificationTimeIfExists (ml_bytecode_file_ospath mod_location)
    
    2234 2234
       loadByteCodeObjectLinkable bco_time bco_object
    
    2235 2235
     
    
    2236 2236
     mkByteCodeObject :: HscEnv -> Module -> ModLocation -> CgInteractiveGuts -> IO ByteCodeObject
    

  • compiler/GHC/Driver/Pipeline/Execute.hs
    ... ... @@ -722,17 +722,18 @@ runHscPhase pipe_env hsc_env0 input_fn src_flavour = do
    722 722
       -- the object file for one module.)
    
    723 723
       -- Note the nasty duplication with the same computation in compileFile above
    
    724 724
       location <- mkOneShotModLocation pipe_env dflags src_flavour mod_name
    
    725
    -  let o_file = ml_obj_file location -- The real object file
    
    726
    -      hi_file = ml_hi_file location
    
    727
    -      hie_file = ml_hie_file location
    
    728
    -      dyn_o_file = ml_dyn_obj_file location
    
    725
    +  let o_file = ml_obj_file_ospath location -- The real object file
    
    726
    +      hi_file = ml_hi_file_ospath location
    
    727
    +      hie_file = ml_hie_file_ospath location
    
    728
    +      dyn_o_file = ml_dyn_obj_file_ospath location
    
    729
    +      bytecode_file = ml_bytecode_file_ospath location
    
    729 730
     
    
    730 731
       src_hash <- getFileHash (basename <.> suff)
    
    731 732
       hi_date <- modificationTimeIfExists hi_file
    
    732 733
       hie_date <- modificationTimeIfExists hie_file
    
    733 734
       o_mod <- modificationTimeIfExists o_file
    
    734 735
       dyn_o_mod <- modificationTimeIfExists dyn_o_file
    
    735
    -  bytecode_date <- modificationTimeIfExists (ml_bytecode_file location)
    
    736
    +  bytecode_date <- modificationTimeIfExists bytecode_file
    
    736 737
     
    
    737 738
       -- Tell the finder cache about this module
    
    738 739
       mod <- do
    

  • compiler/GHC/Linker/Loader.hs
    ... ... @@ -658,7 +658,7 @@ findWholeCoreBindings hsc_env mod = do
    658 658
     
    
    659 659
     findBytecodeLinkableMaybe :: HscEnv -> Module -> ModLocation -> IO (Maybe Linkable)
    
    660 660
     findBytecodeLinkableMaybe hsc_env mod locn = do
    
    661
    -  let bytecode_fn = ml_bytecode_file locn
    
    661
    +  let bytecode_fn = ml_bytecode_file_ospath locn
    
    662 662
       maybe_bytecode_time <- modificationTimeIfExists bytecode_fn
    
    663 663
       case maybe_bytecode_time of
    
    664 664
         Nothing -> return Nothing
    
    ... ... @@ -668,7 +668,7 @@ findBytecodeLinkableMaybe hsc_env mod locn = do
    668 668
           _ <- initIfaceLoad hsc_env $
    
    669 669
                  loadInterface (text "get_reachable_nodes" <+> parens (ppr mod))
    
    670 670
                      mod ImportBySystem
    
    671
    -      bco <- readBinByteCode hsc_env bytecode_fn
    
    671
    +      bco <- readBinByteCode hsc_env (ml_bytecode_file locn)
    
    672 672
           Just <$> loadByteCodeObjectLinkable bytecode_time bco
    
    673 673
     
    
    674 674
     get_reachable_nodes :: HscEnv -> [Module] -> IO ([Module], UniqDSet UnitId)
    

  • compiler/GHC/Unit/Finder.hs
    ... ... @@ -826,7 +826,7 @@ mkStubPaths fopts mod location = do
    826 826
     findObjectLinkableMaybe :: Module -> ModLocation -> IO (Maybe Linkable)
    
    827 827
     findObjectLinkableMaybe mod locn
    
    828 828
        = do let obj_fn = ml_obj_file locn
    
    829
    -        maybe_obj_time <- modificationTimeIfExists obj_fn
    
    829
    +        maybe_obj_time <- modificationTimeIfExists (ml_obj_file_ospath locn)
    
    830 830
             case maybe_obj_time of
    
    831 831
               Nothing -> return Nothing
    
    832 832
               Just obj_time -> liftM Just (findObjectLinkable mod obj_fn obj_time)
    

  • compiler/GHC/Utils/Misc.hs
    ... ... @@ -137,6 +137,8 @@ import Control.Monad ( guard )
    137 137
     import Control.Monad.IO.Class ( MonadIO, liftIO )
    
    138 138
     import System.IO.Error as IO ( isDoesNotExistError )
    
    139 139
     import System.Directory ( doesDirectoryExist, getModificationTime, renameFile )
    
    140
    +import qualified System.Directory.OsPath as OsPath
    
    141
    +import System.OsPath (OsPath)
    
    140 142
     import System.FilePath
    
    141 143
     
    
    142 144
     import Data.Bifunctor   ( first, second )
    
    ... ... @@ -1248,9 +1250,9 @@ getModificationUTCTime = getModificationTime
    1248 1250
     -- --------------------------------------------------------------
    
    1249 1251
     -- check existence & modification time at the same time
    
    1250 1252
     
    
    1251
    -modificationTimeIfExists :: FilePath -> IO (Maybe UTCTime)
    
    1253
    +modificationTimeIfExists :: OsPath -> IO (Maybe UTCTime)
    
    1252 1254
     modificationTimeIfExists f =
    
    1253
    -  (do t <- getModificationUTCTime f; return (Just t))
    
    1255
    +  (do t <- OsPath.getModificationTime f; return (Just t))
    
    1254 1256
             `catchIO` \e -> if isDoesNotExistError e
    
    1255 1257
                             then return Nothing
    
    1256 1258
                             else ioError e