Skip to content
This repository was archived by the owner on Aug 3, 2024. It is now read-only.

Commit b114db9

Browse files
committed
Write PackageInfo into interface file
To keep interface file format backward compatible, instead of using `Binary` instance for `InterfaceFile` we introduce functions to serialise and deserialise, which depends on the interface file version.
1 parent 4b70b39 commit b114db9

File tree

1 file changed

+28
-6
lines changed

1 file changed

+28
-6
lines changed

haddock-api/src/Haddock/InterfaceFile.hs

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -132,10 +132,10 @@ binaryInterfaceMagic = 0xD0Cface
132132
--
133133
binaryInterfaceVersion :: Word16
134134
#if MIN_VERSION_ghc(9,2,0) && !MIN_VERSION_ghc(9,3,0)
135-
binaryInterfaceVersion = 38
135+
binaryInterfaceVersion = 39
136136

137137
binaryInterfaceVersionCompatibility :: [Word16]
138-
binaryInterfaceVersionCompatibility = [37, binaryInterfaceVersion]
138+
binaryInterfaceVersionCompatibility = [37, 38, binaryInterfaceVersion]
139139
#elif defined(__HLINT__)
140140
#else
141141
#error Unsupported GHC version
@@ -176,7 +176,7 @@ writeInterfaceFile filename iface = do
176176
let bh = setUserData bh0 $ newWriteState (putName bin_symtab)
177177
(putName bin_symtab)
178178
(putFastString bin_dict)
179-
put_ bh iface
179+
putInterfaceFile_ bh iface
180180

181181
-- write the symtab pointer at the front of the file
182182
symtab_p <- tellBin bh
@@ -265,7 +265,7 @@ readInterfaceFile (get_name_cache, set_name_cache) filename bypass_checks = do
265265
(getDictFastString dict)
266266

267267
-- load the actual data
268-
iface <- liftIO $ get bh1
268+
iface <- liftIO $ getInterfaceFile bh1 version
269269
return (Right iface)
270270
where
271271
with_name_cache :: forall a.
@@ -422,14 +422,36 @@ instance Binary PackageInfo where
422422
return $ PackageInfo name version
423423

424424
instance Binary InterfaceFile where
425-
put_ bh (InterfaceFile env _ ifaces) = do
425+
put_ bh (InterfaceFile env info ifaces) = do
426426
put_ bh env
427+
put_ bh info
427428
put_ bh ifaces
428429

429430
get bh = do
430431
env <- get bh
432+
info <- get bh
431433
ifaces <- get bh
432-
return (InterfaceFile env PackageInfo { piPackageName = PackageName (mkFastString ""), piPackageVersion = makeVersion [] } ifaces)
434+
return (InterfaceFile env info ifaces)
435+
436+
437+
putInterfaceFile_ :: BinHandle -> InterfaceFile -> IO ()
438+
putInterfaceFile_ bh (InterfaceFile env info ifaces) = do
439+
put_ bh env
440+
put_ bh info
441+
put_ bh ifaces
442+
443+
getInterfaceFile :: BinHandle -> Word16 -> IO InterfaceFile
444+
getInterfaceFile bh v | v <= 38 = do
445+
env <- get bh
446+
let info = PackageInfo (PackageName mempty) (makeVersion [])
447+
ifaces <- get bh
448+
return (InterfaceFile env info ifaces)
449+
getInterfaceFile bh _ = do
450+
env <- get bh
451+
info <- get bh
452+
ifaces <- get bh
453+
return (InterfaceFile env info ifaces)
454+
433455

434456
instance Binary InstalledInterface where
435457
put_ bh (InstalledInterface modu is_sig info docMap argMap

0 commit comments

Comments
 (0)