Skip to content

Commit 1327b9b

Browse files
authored
remove unsafePerformIO (#1383)
1 parent caaaa48 commit 1327b9b

File tree

1 file changed

+8
-13
lines changed

1 file changed

+8
-13
lines changed

ghcide/src/Development/IDE/Core/Shake.hs

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,6 @@ import qualified Development.Shake as Shake
117117
import Control.Monad.Extra
118118
import Data.Time
119119
import GHC.Generics
120-
import System.IO.Unsafe
121120
import Language.LSP.Types
122121
import qualified Control.Monad.STM as STM
123122
import Control.Monad.IO.Class
@@ -371,29 +370,24 @@ data IdeState = IdeState
371370
,shakeSession :: MVar ShakeSession
372371
,shakeClose :: IO ()
373372
,shakeExtras :: ShakeExtras
374-
,shakeProfileDir :: Maybe FilePath
373+
,shakeDatabaseProfile :: ShakeDatabase -> IO (Maybe FilePath)
375374
,stopProgressReporting :: IO ()
376375
}
377376

378377

379378

380379
-- This is debugging code that generates a series of profiles, if the Boolean is true
381-
shakeDatabaseProfile :: Maybe FilePath -> ShakeDatabase -> IO (Maybe FilePath)
382-
shakeDatabaseProfile mbProfileDir shakeDb =
380+
shakeDatabaseProfileIO :: Maybe FilePath -> IO(ShakeDatabase -> IO (Maybe FilePath))
381+
shakeDatabaseProfileIO mbProfileDir = do
382+
profileStartTime <- formatTime defaultTimeLocale "%Y%m%d-%H%M%S" <$> getCurrentTime
383+
profileCounter <- newVar (0::Int)
384+
return $ \shakeDb ->
383385
for mbProfileDir $ \dir -> do
384386
count <- modifyVar profileCounter $ \x -> let !y = x+1 in return (y,y)
385387
let file = "ide-" ++ profileStartTime ++ "-" ++ takeEnd 5 ("0000" ++ show count) <.> "html"
386388
shakeProfileDatabase shakeDb $ dir </> file
387389
return (dir </> file)
388390

389-
{-# NOINLINE profileStartTime #-}
390-
profileStartTime :: String
391-
profileStartTime = unsafePerformIO $ formatTime defaultTimeLocale "%Y%m%d-%H%M%S" <$> getCurrentTime
392-
393-
{-# NOINLINE profileCounter #-}
394-
profileCounter :: Var Int
395-
profileCounter = unsafePerformIO $ newVar 0
396-
397391
setValues :: IdeRule k v
398392
=> Var Values
399393
-> k
@@ -502,6 +496,7 @@ shakeOpen lspEnv logger debouncer
502496
shakeDb <- shakeDbM
503497
initSession <- newSession shakeExtras shakeDb []
504498
shakeSession <- newMVar initSession
499+
shakeDatabaseProfile <- shakeDatabaseProfileIO shakeProfileDir
505500
let ideState = IdeState{..}
506501

507502
IdeOptions{ optOTMemoryProfiling = IdeOTMemoryProfiling otProfilingEnabled } <- getIdeOptionsIO shakeExtras
@@ -628,7 +623,7 @@ shakeRestart IdeState{..} acts =
628623
shakeSession
629624
(\runner -> do
630625
(stopTime,()) <- duration (cancelShakeSession runner)
631-
res <- shakeDatabaseProfile shakeProfileDir shakeDb
626+
res <- shakeDatabaseProfile shakeDb
632627
let profile = case res of
633628
Just fp -> ", profile saved at " <> fp
634629
_ -> ""

0 commit comments

Comments
 (0)