File tree Expand file tree Collapse file tree 1 file changed +9
-1
lines changed
hls-graph/src/Development/IDE/Graph/Internal Expand file tree Collapse file tree 1 file changed +9
-1
lines changed Original file line number Diff line number Diff line change @@ -34,6 +34,7 @@ module Development.IDE.Graph.Internal.Key
34
34
) where
35
35
36
36
-- import Control.Monad.IO.Class ()
37
+ import Control.Exception (evaluate )
37
38
import Data.Coerce
38
39
import Data.Dynamic
39
40
import qualified Data.HashMap.Strict as Map
@@ -85,8 +86,15 @@ newKey k = unsafePerformIO $ do
85
86
86
87
lookupKeyValue :: Key -> KeyValue
87
88
lookupKeyValue (UnsafeMkKey x) = unsafePerformIO $ do
89
+ -- NOTE:
90
+ -- The reason for this evaluate is that the x, if not forced yet, is a thunk
91
+ -- that forces the atomicModifyIORef' in the creation of the new key. If it
92
+ -- isn't forced *before* reading the keyMap, the keyMap will only obtain the new
93
+ -- key (x) *after* the IntMap is already copied out of the keyMap reference,
94
+ -- i.e. when it is forced for the lookup in the IntMap.
95
+ k <- evaluate x
88
96
GlobalKeyValueMap _ im _ <- readIORef keyMap
89
- pure $! im IM. ! x
97
+ pure $! im IM. ! k
90
98
91
99
{-# NOINLINE lookupKeyValue #-}
92
100
You can’t perform that action at this time.
0 commit comments