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"
47 import Control.Exception
50 data CheckHiWay = CheckHiWay | IgnoreHiWay
53 data TraceBinIFaceReading = TraceBinIFaceReading | QuietBinIFaceReading
56 -- ---------------------------------------------------------------------------
57 -- Reading and writing binary interface files
59 readBinIface :: CheckHiWay -> TraceBinIFaceReading -> FilePath
60 -> TcRnIf a b ModIface
61 readBinIface checkHiWay traceBinIFaceReading hi_path = do
63 (new_nc, iface) <- liftIO $
64 readBinIface_ checkHiWay traceBinIFaceReading hi_path nc
68 readBinIface_ :: CheckHiWay -> TraceBinIFaceReading -> FilePath -> NameCache
69 -> IO (NameCache, ModIface)
70 readBinIface_ checkHiWay traceBinIFaceReading hi_path nc = do
71 let printer :: SDoc -> IO ()
72 printer = case traceBinIFaceReading of
73 TraceBinIFaceReading -> \sd -> printSDoc sd defaultDumpStyle
74 QuietBinIFaceReading -> \_ -> return ()
75 wantedGot :: Outputable a => String -> a -> a -> IO ()
76 wantedGot what wanted got
77 = printer (text what <> text ": " <>
78 vcat [text "Wanted " <> ppr wanted <> text ",",
79 text "got " <> ppr got])
81 errorOnMismatch :: (Eq a, Show a) => String -> a -> a -> IO ()
82 errorOnMismatch what wanted got
83 -- This will be caught by readIface which will emit an error
84 -- msg containing the iface module name.
85 = when (wanted /= got) $ throwDyn $ ProgramError
86 (what ++ " (wanted " ++ show wanted
87 ++ ", got " ++ show got ++ ")")
88 bh <- Binary.readBinMem hi_path
90 -- Read the magic number to check that this really is a GHC .hi file
91 -- (This magic number does not change when we change
92 -- GHC interface file format)
94 wantedGot "Magic" binaryInterfaceMagic magic
95 errorOnMismatch "magic number mismatch: old/corrupt interface file?"
96 binaryInterfaceMagic magic
98 -- Get the dictionary pointer. We won't attempt to actually
99 -- read the dictionary until we've done the version checks below,
100 -- just in case this isn't a valid interface. In retrospect the
101 -- version should have come before the dictionary pointer, but this
102 -- is the way it was done originally, and we can't change it now.
103 dict_p <- Binary.get bh -- Get the dictionary ptr
105 -- Check the interface file version and ways.
107 let our_ver = show opt_HiVersion
108 wantedGot "Version" our_ver check_ver
109 errorOnMismatch "mismatched interface file versions" our_ver check_ver
112 way_descr <- getWayDescr
113 wantedGot "Way" way_descr check_way
114 when (checkHiWay == CheckHiWay) $
115 errorOnMismatch "mismatched interface file ways" way_descr check_way
117 -- Read the dictionary
118 -- The next word in the file is a pointer to where the dictionary is
119 -- (probably at the end of the file)
120 data_p <- tellBin bh -- Remember where we are now
122 dict <- getDictionary bh
123 seekBin bh data_p -- Back to where we were before
125 -- Initialise the user-data field of bh
126 ud <- newReadState dict
127 bh <- return (setUserData bh ud)
129 symtab_p <- Binary.get bh -- Get the symtab ptr
130 data_p <- tellBin bh -- Remember where we are now
132 (nc', symtab) <- getSymbolTable bh nc
133 seekBin bh data_p -- Back to where we were before
134 let ud = getUserData bh
135 bh <- return $! setUserData bh ud{ud_symtab = symtab}
140 writeBinIface :: DynFlags -> FilePath -> ModIface -> IO ()
141 writeBinIface dflags hi_path mod_iface = do
142 bh <- openBinMem initBinMemSize
143 put_ bh binaryInterfaceMagic
145 -- Remember where the dictionary pointer will go
146 dict_p_p <- tellBin bh
147 put_ bh dict_p_p -- Placeholder for ptr to dictionary
149 -- The version and way descriptor go next
150 put_ bh (show opt_HiVersion)
151 way_descr <- getWayDescr
154 -- Remember where the symbol table pointer will go
155 symtab_p_p <- tellBin bh
158 -- Make some intial state
159 symtab_next <- newFastMutInt
160 writeFastMutInt symtab_next 0
161 symtab_map <- newIORef emptyUFM
162 let bin_symtab = BinSymbolTable {
163 bin_symtab_next = symtab_next,
164 bin_symtab_map = symtab_map }
165 dict_next_ref <- newFastMutInt
166 writeFastMutInt dict_next_ref 0
167 dict_map_ref <- newIORef emptyUFM
168 let bin_dict = BinDictionary {
169 bin_dict_next = dict_next_ref,
170 bin_dict_map = dict_map_ref }
171 ud <- newWriteState (putName bin_symtab) (putFastString bin_dict)
173 -- Put the main thing,
174 bh <- return $ setUserData bh ud
177 -- Write the symtab pointer at the fornt of the file
178 symtab_p <- tellBin bh -- This is where the symtab will start
179 putAt bh symtab_p_p symtab_p -- Fill in the placeholder
180 seekBin bh symtab_p -- Seek back to the end of the file
182 -- Write the symbol table itself
183 symtab_next <- readFastMutInt symtab_next
184 symtab_map <- readIORef symtab_map
185 putSymbolTable bh symtab_next symtab_map
186 debugTraceMsg dflags 3 (text "writeBinIface:" <+> int symtab_next
189 -- NB. write the dictionary after the symbol table, because
190 -- writing the symbol table may create more dictionary entries.
192 -- Write the dictionary pointer at the fornt of the file
193 dict_p <- tellBin bh -- This is where the dictionary will start
194 putAt bh dict_p_p dict_p -- Fill in the placeholder
195 seekBin bh dict_p -- Seek back to the end of the file
197 -- Write the dictionary itself
198 dict_next <- readFastMutInt dict_next_ref
199 dict_map <- readIORef dict_map_ref
200 putDictionary bh dict_next dict_map
201 debugTraceMsg dflags 3 (text "writeBinIface:" <+> int dict_next
202 <+> text "dict entries")
204 -- And send the result to the file
205 writeBinMem bh hi_path
207 initBinMemSize :: Int
208 initBinMemSize = 1024 * 1024
210 -- The *host* architecture version:
211 #include "MachDeps.h"
213 binaryInterfaceMagic :: Word32
214 #if WORD_SIZE_IN_BITS == 32
215 binaryInterfaceMagic = 0x1face
216 #elif WORD_SIZE_IN_BITS == 64
217 binaryInterfaceMagic = 0x1face64
220 -- -----------------------------------------------------------------------------
223 putSymbolTable :: BinHandle -> Int -> UniqFM (Int,Name) -> IO ()
224 putSymbolTable bh next_off symtab = do
226 let names = elems (array (0,next_off-1) (eltsUFM symtab))
227 mapM_ (\n -> serialiseName bh n symtab) names
229 getSymbolTable :: BinHandle -> NameCache -> IO (NameCache, Array Int Name)
230 getSymbolTable bh namecache = do
232 od_names <- sequence (replicate sz (get bh))
234 arr = listArray (0,sz-1) names
235 (namecache', names) =
236 mapAccumR (fromOnDiskName arr) namecache od_names
238 return (namecache', arr)
240 type OnDiskName = (PackageId, ModuleName, OccName)
247 fromOnDiskName _ nc (pid, mod_name, occ) =
249 mod = mkModule pid mod_name
252 case lookupOrigNameCache cache mod occ of
253 Just name -> (nc, name)
257 uniq = uniqFromSupply us
258 name = mkExternalName uniq mod occ noSrcSpan
259 new_cache = extendNameCache cache mod occ name
261 case splitUniqSupply us of { (us',_) ->
262 ( nc{ nsUniqs = us', nsNames = new_cache }, name )
265 serialiseName :: BinHandle -> Name -> UniqFM (Int,Name) -> IO ()
266 serialiseName bh name _ = do
267 let mod = nameModule name
268 put_ bh (modulePackageId mod, moduleName mod, nameOccName name)
271 putName :: BinSymbolTable -> BinHandle -> Name -> IO ()
272 putName BinSymbolTable{
273 bin_symtab_map = symtab_map_ref,
274 bin_symtab_next = symtab_next } bh name
276 symtab_map <- readIORef symtab_map_ref
277 case lookupUFM symtab_map name of
278 Just (off,_) -> put_ bh off
280 off <- readFastMutInt symtab_next
281 writeFastMutInt symtab_next (off+1)
282 writeIORef symtab_map_ref
283 $! addToUFM symtab_map name (off,name)
287 data BinSymbolTable = BinSymbolTable {
288 bin_symtab_next :: !FastMutInt, -- The next index to use
289 bin_symtab_map :: !(IORef (UniqFM (Int,Name)))
294 putFastString :: BinDictionary -> BinHandle -> FastString -> IO ()
295 putFastString BinDictionary { bin_dict_next = j_r,
296 bin_dict_map = out_r} bh f
298 out <- readIORef out_r
299 let uniq = getUnique f
300 case lookupUFM out uniq of
301 Just (j, _) -> put_ bh j
303 j <- readFastMutInt j_r
305 writeFastMutInt j_r (j + 1)
306 writeIORef out_r $! addToUFM out uniq (j, f)
309 data BinDictionary = BinDictionary {
310 bin_dict_next :: !FastMutInt, -- The next index to use
311 bin_dict_map :: !(IORef (UniqFM (Int,FastString)))
312 -- indexed by FastString
315 -- -----------------------------------------------------------------------------
316 -- All the binary instances
319 {-! for IPName derive: Binary !-}
320 {-! for Fixity derive: Binary !-}
321 {-! for FixityDirection derive: Binary !-}
322 {-! for Boxity derive: Binary !-}
323 {-! for StrictnessMark derive: Binary !-}
324 {-! for Activation derive: Binary !-}
327 {-! for Demand derive: Binary !-}
328 {-! for Demands derive: Binary !-}
329 {-! for DmdResult derive: Binary !-}
330 {-! for StrictSig derive: Binary !-}
333 {-! for DefMeth derive: Binary !-}
336 {-! for HsPred derive: Binary !-}
337 {-! for HsType derive: Binary !-}
338 {-! for TupCon derive: Binary !-}
339 {-! for HsTyVarBndr derive: Binary !-}
342 {-! for UfExpr derive: Binary !-}
343 {-! for UfConAlt derive: Binary !-}
344 {-! for UfBinding derive: Binary !-}
345 {-! for UfBinder derive: Binary !-}
346 {-! for HsIdInfo derive: Binary !-}
347 {-! for UfNote derive: Binary !-}
350 {-! for ConDetails derive: Binary !-}
351 {-! for BangType derive: Binary !-}
354 {-! for IsCafCC derive: Binary !-}
355 {-! for IsDupdCC derive: Binary !-}
356 {-! for CostCentre derive: Binary !-}
360 -- ---------------------------------------------------------------------------
361 -- Reading a binary interface into ParsedIface
363 instance Binary ModIface where
367 mi_iface_hash= iface_hash,
368 mi_mod_hash = mod_hash,
370 mi_finsts = hasFamInsts,
373 mi_exports = exports,
374 mi_exp_hash = exp_hash,
375 mi_fixities = fixities,
376 mi_deprecs = deprecs,
379 mi_fam_insts = fam_insts,
381 mi_orphan_hash = orphan_hash,
382 mi_vect_info = vect_info,
383 mi_hpc = hpc_info }) = do
410 hasFamInsts <- get bh
412 usages <- {-# SCC "bin_usages" #-} lazyGet bh
413 exports <- {-# SCC "bin_exports" #-} get bh
415 fixities <- {-# SCC "bin_fixities" #-} get bh
416 deprecs <- {-# SCC "bin_deprecs" #-} lazyGet bh
417 decls <- {-# SCC "bin_tycldecls" #-} get bh
418 insts <- {-# SCC "bin_insts" #-} get bh
419 fam_insts <- {-# SCC "bin_fam_insts" #-} get bh
420 rules <- {-# SCC "bin_rules" #-} lazyGet bh
421 orphan_hash <- get bh
425 mi_module = mod_name,
427 mi_iface_hash = iface_hash,
428 mi_mod_hash = mod_hash,
430 mi_finsts = hasFamInsts,
433 mi_exports = exports,
434 mi_exp_hash = exp_hash,
435 mi_fixities = fixities,
436 mi_deprecs = deprecs,
438 mi_globals = Nothing,
440 mi_fam_insts = fam_insts,
442 mi_orphan_hash = orphan_hash,
443 mi_vect_info = vect_info,
445 -- And build the cached values
446 mi_dep_fn = mkIfaceDepCache deprecs,
447 mi_fix_fn = mkIfaceFixCache fixities,
448 mi_hash_fn = mkIfaceHashCache decls })
450 getWayDescr :: IO String
452 tag <- readIORef v_Build_tag
453 if cGhcUnregisterised == "YES" then return ('u':tag) else return tag
454 -- if this is an unregisterised build, make sure our interfaces
455 -- can't be used by a registerised build.
457 -------------------------------------------------------------------------
458 -- Types from: HscTypes
459 -------------------------------------------------------------------------
461 instance Binary Dependencies where
462 put_ bh deps = do put_ bh (dep_mods deps)
463 put_ bh (dep_pkgs deps)
464 put_ bh (dep_orphs deps)
465 put_ bh (dep_finsts deps)
467 get bh = do ms <- get bh
471 return (Deps { dep_mods = ms, dep_pkgs = ps, dep_orphs = os,
474 instance (Binary name) => Binary (GenAvailInfo name) where
475 put_ bh (Avail aa) = do
478 put_ bh (AvailTC ab ac) = do
489 return (AvailTC ab ac)
491 instance Binary Usage where
492 put_ bh usg@UsagePackageModule{} = do
494 put_ bh (usg_mod usg)
495 put_ bh (usg_mod_hash usg)
496 put_ bh usg@UsageHomeModule{} = do
498 put_ bh (usg_mod_name usg)
499 put_ bh (usg_mod_hash usg)
500 put_ bh (usg_exports usg)
501 put_ bh (usg_entities usg)
509 return UsagePackageModule { usg_mod = nm, usg_mod_hash = mod }
515 return UsageHomeModule { usg_mod_name = nm, usg_mod_hash = mod,
516 usg_exports = exps, usg_entities = ents }
518 instance Binary Deprecations where
519 put_ bh NoDeprecs = putByte bh 0
520 put_ bh (DeprecAll t) = do
523 put_ bh (DeprecSome ts) = do
530 0 -> return NoDeprecs
532 return (DeprecAll aa)
534 return (DeprecSome aa)
536 -------------------------------------------------------------------------
537 -- Types from: BasicTypes
538 -------------------------------------------------------------------------
540 instance Binary Activation where
541 put_ bh NeverActive = do
543 put_ bh AlwaysActive = do
545 put_ bh (ActiveBefore aa) = do
548 put_ bh (ActiveAfter ab) = do
554 0 -> do return NeverActive
555 1 -> do return AlwaysActive
557 return (ActiveBefore aa)
559 return (ActiveAfter ab)
561 instance Binary StrictnessMark where
562 put_ bh MarkedStrict = do
564 put_ bh MarkedUnboxed = do
566 put_ bh NotMarkedStrict = do
571 0 -> do return MarkedStrict
572 1 -> do return MarkedUnboxed
573 _ -> do return NotMarkedStrict
575 instance Binary Boxity where
584 _ -> do return Unboxed
586 instance Binary TupCon where
587 put_ bh (TupCon ab ac) = do
593 return (TupCon ab ac)
595 instance Binary RecFlag where
596 put_ bh Recursive = do
598 put_ bh NonRecursive = do
603 0 -> do return Recursive
604 _ -> do return NonRecursive
606 instance Binary DefMeth where
607 put_ bh NoDefMeth = putByte bh 0
608 put_ bh DefMeth = putByte bh 1
609 put_ bh GenDefMeth = putByte bh 2
613 0 -> return NoDefMeth
615 _ -> return GenDefMeth
617 instance Binary FixityDirection where
627 0 -> do return InfixL
628 1 -> do return InfixR
629 _ -> do return InfixN
631 instance Binary Fixity where
632 put_ bh (Fixity aa ab) = do
638 return (Fixity aa ab)
640 instance (Binary name) => Binary (IPName name) where
641 put_ bh (IPName aa) = put_ bh aa
642 get bh = do aa <- get bh
645 -------------------------------------------------------------------------
646 -- Types from: Demand
647 -------------------------------------------------------------------------
649 instance Binary DmdType where
650 -- Ignore DmdEnv when spitting out the DmdType
651 put bh (DmdType _ ds dr) = do p <- put bh ds; put bh dr; return (castBin p)
652 get bh = do ds <- get bh; dr <- get bh; return (DmdType emptyVarEnv ds dr)
654 instance Binary Demand where
659 put_ bh (Call aa) = do
662 put_ bh (Eval ab) = do
665 put_ bh (Defer ac) = do
668 put_ bh (Box ad) = do
688 instance Binary Demands where
689 put_ bh (Poly aa) = do
692 put_ bh (Prod ab) = do
703 instance Binary DmdResult where
713 0 -> do return TopRes
714 1 -> do return RetCPR -- Really use RetCPR even if -fcpr-off
715 -- The wrapper was generated for CPR in
716 -- the imported module!
717 _ -> do return BotRes
719 instance Binary StrictSig where
720 put_ bh (StrictSig aa) = do
724 return (StrictSig aa)
727 -------------------------------------------------------------------------
728 -- Types from: CostCentre
729 -------------------------------------------------------------------------
731 instance Binary IsCafCC where
734 put_ bh NotCafCC = do
740 _ -> do return NotCafCC
742 instance Binary IsDupdCC where
743 put_ bh OriginalCC = do
750 0 -> do return OriginalCC
751 _ -> do return DupdCC
753 instance Binary CostCentre where
754 put_ bh NoCostCentre = do
756 put_ bh (NormalCC aa ab ac ad) = do
762 put_ bh (AllCafsCC ae) = do
768 0 -> do return NoCostCentre
773 return (NormalCC aa ab ac ad)
775 return (AllCafsCC ae)
777 -------------------------------------------------------------------------
778 -- IfaceTypes and friends
779 -------------------------------------------------------------------------
781 instance Binary IfaceBndr where
782 put_ bh (IfaceIdBndr aa) = do
785 put_ bh (IfaceTvBndr ab) = do
792 return (IfaceIdBndr aa)
794 return (IfaceTvBndr ab)
796 instance Binary IfaceLetBndr where
797 put_ bh (IfLetBndr a b c) = do
801 get bh = do a <- get bh
804 return (IfLetBndr a b c)
806 instance Binary IfaceType where
807 put_ bh (IfaceForAllTy aa ab) = do
811 put_ bh (IfaceTyVar ad) = do
814 put_ bh (IfaceAppTy ae af) = do
818 put_ bh (IfaceFunTy ag ah) = do
822 put_ bh (IfacePredTy aq) = do
826 -- Simple compression for common cases of TyConApp
827 put_ bh (IfaceTyConApp IfaceIntTc []) = putByte bh 6
828 put_ bh (IfaceTyConApp IfaceCharTc []) = putByte bh 7
829 put_ bh (IfaceTyConApp IfaceBoolTc []) = putByte bh 8
830 put_ bh (IfaceTyConApp IfaceListTc [ty]) = do { putByte bh 9; put_ bh ty }
831 -- Unit tuple and pairs
832 put_ bh (IfaceTyConApp (IfaceTupTc Boxed 0) []) = putByte bh 10
833 put_ bh (IfaceTyConApp (IfaceTupTc Boxed 2) [t1,t2]) = do { putByte bh 11; put_ bh t1; put_ bh t2 }
835 put_ bh (IfaceTyConApp IfaceLiftedTypeKindTc []) = putByte bh 12
836 put_ bh (IfaceTyConApp IfaceOpenTypeKindTc []) = putByte bh 13
837 put_ bh (IfaceTyConApp IfaceUnliftedTypeKindTc []) = putByte bh 14
838 put_ bh (IfaceTyConApp IfaceUbxTupleKindTc []) = putByte bh 15
839 put_ bh (IfaceTyConApp IfaceArgTypeKindTc []) = putByte bh 16
843 put_ bh (IfaceTyConApp (IfaceTc tc) tys) = do { putByte bh 18; put_ bh tc; put_ bh tys }
844 put_ bh (IfaceTyConApp tc tys) = do { putByte bh 19; put_ bh tc; put_ bh tys }
851 return (IfaceForAllTy aa ab)
853 return (IfaceTyVar ad)
856 return (IfaceAppTy ae af)
859 return (IfaceFunTy ag ah)
861 return (IfacePredTy ap)
863 -- Now the special cases for TyConApp
864 6 -> return (IfaceTyConApp IfaceIntTc [])
865 7 -> return (IfaceTyConApp IfaceCharTc [])
866 8 -> return (IfaceTyConApp IfaceBoolTc [])
867 9 -> do { ty <- get bh; return (IfaceTyConApp IfaceListTc [ty]) }
868 10 -> return (IfaceTyConApp (IfaceTupTc Boxed 0) [])
869 11 -> do { t1 <- get bh; t2 <- get bh; return (IfaceTyConApp (IfaceTupTc Boxed 2) [t1,t2]) }
870 12 -> return (IfaceTyConApp IfaceLiftedTypeKindTc [])
871 13 -> return (IfaceTyConApp IfaceOpenTypeKindTc [])
872 14 -> return (IfaceTyConApp IfaceUnliftedTypeKindTc [])
873 15 -> return (IfaceTyConApp IfaceUbxTupleKindTc [])
874 16 -> return (IfaceTyConApp IfaceArgTypeKindTc [])
876 18 -> do { tc <- get bh; tys <- get bh; return (IfaceTyConApp (IfaceTc tc) tys) }
877 _ -> do { tc <- get bh; tys <- get bh; return (IfaceTyConApp tc tys) }
879 instance Binary IfaceTyCon where
880 -- Int,Char,Bool can't show up here because they can't not be saturated
882 put_ bh IfaceIntTc = putByte bh 1
883 put_ bh IfaceBoolTc = putByte bh 2
884 put_ bh IfaceCharTc = putByte bh 3
885 put_ bh IfaceListTc = putByte bh 4
886 put_ bh IfacePArrTc = putByte bh 5
887 put_ bh IfaceLiftedTypeKindTc = putByte bh 6
888 put_ bh IfaceOpenTypeKindTc = putByte bh 7
889 put_ bh IfaceUnliftedTypeKindTc = putByte bh 8
890 put_ bh IfaceUbxTupleKindTc = putByte bh 9
891 put_ bh IfaceArgTypeKindTc = putByte bh 10
892 put_ bh (IfaceTupTc bx ar) = do { putByte bh 11; put_ bh bx; put_ bh ar }
893 put_ bh (IfaceTc ext) = do { putByte bh 12; put_ bh ext }
898 1 -> return IfaceIntTc
899 2 -> return IfaceBoolTc
900 3 -> return IfaceCharTc
901 4 -> return IfaceListTc
902 5 -> return IfacePArrTc
903 6 -> return IfaceLiftedTypeKindTc
904 7 -> return IfaceOpenTypeKindTc
905 8 -> return IfaceUnliftedTypeKindTc
906 9 -> return IfaceUbxTupleKindTc
907 10 -> return IfaceArgTypeKindTc
908 11 -> do { bx <- get bh; ar <- get bh; return (IfaceTupTc bx ar) }
909 _ -> do { ext <- get bh; return (IfaceTc ext) }
911 instance Binary IfacePredType where
912 put_ bh (IfaceClassP aa ab) = do
916 put_ bh (IfaceIParam ac ad) = do
920 put_ bh (IfaceEqPred ac ad) = do
929 return (IfaceClassP aa ab)
932 return (IfaceIParam ac ad)
935 return (IfaceEqPred ac ad)
936 _ -> panic ("get IfacePredType " ++ show h)
938 -------------------------------------------------------------------------
939 -- IfaceExpr and friends
940 -------------------------------------------------------------------------
942 instance Binary IfaceExpr where
943 put_ bh (IfaceLcl aa) = do
946 put_ bh (IfaceType ab) = do
949 put_ bh (IfaceTuple ac ad) = do
953 put_ bh (IfaceLam ae af) = do
957 put_ bh (IfaceApp ag ah) = do
962 put_ bh (IfaceCase ai aj al ak) = do
969 put_ bh (IfaceLet al am) = do
973 put_ bh (IfaceNote an ao) = do
977 put_ bh (IfaceLit ap) = do
980 put_ bh (IfaceFCall as at) = do
984 put_ bh (IfaceExt aa) = do
987 put_ bh (IfaceCast ie ico) = do
991 put_ bh (IfaceTick m ix) = do
1000 1 -> do ab <- get bh
1001 return (IfaceType ab)
1002 2 -> do ac <- get bh
1004 return (IfaceTuple ac ad)
1005 3 -> do ae <- get bh
1007 return (IfaceLam ae af)
1008 4 -> do ag <- get bh
1010 return (IfaceApp ag ah)
1011 5 -> do ai <- get bh
1017 return (IfaceCase ai aj al ak)
1018 6 -> do al <- get bh
1020 return (IfaceLet al am)
1021 7 -> do an <- get bh
1023 return (IfaceNote an ao)
1024 8 -> do ap <- get bh
1025 return (IfaceLit ap)
1026 9 -> do as <- get bh
1028 return (IfaceFCall as at)
1029 10 -> do aa <- get bh
1030 return (IfaceExt aa)
1031 11 -> do ie <- get bh
1033 return (IfaceCast ie ico)
1034 12 -> do m <- get bh
1036 return (IfaceTick m ix)
1037 _ -> panic ("get IfaceExpr " ++ show h)
1039 instance Binary IfaceConAlt where
1040 put_ bh IfaceDefault = do
1042 put_ bh (IfaceDataAlt aa) = do
1045 put_ bh (IfaceTupleAlt ab) = do
1048 put_ bh (IfaceLitAlt ac) = do
1054 0 -> do return IfaceDefault
1055 1 -> do aa <- get bh
1056 return (IfaceDataAlt aa)
1057 2 -> do ab <- get bh
1058 return (IfaceTupleAlt ab)
1059 _ -> do ac <- get bh
1060 return (IfaceLitAlt ac)
1062 instance Binary IfaceBinding where
1063 put_ bh (IfaceNonRec aa ab) = do
1067 put_ bh (IfaceRec ac) = do
1073 0 -> do aa <- get bh
1075 return (IfaceNonRec aa ab)
1076 _ -> do ac <- get bh
1077 return (IfaceRec ac)
1079 instance Binary IfaceIdInfo where
1080 put_ bh NoInfo = putByte bh 0
1081 put_ bh (HasInfo i) = do
1083 lazyPut bh i -- NB lazyPut
1089 _ -> do info <- lazyGet bh -- NB lazyGet
1090 return (HasInfo info)
1092 instance Binary IfaceInfoItem where
1093 put_ bh (HsArity aa) = do
1096 put_ bh (HsStrictness ab) = do
1099 put_ bh (HsUnfold ad) = do
1102 put_ bh (HsInline ad) = do
1105 put_ bh HsNoCafRefs = do
1107 put_ bh (HsWorker ae af) = do
1114 0 -> do aa <- get bh
1116 1 -> do ab <- get bh
1117 return (HsStrictness ab)
1118 2 -> do ad <- get bh
1119 return (HsUnfold ad)
1120 3 -> do ad <- get bh
1121 return (HsInline ad)
1122 4 -> do return HsNoCafRefs
1123 _ -> do ae <- get bh
1125 return (HsWorker ae af)
1127 instance Binary IfaceNote where
1128 put_ bh (IfaceSCC aa) = do
1131 put_ bh IfaceInlineMe = do
1133 put_ bh (IfaceCoreNote s) = do
1139 0 -> do aa <- get bh
1140 return (IfaceSCC aa)
1141 3 -> do return IfaceInlineMe
1142 4 -> do ac <- get bh
1143 return (IfaceCoreNote ac)
1144 _ -> panic ("get IfaceNote " ++ show h)
1146 -------------------------------------------------------------------------
1147 -- IfaceDecl and friends
1148 -------------------------------------------------------------------------
1150 -- A bit of magic going on here: there's no need to store the OccName
1151 -- for a decl on the disk, since we can infer the namespace from the
1152 -- context; however it is useful to have the OccName in the IfaceDecl
1153 -- to avoid re-building it in various places. So we build the OccName
1154 -- when de-serialising.
1156 instance Binary IfaceDecl where
1157 put_ bh (IfaceId name ty idinfo) = do
1159 put_ bh (occNameFS name)
1162 put_ _ (IfaceForeign _ _) =
1163 error "Binary.put_(IfaceDecl): IfaceForeign"
1164 put_ bh (IfaceData a1 a2 a3 a4 a5 a6 a7 a8) = do
1166 put_ bh (occNameFS a1)
1174 put_ bh (IfaceSyn a1 a2 a3 a4 a5) = do
1176 put_ bh (occNameFS a1)
1181 put_ bh (IfaceClass a1 a2 a3 a4 a5 a6 a7) = do
1184 put_ bh (occNameFS a2)
1193 0 -> do name <- get bh
1196 occ <- return $! mkOccNameFS varName name
1197 return (IfaceId occ ty idinfo)
1198 1 -> error "Binary.get(TyClDecl): ForeignType"
1208 occ <- return $! mkOccNameFS tcName a1
1209 return (IfaceData occ a2 a3 a4 a5 a6 a7 a8)
1216 occ <- return $! mkOccNameFS tcName a1
1217 return (IfaceSyn occ a2 a3 a4 a5)
1226 occ <- return $! mkOccNameFS clsName a2
1227 return (IfaceClass a1 occ a3 a4 a5 a6 a7)
1229 instance Binary IfaceInst where
1230 put_ bh (IfaceInst cls tys dfun flag orph) = do
1236 get bh = do cls <- get bh
1241 return (IfaceInst cls tys dfun flag orph)
1243 instance Binary IfaceFamInst where
1244 put_ bh (IfaceFamInst fam tys tycon) = do
1248 get bh = do fam <- get bh
1251 return (IfaceFamInst fam tys tycon)
1253 instance Binary OverlapFlag where
1254 put_ bh NoOverlap = putByte bh 0
1255 put_ bh OverlapOk = putByte bh 1
1256 put_ bh Incoherent = putByte bh 2
1257 get bh = do h <- getByte bh
1259 0 -> return NoOverlap
1260 1 -> return OverlapOk
1261 2 -> return Incoherent
1262 _ -> panic ("get OverlapFlag " ++ show h)
1264 instance Binary IfaceConDecls where
1265 put_ bh IfAbstractTyCon = putByte bh 0
1266 put_ bh IfOpenDataTyCon = putByte bh 1
1267 put_ bh (IfDataTyCon cs) = do { putByte bh 2
1269 put_ bh (IfNewTyCon c) = do { putByte bh 3
1274 0 -> return IfAbstractTyCon
1275 1 -> return IfOpenDataTyCon
1276 2 -> do cs <- get bh
1277 return (IfDataTyCon cs)
1278 _ -> do aa <- get bh
1279 return (IfNewTyCon aa)
1281 instance Binary IfaceConDecl where
1282 put_ bh (IfCon a1 a2 a3 a4 a5 a6 a7 a8 a9) = do
1292 get bh = do a1 <- get bh
1301 return (IfCon a1 a2 a3 a4 a5 a6 a7 a8 a9)
1303 instance Binary IfaceClassOp where
1304 put_ bh (IfaceClassOp n def ty) = do
1305 put_ bh (occNameFS n)
1312 occ <- return $! mkOccNameFS varName n
1313 return (IfaceClassOp occ def ty)
1315 instance Binary IfaceRule where
1316 put_ bh (IfaceRule a1 a2 a3 a4 a5 a6 a7) = do
1332 return (IfaceRule a1 a2 a3 a4 a5 a6 a7)
1334 instance Binary IfaceVectInfo where
1335 put_ bh (IfaceVectInfo a1 a2 a3) = do
1343 return (IfaceVectInfo a1 a2 a3)