diff options
| author | Niklas Hambüchen <mail@nh2.me> | 2013-08-22 11:05:56 +0900 |
|---|---|---|
| committer | Austin Seipp <aseipp@pobox.com> | 2013-08-22 16:25:02 -0500 |
| commit | 677820ee3a3aadbf2ed414deb3926381d94b13a8 (patch) | |
| tree | d0e19887f49fca9b339310d4a395bebf396f2afb /compiler/utils/Fingerprint.hsc | |
| parent | 16ae2f0c3ff45e0c78b90ae0761a0f86c70188bd (diff) | |
| download | haskell-677820ee3a3aadbf2ed414deb3926381d94b13a8.tar.gz | |
Fix interface hashes including time stamp of dependent files.
Fixes #8144.
Before, the modification time of e.g. #included files (and everything
that ends up as a UsageFile, e.g. via addDependentFile) was taken as
input for the interface hash of a module.
This lead to different hashes for identical inputs on every compilation.
We now use file content hashes instead.
This changes the interface file format.
You will get "Binary.get(Usage): 50" when you try to do an incremental
using .hi files that were created with a GHC 7.7 (only) older than this commit.
To calculate the md5 hash (`Fingerprint`) of a file in constant space,
there now is GHC.Fingerprint.getFileHash, and a fallback version
for older GHCs that needs to load the file into memory completely
(only used when compiling stage1 with an older GHC).
Signed-off-by: Austin Seipp <aseipp@pobox.com>
Diffstat (limited to 'compiler/utils/Fingerprint.hsc')
| -rw-r--r-- | compiler/utils/Fingerprint.hsc | 31 |
1 files changed, 29 insertions, 2 deletions
diff --git a/compiler/utils/Fingerprint.hsc b/compiler/utils/Fingerprint.hsc index 95f31c08bb..895906a3c6 100644 --- a/compiler/utils/Fingerprint.hsc +++ b/compiler/utils/Fingerprint.hsc @@ -8,18 +8,22 @@ -- -- ---------------------------------------------------------------------------- -{-# OPTIONS_GHC -fno-warn-orphans #-} module Fingerprint ( Fingerprint(..), fingerprint0, readHexFingerprint, fingerprintData, - fingerprintString + fingerprintString, + -- Re-exported rom GHC.Fingerprint for GHC >= 7.7, local otherwise + getFileHash ) where #include "md5.h" ##include "HsVersions.h" import Numeric ( readHex ) +import Foreign +import Panic +import System.IO import GHC.Fingerprint @@ -30,3 +34,26 @@ readHexFingerprint s = Fingerprint w1 w2 [(w1,"")] = readHex s1 [(w2,"")] = readHex (take 16 s2) + +#if __GLASGOW_HASKELL__ < 707 +-- Only use this if we're smaller than GHC 7.7, otherwise +-- GHC.Fingerprint exports a better version of this function. + +-- | Computes the hash of a given file. +-- It loads the full file into memory an does not work with files bigger than +-- MAXINT. +getFileHash :: FilePath -> IO Fingerprint +getFileHash path = withBinaryFile path ReadMode $ \h -> do + + fileSize <- toIntFileSize `fmap` hFileSize h + + allocaBytes fileSize (\bufPtr -> fingerprintData bufPtr fileSize) + + where + toIntFileSize :: Integer -> Int + toIntFileSize size + | size > fromIntegral (maxBound :: Int) = throwGhcException $ + Sorry $ "Fingerprint.getFileHash: Tried to calculate hash of file " + ++ path ++ " with size > maxBound :: Int. This is not supported." + | otherwise = fromIntegral size +#endif |
