3 -- (c) The University of Glasgow 2002-2006
5 -- Binary interface file support.
7 module BinIface ( writeBinIface, readBinIface,
8 CheckHiWay(..), TraceBinIFaceReading(..) ) where
10 #include "HsVersions.h"
43 import Control.Exception
46 data CheckHiWay = CheckHiWay | IgnoreHiWay
49 data TraceBinIFaceReading = TraceBinIFaceReading | QuietBinIFaceReading
52 -- ---------------------------------------------------------------------------
53 -- Reading and writing binary interface files
55 readBinIface :: CheckHiWay -> TraceBinIFaceReading -> FilePath
56 -> TcRnIf a b ModIface
57 readBinIface checkHiWay traceBinIFaceReading hi_path = do
59 (new_nc, iface) <- liftIO $
60 readBinIface_ checkHiWay traceBinIFaceReading hi_path nc
64 readBinIface_ :: CheckHiWay -> TraceBinIFaceReading -> FilePath -> NameCache
65 -> IO (NameCache, ModIface)
66 readBinIface_ checkHiWay traceBinIFaceReading hi_path nc = do
67 let printer :: SDoc -> IO ()
68 printer = case traceBinIFaceReading of
69 TraceBinIFaceReading -> \sd -> printSDoc sd defaultDumpStyle
70 QuietBinIFaceReading -> \_ -> return ()
71 wantedGot :: Outputable a => String -> a -> a -> IO ()
72 wantedGot what wanted got
73 = printer (text what <> text ": " <>
74 vcat [text "Wanted " <> ppr wanted <> text ",",
75 text "got " <> ppr got])
77 errorOnMismatch :: (Eq a, Show a) => String -> a -> a -> IO ()
78 errorOnMismatch what wanted got
79 -- This will be caught by readIface which will emit an error
80 -- msg containing the iface module name.
81 = when (wanted /= got) $ throwDyn $ ProgramError
82 (what ++ " (wanted " ++ show wanted
83 ++ ", got " ++ show got ++ ")")
84 bh <- Binary.readBinMem hi_path
86 -- Read the magic number to check that this really is a GHC .hi file
87 -- (This magic number does not change when we change
88 -- GHC interface file format)
90 wantedGot "Magic" binaryInterfaceMagic magic
91 errorOnMismatch "magic number mismatch: old/corrupt interface file?"
92 binaryInterfaceMagic magic
94 -- Get the dictionary pointer. We won't attempt to actually
95 -- read the dictionary until we've done the version checks below,
96 -- just in case this isn't a valid interface. In retrospect the
97 -- version should have come before the dictionary pointer, but this
98 -- is the way it was done originally, and we can't change it now.
99 dict_p <- Binary.get bh -- Get the dictionary ptr
101 -- Check the interface file version and ways.
103 let our_ver = show opt_HiVersion
104 wantedGot "Version" our_ver check_ver
105 errorOnMismatch "mismatched interface file versions" our_ver check_ver
108 way_descr <- getWayDescr
109 wantedGot "Way" way_descr check_way
110 when (checkHiWay == CheckHiWay) $
111 errorOnMismatch "mismatched interface file ways" way_descr check_way
113 -- Read the dictionary
114 -- The next word in the file is a pointer to where the dictionary is
115 -- (probably at the end of the file)
116 data_p <- tellBin bh -- Remember where we are now
118 dict <- getDictionary bh
119 seekBin bh data_p -- Back to where we were before
121 -- Initialise the user-data field of bh
122 ud <- newReadState dict
123 bh <- return (setUserData bh ud)
125 symtab_p <- Binary.get bh -- Get the symtab ptr
126 data_p <- tellBin bh -- Remember where we are now
128 (nc', symtab) <- getSymbolTable bh nc
129 seekBin bh data_p -- Back to where we were before
130 let ud = getUserData bh
131 bh <- return $! setUserData bh ud{ud_symtab = symtab}
136 writeBinIface :: DynFlags -> FilePath -> ModIface -> IO ()
137 writeBinIface dflags hi_path mod_iface = do
138 bh <- openBinMem initBinMemSize
139 put_ bh binaryInterfaceMagic
141 -- Remember where the dictionary pointer will go
142 dict_p_p <- tellBin bh
143 put_ bh dict_p_p -- Placeholder for ptr to dictionary
145 -- The version and way descriptor go next
146 put_ bh (show opt_HiVersion)
147 way_descr <- getWayDescr
150 -- Remember where the symbol table pointer will go
151 symtab_p_p <- tellBin bh
154 -- Make some intial state
155 symtab_next <- newFastMutInt
156 writeFastMutInt symtab_next 0
157 symtab_map <- newIORef emptyUFM
158 let bin_symtab = BinSymbolTable {
159 bin_symtab_next = symtab_next,
160 bin_symtab_map = symtab_map }
161 dict_next_ref <- newFastMutInt
162 writeFastMutInt dict_next_ref 0
163 dict_map_ref <- newIORef emptyUFM
164 let bin_dict = BinDictionary {
165 bin_dict_next = dict_next_ref,
166 bin_dict_map = dict_map_ref }
167 ud <- newWriteState (putName bin_symtab) (putFastString bin_dict)
169 -- Put the main thing,
170 bh <- return $ setUserData bh ud
173 -- Write the symtab pointer at the fornt of the file
174 symtab_p <- tellBin bh -- This is where the symtab will start
175 putAt bh symtab_p_p symtab_p -- Fill in the placeholder
176 seekBin bh symtab_p -- Seek back to the end of the file
178 -- Write the symbol table itself
179 symtab_next <- readFastMutInt symtab_next
180 symtab_map <- readIORef symtab_map
181 putSymbolTable bh symtab_next symtab_map
182 debugTraceMsg dflags 3 (text "writeBinIface:" <+> int symtab_next
185 -- NB. write the dictionary after the symbol table, because
186 -- writing the symbol table may create more dictionary entries.
188 -- Write the dictionary pointer at the fornt of the file
189 dict_p <- tellBin bh -- This is where the dictionary will start
190 putAt bh dict_p_p dict_p -- Fill in the placeholder
191 seekBin bh dict_p -- Seek back to the end of the file
193 -- Write the dictionary itself
194 dict_next <- readFastMutInt dict_next_ref
195 dict_map <- readIORef dict_map_ref
196 putDictionary bh dict_next dict_map
197 debugTraceMsg dflags 3 (text "writeBinIface:" <+> int dict_next
198 <+> text "dict entries")
200 -- And send the result to the file
201 writeBinMem bh hi_path
203 initBinMemSize :: Int
204 initBinMemSize = 1024 * 1024
206 -- The *host* architecture version:
207 #include "MachDeps.h"
209 binaryInterfaceMagic :: Word32
210 #if WORD_SIZE_IN_BITS == 32
211 binaryInterfaceMagic = 0x1face
212 #elif WORD_SIZE_IN_BITS == 64
213 binaryInterfaceMagic = 0x1face64
216 -- -----------------------------------------------------------------------------
219 putSymbolTable :: BinHandle -> Int -> UniqFM (Int,Name) -> IO ()
220 putSymbolTable bh next_off symtab = do
222 let names = elems (array (0,next_off-1) (eltsUFM symtab))
223 mapM_ (\n -> serialiseName bh n symtab) names
225 getSymbolTable :: BinHandle -> NameCache -> IO (NameCache, Array Int Name)
226 getSymbolTable bh namecache = do
228 od_names <- sequence (replicate sz (get bh))
230 arr = listArray (0,sz-1) names
231 (namecache', names) =
232 mapAccumR (fromOnDiskName arr) namecache od_names
234 return (namecache', arr)
236 type OnDiskName = (PackageId, ModuleName, OccName)
243 fromOnDiskName _ nc (pid, mod_name, occ) =
245 mod = mkModule pid mod_name
248 case lookupOrigNameCache cache mod occ of
249 Just name -> (nc, name)
253 uniq = uniqFromSupply us
254 name = mkExternalName uniq mod occ noSrcSpan
255 new_cache = extendNameCache cache mod occ name
257 case splitUniqSupply us of { (us',_) ->
258 ( nc{ nsUniqs = us', nsNames = new_cache }, name )
261 serialiseName :: BinHandle -> Name -> UniqFM (Int,Name) -> IO ()
262 serialiseName bh name _ = do
263 let mod = nameModule name
264 put_ bh (modulePackageId mod, moduleName mod, nameOccName name)
267 putName :: BinSymbolTable -> BinHandle -> Name -> IO ()
268 putName BinSymbolTable{
269 bin_symtab_map = symtab_map_ref,
270 bin_symtab_next = symtab_next } bh name
272 symtab_map <- readIORef symtab_map_ref
273 case lookupUFM symtab_map name of
274 Just (off,_) -> put_ bh off
276 off <- readFastMutInt symtab_next
277 writeFastMutInt symtab_next (off+1)
278 writeIORef symtab_map_ref
279 $! addToUFM symtab_map name (off,name)
283 data BinSymbolTable = BinSymbolTable {
284 bin_symtab_next :: !FastMutInt, -- The next index to use
285 bin_symtab_map :: !(IORef (UniqFM (Int,Name)))
290 putFastString :: BinDictionary -> BinHandle -> FastString -> IO ()
291 putFastString BinDictionary { bin_dict_next = j_r,
292 bin_dict_map = out_r} bh f
294 out <- readIORef out_r
295 let uniq = getUnique f
296 case lookupUFM out uniq of
297 Just (j, _) -> put_ bh j
299 j <- readFastMutInt j_r
301 writeFastMutInt j_r (j + 1)
302 writeIORef out_r $! addToUFM out uniq (j, f)
305 data BinDictionary = BinDictionary {
306 bin_dict_next :: !FastMutInt, -- The next index to use
307 bin_dict_map :: !(IORef (UniqFM (Int,FastString)))
308 -- indexed by FastString
311 -- -----------------------------------------------------------------------------
312 -- All the binary instances
315 {-! for IPName derive: Binary !-}
316 {-! for Fixity derive: Binary !-}
317 {-! for FixityDirection derive: Binary !-}
318 {-! for Boxity derive: Binary !-}
319 {-! for StrictnessMark derive: Binary !-}
320 {-! for Activation derive: Binary !-}
323 {-! for Demand derive: Binary !-}
324 {-! for Demands derive: Binary !-}
325 {-! for DmdResult derive: Binary !-}
326 {-! for StrictSig derive: Binary !-}
329 {-! for DefMeth derive: Binary !-}
332 {-! for HsPred derive: Binary !-}
333 {-! for HsType derive: Binary !-}
334 {-! for TupCon derive: Binary !-}
335 {-! for HsTyVarBndr derive: Binary !-}
338 {-! for UfExpr derive: Binary !-}
339 {-! for UfConAlt derive: Binary !-}
340 {-! for UfBinding derive: Binary !-}
341 {-! for UfBinder derive: Binary !-}
342 {-! for HsIdInfo derive: Binary !-}
343 {-! for UfNote derive: Binary !-}
346 {-! for ConDetails derive: Binary !-}
347 {-! for BangType derive: Binary !-}
350 {-! for IsCafCC derive: Binary !-}
351 {-! for IsDupdCC derive: Binary !-}
352 {-! for CostCentre derive: Binary !-}
356 -- ---------------------------------------------------------------------------
357 -- Reading a binary interface into ParsedIface
359 instance Binary ModIface where
363 mi_iface_hash= iface_hash,
364 mi_mod_hash = mod_hash,
366 mi_finsts = hasFamInsts,
369 mi_exports = exports,
370 mi_exp_hash = exp_hash,
371 mi_fixities = fixities,
372 mi_deprecs = deprecs,
375 mi_fam_insts = fam_insts,
377 mi_orphan_hash = orphan_hash,
378 mi_vect_info = vect_info,
379 mi_hpc = hpc_info }) = do
406 hasFamInsts <- get bh
408 usages <- {-# SCC "bin_usages" #-} lazyGet bh
409 exports <- {-# SCC "bin_exports" #-} get bh
411 fixities <- {-# SCC "bin_fixities" #-} get bh
412 deprecs <- {-# SCC "bin_deprecs" #-} lazyGet bh
413 decls <- {-# SCC "bin_tycldecls" #-} get bh
414 insts <- {-# SCC "bin_insts" #-} get bh
415 fam_insts <- {-# SCC "bin_fam_insts" #-} get bh
416 rules <- {-# SCC "bin_rules" #-} lazyGet bh
417 orphan_hash <- get bh
421 mi_module = mod_name,
423 mi_iface_hash = iface_hash,
424 mi_mod_hash = mod_hash,
426 mi_finsts = hasFamInsts,
429 mi_exports = exports,
430 mi_exp_hash = exp_hash,
431 mi_fixities = fixities,
432 mi_deprecs = deprecs,
434 mi_globals = Nothing,
436 mi_fam_insts = fam_insts,
438 mi_orphan_hash = orphan_hash,
439 mi_vect_info = vect_info,
441 -- And build the cached values
442 mi_dep_fn = mkIfaceDepCache deprecs,
443 mi_fix_fn = mkIfaceFixCache fixities,
444 mi_hash_fn = mkIfaceHashCache decls })
446 getWayDescr :: IO String
448 tag <- readIORef v_Build_tag
449 if cGhcUnregisterised == "YES" then return ('u':tag) else return tag
450 -- if this is an unregisterised build, make sure our interfaces
451 -- can't be used by a registerised build.
453 -------------------------------------------------------------------------
454 -- Types from: HscTypes
455 -------------------------------------------------------------------------
457 instance Binary Dependencies where
458 put_ bh deps = do put_ bh (dep_mods deps)
459 put_ bh (dep_pkgs deps)
460 put_ bh (dep_orphs deps)
461 put_ bh (dep_finsts deps)
463 get bh = do ms <- get bh
467 return (Deps { dep_mods = ms, dep_pkgs = ps, dep_orphs = os,
470 instance (Binary name) => Binary (GenAvailInfo name) where
471 put_ bh (Avail aa) = do
474 put_ bh (AvailTC ab ac) = do
485 return (AvailTC ab ac)
487 instance Binary Usage where
488 put_ bh usg@UsagePackageModule{} = do
490 put_ bh (usg_mod usg)
491 put_ bh (usg_mod_hash usg)
492 put_ bh usg@UsageHomeModule{} = do
494 put_ bh (usg_mod_name usg)
495 put_ bh (usg_mod_hash usg)
496 put_ bh (usg_exports usg)
497 put_ bh (usg_entities usg)
505 return UsagePackageModule { usg_mod = nm, usg_mod_hash = mod }
511 return UsageHomeModule { usg_mod_name = nm, usg_mod_hash = mod,
512 usg_exports = exps, usg_entities = ents }
514 instance Binary Deprecations where
515 put_ bh NoDeprecs = putByte bh 0
516 put_ bh (DeprecAll t) = do
519 put_ bh (DeprecSome ts) = do
526 0 -> return NoDeprecs
528 return (DeprecAll aa)
530 return (DeprecSome aa)
532 -------------------------------------------------------------------------
533 -- Types from: BasicTypes
534 -------------------------------------------------------------------------
536 instance Binary Activation where
537 put_ bh NeverActive = do
539 put_ bh AlwaysActive = do
541 put_ bh (ActiveBefore aa) = do
544 put_ bh (ActiveAfter ab) = do
550 0 -> do return NeverActive
551 1 -> do return AlwaysActive
553 return (ActiveBefore aa)
555 return (ActiveAfter ab)
557 instance Binary StrictnessMark where
558 put_ bh MarkedStrict = do
560 put_ bh MarkedUnboxed = do
562 put_ bh NotMarkedStrict = do
567 0 -> do return MarkedStrict
568 1 -> do return MarkedUnboxed
569 _ -> do return NotMarkedStrict
571 instance Binary Boxity where
580 _ -> do return Unboxed
582 instance Binary TupCon where
583 put_ bh (TupCon ab ac) = do
589 return (TupCon ab ac)
591 instance Binary RecFlag where
592 put_ bh Recursive = do
594 put_ bh NonRecursive = do
599 0 -> do return Recursive
600 _ -> do return NonRecursive
602 instance Binary DefMeth where
603 put_ bh NoDefMeth = putByte bh 0
604 put_ bh DefMeth = putByte bh 1
605 put_ bh GenDefMeth = putByte bh 2
609 0 -> return NoDefMeth
611 _ -> return GenDefMeth
613 instance Binary FixityDirection where
623 0 -> do return InfixL
624 1 -> do return InfixR
625 _ -> do return InfixN
627 instance Binary Fixity where
628 put_ bh (Fixity aa ab) = do
634 return (Fixity aa ab)
636 instance (Binary name) => Binary (IPName name) where
637 put_ bh (IPName aa) = put_ bh aa
638 get bh = do aa <- get bh
641 -------------------------------------------------------------------------
642 -- Types from: Demand
643 -------------------------------------------------------------------------
645 instance Binary DmdType where
646 -- Ignore DmdEnv when spitting out the DmdType
647 put bh (DmdType _ ds dr) = do p <- put bh ds; put bh dr; return (castBin p)
648 get bh = do ds <- get bh; dr <- get bh; return (DmdType emptyVarEnv ds dr)
650 instance Binary Demand where
655 put_ bh (Call aa) = do
658 put_ bh (Eval ab) = do
661 put_ bh (Defer ac) = do
664 put_ bh (Box ad) = do
684 instance Binary Demands where
685 put_ bh (Poly aa) = do
688 put_ bh (Prod ab) = do
699 instance Binary DmdResult where
709 0 -> do return TopRes
710 1 -> do return RetCPR -- Really use RetCPR even if -fcpr-off
711 -- The wrapper was generated for CPR in
712 -- the imported module!
713 _ -> do return BotRes
715 instance Binary StrictSig where
716 put_ bh (StrictSig aa) = do
720 return (StrictSig aa)
723 -------------------------------------------------------------------------
724 -- Types from: CostCentre
725 -------------------------------------------------------------------------
727 instance Binary IsCafCC where
730 put_ bh NotCafCC = do
736 _ -> do return NotCafCC
738 instance Binary IsDupdCC where
739 put_ bh OriginalCC = do
746 0 -> do return OriginalCC
747 _ -> do return DupdCC
749 instance Binary CostCentre where
750 put_ bh NoCostCentre = do
752 put_ bh (NormalCC aa ab ac ad) = do
758 put_ bh (AllCafsCC ae) = do
764 0 -> do return NoCostCentre
769 return (NormalCC aa ab ac ad)
771 return (AllCafsCC ae)
773 -------------------------------------------------------------------------
774 -- IfaceTypes and friends
775 -------------------------------------------------------------------------
777 instance Binary IfaceBndr where
778 put_ bh (IfaceIdBndr aa) = do
781 put_ bh (IfaceTvBndr ab) = do
788 return (IfaceIdBndr aa)
790 return (IfaceTvBndr ab)
792 instance Binary IfaceLetBndr where
793 put_ bh (IfLetBndr a b c) = do
797 get bh = do a <- get bh
800 return (IfLetBndr a b c)
802 instance Binary IfaceType where
803 put_ bh (IfaceForAllTy aa ab) = do
807 put_ bh (IfaceTyVar ad) = do
810 put_ bh (IfaceAppTy ae af) = do
814 put_ bh (IfaceFunTy ag ah) = do
818 put_ bh (IfacePredTy aq) = do
822 -- Simple compression for common cases of TyConApp
823 put_ bh (IfaceTyConApp IfaceIntTc []) = putByte bh 6
824 put_ bh (IfaceTyConApp IfaceCharTc []) = putByte bh 7
825 put_ bh (IfaceTyConApp IfaceBoolTc []) = putByte bh 8
826 put_ bh (IfaceTyConApp IfaceListTc [ty]) = do { putByte bh 9; put_ bh ty }
827 -- Unit tuple and pairs
828 put_ bh (IfaceTyConApp (IfaceTupTc Boxed 0) []) = putByte bh 10
829 put_ bh (IfaceTyConApp (IfaceTupTc Boxed 2) [t1,t2]) = do { putByte bh 11; put_ bh t1; put_ bh t2 }
831 put_ bh (IfaceTyConApp IfaceLiftedTypeKindTc []) = putByte bh 12
832 put_ bh (IfaceTyConApp IfaceOpenTypeKindTc []) = putByte bh 13
833 put_ bh (IfaceTyConApp IfaceUnliftedTypeKindTc []) = putByte bh 14
834 put_ bh (IfaceTyConApp IfaceUbxTupleKindTc []) = putByte bh 15
835 put_ bh (IfaceTyConApp IfaceArgTypeKindTc []) = putByte bh 16
839 put_ bh (IfaceTyConApp (IfaceTc tc) tys) = do { putByte bh 18; put_ bh tc; put_ bh tys }
840 put_ bh (IfaceTyConApp tc tys) = do { putByte bh 19; put_ bh tc; put_ bh tys }
847 return (IfaceForAllTy aa ab)
849 return (IfaceTyVar ad)
852 return (IfaceAppTy ae af)
855 return (IfaceFunTy ag ah)
857 return (IfacePredTy ap)
859 -- Now the special cases for TyConApp
860 6 -> return (IfaceTyConApp IfaceIntTc [])
861 7 -> return (IfaceTyConApp IfaceCharTc [])
862 8 -> return (IfaceTyConApp IfaceBoolTc [])
863 9 -> do { ty <- get bh; return (IfaceTyConApp IfaceListTc [ty]) }
864 10 -> return (IfaceTyConApp (IfaceTupTc Boxed 0) [])
865 11 -> do { t1 <- get bh; t2 <- get bh; return (IfaceTyConApp (IfaceTupTc Boxed 2) [t1,t2]) }
866 12 -> return (IfaceTyConApp IfaceLiftedTypeKindTc [])
867 13 -> return (IfaceTyConApp IfaceOpenTypeKindTc [])
868 14 -> return (IfaceTyConApp IfaceUnliftedTypeKindTc [])
869 15 -> return (IfaceTyConApp IfaceUbxTupleKindTc [])
870 16 -> return (IfaceTyConApp IfaceArgTypeKindTc [])
872 18 -> do { tc <- get bh; tys <- get bh; return (IfaceTyConApp (IfaceTc tc) tys) }
873 _ -> do { tc <- get bh; tys <- get bh; return (IfaceTyConApp tc tys) }
875 instance Binary IfaceTyCon where
876 -- Int,Char,Bool can't show up here because they can't not be saturated
878 put_ bh IfaceIntTc = putByte bh 1
879 put_ bh IfaceBoolTc = putByte bh 2
880 put_ bh IfaceCharTc = putByte bh 3
881 put_ bh IfaceListTc = putByte bh 4
882 put_ bh IfacePArrTc = putByte bh 5
883 put_ bh IfaceLiftedTypeKindTc = putByte bh 6
884 put_ bh IfaceOpenTypeKindTc = putByte bh 7
885 put_ bh IfaceUnliftedTypeKindTc = putByte bh 8
886 put_ bh IfaceUbxTupleKindTc = putByte bh 9
887 put_ bh IfaceArgTypeKindTc = putByte bh 10
888 put_ bh (IfaceTupTc bx ar) = do { putByte bh 11; put_ bh bx; put_ bh ar }
889 put_ bh (IfaceTc ext) = do { putByte bh 12; put_ bh ext }
894 1 -> return IfaceIntTc
895 2 -> return IfaceBoolTc
896 3 -> return IfaceCharTc
897 4 -> return IfaceListTc
898 5 -> return IfacePArrTc
899 6 -> return IfaceLiftedTypeKindTc
900 7 -> return IfaceOpenTypeKindTc
901 8 -> return IfaceUnliftedTypeKindTc
902 9 -> return IfaceUbxTupleKindTc
903 10 -> return IfaceArgTypeKindTc
904 11 -> do { bx <- get bh; ar <- get bh; return (IfaceTupTc bx ar) }
905 _ -> do { ext <- get bh; return (IfaceTc ext) }
907 instance Binary IfacePredType where
908 put_ bh (IfaceClassP aa ab) = do
912 put_ bh (IfaceIParam ac ad) = do
916 put_ bh (IfaceEqPred ac ad) = do
925 return (IfaceClassP aa ab)
928 return (IfaceIParam ac ad)
931 return (IfaceEqPred ac ad)
932 _ -> panic ("get IfacePredType " ++ show h)
934 -------------------------------------------------------------------------
935 -- IfaceExpr and friends
936 -------------------------------------------------------------------------
938 instance Binary IfaceExpr where
939 put_ bh (IfaceLcl aa) = do
942 put_ bh (IfaceType ab) = do
945 put_ bh (IfaceTuple ac ad) = do
949 put_ bh (IfaceLam ae af) = do
953 put_ bh (IfaceApp ag ah) = do
958 put_ bh (IfaceCase ai aj al ak) = do
965 put_ bh (IfaceLet al am) = do
969 put_ bh (IfaceNote an ao) = do
973 put_ bh (IfaceLit ap) = do
976 put_ bh (IfaceFCall as at) = do
980 put_ bh (IfaceExt aa) = do
983 put_ bh (IfaceCast ie ico) = do
987 put_ bh (IfaceTick m ix) = do
997 return (IfaceType ab)
1000 return (IfaceTuple ac ad)
1001 3 -> do ae <- get bh
1003 return (IfaceLam ae af)
1004 4 -> do ag <- get bh
1006 return (IfaceApp ag ah)
1007 5 -> do ai <- get bh
1013 return (IfaceCase ai aj al ak)
1014 6 -> do al <- get bh
1016 return (IfaceLet al am)
1017 7 -> do an <- get bh
1019 return (IfaceNote an ao)
1020 8 -> do ap <- get bh
1021 return (IfaceLit ap)
1022 9 -> do as <- get bh
1024 return (IfaceFCall as at)
1025 10 -> do aa <- get bh
1026 return (IfaceExt aa)
1027 11 -> do ie <- get bh
1029 return (IfaceCast ie ico)
1030 12 -> do m <- get bh
1032 return (IfaceTick m ix)
1033 _ -> panic ("get IfaceExpr " ++ show h)
1035 instance Binary IfaceConAlt where
1036 put_ bh IfaceDefault = do
1038 put_ bh (IfaceDataAlt aa) = do
1041 put_ bh (IfaceTupleAlt ab) = do
1044 put_ bh (IfaceLitAlt ac) = do
1050 0 -> do return IfaceDefault
1051 1 -> do aa <- get bh
1052 return (IfaceDataAlt aa)
1053 2 -> do ab <- get bh
1054 return (IfaceTupleAlt ab)
1055 _ -> do ac <- get bh
1056 return (IfaceLitAlt ac)
1058 instance Binary IfaceBinding where
1059 put_ bh (IfaceNonRec aa ab) = do
1063 put_ bh (IfaceRec ac) = do
1069 0 -> do aa <- get bh
1071 return (IfaceNonRec aa ab)
1072 _ -> do ac <- get bh
1073 return (IfaceRec ac)
1075 instance Binary IfaceIdInfo where
1076 put_ bh NoInfo = putByte bh 0
1077 put_ bh (HasInfo i) = do
1079 lazyPut bh i -- NB lazyPut
1085 _ -> do info <- lazyGet bh -- NB lazyGet
1086 return (HasInfo info)
1088 instance Binary IfaceInfoItem where
1089 put_ bh (HsArity aa) = do
1092 put_ bh (HsStrictness ab) = do
1095 put_ bh (HsUnfold ad) = do
1098 put_ bh (HsInline ad) = do
1101 put_ bh HsNoCafRefs = do
1103 put_ bh (HsWorker ae af) = do
1110 0 -> do aa <- get bh
1112 1 -> do ab <- get bh
1113 return (HsStrictness ab)
1114 2 -> do ad <- get bh
1115 return (HsUnfold ad)
1116 3 -> do ad <- get bh
1117 return (HsInline ad)
1118 4 -> do return HsNoCafRefs
1119 _ -> do ae <- get bh
1121 return (HsWorker ae af)
1123 instance Binary IfaceNote where
1124 put_ bh (IfaceSCC aa) = do
1127 put_ bh IfaceInlineMe = do
1129 put_ bh (IfaceCoreNote s) = do
1135 0 -> do aa <- get bh
1136 return (IfaceSCC aa)
1137 3 -> do return IfaceInlineMe
1138 4 -> do ac <- get bh
1139 return (IfaceCoreNote ac)
1140 _ -> panic ("get IfaceNote " ++ show h)
1142 -------------------------------------------------------------------------
1143 -- IfaceDecl and friends
1144 -------------------------------------------------------------------------
1146 -- A bit of magic going on here: there's no need to store the OccName
1147 -- for a decl on the disk, since we can infer the namespace from the
1148 -- context; however it is useful to have the OccName in the IfaceDecl
1149 -- to avoid re-building it in various places. So we build the OccName
1150 -- when de-serialising.
1152 instance Binary IfaceDecl where
1153 put_ bh (IfaceId name ty idinfo) = do
1155 put_ bh (occNameFS name)
1158 put_ _ (IfaceForeign _ _) =
1159 error "Binary.put_(IfaceDecl): IfaceForeign"
1160 put_ bh (IfaceData a1 a2 a3 a4 a5 a6 a7 a8) = do
1162 put_ bh (occNameFS a1)
1170 put_ bh (IfaceSyn a1 a2 a3 a4 a5) = do
1172 put_ bh (occNameFS a1)
1177 put_ bh (IfaceClass a1 a2 a3 a4 a5 a6 a7) = do
1180 put_ bh (occNameFS a2)
1189 0 -> do name <- get bh
1192 occ <- return $! mkOccNameFS varName name
1193 return (IfaceId occ ty idinfo)
1194 1 -> error "Binary.get(TyClDecl): ForeignType"
1204 occ <- return $! mkOccNameFS tcName a1
1205 return (IfaceData occ a2 a3 a4 a5 a6 a7 a8)
1212 occ <- return $! mkOccNameFS tcName a1
1213 return (IfaceSyn occ a2 a3 a4 a5)
1222 occ <- return $! mkOccNameFS clsName a2
1223 return (IfaceClass a1 occ a3 a4 a5 a6 a7)
1225 instance Binary IfaceInst where
1226 put_ bh (IfaceInst cls tys dfun flag orph) = do
1232 get bh = do cls <- get bh
1237 return (IfaceInst cls tys dfun flag orph)
1239 instance Binary IfaceFamInst where
1240 put_ bh (IfaceFamInst fam tys tycon) = do
1244 get bh = do fam <- get bh
1247 return (IfaceFamInst fam tys tycon)
1249 instance Binary OverlapFlag where
1250 put_ bh NoOverlap = putByte bh 0
1251 put_ bh OverlapOk = putByte bh 1
1252 put_ bh Incoherent = putByte bh 2
1253 get bh = do h <- getByte bh
1255 0 -> return NoOverlap
1256 1 -> return OverlapOk
1257 2 -> return Incoherent
1258 _ -> panic ("get OverlapFlag " ++ show h)
1260 instance Binary IfaceConDecls where
1261 put_ bh IfAbstractTyCon = putByte bh 0
1262 put_ bh IfOpenDataTyCon = putByte bh 1
1263 put_ bh (IfDataTyCon cs) = do { putByte bh 2
1265 put_ bh (IfNewTyCon c) = do { putByte bh 3
1270 0 -> return IfAbstractTyCon
1271 1 -> return IfOpenDataTyCon
1272 2 -> do cs <- get bh
1273 return (IfDataTyCon cs)
1274 _ -> do aa <- get bh
1275 return (IfNewTyCon aa)
1277 instance Binary IfaceConDecl where
1278 put_ bh (IfCon a1 a2 a3 a4 a5 a6 a7 a8 a9) = do
1288 get bh = do a1 <- get bh
1297 return (IfCon a1 a2 a3 a4 a5 a6 a7 a8 a9)
1299 instance Binary IfaceClassOp where
1300 put_ bh (IfaceClassOp n def ty) = do
1301 put_ bh (occNameFS n)
1308 occ <- return $! mkOccNameFS varName n
1309 return (IfaceClassOp occ def ty)
1311 instance Binary IfaceRule where
1312 put_ bh (IfaceRule a1 a2 a3 a4 a5 a6 a7) = do
1328 return (IfaceRule a1 a2 a3 a4 a5 a6 a7)
1330 instance Binary IfaceVectInfo where
1331 put_ bh (IfaceVectInfo a1 a2 a3) = do
1339 return (IfaceVectInfo a1 a2 a3)