Skip to content

Commit d5673be

Browse files
committed
lock-less globals
1 parent 7823c7d commit d5673be

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ data ShakeExtras = ShakeExtras
190190
lspEnv :: Maybe (LSP.LanguageContextEnv Config)
191191
,debouncer :: Debouncer NormalizedUri
192192
,logger :: Logger
193-
,globals :: Var (HMap.HashMap TypeRep Dynamic)
193+
,globals :: IORef (HMap.HashMap TypeRep Dynamic)
194194
,state :: Values
195195
,diagnostics :: STMDiagnosticStore
196196
,hiddenDiagnostics :: STMDiagnosticStore
@@ -283,15 +283,15 @@ addIdeGlobal x = do
283283

284284
addIdeGlobalExtras :: IsIdeGlobal a => ShakeExtras -> a -> IO ()
285285
addIdeGlobalExtras ShakeExtras{globals} x@(typeOf -> ty) =
286-
void $ liftIO $ modifyVarIO' globals $ \mp -> case HMap.lookup ty mp of
287-
Just _ -> errorIO $ "Internal error, addIdeGlobalExtras, got the same type twice for " ++ show ty
288-
Nothing -> return $! HMap.insert ty (toDyn x) mp
286+
void $ liftIO $ atomicModifyIORef'_ globals $ \mp -> case HMap.lookup ty mp of
287+
Just _ -> error $ "Internal error, addIdeGlobalExtras, got the same type twice for " ++ show ty
288+
Nothing -> HMap.insert ty (toDyn x) mp
289289

290290

291291
getIdeGlobalExtras :: forall a . IsIdeGlobal a => ShakeExtras -> IO a
292292
getIdeGlobalExtras ShakeExtras{globals} = do
293293
let typ = typeRep (Proxy :: Proxy a)
294-
x <- HMap.lookup (typeRep (Proxy :: Proxy a)) <$> readVar globals
294+
x <- HMap.lookup (typeRep (Proxy :: Proxy a)) <$> readIORef globals
295295
case x of
296296
Just x
297297
| Just x <- fromDynamic x -> pure x
@@ -509,7 +509,7 @@ shakeOpen lspEnv defaultConfig logger debouncer
509509
us <- mkSplitUniqSupply 'r'
510510
ideNc <- newIORef (initNameCache us knownKeyNames)
511511
shakeExtras <- do
512-
globals <- newVar HMap.empty
512+
globals <- newIORef HMap.empty
513513
state <- STM.newIO
514514
diagnostics <- STM.newIO
515515
hiddenDiagnostics <- STM.newIO

0 commit comments

Comments
 (0)