@@ -10,18 +10,15 @@ where
10
10
import Control.Exception (throwIO )
11
11
import Control.Monad.IO.Class
12
12
import Data.Bifunctor (first )
13
- import Data.IORef
14
13
import Data.List.NonEmpty (NonEmpty )
15
- import Data.Map.Strict (Map )
16
- import Data.Map.Strict qualified as Map
17
14
import Data.Text qualified as T
18
15
import Data.Text.IO.Utf8 qualified as T.Utf8
19
16
import Distribution.ModuleName (ModuleName )
20
17
import Distribution.Types.PackageName (PackageName )
21
18
import Ormolu.Exception
22
19
import Ormolu.Fixity
23
20
import Ormolu.Fixity.Parser
24
- import Ormolu.Utils.IO (findClosestFileSatisfying , withIORefCache )
21
+ import Ormolu.Utils.IO (Cache , findClosestFileSatisfying , newCache , withCache )
25
22
import System.Directory
26
23
import System.IO.Unsafe (unsafePerformIO )
27
24
import Text.Megaparsec (errorBundlePretty )
@@ -37,7 +34,7 @@ getDotOrmoluForSourceFile ::
37
34
m (FixityOverrides , ModuleReexports )
38
35
getDotOrmoluForSourceFile sourceFile =
39
36
liftIO (findDotOrmoluFile sourceFile) >>= \ case
40
- Just dotOrmoluFile -> liftIO $ withIORefCache cacheRef dotOrmoluFile $ do
37
+ Just dotOrmoluFile -> liftIO $ withCache cacheRef dotOrmoluFile $ do
41
38
dotOrmoluRelative <- makeRelativeToCurrentDirectory dotOrmoluFile
42
39
contents <- T.Utf8. readFile dotOrmoluFile
43
40
case parseDotOrmolu dotOrmoluRelative contents of
@@ -58,8 +55,8 @@ findDotOrmoluFile = findClosestFileSatisfying $ \x ->
58
55
x == " .ormolu"
59
56
60
57
-- | Cache ref that maps names of @.ormolu@ files to their contents.
61
- cacheRef :: IORef ( Map FilePath (FixityOverrides , ModuleReexports ) )
62
- cacheRef = unsafePerformIO (newIORef Map. empty)
58
+ cacheRef :: Cache FilePath (FixityOverrides , ModuleReexports )
59
+ cacheRef = unsafePerformIO newCache
63
60
{-# NOINLINE cacheRef #-}
64
61
65
62
-- | A wrapper around 'parseFixityDeclaration' for parsing individual fixity
0 commit comments