@@ -178,10 +178,9 @@ import System.Info.Extra (isWindows)
178178import qualified Data.IntMap as IM
179179import GHC.Fingerprint
180180import qualified Data.Map.Strict as Map
181- import System.FilePath (takeExtension , takeFileName , normalise , dropTrailingPathSeparator , dropExtension , splitDirectories )
181+ import System.FilePath (takeExtension , takeFileName , normalise , dropExtension , splitDirectories )
182182import Data.Char (isUpper )
183183import System.Directory.Extra (listFilesInside )
184- import System.IO.Unsafe
185184
186185data Log
187186 = LogShake Shake. Log
@@ -625,15 +624,13 @@ getModuleGraphRule recorder = defineEarlyCutOffNoFile (cmapWithPrio LogShake rec
625624 fs <- toKnownFiles <$> useNoFile_ GetKnownTargets
626625 dependencyInfoForFiles (HashSet. toList fs)
627626
628- {-# NOINLINE cacheVar #-}
629- -- TODO: this should not use unsaferPerformIO
630- cacheVar = unsafePerformIO (newTVarIO mempty )
631-
632627getModulesPathsRule :: Recorder (WithPriority Log ) -> Rules ()
633628getModulesPathsRule recorder = defineEarlyCutoff (cmapWithPrio LogShake recorder) $ Rule $ \ GetModulesPaths file -> do
634629 env_eq <- use_ GhcSession file
635630
636- cache <- liftIO (readTVarIO cacheVar)
631+ ShakeExtras {moduleToPathCache} <- getShakeExtras
632+
633+ cache <- liftIO (readTVarIO moduleToPathCache)
637634 case Map. lookup (envUnique env_eq) cache of
638635 Just res -> pure (mempty , ([] , Just res))
639636 Nothing -> do
@@ -646,7 +643,9 @@ getModulesPathsRule recorder = defineEarlyCutoff (cmapWithPrio LogShake recorder
646643 (unzip -> (a, b)) <- flip mapM import_dirs $ \ (u, dyn) -> do
647644 (unzip -> (a, b)) <- flip mapM (importPaths dyn) $ \ dir' -> do
648645 let dir = normalise dir'
649- let predicate path = pure (normalise path == dir || isUpper (head (takeFileName path)))
646+ let predicate path = pure (normalise path == dir || case takeFileName path of
647+ [] -> False
648+ (x: _) -> isUpper x)
650649 let dir_number_directories = length (splitDirectories dir)
651650 let toModule file = mkModuleName (intercalate " ." $ drop dir_number_directories (splitDirectories (dropExtension file)))
652651
@@ -662,7 +661,7 @@ getModulesPathsRule recorder = defineEarlyCutoff (cmapWithPrio LogShake recorder
662661 pure (fmap (u,) $ mconcat a, fmap (u, ) $ mconcat b)
663662
664663 let res = (mconcat a, mconcat b)
665- liftIO $ atomically $ modifyTVar' cacheVar (Map. insert (envUnique env_eq) res)
664+ liftIO $ atomically $ modifyTVar' moduleToPathCache (Map. insert (envUnique env_eq) res)
666665
667666 pure (mempty , ([] , Just res))
668667
0 commit comments