Implement recompilation checking for -fignore-asserts
[ghc.git] / compiler / iface / BinFingerprint.hs
1 {-# LANGUAGE CPP #-}
2
3 -- | Computing fingerprints of values serializeable with GHC's "Binary" module.
4 module BinFingerprint
5 ( -- * Computing fingerprints
6 fingerprintBinMem
7 , computeFingerprint
8 , putNameLiterally
9 ) where
10
11 #include "HsVersions.h"
12
13 import Fingerprint
14 import Binary
15 import Name
16 import Panic
17 import Util
18
19 fingerprintBinMem :: BinHandle -> IO Fingerprint
20 fingerprintBinMem bh = withBinBuffer bh f
21 where
22 f bs =
23 -- we need to take care that we force the result here
24 -- lest a reference to the ByteString may leak out of
25 -- withBinBuffer.
26 let fp = fingerprintByteString bs
27 in fp `seq` return fp
28
29 computeFingerprint :: (Binary a)
30 => (BinHandle -> Name -> IO ())
31 -> a
32 -> IO Fingerprint
33 computeFingerprint put_nonbinding_name a = do
34 bh <- fmap set_user_data $ openBinMem (3*1024) -- just less than a block
35 put_ bh a
36 fp <- fingerprintBinMem bh
37 return fp
38 where
39 set_user_data bh =
40 setUserData bh $ newWriteState put_nonbinding_name putNameLiterally putFS
41
42 -- | Used when we want to fingerprint a structure without depending on the
43 -- fingerprints of external Names that it refers to.
44 putNameLiterally :: BinHandle -> Name -> IO ()
45 putNameLiterally bh name = ASSERT( isExternalName name ) do
46 put_ bh $! nameModule name
47 put_ bh $! nameOccName name