Wolfgang Jeltsch pushed to branch wip/jeltsch/file-and-dir-cache-with-fast-string-keys at Glasgow Haskell Compiler / GHC

Commits:

1 changed file:

Changes:

  • compiler/GHC/Unit/Finder.hs
    ... ... @@ -56,6 +56,7 @@ import GHC.Data.IOEnv (IOEnv, runIOEnv, getEnv)
    56 56
     import GHC.Data.OsPath
    
    57 57
     import qualified GHC.Data.ShortText as ST
    
    58 58
     import GHC.Data.FastString (FastString, unpackFS)
    
    59
    +import GHC.Data.FastString.Env (emptyFsEnv, lookupFsEnv, extendFsEnv)
    
    59 60
     
    
    60 61
     import GHC.Driver.Env
    
    61 62
     import GHC.Driver.Config.Finder
    
    ... ... @@ -122,30 +123,30 @@ type BaseName = OsPath -- Basename of file
    122 123
     initFinderCache :: IO FinderCache
    
    123 124
     initFinderCache = do
    
    124 125
       home_cache <- newHomeFinderCache
    
    125
    -  file_cache <- newIORef emptyUniqMap
    
    126
    -  dir_cache <- newIORef emptyUniqMap
    
    126
    +  file_cache <- newIORef emptyFsEnv
    
    127
    +  dir_cache <- newIORef emptyFsEnv
    
    127 128
       let flushFinderCaches :: IO ()
    
    128 129
           flushFinderCaches = do
    
    129 130
             clearHomeFinderCache home_cache
    
    130
    -        atomicModifyIORef' file_cache $ \_ -> (emptyUniqMap, ())
    
    131
    -        atomicModifyIORef' dir_cache  $ \_ -> (emptyUniqMap, ())
    
    131
    +        atomicModifyIORef' file_cache $ \_ -> (emptyFsEnv, ())
    
    132
    +        atomicModifyIORef' dir_cache  $ \_ -> (emptyFsEnv, ())
    
    132 133
     
    
    133 134
           lookupFileCache :: FastString -> IO Fingerprint
    
    134 135
           lookupFileCache key = do
    
    135 136
              c <- readIORef file_cache
    
    136
    -         case lookupUniqMap c key of
    
    137
    +         case lookupFsEnv c key of
    
    137 138
                Nothing -> do
    
    138 139
                  hash <- getFileHash (unpackFS key)
    
    139
    -             atomicModifyIORef' file_cache $ \c -> (addToUniqMap c key hash, ())
    
    140
    +             atomicModifyIORef' file_cache $ \c -> (extendFsEnv c key hash, ())
    
    140 141
                  return hash
    
    141 142
                Just fp -> return fp
    
    142 143
           lookupDirCache :: FastString -> IO Fingerprint
    
    143 144
           lookupDirCache key = do
    
    144 145
              c <- readIORef dir_cache
    
    145
    -         case lookupUniqMap c key of
    
    146
    +         case lookupFsEnv c key of
    
    146 147
                Nothing -> do
    
    147 148
                  hash <- getDirHash (unpackFS key)
    
    148
    -             atomicModifyIORef' dir_cache $ \c -> (addToUniqMap c key hash, ())
    
    149
    +             atomicModifyIORef' dir_cache $ \c -> (extendFsEnv c key hash, ())
    
    149 150
                  return hash
    
    150 151
                Just fp -> return fp
    
    151 152
       return $