Skip to content

Mangoiv/improve key business #4654

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 11, 2025
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