Skip to content

Commit 115d063

Browse files
committed
remove 64 bits assumption
1 parent ef2974d commit 115d063

File tree

2 files changed

+15
-24
lines changed

2 files changed

+15
-24
lines changed

ghcide/src/Development/IDE/Core/Compile.hs

Lines changed: 9 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,10 @@ import TcEnv (tcLookup)
113113
import Control.Concurrent.Extra
114114
import Control.Concurrent.STM hiding (orElse)
115115
import Data.Aeson (toJSON)
116+
import Data.Binary
117+
import Data.Binary.Put
116118
import Data.Bits (shiftR)
119+
import qualified Data.ByteString.Lazy as LBS
117120
import Data.Coerce
118121
import Data.Functor
119122
import qualified Data.HashMap.Strict as HashMap
@@ -759,35 +762,17 @@ getModSummaryFromImports env fp modTime contents = do
759762
-- Compute a fingerprint from the contents of `ModSummary`,
760763
-- eliding the timestamps, the preprocessed source and other non relevant fields
761764
computeFingerprint opts ModSummary{..} = do
762-
let moduleUniques =
763-
[ b
764-
| m <- moduleName ms_mod
765-
: map (unLoc . snd) (ms_srcimps ++ ms_textual_imps)
766-
, b <- toBytes $ uniq $ moduleNameFS m
767-
] ++
768-
[ b
769-
| (Just p, _) <- ms_srcimps ++ ms_textual_imps
770-
, b <- toBytes $ uniq p
771-
]
772-
fingerPrintImports <- withArrayLen moduleUniques $ \len p ->
773-
fingerprintData p len
765+
let moduleUniques = runPut $ do
766+
put $ uniq $ moduleNameFS $ moduleName ms_mod
767+
forM_ (ms_srcimps ++ ms_textual_imps) $ \(mb_p, m) -> do
768+
put $ uniq $ moduleNameFS $ unLoc m
769+
whenJust mb_p $ put . uniq
770+
fingerPrintImports <- fingerprintFromByteString $ LBS.toStrict moduleUniques
774771
return $ fingerprintFingerprints $
775772
[ fingerprintString fp
776773
, fingerPrintImports
777774
] ++ map fingerprintString opts
778775

779-
toBytes :: Int -> [Word8]
780-
toBytes w64 =
781-
[ fromIntegral (w64 `shiftR` 56)
782-
, fromIntegral (w64 `shiftR` 48)
783-
, fromIntegral (w64 `shiftR` 40)
784-
, fromIntegral (w64 `shiftR` 32)
785-
, fromIntegral (w64 `shiftR` 24)
786-
, fromIntegral (w64 `shiftR` 16)
787-
, fromIntegral (w64 `shiftR` 8)
788-
, fromIntegral w64
789-
]
790-
791776

792777
-- | Parse only the module header
793778
parseHeader

ghcide/src/Development/IDE/GHC/Util.hs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ module Development.IDE.GHC.Util(
1919
moduleImportPath,
2020
cgGutsToCoreModule,
2121
fingerprintToBS,
22+
fingerprintFromByteString,
2223
fingerprintFromStringBuffer,
2324
-- * General utilities
2425
readFileUtf8,
@@ -200,6 +201,11 @@ fingerprintFromStringBuffer :: StringBuffer -> IO Fingerprint
200201
fingerprintFromStringBuffer (StringBuffer buf len cur) =
201202
withForeignPtr buf $ \ptr -> fingerprintData (ptr `plusPtr` cur) len
202203

204+
fingerprintFromByteString :: ByteString -> IO Fingerprint
205+
fingerprintFromByteString bs = do
206+
let (fptr, offset, len) = BS.toForeignPtr bs
207+
withForeignPtr fptr $ \ptr ->
208+
fingerprintData (ptr `plusPtr` offset) len
203209

204210
-- | A slightly modified version of 'hDuplicateTo' from GHC.
205211
-- Importantly, it avoids the bug listed in https://gitlab.haskell.org/ghc/ghc/merge_requests/2318.

0 commit comments

Comments
 (0)