Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion hls-graph/src/Development/IDE/Graph/Internal/Key.hs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ module Development.IDE.Graph.Internal.Key
) where

--import Control.Monad.IO.Class ()
import Control.Exception (evaluate)
import Data.Coerce
import Data.Dynamic
import qualified Data.HashMap.Strict as Map
Expand Down Expand Up @@ -85,8 +86,15 @@ newKey k = unsafePerformIO $ do

lookupKeyValue :: Key -> KeyValue
lookupKeyValue (UnsafeMkKey x) = unsafePerformIO $ do
-- NOTE:
-- The reason for this evaluate is that the x, if not forced yet, is a thunk
-- that forces the atomicModifyIORef' in the creation of the new key. If it
-- isn't forced *before* reading the keyMap, the keyMap will only obtain the new
-- key (x) *after* the IntMap is already copied out of the keyMap reference,
-- i.e. when it is forced for the lookup in the IntMap.
k <- evaluate x
GlobalKeyValueMap _ im _ <- readIORef keyMap
pure $! im IM.! x
pure $! im IM.! k

{-# NOINLINE lookupKeyValue #-}

Expand Down
Loading