Commit 01bb17fd authored by Tamar Christina's avatar Tamar Christina Committed by Ben Gamari

Make finalizers more reliable.

Ignore any errors thrown by finalizers when running them.

This prevents a faulty finalizer from stopping the rest being called.

Test Plan: ./validate, new test T13167

Reviewers: hvr, bgamari, simonmar

Reviewed By: bgamari, simonmar

Subscribers: rwbarton, thomie, carter

GHC Trac Issues: #13167

Differential Revision: https://phabricator.haskell.org/D4693
parent 838b6903
......@@ -149,8 +149,9 @@ runFinalizerBatch (I# n) arr =
0# -> (# s, () #)
_ -> let !m' = m -# 1# in
case indexArray# arr m' of { (# io #) ->
case io s of { s' ->
unIO (go m') s'
case catch# (\p -> (# io p, () #))
(\_ s'' -> (# s'', () #)) s of {
(# s', _ #) -> unIO (go m') s'
}}
in
go n
import Data.IORef
import Control.Monad
import Control.Exception
import Control.Concurrent.MVar
import System.Mem
main :: IO ()
main = do
run
run
run
run
m <- newEmptyMVar
quit m
performMajorGC
takeMVar m
run :: IO ()
run = do
ref <- newIORef ()
void $ mkWeakIORef ref $ do
putStr "."
throwIO $ ErrorCall "failed"
quit :: MVar () -> IO ()
quit m = do
ref <- newIORef ()
void $ mkWeakIORef ref $ do
putMVar m ()
......@@ -224,3 +224,4 @@ test('T3474',
test('T14425', normal, compile_and_run, [''])
test('T10412', normal, compile_and_run, [''])
test('T13896', normal, compile_and_run, [''])
test('T13167', normal, compile_and_run, [''])
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment