Skip to content

Commit d2f2e8d

Browse files
committed
lock-less globals
1 parent 1f9b5fa commit d2f2e8d

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
@@ -191,7 +191,7 @@ data ShakeExtras = ShakeExtras
191191
lspEnv :: Maybe (LSP.LanguageContextEnv Config)
192192
,debouncer :: Debouncer NormalizedUri
193193
,logger :: Logger
194-
,globals :: Var (HMap.HashMap TypeRep Dynamic)
194+
,globals :: IORef (HMap.HashMap TypeRep Dynamic)
195195
,state :: Values
196196
,diagnostics :: STMDiagnosticStore
197197
,hiddenDiagnostics :: STMDiagnosticStore
@@ -284,15 +284,15 @@ addIdeGlobal x = do
284284

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

291291

292292
getIdeGlobalExtras :: forall a . IsIdeGlobal a => ShakeExtras -> IO a
293293
getIdeGlobalExtras ShakeExtras{globals} = do
294294
let typ = typeRep (Proxy :: Proxy a)
295-
x <- HMap.lookup (typeRep (Proxy :: Proxy a)) <$> readVar globals
295+
x <- HMap.lookup (typeRep (Proxy :: Proxy a)) <$> readIORef globals
296296
case x of
297297
Just x
298298
| Just x <- fromDynamic x -> pure x
@@ -501,7 +501,7 @@ shakeOpen lspEnv defaultConfig logger debouncer
501501
us <- mkSplitUniqSupply 'r'
502502
ideNc <- newIORef (initNameCache us knownKeyNames)
503503
shakeExtras <- do
504-
globals <- newVar HMap.empty
504+
globals <- newIORef HMap.empty
505505
state <- STM.newIO
506506
diagnostics <- STM.newIO
507507
hiddenDiagnostics <- STM.newIO

0 commit comments

Comments
 (0)