summaryrefslogtreecommitdiff
path: root/compiler/GHC/Iface/Binary.hs
diff options
context:
space:
mode:
authorAndreas Klebinger <klebinger.andreas@gmx.at>2020-05-15 14:21:04 +0200
committerMarge Bot <ben+marge-bot@smart-cactus.org>2020-05-21 12:21:53 -0400
commit4ca0c8a17b9d3a7e8ff8a93cc9e83be5173f8e14 (patch)
tree1b5f13113068a50ef48a407ca6b206d84480b827 /compiler/GHC/Iface/Binary.hs
parent1b508a9e14c7c894ff4f080f099f3947813f41ec (diff)
downloadhaskell-4ca0c8a17b9d3a7e8ff8a93cc9e83be5173f8e14.tar.gz
Don't variable-length encode magic iface constant.
We changed to use variable length encodings for many types by default, including Word32. This makes sense for numbers but not when Word32 is meant to represent four bytes. I added a FixedLengthEncoding newtype to Binary who's instances interpret their argument as a collection of bytes instead of a number. We then use this when writing/reading magic numbers to the iface file. I also took the libery to remove the dummy iface field. This fixes #18180.
Diffstat (limited to 'compiler/GHC/Iface/Binary.hs')
-rw-r--r--compiler/GHC/Iface/Binary.hs28
1 files changed, 5 insertions, 23 deletions
diff --git a/compiler/GHC/Iface/Binary.hs b/compiler/GHC/Iface/Binary.hs
index a14cb17e04..cefe981847 100644
--- a/compiler/GHC/Iface/Binary.hs
+++ b/compiler/GHC/Iface/Binary.hs
@@ -123,20 +123,9 @@ readBinIface_ dflags checkHiWay traceBinIFaceReading hi_path ncu = do
-- (This magic number does not change when we change
-- GHC interface file format)
magic <- get bh
- wantedGot "Magic" (binaryInterfaceMagic platform) magic ppr
+ wantedGot "Magic" (binaryInterfaceMagic platform) magic (ppr . unFixedLength)
errorOnMismatch "magic number mismatch: old/corrupt interface file?"
- (binaryInterfaceMagic platform) magic
-
- -- Note [dummy iface field]
- -- read a dummy 32/64 bit value. This field used to hold the
- -- dictionary pointer in old interface file formats, but now
- -- the dictionary pointer is after the version (where it
- -- should be). Also, the serialisation of value of type "Bin
- -- a" used to depend on the word size of the machine, now they
- -- are always 32 bits.
- case platformWordSize platform of
- PW4 -> do _ <- Binary.get bh :: IO Word32; return ()
- PW8 -> do _ <- Binary.get bh :: IO Word64; return ()
+ (unFixedLength $ binaryInterfaceMagic platform) (unFixedLength magic)
-- Check the interface file version and ways.
check_ver <- get bh
@@ -198,13 +187,6 @@ writeBinIface dflags hi_path mod_iface = do
let platform = targetPlatform dflags
put_ bh (binaryInterfaceMagic platform)
- -- dummy 32/64-bit field before the version/way for
- -- compatibility with older interface file formats.
- -- See Note [dummy iface field] above.
- case platformWordSize platform of
- PW4 -> Binary.put_ bh (0 :: Word32)
- PW8 -> Binary.put_ bh (0 :: Word64)
-
-- The version and way descriptor go next
put_ bh (show hiVersion)
let way_descr = getWayDescr dflags
@@ -290,10 +272,10 @@ putWithUserData log_action bh payload = do
initBinMemSize :: Int
initBinMemSize = 1024 * 1024
-binaryInterfaceMagic :: Platform -> Word32
+binaryInterfaceMagic :: Platform -> FixedLengthEncoding Word32
binaryInterfaceMagic platform
- | target32Bit platform = 0x1face
- | otherwise = 0x1face64
+ | target32Bit platform = FixedLengthEncoding 0x1face
+ | otherwise = FixedLengthEncoding 0x1face64
-- -----------------------------------------------------------------------------