Skip to content

Commit ca14a80

Browse files
committed
[fix] add bang pattern to lookupKeyValue to avoid reordering with newKey
1 parent 60fb24f commit ca14a80

File tree

1 file changed

+8
-1
lines changed
  • hls-graph/src/Development/IDE/Graph/Internal

1 file changed

+8
-1
lines changed

hls-graph/src/Development/IDE/Graph/Internal/Key.hs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,15 @@ newKey k = unsafePerformIO $ do
8383
in (GlobalKeyValueMap (Map.insert newKey new_index hm) (IM.insert n newKey im) (n+1), new_index)
8484
{-# NOINLINE newKey #-}
8585

86+
-- NOTE:
87+
-- The argument to this function has a bang pattern. This bang pattern is a load
88+
-- bearing bang pattern. The reason is that the x, if not forced yet, is a thunk
89+
-- that forces the atomicModifyIORef' in the creation of the new key. If it
90+
-- isn't forced *before* reading the keyMap, the keyMap will only obtain the new
91+
-- key (x) *after* the IntMap is already copied out of the keyMap reference,
92+
-- i.e. when it is forced for the lookup in the IntMap.
8693
lookupKeyValue :: Key -> KeyValue
87-
lookupKeyValue (UnsafeMkKey x) = unsafePerformIO $ do
94+
lookupKeyValue (UnsafeMkKey !x) = unsafePerformIO $ do
8895
GlobalKeyValueMap _ im _ <- readIORef keyMap
8996
pure $! im IM.! x
9097

0 commit comments

Comments
 (0)