Skip to content
Snippets Groups Projects
Commit 8d8426c9 authored by Sven Tennie's avatar Sven Tennie :smiley_cat: Committed by Marge Bot
Browse files

Document entertainGC in test

It wasn't obvious why it's there and what its role is.

Also, increase the "entertainment level" a bit.

I checked in STG and Cmm dumps that this really generates closures (and
is not e.g. constant folded away.)
parent d4c2c1af
No related branches found
No related tags found
No related merge requests found
...@@ -327,13 +327,13 @@ type SetupFunction = State# RealWorld -> (# State# RealWorld, StackSnapshot# #) ...@@ -327,13 +327,13 @@ type SetupFunction = State# RealWorld -> (# State# RealWorld, StackSnapshot# #)
test :: HasCallStack => SetupFunction -> (StackFrame -> IO ()) -> IO () test :: HasCallStack => SetupFunction -> (StackFrame -> IO ()) -> IO ()
test setup assertion = do test setup assertion = do
stackSnapshot <- getStackSnapshot setup stackSnapshot <- getStackSnapshot setup
performGC traceM $ "entertainGC - " ++ entertainGC 10000
traceM $ "entertainGC - " ++ entertainGC 100
-- Run garbage collection now, to prevent later surprises: It's hard to debug -- Run garbage collection now, to prevent later surprises: It's hard to debug
-- when the GC suddenly does it's work and there were bad closures or pointers. -- when the GC suddenly does it's work and there were bad closures or pointers.
-- Better fail early, here. -- Better fail early, here.
performGC performGC
stackClosure <- decodeStack stackSnapshot stackClosure <- decodeStack stackSnapshot
traceM $ "entertainGC - " ++ entertainGC 10000
performGC performGC
let stack = ssc_stack stackClosure let stack = ssc_stack stackClosure
performGC performGC
...@@ -345,9 +345,19 @@ test setup assertion = do ...@@ -345,9 +345,19 @@ test setup assertion = do
assertEqual (length stack) 2 assertEqual (length stack) 2
assertion $ head stack assertion $ head stack
-- | Generate some bogus closures to give the GC work
--
-- There are thresholds in the GC when it starts working. We want to force this
-- to show that the decoding code is GC-save (updated pointers/references are a
-- big topic here as the GC cares about references to the StgStack itself, but
-- not to its frames.)
--
-- The "level of entertainment" x is a bit arbitrarily choosen: A future
-- performace improvement may be to reduce it to a smaller number.
entertainGC :: Int -> String entertainGC :: Int -> String
entertainGC 0 = "0" entertainGC 0 = "0"
entertainGC x = show x ++ entertainGC (x - 1) entertainGC x = show x ++ entertainGC (x - 1)
{-# NOINLINE entertainGC #-}
testSize :: HasCallStack => SetupFunction -> Int -> IO () testSize :: HasCallStack => SetupFunction -> Int -> IO ()
testSize setup expectedSize = do testSize setup expectedSize = do
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment