@@ -239,6 +239,9 @@ relinkForks :: UniqueGen -> EnvRefCache -> Forks -> IO Forks
239relinkForks ug cache = \case
239relinkForks ug cache = \case
240 NoFork -> pure NoFork
240 NoFork -> pure NoFork
241 Forks fid lref0 forks -> do
241 Forks fid lref0 forks -> do
242+ -- A specific IORef EnvRef can be held by more than one local environment
243+ -- and we need to replace all its occurences with the same, new value
244+ -- containing its clone.
242 readIORef cache >>= pure . M.lookup fid >>= \case
245 readIORef cache >>= pure . M.lookup fid >>= \case
243 Just lref -> Forks fid <$> pure lref
246 Just lref -> Forks fid <$> pure lref
244 <*> relinkForks ug cache forks
247 <*> relinkForks ug cache forks