I am seeking some advice on part of Stack’s code. It has:
entrypointMVar :: MVar Bool
{-# NOINLINE entrypointMVar #-}
entrypointMVar = unsafePerformIO (newMVar False)
and that gets used in one place only, namely:
entrypoint :: (HasProcessContext env, HasLogFunc env)
=> Config
-> DockerEntrypoint
-> RIO env ()
entrypoint config@Config{} DockerEntrypoint{..} =
modifyMVar_ entrypointMVar $ \alreadyRan -> do ...
The STAN tool advises me to do away with the unsafePerformIO
.
I am assuming that I could do that with:
newEntrypointMVar :: RIO env (MVar Bool)
{-# NOINLINE newEntrypointMVar #-}
newEntrypointMVar = liftIO $ newMVar False
entrypoint config@Config{} DockerEntrypoint{..} = do
entryPointMVar <- newEntryPointMVar
modifyMVar_ entrypointMVar $ \alreadyRan -> do ...
My questions are:
- Could there have been some important reason for the original use of
unsafePerformIO
that I am missing? - What could have been the purpose of the
NOINLINE
pragma? Is it still needed?
Any help, gratefully received.