Merge branch 'master' into atomics
[ghc.git] / testsuite / tests / simplCore / should_compile / T7796.hs
1 {-# LANGUAGE MagicHash #-}
2
3 module T7796 where
4
5 import GHC.Prim
6
7 --
8 -- test for #7796
9 --
10 -- created by nicolas.frisby@gmail.com, feel free to email me!
11 --
12 -- a delicate interaction between specialisation and w/w creates a
13 -- binding that is dead but is allocated at run-time
14 --
15
16 --
17 -- we grep the -ddump-prep for $s$go, and the actual test expects a
18 -- particular number of hits
19 --
20 -- thus the test will fail in two scenarios:
21 --
22 -- * the actually interesting case where the zombie $s$go binding
23 -- survives, or
24 --
25 -- * the naming convention for specialised things changes, in which
26 -- case the Makefile rule for this test needs to be updated to
27 -- scrape the -ddump-prep output differently
28 --
29
30 --
31 -- the zombie binding is $sgo; here's how we reproduce it:
32 --
33 -- 1. specialise go such that the RHS of $sgo uses both $sgo and go
34 --
35 -- 2. worker-wrapper $sgo but *not* go
36 --
37 -- thus: $sgo uses $w$sgo uses go uses $sgo
38 --
39 -- the key point: the last "use" is only via a RULE; see the ticket
40 -- #7796 for more discussion and related tickets
41 --
42
43 data L = C Int# L | N Int# -- I'm using unboxed elements to avoid ww'd
44 -- unrelated to the bug
45
46 host :: Eq b => b -> L -> Bool
47 host b x =
48 let go :: Eq a => -- must be used (to trigger specialise), but not
49 -- strict (else we ww the unspecialised version)
50
51 a -> -- must be strict, so that we ww the
52 -- specialisation
53
54 L -> -- not sure what this needs... but strict is
55 -- doing the trick
56
57 Bool
58
59 go d (N i) = d `seq` case i of
60 0# -> True
61 o -> go b (N (i -# 1#)) -- NB must at (a ~ b)
62
63 go d (C x xs) = (d == d) `seq` go d (C (x -# 1#) xs)
64 in go (3 :: Int) x