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])
76 errorOnMismatch :: (Eq a, Show a) => String -> a -> a -> IO ()
77 errorOnMismatch what wanted got
78 -- This will be caught by readIface which will emit an error
79 -- msg containing the iface module name.
80 = when (wanted /= got) $ throwDyn $ ProgramError
81 (what ++ " (wanted " ++ show wanted
82 ++ ", got " ++ show got ++ ")")
83 bh <- Binary.readBinMem hi_path
85 -- Read the magic number to check that this really is a GHC .hi file
86 -- (This magic number does not change when we change
87 -- GHC interface file format)
89 wantedGot "Magic" binaryInterfaceMagic magic
90 errorOnMismatch "magic number mismatch: old/corrupt interface file?"
91 binaryInterfaceMagic magic
93 -- Get the dictionary pointer. We won't attempt to actually
94 -- read the dictionary until we've done the version checks below,
95 -- just in case this isn't a valid interface. In retrospect the
96 -- version should have come before the dictionary pointer, but this
97 -- is the way it was done originally, and we can't change it now.
98 dict_p <- Binary.get bh -- Get the dictionary ptr
100 -- Check the interface file version and ways.
102 let our_ver = show opt_HiVersion
103 wantedGot "Version" our_ver check_ver
104 errorOnMismatch "mismatched interface file versions" our_ver check_ver
107 way_descr <- getWayDescr
108 wantedGot "Way" way_descr check_way
109 when (checkHiWay == CheckHiWay) $
110 errorOnMismatch "mismatched interface file ways" way_descr check_way
112 -- Read the dictionary
113 -- The next word in the file is a pointer to where the dictionary is
114 -- (probably at the end of the file)
115 data_p <- tellBin bh -- Remember where we are now
117 dict <- getDictionary bh
118 seekBin bh data_p -- Back to where we were before
120 -- Initialise the user-data field of bh
121 ud <- newReadState dict
122 bh <- return (setUserData bh ud)
124 symtab_p <- Binary.get bh -- Get the symtab ptr
125 data_p <- tellBin bh -- Remember where we are now
127 (nc', symtab) <- getSymbolTable bh nc
128 seekBin bh data_p -- Back to where we were before
129 let ud = getUserData bh
130 bh <- return $! setUserData bh ud{ud_symtab = symtab}
135 writeBinIface :: DynFlags -> FilePath -> ModIface -> IO ()
136 writeBinIface dflags hi_path mod_iface = do
137 bh <- openBinMem initBinMemSize
138 put_ bh binaryInterfaceMagic
140 -- Remember where the dictionary pointer will go
141 dict_p_p <- tellBin bh
142 put_ bh dict_p_p -- Placeholder for ptr to dictionary
144 -- The version and way descriptor go next
145 put_ bh (show opt_HiVersion)
146 way_descr <- getWayDescr
149 -- Remember where the symbol table pointer will go
150 symtab_p_p <- tellBin bh
153 -- Make some intial state
154 symtab_next <- newFastMutInt
155 writeFastMutInt symtab_next 0
156 symtab_map <- newIORef emptyUFM
157 let bin_symtab = BinSymbolTable {
158 bin_symtab_next = symtab_next,
159 bin_symtab_map = symtab_map }
160 dict_next_ref <- newFastMutInt
161 writeFastMutInt dict_next_ref 0
162 dict_map_ref <- newIORef emptyUFM
163 let bin_dict = BinDictionary {
164 bin_dict_next = dict_next_ref,
165 bin_dict_map = dict_map_ref }
166 ud <- newWriteState (putName bin_symtab) (putFastString bin_dict)
168 -- Put the main thing,
169 bh <- return $ setUserData bh ud
172 -- Write the symtab pointer at the fornt of the file
173 symtab_p <- tellBin bh -- This is where the symtab will start
174 putAt bh symtab_p_p symtab_p -- Fill in the placeholder
175 seekBin bh symtab_p -- Seek back to the end of the file
177 -- Write the symbol table itself
178 symtab_next <- readFastMutInt symtab_next
179 symtab_map <- readIORef symtab_map
180 putSymbolTable bh symtab_next symtab_map
181 debugTraceMsg dflags 3 (text "writeBinIface:" <+> int symtab_next
184 -- NB. write the dictionary after the symbol table, because
185 -- writing the symbol table may create more dictionary entries.
187 -- Write the dictionary pointer at the fornt of the file
188 dict_p <- tellBin bh -- This is where the dictionary will start
189 putAt bh dict_p_p dict_p -- Fill in the placeholder
190 seekBin bh dict_p -- Seek back to the end of the file
192 -- Write the dictionary itself
193 dict_next <- readFastMutInt dict_next_ref
194 dict_map <- readIORef dict_map_ref
195 putDictionary bh dict_next dict_map
196 debugTraceMsg dflags 3 (text "writeBinIface:" <+> int dict_next
197 <+> text "dict entries")
199 -- And send the result to the file
200 writeBinMem bh hi_path
202 initBinMemSize :: Int
203 initBinMemSize = 1024 * 1024
205 -- The *host* architecture version:
206 #include "MachDeps.h"
208 binaryInterfaceMagic :: Word32
209 #if WORD_SIZE_IN_BITS == 32
210 binaryInterfaceMagic = 0x1face
211 #elif WORD_SIZE_IN_BITS == 64
212 binaryInterfaceMagic = 0x1face64
215 -- -----------------------------------------------------------------------------
218 putSymbolTable :: BinHandle -> Int -> UniqFM (Int,Name) -> IO ()
219 putSymbolTable bh next_off symtab = do
221 let names = elems (array (0,next_off-1) (eltsUFM symtab))
222 mapM_ (\n -> serialiseName bh n symtab) names
224 getSymbolTable :: BinHandle -> NameCache -> IO (NameCache, Array Int Name)
225 getSymbolTable bh namecache = do
227 od_names <- sequence (replicate sz (get bh))
229 arr = listArray (0,sz-1) names
230 (namecache', names) =
231 mapAccumR (fromOnDiskName arr) namecache od_names
233 return (namecache', arr)
235 type OnDiskName = (PackageId, ModuleName, OccName)
242 fromOnDiskName _ nc (pid, mod_name, occ) =
244 mod = mkModule pid mod_name
247 case lookupOrigNameCache cache mod occ of
248 Just name -> (nc, name)
252 uniq = uniqFromSupply us
253 name = mkExternalName uniq mod occ noSrcSpan
254 new_cache = extendNameCache cache mod occ name
256 case splitUniqSupply us of { (us',_) ->
257 ( nc{ nsUniqs = us', nsNames = new_cache }, name )
260 serialiseName :: BinHandle -> Name -> UniqFM (Int,Name) -> IO ()
261 serialiseName bh name _ = do
262 let mod = nameModule name
263 put_ bh (modulePackageId mod, moduleName mod, nameOccName name)
266 putName :: BinSymbolTable -> BinHandle -> Name -> IO ()
267 putName BinSymbolTable{
268 bin_symtab_map = symtab_map_ref,
269 bin_symtab_next = symtab_next } bh name
271 symtab_map <- readIORef symtab_map_ref
272 case lookupUFM symtab_map name of
273 Just (off,_) -> put_ bh off
275 off <- readFastMutInt symtab_next
276 writeFastMutInt symtab_next (off+1)
277 writeIORef symtab_map_ref
278 $! addToUFM symtab_map name (off,name)
282 data BinSymbolTable = BinSymbolTable {
283 bin_symtab_next :: !FastMutInt, -- The next index to use
284 bin_symtab_map :: !(IORef (UniqFM (Int,Name)))
289 putFastString :: BinDictionary -> BinHandle -> FastString -> IO ()
290 putFastString BinDictionary { bin_dict_next = j_r,
291 bin_dict_map = out_r} bh f
293 out <- readIORef out_r
294 let uniq = getUnique f
295 case lookupUFM out uniq of
296 Just (j, _) -> put_ bh j
298 j <- readFastMutInt j_r
300 writeFastMutInt j_r (j + 1)
301 writeIORef out_r $! addToUFM out uniq (j, f)
304 data BinDictionary = BinDictionary {
305 bin_dict_next :: !FastMutInt, -- The next index to use
306 bin_dict_map :: !(IORef (UniqFM (Int,FastString)))
307 -- indexed by FastString
310 -- -----------------------------------------------------------------------------
311 -- All the binary instances
314 {-! for IPName derive: Binary !-}
315 {-! for Fixity derive: Binary !-}
316 {-! for FixityDirection derive: Binary !-}
317 {-! for Boxity derive: Binary !-}
318 {-! for StrictnessMark derive: Binary !-}
319 {-! for Activation derive: Binary !-}
322 {-! for Demand derive: Binary !-}
323 {-! for Demands derive: Binary !-}
324 {-! for DmdResult derive: Binary !-}
325 {-! for StrictSig derive: Binary !-}
328 {-! for DefMeth derive: Binary !-}
331 {-! for HsPred derive: Binary !-}
332 {-! for HsType derive: Binary !-}
333 {-! for TupCon derive: Binary !-}
334 {-! for HsTyVarBndr derive: Binary !-}
337 {-! for UfExpr derive: Binary !-}
338 {-! for UfConAlt derive: Binary !-}
339 {-! for UfBinding derive: Binary !-}
340 {-! for UfBinder derive: Binary !-}
341 {-! for HsIdInfo derive: Binary !-}
342 {-! for UfNote derive: Binary !-}
345 {-! for ConDetails derive: Binary !-}
346 {-! for BangType derive: Binary !-}
349 {-! for IsCafCC derive: Binary !-}
350 {-! for IsDupdCC derive: Binary !-}
351 {-! for CostCentre derive: Binary !-}
355 -- ---------------------------------------------------------------------------
356 -- Reading a binary interface into ParsedIface
358 instance Binary ModIface where
362 mi_iface_hash= iface_hash,
363 mi_mod_hash = mod_hash,
365 mi_finsts = hasFamInsts,
368 mi_exports = exports,
369 mi_exp_hash = exp_hash,
370 mi_fixities = fixities,
371 mi_deprecs = deprecs,
374 mi_fam_insts = fam_insts,
376 mi_orphan_hash = orphan_hash,
377 mi_vect_info = vect_info,
378 mi_hpc = hpc_info }) = do
405 hasFamInsts <- get bh
407 usages <- {-# SCC "bin_usages" #-} lazyGet bh
408 exports <- {-# SCC "bin_exports" #-} get bh
410 fixities <- {-# SCC "bin_fixities" #-} get bh
411 deprecs <- {-# SCC "bin_deprecs" #-} lazyGet bh
412 decls <- {-# SCC "bin_tycldecls" #-} get bh
413 insts <- {-# SCC "bin_insts" #-} get bh
414 fam_insts <- {-# SCC "bin_fam_insts" #-} get bh
415 rules <- {-# SCC "bin_rules" #-} lazyGet bh
416 orphan_hash <- get bh
420 mi_module = mod_name,
422 mi_iface_hash = iface_hash,
423 mi_mod_hash = mod_hash,
425 mi_finsts = hasFamInsts,
428 mi_exports = exports,
429 mi_exp_hash = exp_hash,
430 mi_fixities = fixities,
431 mi_deprecs = deprecs,
433 mi_globals = Nothing,
435 mi_fam_insts = fam_insts,
437 mi_orphan_hash = orphan_hash,
438 mi_vect_info = vect_info,
440 -- And build the cached values
441 mi_dep_fn = mkIfaceDepCache deprecs,
442 mi_fix_fn = mkIfaceFixCache fixities,
443 mi_hash_fn = mkIfaceHashCache decls })
445 getWayDescr :: IO String
447 tag <- readIORef v_Build_tag
448 if cGhcUnregisterised == "YES" then return ('u':tag) else return tag
449 -- if this is an unregisterised build, make sure our interfaces
450 -- can't be used by a registerised build.
452 -------------------------------------------------------------------------
453 -- Types from: HscTypes
454 -------------------------------------------------------------------------
456 instance Binary Dependencies where
457 put_ bh deps = do put_ bh (dep_mods deps)
458 put_ bh (dep_pkgs deps)
459 put_ bh (dep_orphs deps)
460 put_ bh (dep_finsts deps)
462 get bh = do ms <- get bh
466 return (Deps { dep_mods = ms, dep_pkgs = ps, dep_orphs = os,
469 instance (Binary name) => Binary (GenAvailInfo name) where
470 put_ bh (Avail aa) = do
473 put_ bh (AvailTC ab ac) = do
484 return (AvailTC ab ac)
486 instance Binary Usage where
487 put_ bh usg@UsagePackageModule{} = do
489 put_ bh (usg_mod usg)
490 put_ bh (usg_mod_hash usg)
491 put_ bh usg@UsageHomeModule{} = do
493 put_ bh (usg_mod_name usg)
494 put_ bh (usg_mod_hash usg)
495 put_ bh (usg_exports usg)
496 put_ bh (usg_entities usg)
504 return UsagePackageModule { usg_mod = nm, usg_mod_hash = mod }
510 return UsageHomeModule { usg_mod_name = nm, usg_mod_hash = mod,
511 usg_exports = exps, usg_entities = ents }
513 instance Binary Deprecations where
514 put_ bh NoDeprecs = putByte bh 0
515 put_ bh (DeprecAll t) = do
518 put_ bh (DeprecSome ts) = do
525 0 -> return NoDeprecs
527 return (DeprecAll aa)
529 return (DeprecSome aa)
531 -------------------------------------------------------------------------
532 -- Types from: BasicTypes
533 -------------------------------------------------------------------------
535 instance Binary Activation where
536 put_ bh NeverActive = do
538 put_ bh AlwaysActive = do
540 put_ bh (ActiveBefore aa) = do
543 put_ bh (ActiveAfter ab) = do
549 0 -> do return NeverActive
550 1 -> do return AlwaysActive
552 return (ActiveBefore aa)
554 return (ActiveAfter ab)
556 instance Binary StrictnessMark where
557 put_ bh MarkedStrict = do
559 put_ bh MarkedUnboxed = do
561 put_ bh NotMarkedStrict = do
566 0 -> do return MarkedStrict
567 1 -> do return MarkedUnboxed
568 _ -> do return NotMarkedStrict
570 instance Binary Boxity where
579 _ -> do return Unboxed
581 instance Binary TupCon where
582 put_ bh (TupCon ab ac) = do
588 return (TupCon ab ac)
590 instance Binary RecFlag where
591 put_ bh Recursive = do
593 put_ bh NonRecursive = do
598 0 -> do return Recursive
599 _ -> do return NonRecursive
601 instance Binary DefMeth where
602 put_ bh NoDefMeth = putByte bh 0
603 put_ bh DefMeth = putByte bh 1
604 put_ bh GenDefMeth = putByte bh 2
608 0 -> return NoDefMeth
610 _ -> return GenDefMeth
612 instance Binary FixityDirection where
622 0 -> do return InfixL
623 1 -> do return InfixR
624 _ -> do return InfixN
626 instance Binary Fixity where
627 put_ bh (Fixity aa ab) = do
633 return (Fixity aa ab)
635 instance (Binary name) => Binary (IPName name) where
636 put_ bh (IPName aa) = put_ bh aa
637 get bh = do aa <- get bh
640 -------------------------------------------------------------------------
641 -- Types from: Demand
642 -------------------------------------------------------------------------
644 instance Binary DmdType where
645 -- Ignore DmdEnv when spitting out the DmdType
646 put bh (DmdType _ ds dr) = do p <- put bh ds; put bh dr; return (castBin p)
647 get bh = do ds <- get bh; dr <- get bh; return (DmdType emptyVarEnv ds dr)
649 instance Binary Demand where
654 put_ bh (Call aa) = do
657 put_ bh (Eval ab) = do
660 put_ bh (Defer ac) = do
663 put_ bh (Box ad) = do
683 instance Binary Demands where
684 put_ bh (Poly aa) = do
687 put_ bh (Prod ab) = do
698 instance Binary DmdResult where
708 0 -> do return TopRes
709 1 -> do return RetCPR -- Really use RetCPR even if -fcpr-off
710 -- The wrapper was generated for CPR in
711 -- the imported module!
712 _ -> do return BotRes
714 instance Binary StrictSig where
715 put_ bh (StrictSig aa) = do
719 return (StrictSig aa)
722 -------------------------------------------------------------------------
723 -- Types from: CostCentre
724 -------------------------------------------------------------------------
726 instance Binary IsCafCC where
729 put_ bh NotCafCC = do
735 _ -> do return NotCafCC
737 instance Binary IsDupdCC where
738 put_ bh OriginalCC = do
745 0 -> do return OriginalCC
746 _ -> do return DupdCC
748 instance Binary CostCentre where
749 put_ bh NoCostCentre = do
751 put_ bh (NormalCC aa ab ac ad) = do
757 put_ bh (AllCafsCC ae) = do
763 0 -> do return NoCostCentre
768 return (NormalCC aa ab ac ad)
770 return (AllCafsCC ae)
772 -------------------------------------------------------------------------
773 -- IfaceTypes and friends
774 -------------------------------------------------------------------------
776 instance Binary IfaceBndr where
777 put_ bh (IfaceIdBndr aa) = do
780 put_ bh (IfaceTvBndr ab) = do
787 return (IfaceIdBndr aa)
789 return (IfaceTvBndr ab)
791 instance Binary IfaceLetBndr where
792 put_ bh (IfLetBndr a b c) = do
796 get bh = do a <- get bh
799 return (IfLetBndr a b c)
801 instance Binary IfaceType where
802 put_ bh (IfaceForAllTy aa ab) = do
806 put_ bh (IfaceTyVar ad) = do
809 put_ bh (IfaceAppTy ae af) = do
813 put_ bh (IfaceFunTy ag ah) = do
817 put_ bh (IfacePredTy aq) = do
821 -- Simple compression for common cases of TyConApp
822 put_ bh (IfaceTyConApp IfaceIntTc []) = putByte bh 6
823 put_ bh (IfaceTyConApp IfaceCharTc []) = putByte bh 7
824 put_ bh (IfaceTyConApp IfaceBoolTc []) = putByte bh 8
825 put_ bh (IfaceTyConApp IfaceListTc [ty]) = do { putByte bh 9; put_ bh ty }
826 -- Unit tuple and pairs
827 put_ bh (IfaceTyConApp (IfaceTupTc Boxed 0) []) = putByte bh 10
828 put_ bh (IfaceTyConApp (IfaceTupTc Boxed 2) [t1,t2]) = do { putByte bh 11; put_ bh t1; put_ bh t2 }
830 put_ bh (IfaceTyConApp IfaceLiftedTypeKindTc []) = putByte bh 12
831 put_ bh (IfaceTyConApp IfaceOpenTypeKindTc []) = putByte bh 13
832 put_ bh (IfaceTyConApp IfaceUnliftedTypeKindTc []) = putByte bh 14
833 put_ bh (IfaceTyConApp IfaceUbxTupleKindTc []) = putByte bh 15
834 put_ bh (IfaceTyConApp IfaceArgTypeKindTc []) = putByte bh 16
838 put_ bh (IfaceTyConApp (IfaceTc tc) tys) = do { putByte bh 18; put_ bh tc; put_ bh tys }
839 put_ bh (IfaceTyConApp tc tys) = do { putByte bh 19; put_ bh tc; put_ bh tys }
846 return (IfaceForAllTy aa ab)
848 return (IfaceTyVar ad)
851 return (IfaceAppTy ae af)
854 return (IfaceFunTy ag ah)
856 return (IfacePredTy ap)
858 -- Now the special cases for TyConApp
859 6 -> return (IfaceTyConApp IfaceIntTc [])
860 7 -> return (IfaceTyConApp IfaceCharTc [])
861 8 -> return (IfaceTyConApp IfaceBoolTc [])
862 9 -> do { ty <- get bh; return (IfaceTyConApp IfaceListTc [ty]) }
863 10 -> return (IfaceTyConApp (IfaceTupTc Boxed 0) [])
864 11 -> do { t1 <- get bh; t2 <- get bh; return (IfaceTyConApp (IfaceTupTc Boxed 2) [t1,t2]) }
865 12 -> return (IfaceTyConApp IfaceLiftedTypeKindTc [])
866 13 -> return (IfaceTyConApp IfaceOpenTypeKindTc [])
867 14 -> return (IfaceTyConApp IfaceUnliftedTypeKindTc [])
868 15 -> return (IfaceTyConApp IfaceUbxTupleKindTc [])
869 16 -> return (IfaceTyConApp IfaceArgTypeKindTc [])
871 18 -> do { tc <- get bh; tys <- get bh; return (IfaceTyConApp (IfaceTc tc) tys) }
872 _ -> do { tc <- get bh; tys <- get bh; return (IfaceTyConApp tc tys) }
874 instance Binary IfaceTyCon where
875 -- Int,Char,Bool can't show up here because they can't not be saturated
877 put_ bh IfaceIntTc = putByte bh 1
878 put_ bh IfaceBoolTc = putByte bh 2
879 put_ bh IfaceCharTc = putByte bh 3
880 put_ bh IfaceListTc = putByte bh 4
881 put_ bh IfacePArrTc = putByte bh 5
882 put_ bh IfaceLiftedTypeKindTc = putByte bh 6
883 put_ bh IfaceOpenTypeKindTc = putByte bh 7
884 put_ bh IfaceUnliftedTypeKindTc = putByte bh 8
885 put_ bh IfaceUbxTupleKindTc = putByte bh 9
886 put_ bh IfaceArgTypeKindTc = putByte bh 10
887 put_ bh (IfaceTupTc bx ar) = do { putByte bh 11; put_ bh bx; put_ bh ar }
888 put_ bh (IfaceTc ext) = do { putByte bh 12; put_ bh ext }
893 1 -> return IfaceIntTc
894 2 -> return IfaceBoolTc
895 3 -> return IfaceCharTc
896 4 -> return IfaceListTc
897 5 -> return IfacePArrTc
898 6 -> return IfaceLiftedTypeKindTc
899 7 -> return IfaceOpenTypeKindTc
900 8 -> return IfaceUnliftedTypeKindTc
901 9 -> return IfaceUbxTupleKindTc
902 10 -> return IfaceArgTypeKindTc
903 11 -> do { bx <- get bh; ar <- get bh; return (IfaceTupTc bx ar) }
904 _ -> do { ext <- get bh; return (IfaceTc ext) }
906 instance Binary IfacePredType where
907 put_ bh (IfaceClassP aa ab) = do
911 put_ bh (IfaceIParam ac ad) = do
915 put_ bh (IfaceEqPred ac ad) = do
924 return (IfaceClassP aa ab)
927 return (IfaceIParam ac ad)
930 return (IfaceEqPred ac ad)
931 _ -> panic ("get IfacePredType " ++ show h)
933 -------------------------------------------------------------------------
934 -- IfaceExpr and friends
935 -------------------------------------------------------------------------
937 instance Binary IfaceExpr where
938 put_ bh (IfaceLcl aa) = do
941 put_ bh (IfaceType ab) = do
944 put_ bh (IfaceTuple ac ad) = do
948 put_ bh (IfaceLam ae af) = do
952 put_ bh (IfaceApp ag ah) = do
957 put_ bh (IfaceCase ai aj al ak) = do
964 put_ bh (IfaceLet al am) = do
968 put_ bh (IfaceNote an ao) = do
972 put_ bh (IfaceLit ap) = do
975 put_ bh (IfaceFCall as at) = do
979 put_ bh (IfaceExt aa) = do
982 put_ bh (IfaceCast ie ico) = do
986 put_ bh (IfaceTick m ix) = do
996 return (IfaceType ab)
999 return (IfaceTuple ac ad)
1000 3 -> do ae <- get bh
1002 return (IfaceLam ae af)
1003 4 -> do ag <- get bh
1005 return (IfaceApp ag ah)
1006 5 -> do ai <- get bh
1012 return (IfaceCase ai aj al ak)
1013 6 -> do al <- get bh
1015 return (IfaceLet al am)
1016 7 -> do an <- get bh
1018 return (IfaceNote an ao)
1019 8 -> do ap <- get bh
1020 return (IfaceLit ap)
1021 9 -> do as <- get bh
1023 return (IfaceFCall as at)
1024 10 -> do aa <- get bh
1025 return (IfaceExt aa)
1026 11 -> do ie <- get bh
1028 return (IfaceCast ie ico)
1029 12 -> do m <- get bh
1031 return (IfaceTick m ix)
1032 _ -> panic ("get IfaceExpr " ++ show h)
1034 instance Binary IfaceConAlt where
1035 put_ bh IfaceDefault = do
1037 put_ bh (IfaceDataAlt aa) = do
1040 put_ bh (IfaceTupleAlt ab) = do
1043 put_ bh (IfaceLitAlt ac) = do
1049 0 -> do return IfaceDefault
1050 1 -> do aa <- get bh
1051 return (IfaceDataAlt aa)
1052 2 -> do ab <- get bh
1053 return (IfaceTupleAlt ab)
1054 _ -> do ac <- get bh
1055 return (IfaceLitAlt ac)
1057 instance Binary IfaceBinding where
1058 put_ bh (IfaceNonRec aa ab) = do
1062 put_ bh (IfaceRec ac) = do
1068 0 -> do aa <- get bh
1070 return (IfaceNonRec aa ab)
1071 _ -> do ac <- get bh
1072 return (IfaceRec ac)
1074 instance Binary IfaceIdInfo where
1075 put_ bh NoInfo = putByte bh 0
1076 put_ bh (HasInfo i) = do
1078 lazyPut bh i -- NB lazyPut
1084 _ -> do info <- lazyGet bh -- NB lazyGet
1085 return (HasInfo info)
1087 instance Binary IfaceInfoItem where
1088 put_ bh (HsArity aa) = do
1091 put_ bh (HsStrictness ab) = do
1094 put_ bh (HsUnfold ad) = do
1097 put_ bh (HsInline ad) = do
1100 put_ bh HsNoCafRefs = do
1102 put_ bh (HsWorker ae af) = do
1109 0 -> do aa <- get bh
1111 1 -> do ab <- get bh
1112 return (HsStrictness ab)
1113 2 -> do ad <- get bh
1114 return (HsUnfold ad)
1115 3 -> do ad <- get bh
1116 return (HsInline ad)
1117 4 -> do return HsNoCafRefs
1118 _ -> do ae <- get bh
1120 return (HsWorker ae af)
1122 instance Binary IfaceNote where
1123 put_ bh (IfaceSCC aa) = do
1126 put_ bh IfaceInlineMe = do
1128 put_ bh (IfaceCoreNote s) = do
1134 0 -> do aa <- get bh
1135 return (IfaceSCC aa)
1136 3 -> do return IfaceInlineMe
1137 4 -> do ac <- get bh
1138 return (IfaceCoreNote ac)
1139 _ -> panic ("get IfaceNote " ++ show h)
1141 -------------------------------------------------------------------------
1142 -- IfaceDecl and friends
1143 -------------------------------------------------------------------------
1145 -- A bit of magic going on here: there's no need to store the OccName
1146 -- for a decl on the disk, since we can infer the namespace from the
1147 -- context; however it is useful to have the OccName in the IfaceDecl
1148 -- to avoid re-building it in various places. So we build the OccName
1149 -- when de-serialising.
1151 instance Binary IfaceDecl where
1152 put_ bh (IfaceId name ty idinfo) = do
1154 put_ bh (occNameFS name)
1157 put_ _ (IfaceForeign _ _) =
1158 error "Binary.put_(IfaceDecl): IfaceForeign"
1159 put_ bh (IfaceData a1 a2 a3 a4 a5 a6 a7 a8) = do
1161 put_ bh (occNameFS a1)
1169 put_ bh (IfaceSyn a1 a2 a3 a4 a5) = do
1171 put_ bh (occNameFS a1)
1176 put_ bh (IfaceClass a1 a2 a3 a4 a5 a6 a7) = do
1179 put_ bh (occNameFS a2)
1188 0 -> do name <- get bh
1191 occ <- return $! mkOccNameFS varName name
1192 return (IfaceId occ ty idinfo)
1193 1 -> error "Binary.get(TyClDecl): ForeignType"
1203 occ <- return $! mkOccNameFS tcName a1
1204 return (IfaceData occ a2 a3 a4 a5 a6 a7 a8)
1211 occ <- return $! mkOccNameFS tcName a1
1212 return (IfaceSyn occ a2 a3 a4 a5)
1221 occ <- return $! mkOccNameFS clsName a2
1222 return (IfaceClass a1 occ a3 a4 a5 a6 a7)
1224 instance Binary IfaceInst where
1225 put_ bh (IfaceInst cls tys dfun flag orph) = do
1231 get bh = do cls <- get bh
1236 return (IfaceInst cls tys dfun flag orph)
1238 instance Binary IfaceFamInst where
1239 put_ bh (IfaceFamInst fam tys tycon) = do
1243 get bh = do fam <- get bh
1246 return (IfaceFamInst fam tys tycon)
1248 instance Binary OverlapFlag where
1249 put_ bh NoOverlap = putByte bh 0
1250 put_ bh OverlapOk = putByte bh 1
1251 put_ bh Incoherent = putByte bh 2
1252 get bh = do h <- getByte bh
1254 0 -> return NoOverlap
1255 1 -> return OverlapOk
1256 2 -> return Incoherent
1257 _ -> panic ("get OverlapFlag " ++ show h)
1259 instance Binary IfaceConDecls where
1260 put_ bh IfAbstractTyCon = putByte bh 0
1261 put_ bh IfOpenDataTyCon = putByte bh 1
1262 put_ bh (IfDataTyCon cs) = do { putByte bh 2
1264 put_ bh (IfNewTyCon c) = do { putByte bh 3
1269 0 -> return IfAbstractTyCon
1270 1 -> return IfOpenDataTyCon
1271 2 -> do cs <- get bh
1272 return (IfDataTyCon cs)
1273 _ -> do aa <- get bh
1274 return (IfNewTyCon aa)
1276 instance Binary IfaceConDecl where
1277 put_ bh (IfCon a1 a2 a3 a4 a5 a6 a7 a8 a9) = do
1287 get bh = do a1 <- get bh
1296 return (IfCon a1 a2 a3 a4 a5 a6 a7 a8 a9)
1298 instance Binary IfaceClassOp where
1299 put_ bh (IfaceClassOp n def ty) = do
1300 put_ bh (occNameFS n)
1307 occ <- return $! mkOccNameFS varName n
1308 return (IfaceClassOp occ def ty)
1310 instance Binary IfaceRule where
1311 put_ bh (IfaceRule a1 a2 a3 a4 a5 a6 a7) = do
1327 return (IfaceRule a1 a2 a3 a4 a5 a6 a7)
1329 instance Binary IfaceVectInfo where
1330 put_ bh (IfaceVectInfo a1 a2 a3) = do
1338 return (IfaceVectInfo a1 a2 a3)