1 {-% DrIFT (Automatic class derivations for Haskell) v1.1 %-}
2 {-% DrIFT (Automatic class derivations for Haskell) v1.1 %-}
4 -- (c) The University of Glasgow 2002
6 -- Binary interface file support.
8 module BinIface ( writeBinIface, readBinIface, v_IgnoreHiWay ) where
10 #include "HsVersions.h"
12 import TcRnMonad ( TcRnIf, ioToIOEnv )
18 import Module ( ModuleName, mkModule, modulePackageId, moduleName )
20 import OccName ( OccName )
22 import InstEnv ( OverlapFlag(..) )
23 import Class ( DefMeth(..) )
24 import DynFlags ( DynFlags )
25 import UniqFM ( UniqFM, eltsUFM )
26 import UniqSupply ( uniqFromSupply, splitUniqSupply )
28 import StaticFlags ( opt_HiVersion, v_Build_tag )
30 isLiftedTypeKind, isUnliftedTypeKind, isOpenTypeKind,
31 isArgTypeKind, isUbxTupleKind, liftedTypeKind,
32 unliftedTypeKind, openTypeKind, argTypeKind,
33 ubxTupleKind, mkArrowKind, splitFunTy_maybe )
34 import PackageConfig ( PackageId )
37 import SrcLoc ( noSrcLoc )
39 import ErrUtils ( debugTraceMsg )
40 import Config ( cGhcUnregisterised )
41 import FastMutInt ( readFastMutInt )
43 import Data.Word ( Word32 )
44 import Data.Array ( Array, array, elems, listArray, (!) )
46 import EXCEPTION ( throwDyn )
50 #include "HsVersions.h"
52 -- ---------------------------------------------------------------------------
53 -- Reading and writing binary interface files
55 readBinIface :: FilePath -> TcRnIf a b ModIface
56 readBinIface hi_path = do
58 (new_nc, iface) <- ioToIOEnv $ readBinIface_ hi_path nc
62 readBinIface_ :: FilePath -> NameCache -> IO (NameCache, ModIface)
63 readBinIface_ hi_path nc = do
64 bh <- Binary.readBinMem hi_path
66 -- Read the magic number to check that this really is a GHC .hi file
67 -- (This magic number does not change when we change
68 -- GHC interface file format)
70 when (magic /= binaryInterfaceMagic) $
71 throwDyn (ProgramError (
72 "magic number mismatch: old/corrupt interface file?"))
74 -- Read the dictionary
75 -- The next word in the file is a pointer to where the dictionary is
76 -- (probably at the end of the file)
77 dict_p <- Binary.get bh -- Get the dictionary ptr
78 data_p <- tellBin bh -- Remember where we are now
80 dict <- getDictionary bh
81 seekBin bh data_p -- Back to where we were before
83 -- Initialise the user-data field of bh
84 ud <- newReadState dict
85 bh <- return (setUserData bh ud)
87 symtab_p <- Binary.get bh -- Get the symtab ptr
88 data_p <- tellBin bh -- Remember where we are now
90 (nc', symtab) <- getSymbolTable bh nc
91 seekBin bh data_p -- Back to where we were before
92 let ud = getUserData bh
93 bh <- return $! setUserData bh ud{ud_symtab = symtab}
98 writeBinIface :: DynFlags -> FilePath -> ModIface -> IO ()
99 writeBinIface dflags hi_path mod_iface = do
100 bh <- openBinMem initBinMemSize
101 put_ bh binaryInterfaceMagic
103 -- Remember where the dictionary pointer will go
104 dict_p_p <- tellBin bh
105 put_ bh dict_p_p -- Placeholder for ptr to dictionary
107 -- Remember where the symbol table pointer will go
108 symtab_p_p <- tellBin bh
111 -- Make some intial state
114 -- Put the main thing,
115 bh <- return $ setUserData bh ud
118 -- Write the symtab pointer at the fornt of the file
119 symtab_p <- tellBin bh -- This is where the symtab will start
120 putAt bh symtab_p_p symtab_p -- Fill in the placeholder
121 seekBin bh symtab_p -- Seek back to the end of the file
123 -- Write the symbol table itself
124 symtab_next <- readFastMutInt (ud_symtab_next ud)
125 symtab_map <- readIORef (ud_symtab_map ud)
126 putSymbolTable bh symtab_next symtab_map
127 debugTraceMsg dflags 3 (text "writeBinIface:" <+> int symtab_next
130 -- NB. write the dictionary after the symbol table, because
131 -- writing the symbol table may create more dictionary entries.
133 -- Write the dictionary pointer at the fornt of the file
134 dict_p <- tellBin bh -- This is where the dictionary will start
135 putAt bh dict_p_p dict_p -- Fill in the placeholder
136 seekBin bh dict_p -- Seek back to the end of the file
138 -- Write the dictionary itself
139 dict_next <- readFastMutInt (ud_dict_next ud)
140 dict_map <- readIORef (ud_dict_map ud)
141 putDictionary bh dict_next dict_map
142 debugTraceMsg dflags 3 (text "writeBinIface:" <+> int dict_next
143 <+> text "dict entries")
145 -- And send the result to the file
146 writeBinMem bh hi_path
148 initBinMemSize = (1024*1024) :: Int
150 -- The *host* architecture version:
151 #include "MachDeps.h"
153 #if WORD_SIZE_IN_BITS == 32
154 binaryInterfaceMagic = 0x1face :: Word32
155 #elif WORD_SIZE_IN_BITS == 64
156 binaryInterfaceMagic = 0x1face64 :: Word32
159 -- -----------------------------------------------------------------------------
162 putSymbolTable :: BinHandle -> Int -> UniqFM (Int,Name) -> IO ()
163 putSymbolTable bh next_off symtab = do
165 let names = elems (array (0,next_off-1) (eltsUFM symtab))
166 mapM_ (\n -> serialiseName bh n symtab) names
168 getSymbolTable :: BinHandle -> NameCache -> IO (NameCache, Array Int Name)
169 getSymbolTable bh namecache = do
171 od_names <- sequence (replicate sz (get bh))
173 arr = listArray (0,sz-1) names
174 (namecache', names) =
175 mapAccumR (fromOnDiskName arr) namecache od_names
177 return (namecache', arr)
179 type OnDiskName = (PackageId, ModuleName, OccName)
186 fromOnDiskName arr nc (pid, mod_name, occ) =
188 mod = mkModule pid mod_name
191 case lookupOrigNameCache cache mod occ of
192 Just name -> (nc, name)
196 uniq = uniqFromSupply us
197 name = mkExternalName uniq mod occ noSrcLoc
198 new_cache = extendNameCache cache mod occ name
200 case splitUniqSupply us of { (us',_) ->
201 ( nc{ nsUniqs = us', nsNames = new_cache }, name )
204 serialiseName :: BinHandle -> Name -> UniqFM (Int,Name) -> IO ()
205 serialiseName bh name symtab = do
206 let mod = nameModule name
207 put_ bh (modulePackageId mod, moduleName mod, nameOccName name)
209 -- -----------------------------------------------------------------------------
210 -- All the binary instances
213 {-! for IPName derive: Binary !-}
214 {-! for Fixity derive: Binary !-}
215 {-! for FixityDirection derive: Binary !-}
216 {-! for Boxity derive: Binary !-}
217 {-! for StrictnessMark derive: Binary !-}
218 {-! for Activation derive: Binary !-}
221 {-! for Demand derive: Binary !-}
222 {-! for Demands derive: Binary !-}
223 {-! for DmdResult derive: Binary !-}
224 {-! for StrictSig derive: Binary !-}
227 {-! for DefMeth derive: Binary !-}
230 {-! for HsPred derive: Binary !-}
231 {-! for HsType derive: Binary !-}
232 {-! for TupCon derive: Binary !-}
233 {-! for HsTyVarBndr derive: Binary !-}
236 {-! for UfExpr derive: Binary !-}
237 {-! for UfConAlt derive: Binary !-}
238 {-! for UfBinding derive: Binary !-}
239 {-! for UfBinder derive: Binary !-}
240 {-! for HsIdInfo derive: Binary !-}
241 {-! for UfNote derive: Binary !-}
244 {-! for ConDetails derive: Binary !-}
245 {-! for BangType derive: Binary !-}
248 {-! for IsCafCC derive: Binary !-}
249 {-! for IsDupdCC derive: Binary !-}
250 {-! for CostCentre derive: Binary !-}
254 -- ---------------------------------------------------------------------------
255 -- Reading a binary interface into ParsedIface
257 instance Binary ModIface where
261 mi_mod_vers = mod_vers,
265 mi_exports = exports,
266 mi_exp_vers = exp_vers,
267 mi_fixities = fixities,
268 mi_deprecs = deprecs,
271 mi_fam_insts = fam_insts,
273 mi_rule_vers = rule_vers }) = do
274 put_ bh (show opt_HiVersion)
275 way_descr <- getWayDescr
295 let our_ver = show opt_HiVersion
296 when (check_ver /= our_ver) $
297 -- use userError because this will be caught by readIface
298 -- which will emit an error msg containing the iface module name.
299 throwDyn (ProgramError (
300 "mismatched interface file versions: expected "
301 ++ our_ver ++ ", found " ++ check_ver))
304 ignore_way <- readIORef v_IgnoreHiWay
305 way_descr <- getWayDescr
306 when (not ignore_way && check_way /= way_descr) $
307 -- use userError because this will be caught by readIface
308 -- which will emit an error msg containing the iface module name.
309 throwDyn (ProgramError (
310 "mismatched interface file ways: expected "
311 ++ way_descr ++ ", found " ++ check_way))
318 usages <- {-# SCC "bin_usages" #-} lazyGet bh
319 exports <- {-# SCC "bin_exports" #-} get bh
321 fixities <- {-# SCC "bin_fixities" #-} get bh
322 deprecs <- {-# SCC "bin_deprecs" #-} lazyGet bh
323 decls <- {-# SCC "bin_tycldecls" #-} get bh
324 insts <- {-# SCC "bin_insts" #-} get bh
325 fam_insts <- {-# SCC "bin_fam_insts" #-} get bh
326 rules <- {-# SCC "bin_rules" #-} lazyGet bh
329 mi_module = mod_name,
331 mi_mod_vers = mod_vers,
335 mi_exports = exports,
336 mi_exp_vers = exp_vers,
337 mi_fixities = fixities,
338 mi_deprecs = deprecs,
340 mi_globals = Nothing,
342 mi_fam_insts = fam_insts,
344 mi_rule_vers = rule_vers,
345 -- And build the cached values
346 mi_dep_fn = mkIfaceDepCache deprecs,
347 mi_fix_fn = mkIfaceFixCache fixities,
348 mi_ver_fn = mkIfaceVerCache decls })
350 GLOBAL_VAR(v_IgnoreHiWay, False, Bool)
352 getWayDescr :: IO String
354 tag <- readIORef v_Build_tag
355 if cGhcUnregisterised == "YES" then return ('u':tag) else return tag
356 -- if this is an unregisterised build, make sure our interfaces
357 -- can't be used by a registerised build.
359 -------------------------------------------------------------------------
360 -- Types from: HscTypes
361 -------------------------------------------------------------------------
363 instance Binary Dependencies where
364 put_ bh deps = do put_ bh (dep_mods deps)
365 put_ bh (dep_pkgs deps)
366 put_ bh (dep_orphs deps)
368 get bh = do ms <- get bh
371 return (Deps { dep_mods = ms, dep_pkgs = ps, dep_orphs = os })
373 instance (Binary name) => Binary (GenAvailInfo name) where
374 put_ bh (Avail aa) = do
377 put_ bh (AvailTC ab ac) = do
388 return (AvailTC ab ac)
390 instance Binary Usage where
392 put_ bh (usg_name usg)
393 put_ bh (usg_mod usg)
394 put_ bh (usg_exports usg)
395 put_ bh (usg_entities usg)
396 put_ bh (usg_rules usg)
404 return (Usage { usg_name = nm, usg_mod = mod,
405 usg_exports = exps, usg_entities = ents,
408 instance Binary a => Binary (Deprecs a) where
409 put_ bh NoDeprecs = putByte bh 0
410 put_ bh (DeprecAll t) = do
413 put_ bh (DeprecSome ts) = do
420 0 -> return NoDeprecs
422 return (DeprecAll aa)
424 return (DeprecSome aa)
426 -------------------------------------------------------------------------
427 -- Types from: BasicTypes
428 -------------------------------------------------------------------------
430 instance Binary Activation where
431 put_ bh NeverActive = do
433 put_ bh AlwaysActive = do
435 put_ bh (ActiveBefore aa) = do
438 put_ bh (ActiveAfter ab) = do
444 0 -> do return NeverActive
445 1 -> do return AlwaysActive
447 return (ActiveBefore aa)
449 return (ActiveAfter ab)
451 instance Binary StrictnessMark where
452 put_ bh MarkedStrict = do
454 put_ bh MarkedUnboxed = do
456 put_ bh NotMarkedStrict = do
461 0 -> do return MarkedStrict
462 1 -> do return MarkedUnboxed
463 _ -> do return NotMarkedStrict
465 instance Binary Boxity where
474 _ -> do return Unboxed
476 instance Binary TupCon where
477 put_ bh (TupCon ab ac) = do
483 return (TupCon ab ac)
485 instance Binary RecFlag where
486 put_ bh Recursive = do
488 put_ bh NonRecursive = do
493 0 -> do return Recursive
494 _ -> do return NonRecursive
496 instance Binary DefMeth where
497 put_ bh NoDefMeth = putByte bh 0
498 put_ bh DefMeth = putByte bh 1
499 put_ bh GenDefMeth = putByte bh 2
503 0 -> return NoDefMeth
505 _ -> return GenDefMeth
507 instance Binary FixityDirection where
517 0 -> do return InfixL
518 1 -> do return InfixR
519 _ -> do return InfixN
521 instance Binary Fixity where
522 put_ bh (Fixity aa ab) = do
528 return (Fixity aa ab)
530 instance (Binary name) => Binary (IPName name) where
531 put_ bh (IPName aa) = put_ bh aa
532 get bh = do aa <- get bh
535 -------------------------------------------------------------------------
536 -- Types from: Demand
537 -------------------------------------------------------------------------
539 instance Binary DmdType where
540 -- Ignore DmdEnv when spitting out the DmdType
541 put bh (DmdType _ ds dr) = do p <- put bh ds; put bh dr; return (castBin p)
542 get bh = do ds <- get bh; dr <- get bh; return (DmdType emptyVarEnv ds dr)
544 instance Binary Demand where
549 put_ bh (Call aa) = do
552 put_ bh (Eval ab) = do
555 put_ bh (Defer ac) = do
558 put_ bh (Box ad) = do
578 instance Binary Demands where
579 put_ bh (Poly aa) = do
582 put_ bh (Prod ab) = do
593 instance Binary DmdResult where
603 0 -> do return TopRes
604 1 -> do return RetCPR -- Really use RetCPR even if -fcpr-off
605 -- The wrapper was generated for CPR in
606 -- the imported module!
607 _ -> do return BotRes
609 instance Binary StrictSig where
610 put_ bh (StrictSig aa) = do
614 return (StrictSig aa)
617 -------------------------------------------------------------------------
618 -- Types from: CostCentre
619 -------------------------------------------------------------------------
621 instance Binary IsCafCC where
624 put_ bh NotCafCC = do
630 _ -> do return NotCafCC
632 instance Binary IsDupdCC where
633 put_ bh OriginalCC = do
640 0 -> do return OriginalCC
641 _ -> do return DupdCC
643 instance Binary CostCentre where
644 put_ bh NoCostCentre = do
646 put_ bh (NormalCC aa ab ac ad) = do
652 put_ bh (AllCafsCC ae) = do
658 0 -> do return NoCostCentre
663 return (NormalCC aa ab ac ad)
665 return (AllCafsCC ae)
667 -------------------------------------------------------------------------
668 -- IfaceTypes and friends
669 -------------------------------------------------------------------------
671 instance Binary IfaceBndr where
672 put_ bh (IfaceIdBndr aa) = do
675 put_ bh (IfaceTvBndr ab) = do
682 return (IfaceIdBndr aa)
684 return (IfaceTvBndr ab)
686 instance Binary IfaceType where
687 put_ bh (IfaceForAllTy aa ab) = do
691 put_ bh (IfaceTyVar ad) = do
694 put_ bh (IfaceAppTy ae af) = do
698 put_ bh (IfaceFunTy ag ah) = do
702 put_ bh (IfacePredTy aq) = do
706 -- Simple compression for common cases of TyConApp
707 put_ bh (IfaceTyConApp IfaceIntTc []) = putByte bh 6
708 put_ bh (IfaceTyConApp IfaceCharTc []) = putByte bh 7
709 put_ bh (IfaceTyConApp IfaceBoolTc []) = putByte bh 8
710 put_ bh (IfaceTyConApp IfaceListTc [ty]) = do { putByte bh 9; put_ bh ty }
711 -- Unit tuple and pairs
712 put_ bh (IfaceTyConApp (IfaceTupTc Boxed 0) []) = putByte bh 10
713 put_ bh (IfaceTyConApp (IfaceTupTc Boxed 2) [t1,t2]) = do { putByte bh 11; put_ bh t1; put_ bh t2 }
715 put_ bh (IfaceTyConApp IfaceLiftedTypeKindTc []) = putByte bh 12
716 put_ bh (IfaceTyConApp IfaceOpenTypeKindTc []) = putByte bh 13
717 put_ bh (IfaceTyConApp IfaceUnliftedTypeKindTc []) = putByte bh 14
718 put_ bh (IfaceTyConApp IfaceUbxTupleKindTc []) = putByte bh 15
719 put_ bh (IfaceTyConApp IfaceArgTypeKindTc []) = putByte bh 16
723 put_ bh (IfaceTyConApp (IfaceTc tc) tys) = do { putByte bh 18; put_ bh tc; put_ bh tys }
724 put_ bh (IfaceTyConApp tc tys) = do { putByte bh 19; put_ bh tc; put_ bh tys }
731 return (IfaceForAllTy aa ab)
733 return (IfaceTyVar ad)
736 return (IfaceAppTy ae af)
739 return (IfaceFunTy ag ah)
741 return (IfacePredTy ap)
743 -- Now the special cases for TyConApp
744 6 -> return (IfaceTyConApp IfaceIntTc [])
745 7 -> return (IfaceTyConApp IfaceCharTc [])
746 8 -> return (IfaceTyConApp IfaceBoolTc [])
747 9 -> do { ty <- get bh; return (IfaceTyConApp IfaceListTc [ty]) }
748 10 -> return (IfaceTyConApp (IfaceTupTc Boxed 0) [])
749 11 -> do { t1 <- get bh; t2 <- get bh; return (IfaceTyConApp (IfaceTupTc Boxed 2) [t1,t2]) }
750 12 -> return (IfaceTyConApp IfaceLiftedTypeKindTc [])
751 13 -> return (IfaceTyConApp IfaceOpenTypeKindTc [])
752 14 -> return (IfaceTyConApp IfaceUnliftedTypeKindTc [])
753 15 -> return (IfaceTyConApp IfaceUbxTupleKindTc [])
754 16 -> return (IfaceTyConApp IfaceArgTypeKindTc [])
756 18 -> do { tc <- get bh; tys <- get bh; return (IfaceTyConApp (IfaceTc tc) tys) }
757 _ -> do { tc <- get bh; tys <- get bh; return (IfaceTyConApp tc tys) }
759 instance Binary IfaceTyCon where
760 -- Int,Char,Bool can't show up here because they can't not be saturated
762 put_ bh IfaceIntTc = putByte bh 1
763 put_ bh IfaceBoolTc = putByte bh 2
764 put_ bh IfaceCharTc = putByte bh 3
765 put_ bh IfaceListTc = putByte bh 4
766 put_ bh IfacePArrTc = putByte bh 5
767 put_ bh IfaceLiftedTypeKindTc = putByte bh 6
768 put_ bh IfaceOpenTypeKindTc = putByte bh 7
769 put_ bh IfaceUnliftedTypeKindTc = putByte bh 8
770 put_ bh IfaceUbxTupleKindTc = putByte bh 9
771 put_ bh IfaceArgTypeKindTc = putByte bh 10
772 put_ bh (IfaceTupTc bx ar) = do { putByte bh 11; put_ bh bx; put_ bh ar }
773 put_ bh (IfaceTc ext) = do { putByte bh 12; put_ bh ext }
778 1 -> return IfaceIntTc
779 2 -> return IfaceBoolTc
780 3 -> return IfaceCharTc
781 4 -> return IfaceListTc
782 5 -> return IfacePArrTc
783 6 -> return IfaceLiftedTypeKindTc
784 7 -> return IfaceOpenTypeKindTc
785 8 -> return IfaceUnliftedTypeKindTc
786 9 -> return IfaceUbxTupleKindTc
787 10 -> return IfaceArgTypeKindTc
788 11 -> do { bx <- get bh; ar <- get bh; return (IfaceTupTc bx ar) }
789 _ -> do { ext <- get bh; return (IfaceTc ext) }
791 instance Binary IfacePredType where
792 put_ bh (IfaceClassP aa ab) = do
796 put_ bh (IfaceIParam ac ad) = do
800 put_ bh (IfaceEqPred ac ad) = do
809 return (IfaceClassP aa ab)
812 return (IfaceIParam ac ad)
815 return (IfaceEqPred ac ad)
817 -------------------------------------------------------------------------
818 -- IfaceExpr and friends
819 -------------------------------------------------------------------------
821 instance Binary IfaceExpr where
822 put_ bh (IfaceLcl aa) = do
825 put_ bh (IfaceType ab) = do
828 put_ bh (IfaceTuple ac ad) = do
832 put_ bh (IfaceLam ae af) = do
836 put_ bh (IfaceApp ag ah) = do
841 put_ bh (IfaceCase ai aj al ak) = do
848 put_ bh (IfaceLet al am) = do
852 put_ bh (IfaceNote an ao) = do
856 put_ bh (IfaceLit ap) = do
859 put_ bh (IfaceFCall as at) = do
863 put_ bh (IfaceExt aa) = do
866 put_ bh (IfaceCast ie ico) = do
876 return (IfaceType ab)
879 return (IfaceTuple ac ad)
882 return (IfaceLam ae af)
885 return (IfaceApp ag ah)
892 return (IfaceCase ai aj al ak)
895 return (IfaceLet al am)
898 return (IfaceNote an ao)
903 return (IfaceFCall as at)
904 10 -> do aa <- get bh
906 11 -> do ie <- get bh
908 return (IfaceCast ie ico)
910 instance Binary IfaceConAlt where
911 put_ bh IfaceDefault = do
913 put_ bh (IfaceDataAlt aa) = do
916 put_ bh (IfaceTupleAlt ab) = do
919 put_ bh (IfaceLitAlt ac) = do
925 0 -> do return IfaceDefault
927 return (IfaceDataAlt aa)
929 return (IfaceTupleAlt ab)
931 return (IfaceLitAlt ac)
933 instance Binary IfaceBinding where
934 put_ bh (IfaceNonRec aa ab) = do
938 put_ bh (IfaceRec ac) = do
946 return (IfaceNonRec aa ab)
950 instance Binary IfaceIdInfo where
951 put_ bh NoInfo = putByte bh 0
952 put_ bh (HasInfo i) = do
954 lazyPut bh i -- NB lazyPut
960 _ -> do info <- lazyGet bh -- NB lazyGet
961 return (HasInfo info)
963 instance Binary IfaceInfoItem where
964 put_ bh (HsArity aa) = do
967 put_ bh (HsStrictness ab) = do
970 put_ bh (HsUnfold ad) = do
973 put_ bh (HsInline ad) = do
976 put_ bh HsNoCafRefs = do
978 put_ bh (HsWorker ae af) = do
988 return (HsStrictness ab)
993 4 -> do return HsNoCafRefs
996 return (HsWorker ae af)
998 instance Binary IfaceNote where
999 put_ bh (IfaceSCC aa) = do
1002 put_ bh IfaceInlineMe = do
1004 put_ bh (IfaceCoreNote s) = do
1010 0 -> do aa <- get bh
1011 return (IfaceSCC aa)
1012 3 -> do return IfaceInlineMe
1013 4 -> do ac <- get bh
1014 return (IfaceCoreNote ac)
1017 -------------------------------------------------------------------------
1018 -- IfaceDecl and friends
1019 -------------------------------------------------------------------------
1021 -- A bit of magic going on here: there's no need to store the OccName
1022 -- for a decl on the disk, since we can infer the namespace from the
1023 -- context; however it is useful to have the OccName in the IfaceDecl
1024 -- to avoid re-building it in various places. So we build the OccName
1025 -- when de-serialising.
1027 instance Binary IfaceDecl where
1028 put_ bh (IfaceId name ty idinfo) = do
1030 put_ bh (occNameFS name)
1033 put_ bh (IfaceForeign ae af) =
1034 error "Binary.put_(IfaceDecl): IfaceForeign"
1035 put_ bh (IfaceData a1 a2 a3 a4 a5 a6 a7 a8) = do
1037 put_ bh (occNameFS a1)
1045 put_ bh (IfaceSyn aq ar as at) = do
1047 put_ bh (occNameFS aq)
1051 put_ bh (IfaceClass a1 a2 a3 a4 a5 a6 a7) = do
1054 put_ bh (occNameFS a2)
1063 0 -> do name <- get bh
1066 occ <- return $! mkOccNameFS varName name
1067 return (IfaceId occ ty idinfo)
1068 1 -> error "Binary.get(TyClDecl): ForeignType"
1078 occ <- return $! mkOccNameFS tcName a1
1079 return (IfaceData occ a2 a3 a4 a5 a6 a7 a8)
1085 occ <- return $! mkOccNameFS tcName aq
1086 return (IfaceSyn occ ar as at)
1095 occ <- return $! mkOccNameFS clsName a2
1096 return (IfaceClass a1 occ a3 a4 a5 a6 a7)
1098 instance Binary IfaceInst where
1099 put_ bh (IfaceInst cls tys dfun flag orph) = do
1105 get bh = do cls <- get bh
1110 return (IfaceInst cls tys dfun flag orph)
1112 instance Binary IfaceFamInst where
1113 put_ bh (IfaceFamInst fam tys tycon) = do
1117 get bh = do fam <- get bh
1120 return (IfaceFamInst fam tys tycon)
1122 instance Binary OverlapFlag where
1123 put_ bh NoOverlap = putByte bh 0
1124 put_ bh OverlapOk = putByte bh 1
1125 put_ bh Incoherent = putByte bh 2
1126 get bh = do h <- getByte bh
1128 0 -> return NoOverlap
1129 1 -> return OverlapOk
1130 2 -> return Incoherent
1132 instance Binary IfaceConDecls where
1133 put_ bh IfAbstractTyCon = putByte bh 0
1134 put_ bh IfOpenDataTyCon = putByte bh 1
1135 put_ bh IfOpenNewTyCon = putByte bh 2
1136 put_ bh (IfDataTyCon cs) = do { putByte bh 3
1138 put_ bh (IfNewTyCon c) = do { putByte bh 4
1143 0 -> return IfAbstractTyCon
1144 1 -> return IfOpenDataTyCon
1145 2 -> return IfOpenNewTyCon
1146 3 -> do cs <- get bh
1147 return (IfDataTyCon cs)
1148 _ -> do aa <- get bh
1149 return (IfNewTyCon aa)
1151 instance Binary IfaceConDecl where
1152 put_ bh (IfCon a1 a2 a3 a4 a5 a6 a7 a8 a9) = do
1162 get bh = do a1 <- get bh
1171 return (IfCon a1 a2 a3 a4 a5 a6 a7 a8 a9)
1173 instance Binary IfaceClassOp where
1174 put_ bh (IfaceClassOp n def ty) = do
1175 put_ bh (occNameFS n)
1182 occ <- return $! mkOccNameFS varName n
1183 return (IfaceClassOp occ def ty)
1185 instance Binary IfaceRule where
1186 put_ bh (IfaceRule a1 a2 a3 a4 a5 a6 a7) = do
1202 return (IfaceRule a1 a2 a3 a4 a5 a6 a7)