3 -- We always optimise this, otherwise performance of a non-optimised
4 -- compiler is severely affected
7 -- (c) The University of Glasgow 2002-2006
9 -- Binary interface file support.
11 module BinIface ( writeBinIface, readBinIface,
12 CheckHiWay(..), TraceBinIFaceReading(..) ) where
14 #include "HsVersions.h"
49 data CheckHiWay = CheckHiWay | IgnoreHiWay
52 data TraceBinIFaceReading = TraceBinIFaceReading | QuietBinIFaceReading
55 -- ---------------------------------------------------------------------------
56 -- Reading and writing binary interface files
58 readBinIface :: CheckHiWay -> TraceBinIFaceReading -> FilePath
59 -> TcRnIf a b ModIface
60 readBinIface checkHiWay traceBinIFaceReading hi_path = do
61 update_nc <- mkNameCacheUpdater
63 liftIO $ readBinIface_ dflags checkHiWay traceBinIFaceReading hi_path update_nc
65 readBinIface_ :: DynFlags -> CheckHiWay -> TraceBinIFaceReading -> FilePath
66 -> NameCacheUpdater (Array Int Name)
68 readBinIface_ dflags checkHiWay traceBinIFaceReading hi_path update_nc = do
69 let printer :: SDoc -> IO ()
70 printer = case traceBinIFaceReading of
71 TraceBinIFaceReading -> \sd -> printSDoc sd defaultDumpStyle
72 QuietBinIFaceReading -> \_ -> return ()
73 wantedGot :: Outputable a => String -> a -> a -> IO ()
74 wantedGot what wanted got
75 = printer (text what <> text ": " <>
76 vcat [text "Wanted " <> ppr wanted <> text ",",
77 text "got " <> ppr got])
79 errorOnMismatch :: (Eq a, Show a) => String -> a -> a -> IO ()
80 errorOnMismatch what wanted got
81 -- This will be caught by readIface which will emit an error
82 -- msg containing the iface module name.
83 = when (wanted /= got) $ ghcError $ ProgramError
84 (what ++ " (wanted " ++ show wanted
85 ++ ", got " ++ show got ++ ")")
86 bh <- Binary.readBinMem hi_path
88 -- Read the magic number to check that this really is a GHC .hi file
89 -- (This magic number does not change when we change
90 -- GHC interface file format)
92 wantedGot "Magic" binaryInterfaceMagic magic
93 errorOnMismatch "magic number mismatch: old/corrupt interface file?"
94 binaryInterfaceMagic magic
96 -- Note [dummy iface field]
97 -- read a dummy 32/64 bit value. This field used to hold the
98 -- dictionary pointer in old interface file formats, but now
99 -- the dictionary pointer is after the version (where it
100 -- should be). Also, the serialisation of value of type "Bin
101 -- a" used to depend on the word size of the machine, now they
102 -- are always 32 bits.
105 then do _ <- Binary.get bh :: IO Word32; return ()
106 else do _ <- Binary.get bh :: IO Word64; return ()
108 -- Check the interface file version and ways.
110 let our_ver = show opt_HiVersion
111 wantedGot "Version" our_ver check_ver
112 errorOnMismatch "mismatched interface file versions" our_ver check_ver
115 let way_descr = getWayDescr dflags
116 wantedGot "Way" way_descr check_way
117 when (checkHiWay == CheckHiWay) $
118 errorOnMismatch "mismatched interface file ways" way_descr check_way
120 -- Read the dictionary
121 -- The next word in the file is a pointer to where the dictionary is
122 -- (probably at the end of the file)
123 dict_p <- Binary.get bh
124 data_p <- tellBin bh -- Remember where we are now
126 dict <- getDictionary bh
127 seekBin bh data_p -- Back to where we were before
129 -- Initialise the user-data field of bh
130 ud <- newReadState dict
131 bh <- return (setUserData bh ud)
133 symtab_p <- Binary.get bh -- Get the symtab ptr
134 data_p <- tellBin bh -- Remember where we are now
136 symtab <- getSymbolTable bh update_nc
137 seekBin bh data_p -- Back to where we were before
138 let ud = getUserData bh
139 bh <- return $! setUserData bh ud{ud_symtab = symtab}
144 writeBinIface :: DynFlags -> FilePath -> ModIface -> IO ()
145 writeBinIface dflags hi_path mod_iface = do
146 bh <- openBinMem initBinMemSize
147 put_ bh binaryInterfaceMagic
149 -- dummy 32/64-bit field before the version/way for
150 -- compatibility with older interface file formats.
151 -- See Note [dummy iface field] above.
153 then Binary.put_ bh (0 :: Word32)
154 else Binary.put_ bh (0 :: Word64)
156 -- The version and way descriptor go next
157 put_ bh (show opt_HiVersion)
158 let way_descr = getWayDescr dflags
161 -- Remember where the dictionary pointer will go
162 dict_p_p <- tellBin bh
163 put_ bh dict_p_p -- Placeholder for ptr to dictionary
165 -- Remember where the symbol table pointer will go
166 symtab_p_p <- tellBin bh
169 -- Make some intial state
170 symtab_next <- newFastMutInt
171 writeFastMutInt symtab_next 0
172 symtab_map <- newIORef emptyUFM
173 let bin_symtab = BinSymbolTable {
174 bin_symtab_next = symtab_next,
175 bin_symtab_map = symtab_map }
176 dict_next_ref <- newFastMutInt
177 writeFastMutInt dict_next_ref 0
178 dict_map_ref <- newIORef emptyUFM
179 let bin_dict = BinDictionary {
180 bin_dict_next = dict_next_ref,
181 bin_dict_map = dict_map_ref }
182 ud <- newWriteState (putName bin_symtab) (putFastString bin_dict)
184 -- Put the main thing,
185 bh <- return $ setUserData bh ud
188 -- Write the symtab pointer at the fornt of the file
189 symtab_p <- tellBin bh -- This is where the symtab will start
190 putAt bh symtab_p_p symtab_p -- Fill in the placeholder
191 seekBin bh symtab_p -- Seek back to the end of the file
193 -- Write the symbol table itself
194 symtab_next <- readFastMutInt symtab_next
195 symtab_map <- readIORef symtab_map
196 putSymbolTable bh symtab_next symtab_map
197 debugTraceMsg dflags 3 (text "writeBinIface:" <+> int symtab_next
200 -- NB. write the dictionary after the symbol table, because
201 -- writing the symbol table may create more dictionary entries.
203 -- Write the dictionary pointer at the fornt of the file
204 dict_p <- tellBin bh -- This is where the dictionary will start
205 putAt bh dict_p_p dict_p -- Fill in the placeholder
206 seekBin bh dict_p -- Seek back to the end of the file
208 -- Write the dictionary itself
209 dict_next <- readFastMutInt dict_next_ref
210 dict_map <- readIORef dict_map_ref
211 putDictionary bh dict_next dict_map
212 debugTraceMsg dflags 3 (text "writeBinIface:" <+> int dict_next
213 <+> text "dict entries")
215 -- And send the result to the file
216 writeBinMem bh hi_path
218 initBinMemSize :: Int
219 initBinMemSize = 1024 * 1024
221 -- The *host* architecture version:
222 #include "../includes/MachDeps.h"
224 binaryInterfaceMagic :: Word32
225 #if WORD_SIZE_IN_BITS == 32
226 binaryInterfaceMagic = 0x1face
227 #elif WORD_SIZE_IN_BITS == 64
228 binaryInterfaceMagic = 0x1face64
231 -- -----------------------------------------------------------------------------
234 putSymbolTable :: BinHandle -> Int -> UniqFM (Int,Name) -> IO ()
235 putSymbolTable bh next_off symtab = do
237 let names = elems (array (0,next_off-1) (eltsUFM symtab))
238 mapM_ (\n -> serialiseName bh n symtab) names
240 getSymbolTable :: BinHandle -> NameCacheUpdater (Array Int Name)
241 -> IO (Array Int Name)
242 getSymbolTable bh update_namecache = do
244 od_names <- sequence (replicate sz (get bh))
245 update_namecache $ \namecache ->
247 arr = listArray (0,sz-1) names
248 (namecache', names) =
249 mapAccumR (fromOnDiskName arr) namecache od_names
252 type OnDiskName = (PackageId, ModuleName, OccName)
259 fromOnDiskName _ nc (pid, mod_name, occ) =
261 mod = mkModule pid mod_name
264 case lookupOrigNameCache cache mod occ of
265 Just name -> (nc, name)
267 case takeUniqFromSupply (nsUniqs nc) of
270 name = mkExternalName uniq mod occ noSrcSpan
271 new_cache = extendNameCache cache mod occ name
273 ( nc{ nsUniqs = us, nsNames = new_cache }, name )
275 serialiseName :: BinHandle -> Name -> UniqFM (Int,Name) -> IO ()
276 serialiseName bh name _ = do
277 let mod = ASSERT2( isExternalName name, ppr name ) nameModule name
278 put_ bh (modulePackageId mod, moduleName mod, nameOccName name)
281 putName :: BinSymbolTable -> BinHandle -> Name -> IO ()
282 putName BinSymbolTable{
283 bin_symtab_map = symtab_map_ref,
284 bin_symtab_next = symtab_next } bh name
286 symtab_map <- readIORef symtab_map_ref
287 case lookupUFM symtab_map name of
288 Just (off,_) -> put_ bh (fromIntegral off :: Word32)
290 off <- readFastMutInt symtab_next
291 writeFastMutInt symtab_next (off+1)
292 writeIORef symtab_map_ref
293 $! addToUFM symtab_map name (off,name)
294 put_ bh (fromIntegral off :: Word32)
297 data BinSymbolTable = BinSymbolTable {
298 bin_symtab_next :: !FastMutInt, -- The next index to use
299 bin_symtab_map :: !(IORef (UniqFM (Int,Name)))
304 putFastString :: BinDictionary -> BinHandle -> FastString -> IO ()
305 putFastString BinDictionary { bin_dict_next = j_r,
306 bin_dict_map = out_r} bh f
308 out <- readIORef out_r
309 let uniq = getUnique f
310 case lookupUFM out uniq of
311 Just (j, _) -> put_ bh (fromIntegral j :: Word32)
313 j <- readFastMutInt j_r
314 put_ bh (fromIntegral j :: Word32)
315 writeFastMutInt j_r (j + 1)
316 writeIORef out_r $! addToUFM out uniq (j, f)
319 data BinDictionary = BinDictionary {
320 bin_dict_next :: !FastMutInt, -- The next index to use
321 bin_dict_map :: !(IORef (UniqFM (Int,FastString)))
322 -- indexed by FastString
325 -- -----------------------------------------------------------------------------
326 -- All the binary instances
329 {-! for IPName derive: Binary !-}
330 {-! for Fixity derive: Binary !-}
331 {-! for FixityDirection derive: Binary !-}
332 {-! for Boxity derive: Binary !-}
333 {-! for StrictnessMark derive: Binary !-}
334 {-! for Activation derive: Binary !-}
337 {-! for Demand derive: Binary !-}
338 {-! for Demands derive: Binary !-}
339 {-! for DmdResult derive: Binary !-}
340 {-! for StrictSig derive: Binary !-}
343 {-! for DefMeth derive: Binary !-}
346 {-! for HsPred derive: Binary !-}
347 {-! for HsType derive: Binary !-}
348 {-! for TupCon derive: Binary !-}
349 {-! for HsTyVarBndr derive: Binary !-}
352 {-! for UfExpr derive: Binary !-}
353 {-! for UfConAlt derive: Binary !-}
354 {-! for UfBinding derive: Binary !-}
355 {-! for UfBinder derive: Binary !-}
356 {-! for HsIdInfo derive: Binary !-}
357 {-! for UfNote derive: Binary !-}
360 {-! for ConDetails derive: Binary !-}
361 {-! for BangType derive: Binary !-}
364 {-! for IsCafCC derive: Binary !-}
365 {-! for IsDupdCC derive: Binary !-}
366 {-! for CostCentre derive: Binary !-}
370 -- ---------------------------------------------------------------------------
371 -- Reading a binary interface into ParsedIface
373 instance Binary ModIface where
377 mi_iface_hash= iface_hash,
378 mi_mod_hash = mod_hash,
380 mi_finsts = hasFamInsts,
383 mi_exports = exports,
384 mi_exp_hash = exp_hash,
385 mi_fixities = fixities,
390 mi_fam_insts = fam_insts,
392 mi_orphan_hash = orphan_hash,
393 mi_vect_info = vect_info,
394 mi_hpc = hpc_info }) = do
422 hasFamInsts <- get bh
424 usages <- {-# SCC "bin_usages" #-} lazyGet bh
425 exports <- {-# SCC "bin_exports" #-} get bh
427 fixities <- {-# SCC "bin_fixities" #-} get bh
428 warns <- {-# SCC "bin_warns" #-} lazyGet bh
429 anns <- {-# SCC "bin_anns" #-} lazyGet bh
430 decls <- {-# SCC "bin_tycldecls" #-} get bh
431 insts <- {-# SCC "bin_insts" #-} get bh
432 fam_insts <- {-# SCC "bin_fam_insts" #-} get bh
433 rules <- {-# SCC "bin_rules" #-} lazyGet bh
434 orphan_hash <- get bh
438 mi_module = mod_name,
440 mi_iface_hash = iface_hash,
441 mi_mod_hash = mod_hash,
443 mi_finsts = hasFamInsts,
446 mi_exports = exports,
447 mi_exp_hash = exp_hash,
449 mi_fixities = fixities,
452 mi_globals = Nothing,
454 mi_fam_insts = fam_insts,
456 mi_orphan_hash = orphan_hash,
457 mi_vect_info = vect_info,
459 -- And build the cached values
460 mi_warn_fn = mkIfaceWarnCache warns,
461 mi_fix_fn = mkIfaceFixCache fixities,
462 mi_hash_fn = mkIfaceHashCache decls })
464 getWayDescr :: DynFlags -> String
466 | cGhcUnregisterised == "YES" = 'u':tag
468 where tag = buildTag dflags
469 -- if this is an unregisterised build, make sure our interfaces
470 -- can't be used by a registerised build.
472 -------------------------------------------------------------------------
473 -- Types from: HscTypes
474 -------------------------------------------------------------------------
476 instance Binary Dependencies where
477 put_ bh deps = do put_ bh (dep_mods deps)
478 put_ bh (dep_pkgs deps)
479 put_ bh (dep_orphs deps)
480 put_ bh (dep_finsts deps)
482 get bh = do ms <- get bh
486 return (Deps { dep_mods = ms, dep_pkgs = ps, dep_orphs = os,
489 instance (Binary name) => Binary (GenAvailInfo name) where
490 put_ bh (Avail aa) = do
493 put_ bh (AvailTC ab ac) = do
504 return (AvailTC ab ac)
506 instance Binary Usage where
507 put_ bh usg@UsagePackageModule{} = do
509 put_ bh (usg_mod usg)
510 put_ bh (usg_mod_hash usg)
511 put_ bh usg@UsageHomeModule{} = do
513 put_ bh (usg_mod_name usg)
514 put_ bh (usg_mod_hash usg)
515 put_ bh (usg_exports usg)
516 put_ bh (usg_entities usg)
524 return UsagePackageModule { usg_mod = nm, usg_mod_hash = mod }
530 return UsageHomeModule { usg_mod_name = nm, usg_mod_hash = mod,
531 usg_exports = exps, usg_entities = ents }
533 instance Binary Warnings where
534 put_ bh NoWarnings = putByte bh 0
535 put_ bh (WarnAll t) = do
538 put_ bh (WarnSome ts) = do
545 0 -> return NoWarnings
551 instance Binary WarningTxt where
552 put_ bh (WarningTxt w) = do
555 put_ bh (DeprecatedTxt d) = do
563 return (WarningTxt w)
565 return (DeprecatedTxt d)
567 -------------------------------------------------------------------------
568 -- Types from: BasicTypes
569 -------------------------------------------------------------------------
571 instance Binary Activation where
572 put_ bh NeverActive = do
574 put_ bh AlwaysActive = do
576 put_ bh (ActiveBefore aa) = do
579 put_ bh (ActiveAfter ab) = do
585 0 -> do return NeverActive
586 1 -> do return AlwaysActive
588 return (ActiveBefore aa)
590 return (ActiveAfter ab)
592 instance Binary RuleMatchInfo where
593 put_ bh FunLike = putByte bh 0
594 put_ bh ConLike = putByte bh 1
597 if h == 1 then return ConLike
600 instance Binary InlinePragma where
601 put_ bh (InlinePragma a b c d) = do
612 return (InlinePragma a b c d)
614 instance Binary InlineSpec where
615 put_ bh EmptyInlineSpec = putByte bh 0
616 put_ bh Inline = putByte bh 1
617 put_ bh Inlinable = putByte bh 2
618 put_ bh NoInline = putByte bh 3
620 get bh = do h <- getByte bh
622 0 -> return EmptyInlineSpec
624 2 -> return Inlinable
627 instance Binary HsBang where
628 put_ bh HsNoBang = putByte bh 0
629 put_ bh HsStrict = putByte bh 1
630 put_ bh HsUnpack = putByte bh 2
631 put_ bh HsUnpackFailed = putByte bh 3
635 0 -> do return HsNoBang
636 1 -> do return HsStrict
637 2 -> do return HsUnpack
638 _ -> do return HsUnpackFailed
640 instance Binary Boxity where
641 put_ bh Boxed = putByte bh 0
642 put_ bh Unboxed = putByte bh 1
647 _ -> do return Unboxed
649 instance Binary TupCon where
650 put_ bh (TupCon ab ac) = do
656 return (TupCon ab ac)
658 instance Binary RecFlag where
659 put_ bh Recursive = do
661 put_ bh NonRecursive = do
666 0 -> do return Recursive
667 _ -> do return NonRecursive
669 instance Binary DefMethSpec where
670 put_ bh NoDM = putByte bh 0
671 put_ bh VanillaDM = putByte bh 1
672 put_ bh GenericDM = putByte bh 2
677 1 -> return VanillaDM
678 _ -> return GenericDM
680 instance Binary FixityDirection where
690 0 -> do return InfixL
691 1 -> do return InfixR
692 _ -> do return InfixN
694 instance Binary Fixity where
695 put_ bh (Fixity aa ab) = do
701 return (Fixity aa ab)
703 instance (Binary name) => Binary (IPName name) where
704 put_ bh (IPName aa) = put_ bh aa
705 get bh = do aa <- get bh
708 -------------------------------------------------------------------------
709 -- Types from: Demand
710 -------------------------------------------------------------------------
712 instance Binary DmdType where
713 -- Ignore DmdEnv when spitting out the DmdType
714 put bh (DmdType _ ds dr) = do p <- put bh ds; put_ bh dr; return (castBin p)
715 get bh = do ds <- get bh; dr <- get bh; return (DmdType emptyVarEnv ds dr)
717 instance Binary Demand where
722 put_ bh (Call aa) = do
725 put_ bh (Eval ab) = do
728 put_ bh (Defer ac) = do
731 put_ bh (Box ad) = do
751 instance Binary Demands where
752 put_ bh (Poly aa) = do
755 put_ bh (Prod ab) = do
766 instance Binary DmdResult where
776 0 -> do return TopRes
777 1 -> do return RetCPR -- Really use RetCPR even if -fcpr-off
778 -- The wrapper was generated for CPR in
779 -- the imported module!
780 _ -> do return BotRes
782 instance Binary StrictSig where
783 put_ bh (StrictSig aa) = do
787 return (StrictSig aa)
790 -------------------------------------------------------------------------
791 -- Types from: CostCentre
792 -------------------------------------------------------------------------
794 instance Binary IsCafCC where
797 put_ bh NotCafCC = do
803 _ -> do return NotCafCC
805 instance Binary IsDupdCC where
806 put_ bh OriginalCC = do
813 0 -> do return OriginalCC
814 _ -> do return DupdCC
816 instance Binary CostCentre where
817 put_ bh NoCostCentre = do
819 put_ bh (NormalCC aa ab ac ad) = do
825 put_ bh (AllCafsCC ae) = do
831 0 -> do return NoCostCentre
836 return (NormalCC aa ab ac ad)
838 return (AllCafsCC ae)
840 -------------------------------------------------------------------------
841 -- IfaceTypes and friends
842 -------------------------------------------------------------------------
844 instance Binary IfaceBndr where
845 put_ bh (IfaceIdBndr aa) = do
848 put_ bh (IfaceTvBndr ab) = do
855 return (IfaceIdBndr aa)
857 return (IfaceTvBndr ab)
859 instance Binary IfaceLetBndr where
860 put_ bh (IfLetBndr a b c) = do
864 get bh = do a <- get bh
867 return (IfLetBndr a b c)
869 instance Binary IfaceType where
870 put_ bh (IfaceForAllTy aa ab) = do
874 put_ bh (IfaceTyVar ad) = do
877 put_ bh (IfaceAppTy ae af) = do
881 put_ bh (IfaceFunTy ag ah) = do
885 put_ bh (IfacePredTy aq) = do
889 -- Simple compression for common cases of TyConApp
890 put_ bh (IfaceTyConApp IfaceIntTc []) = putByte bh 6
891 put_ bh (IfaceTyConApp IfaceCharTc []) = putByte bh 7
892 put_ bh (IfaceTyConApp IfaceBoolTc []) = putByte bh 8
893 put_ bh (IfaceTyConApp IfaceListTc [ty]) = do { putByte bh 9; put_ bh ty }
894 -- Unit tuple and pairs
895 put_ bh (IfaceTyConApp (IfaceTupTc Boxed 0) []) = putByte bh 10
896 put_ bh (IfaceTyConApp (IfaceTupTc Boxed 2) [t1,t2]) = do { putByte bh 11; put_ bh t1; put_ bh t2 }
898 put_ bh (IfaceTyConApp IfaceLiftedTypeKindTc []) = putByte bh 12
899 put_ bh (IfaceTyConApp IfaceOpenTypeKindTc []) = putByte bh 13
900 put_ bh (IfaceTyConApp IfaceUnliftedTypeKindTc []) = putByte bh 14
901 put_ bh (IfaceTyConApp IfaceUbxTupleKindTc []) = putByte bh 15
902 put_ bh (IfaceTyConApp IfaceArgTypeKindTc []) = putByte bh 16
903 put_ bh (IfaceTyConApp (IfaceAnyTc k) []) = do { putByte bh 17; put_ bh k }
907 put_ bh (IfaceTyConApp (IfaceTc tc) tys) = do { putByte bh 18; put_ bh tc; put_ bh tys }
908 put_ bh (IfaceTyConApp tc tys) = do { putByte bh 19; put_ bh tc; put_ bh tys }
915 return (IfaceForAllTy aa ab)
917 return (IfaceTyVar ad)
920 return (IfaceAppTy ae af)
923 return (IfaceFunTy ag ah)
925 return (IfacePredTy ap)
927 -- Now the special cases for TyConApp
928 6 -> return (IfaceTyConApp IfaceIntTc [])
929 7 -> return (IfaceTyConApp IfaceCharTc [])
930 8 -> return (IfaceTyConApp IfaceBoolTc [])
931 9 -> do { ty <- get bh; return (IfaceTyConApp IfaceListTc [ty]) }
932 10 -> return (IfaceTyConApp (IfaceTupTc Boxed 0) [])
933 11 -> do { t1 <- get bh; t2 <- get bh; return (IfaceTyConApp (IfaceTupTc Boxed 2) [t1,t2]) }
934 12 -> return (IfaceTyConApp IfaceLiftedTypeKindTc [])
935 13 -> return (IfaceTyConApp IfaceOpenTypeKindTc [])
936 14 -> return (IfaceTyConApp IfaceUnliftedTypeKindTc [])
937 15 -> return (IfaceTyConApp IfaceUbxTupleKindTc [])
938 16 -> return (IfaceTyConApp IfaceArgTypeKindTc [])
939 17 -> do { k <- get bh; return (IfaceTyConApp (IfaceAnyTc k) []) }
941 18 -> do { tc <- get bh; tys <- get bh; return (IfaceTyConApp (IfaceTc tc) tys) }
942 _ -> do { tc <- get bh; tys <- get bh; return (IfaceTyConApp tc tys) }
944 instance Binary IfaceTyCon where
945 -- Int,Char,Bool can't show up here because they can't not be saturated
947 put_ bh IfaceIntTc = putByte bh 1
948 put_ bh IfaceBoolTc = putByte bh 2
949 put_ bh IfaceCharTc = putByte bh 3
950 put_ bh IfaceListTc = putByte bh 4
951 put_ bh IfacePArrTc = putByte bh 5
952 put_ bh IfaceLiftedTypeKindTc = putByte bh 6
953 put_ bh IfaceOpenTypeKindTc = putByte bh 7
954 put_ bh IfaceUnliftedTypeKindTc = putByte bh 8
955 put_ bh IfaceUbxTupleKindTc = putByte bh 9
956 put_ bh IfaceArgTypeKindTc = putByte bh 10
957 put_ bh (IfaceTupTc bx ar) = do { putByte bh 11; put_ bh bx; put_ bh ar }
958 put_ bh (IfaceTc ext) = do { putByte bh 12; put_ bh ext }
959 put_ bh (IfaceAnyTc k) = do { putByte bh 13; put_ bh k }
964 1 -> return IfaceIntTc
965 2 -> return IfaceBoolTc
966 3 -> return IfaceCharTc
967 4 -> return IfaceListTc
968 5 -> return IfacePArrTc
969 6 -> return IfaceLiftedTypeKindTc
970 7 -> return IfaceOpenTypeKindTc
971 8 -> return IfaceUnliftedTypeKindTc
972 9 -> return IfaceUbxTupleKindTc
973 10 -> return IfaceArgTypeKindTc
974 11 -> do { bx <- get bh; ar <- get bh; return (IfaceTupTc bx ar) }
975 12 -> do { ext <- get bh; return (IfaceTc ext) }
976 _ -> do { k <- get bh; return (IfaceAnyTc k) }
978 instance Binary IfacePredType where
979 put_ bh (IfaceClassP aa ab) = do
983 put_ bh (IfaceIParam ac ad) = do
987 put_ bh (IfaceEqPred ac ad) = do
996 return (IfaceClassP aa ab)
999 return (IfaceIParam ac ad)
1000 2 -> do ac <- get bh
1002 return (IfaceEqPred ac ad)
1003 _ -> panic ("get IfacePredType " ++ show h)
1005 -------------------------------------------------------------------------
1006 -- IfaceExpr and friends
1007 -------------------------------------------------------------------------
1009 instance Binary IfaceExpr where
1010 put_ bh (IfaceLcl aa) = do
1013 put_ bh (IfaceType ab) = do
1016 put_ bh (IfaceTuple ac ad) = do
1020 put_ bh (IfaceLam ae af) = do
1024 put_ bh (IfaceApp ag ah) = do
1029 put_ bh (IfaceCase ai aj al ak) = do
1036 put_ bh (IfaceLet al am) = do
1040 put_ bh (IfaceNote an ao) = do
1044 put_ bh (IfaceLit ap) = do
1047 put_ bh (IfaceFCall as at) = do
1051 put_ bh (IfaceExt aa) = do
1054 put_ bh (IfaceCast ie ico) = do
1058 put_ bh (IfaceTick m ix) = do
1065 0 -> do aa <- get bh
1066 return (IfaceLcl aa)
1067 1 -> do ab <- get bh
1068 return (IfaceType ab)
1069 2 -> do ac <- get bh
1071 return (IfaceTuple ac ad)
1072 3 -> do ae <- get bh
1074 return (IfaceLam ae af)
1075 4 -> do ag <- get bh
1077 return (IfaceApp ag ah)
1078 5 -> do ai <- get bh
1084 return (IfaceCase ai aj al ak)
1085 6 -> do al <- get bh
1087 return (IfaceLet al am)
1088 7 -> do an <- get bh
1090 return (IfaceNote an ao)
1091 8 -> do ap <- get bh
1092 return (IfaceLit ap)
1093 9 -> do as <- get bh
1095 return (IfaceFCall as at)
1096 10 -> do aa <- get bh
1097 return (IfaceExt aa)
1098 11 -> do ie <- get bh
1100 return (IfaceCast ie ico)
1101 12 -> do m <- get bh
1103 return (IfaceTick m ix)
1104 _ -> panic ("get IfaceExpr " ++ show h)
1106 instance Binary IfaceConAlt where
1107 put_ bh IfaceDefault = do
1109 put_ bh (IfaceDataAlt aa) = do
1112 put_ bh (IfaceTupleAlt ab) = do
1115 put_ bh (IfaceLitAlt ac) = do
1121 0 -> do return IfaceDefault
1122 1 -> do aa <- get bh
1123 return (IfaceDataAlt aa)
1124 2 -> do ab <- get bh
1125 return (IfaceTupleAlt ab)
1126 _ -> do ac <- get bh
1127 return (IfaceLitAlt ac)
1129 instance Binary IfaceBinding where
1130 put_ bh (IfaceNonRec aa ab) = do
1134 put_ bh (IfaceRec ac) = do
1140 0 -> do aa <- get bh
1142 return (IfaceNonRec aa ab)
1143 _ -> do ac <- get bh
1144 return (IfaceRec ac)
1146 instance Binary IfaceIdDetails where
1147 put_ bh IfVanillaId = putByte bh 0
1148 put_ bh (IfRecSelId a b) = do { putByte bh 1; put_ bh a; put_ bh b }
1149 put_ bh (IfDFunId n) = do { putByte bh 2; put_ bh n }
1153 0 -> return IfVanillaId
1156 return (IfRecSelId a b)
1157 _ -> do { n <- get bh; return (IfDFunId n) }
1159 instance Binary IfaceIdInfo where
1160 put_ bh NoInfo = putByte bh 0
1161 put_ bh (HasInfo i) = do
1163 lazyPut bh i -- NB lazyPut
1169 _ -> do info <- lazyGet bh -- NB lazyGet
1170 return (HasInfo info)
1172 instance Binary IfaceInfoItem where
1173 put_ bh (HsArity aa) = do
1176 put_ bh (HsStrictness ab) = do
1179 put_ bh (HsUnfold lb ad) = do
1183 put_ bh (HsInline ad) = do
1186 put_ bh HsNoCafRefs = do
1191 0 -> do aa <- get bh
1193 1 -> do ab <- get bh
1194 return (HsStrictness ab)
1195 2 -> do lb <- get bh
1197 return (HsUnfold lb ad)
1198 3 -> do ad <- get bh
1199 return (HsInline ad)
1200 _ -> do return HsNoCafRefs
1202 instance Binary IfaceUnfolding where
1203 put_ bh (IfCoreUnfold s e) = do
1207 put_ bh (IfInlineRule a b c d) = do
1213 put_ bh (IfLclWrapper a n) = do
1217 put_ bh (IfExtWrapper a n) = do
1221 put_ bh (IfDFunUnfold as) = do
1224 put_ bh (IfCompulsory e) = do
1232 return (IfCoreUnfold s e)
1237 return (IfInlineRule a b c d)
1240 return (IfLclWrapper a n)
1243 return (IfExtWrapper a n)
1244 4 -> do as <- get bh
1245 return (IfDFunUnfold as)
1247 return (IfCompulsory e)
1249 instance Binary (DFunArg IfaceExpr) where
1250 put_ bh (DFunPolyArg e) = putByte bh 0 >> put_ bh e
1251 put_ bh (DFunConstArg e) = putByte bh 1 >> put_ bh e
1252 put_ bh (DFunLamArg i) = putByte bh 2 >> put_ bh i
1253 get bh = do { h <- getByte bh
1255 0 -> do { a <- get bh; return (DFunPolyArg a) }
1256 1 -> do { a <- get bh; return (DFunConstArg a) }
1257 _ -> do { a <- get bh; return (DFunLamArg a) } }
1259 instance Binary IfaceNote where
1260 put_ bh (IfaceSCC aa) = do
1263 put_ bh (IfaceCoreNote s) = do
1269 0 -> do aa <- get bh
1270 return (IfaceSCC aa)
1271 4 -> do ac <- get bh
1272 return (IfaceCoreNote ac)
1273 _ -> panic ("get IfaceNote " ++ show h)
1275 -------------------------------------------------------------------------
1276 -- IfaceDecl and friends
1277 -------------------------------------------------------------------------
1279 -- A bit of magic going on here: there's no need to store the OccName
1280 -- for a decl on the disk, since we can infer the namespace from the
1281 -- context; however it is useful to have the OccName in the IfaceDecl
1282 -- to avoid re-building it in various places. So we build the OccName
1283 -- when de-serialising.
1285 instance Binary IfaceDecl where
1286 put_ bh (IfaceId name ty details idinfo) = do
1288 put_ bh (occNameFS name)
1292 put_ _ (IfaceForeign _ _) =
1293 error "Binary.put_(IfaceDecl): IfaceForeign"
1294 put_ bh (IfaceData a1 a2 a3 a4 a5 a6 a7 a8) = do
1296 put_ bh (occNameFS a1)
1304 put_ bh (IfaceSyn a1 a2 a3 a4 a5) = do
1306 put_ bh (occNameFS a1)
1311 put_ bh (IfaceClass a1 a2 a3 a4 a5 a6 a7) = do
1314 put_ bh (occNameFS a2)
1323 0 -> do name <- get bh
1327 occ <- return $! mkOccNameFS varName name
1328 return (IfaceId occ ty details idinfo)
1329 1 -> error "Binary.get(TyClDecl): ForeignType"
1339 occ <- return $! mkOccNameFS tcName a1
1340 return (IfaceData occ a2 a3 a4 a5 a6 a7 a8)
1347 occ <- return $! mkOccNameFS tcName a1
1348 return (IfaceSyn occ a2 a3 a4 a5)
1357 occ <- return $! mkOccNameFS clsName a2
1358 return (IfaceClass a1 occ a3 a4 a5 a6 a7)
1360 instance Binary IfaceInst where
1361 put_ bh (IfaceInst cls tys dfun flag orph) = do
1367 get bh = do cls <- get bh
1372 return (IfaceInst cls tys dfun flag orph)
1374 instance Binary IfaceFamInst where
1375 put_ bh (IfaceFamInst fam tys tycon) = do
1379 get bh = do fam <- get bh
1382 return (IfaceFamInst fam tys tycon)
1384 instance Binary OverlapFlag where
1385 put_ bh NoOverlap = putByte bh 0
1386 put_ bh OverlapOk = putByte bh 1
1387 put_ bh Incoherent = putByte bh 2
1388 get bh = do h <- getByte bh
1390 0 -> return NoOverlap
1391 1 -> return OverlapOk
1392 2 -> return Incoherent
1393 _ -> panic ("get OverlapFlag " ++ show h)
1395 instance Binary IfaceConDecls where
1396 put_ bh IfAbstractTyCon = putByte bh 0
1397 put_ bh IfOpenDataTyCon = putByte bh 1
1398 put_ bh (IfDataTyCon cs) = do { putByte bh 2
1400 put_ bh (IfNewTyCon c) = do { putByte bh 3
1405 0 -> return IfAbstractTyCon
1406 1 -> return IfOpenDataTyCon
1407 2 -> do cs <- get bh
1408 return (IfDataTyCon cs)
1409 _ -> do aa <- get bh
1410 return (IfNewTyCon aa)
1412 instance Binary IfaceConDecl where
1413 put_ bh (IfCon a1 a2 a3 a4 a5 a6 a7 a8 a9 a10) = do
1424 get bh = do a1 <- get bh
1434 return (IfCon a1 a2 a3 a4 a5 a6 a7 a8 a9 a10)
1436 instance Binary IfaceClassOp where
1437 put_ bh (IfaceClassOp n def ty) = do
1438 put_ bh (occNameFS n)
1445 occ <- return $! mkOccNameFS varName n
1446 return (IfaceClassOp occ def ty)
1448 instance Binary IfaceRule where
1449 put_ bh (IfaceRule a1 a2 a3 a4 a5 a6 a7 a8) = do
1467 return (IfaceRule a1 a2 a3 a4 a5 a6 a7 a8)
1469 instance Binary IfaceAnnotation where
1470 put_ bh (IfaceAnnotation a1 a2) = do
1476 return (IfaceAnnotation a1 a2)
1478 instance Binary name => Binary (AnnTarget name) where
1479 put_ bh (NamedTarget a) = do
1482 put_ bh (ModuleTarget a) = do
1489 return (NamedTarget a)
1491 return (ModuleTarget a)
1493 instance Binary IfaceVectInfo where
1494 put_ bh (IfaceVectInfo a1 a2 a3) = do
1502 return (IfaceVectInfo a1 a2 a3)