diff options
author | simonpj <unknown> | 2003-10-09 11:59:43 +0000 |
---|---|---|
committer | simonpj <unknown> | 2003-10-09 11:59:43 +0000 |
commit | 98688c6e8fd33f31c51218cf93cbf03fe3a5e73d (patch) | |
tree | 417682357fcd0733cd447f69e9b9032474348291 /ghc/compiler/main/BinIface.hs | |
parent | 79c93a8a30aaaa6bd940c0677d6f3c57eb727fa2 (diff) | |
download | haskell-98688c6e8fd33f31c51218cf93cbf03fe3a5e73d.tar.gz |
[project @ 2003-10-09 11:58:39 by simonpj]
-------------------------
GHC heart/lung transplant
-------------------------
This major commit changes the way that GHC deals with importing
types and functions defined in other modules, during renaming and
typechecking. On the way I've changed or cleaned up numerous other
things, including many that I probably fail to mention here.
Major benefit: GHC should suck in many fewer interface files when
compiling (esp with -O). (You can see this with -ddump-rn-stats.)
It's also some 1500 lines of code shorter than before.
** So expect bugs! I can do a 3-stage bootstrap, and run
** the test suite, but you may be doing stuff I havn't tested.
** Don't update if you are relying on a working HEAD.
In particular, (a) External Core and (b) GHCi are very little tested.
But please, please DO test this version!
------------------------
Big things
------------------------
Interface files, version control, and importing declarations
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* There is a totally new data type for stuff that lives in interface files:
Original names IfaceType.IfaceExtName
Types IfaceType.IfaceType
Declarations (type,class,id) IfaceSyn.IfaceDecl
Unfoldings IfaceSyn.IfaceExpr
(Previously we used HsSyn for type/class decls, and UfExpr for unfoldings.)
The new data types are in iface/IfaceType and iface/IfaceSyn. They are
all instances of Binary, so they can be written into interface files.
Previous engronkulation concering the binary instance of RdrName has
gone away -- RdrName is not an instance of Binary any more. Nor does
Binary.lhs need to know about the ``current module'' which it used to,
which made it specialised to GHC.
A good feature of this is that the type checker for source code doesn't
need to worry about the possibility that we might be typechecking interface
file stuff. Nor does it need to do renaming; we can typecheck direct from
IfaceSyn, saving a whole pass (module TcIface)
* Stuff from interface files is sucked in *lazily*, rather than being eagerly
sucked in by the renamer. Instead, we use unsafeInterleaveIO to capture
a thunk for the unfolding of an imported function (say). If that unfolding
is every pulled on, TcIface will scramble over the unfolding, which may
in turn pull in the interface files of things mentioned in the unfolding.
The External Package State is held in a mutable variable so that it
can be side-effected by this lazy-sucking-in process (which may happen
way later, e.g. when the simplifier runs). In effect, the EPS is a kind
of lazy memo table, filled in as we suck things in. Or you could think
of it as a global symbol table, populated on demand.
* This lazy sucking is very cool, but it can lead to truly awful bugs. The
intent is that updates to the symbol table happen atomically, but very bad
things happen if you read the variable for the table, and then force a
thunk which updates the table. Updates can get lost that way. I regret
this subtlety.
One example of the way it showed up is that the top level of TidyPgm
(which updates the global name cache) to be much more disciplined about
those updates, since TidyPgm may itself force thunks which allocate new
names.
* Version numbering in interface files has changed completely, fixing
one major bug with ghc --make. Previously, the version of A.f changed
only if A.f's type and unfolding was textually different. That missed
changes to things that A.f's unfolding mentions; which was fixed by
eagerly sucking in all of those things, and listing them in the module's
usage list. But that didn't work with --make, because they might have
been already sucked in.
Now, A.f's version changes if anything reachable from A.f (via interface
files) changes. A module with unchanged source code needs recompiling
only if the versions of any of its free variables changes. [This isn't
quite right for dictionary functions and rules, which aren't mentioned
explicitly in the source. There are extensive comments in module MkIface,
where all version-handling stuff is done.]
* We don't need equality on HsDecls any more (because they aren't used in
interface files). Instead we have a specialised equality for IfaceSyn
(eqIfDecl etc), which uses IfaceEq instead of Bool as its result type.
See notes in IfaceSyn.
* The horrid bit of the renamer that tried to predict what instance decls
would be needed has gone entirely. Instead, the type checker simply
sucks in whatever instance decls it needs, when it needs them. Easy!
Similarly, no need for 'implicitModuleFVs' and 'implicitTemplateHaskellFVs'
etc. Hooray!
Types and type checking
~~~~~~~~~~~~~~~~~~~~~~~
* Kind-checking of types is far far tidier (new module TcHsTypes replaces
the badly-named TcMonoType). Strangely, this was one of my
original goals, because the kind check for types is the Right Place to
do type splicing, but it just didn't fit there before.
* There's a new representation for newtypes in TypeRep.lhs. Previously
they were represented using "SourceTypes" which was a funny compromise.
Now they have their own constructor in the Type datatype. SourceType
has turned back into PredType, which is what it used to be.
* Instance decl overlap checking done lazily. Consider
instance C Int b
instance C a Int
These were rejected before as overlapping, because when seeking
(C Int Int) one couldn't tell which to use. But there's no problem when
seeking (C Bool Int); it can only be the second.
So instead of checking for overlap when adding a new instance declaration,
we check for overlap when looking up an Inst. If we find more than one
matching instance, we see if any of the candidates dominates the others
(in the sense of being a substitution instance of all the others);
and only if not do we report an error.
------------------------
Medium things
------------------------
* The TcRn monad is generalised a bit further. It's now based on utils/IOEnv.lhs,
the IO monad with an environment. The desugarer uses the monad too,
so that anything it needs can get faulted in nicely.
* Reduce the number of wired-in things; in particular Word and Integer
are no longer wired in. The latter required HsLit.HsInteger to get a
Type argument. The 'derivable type classes' data types (:+:, :*: etc)
are not wired in any more either (see stuff about derivable type classes
below).
* The PersistentComilerState is now held in a mutable variable
in the HscEnv. Previously (a) it was passed to and then returned by
many top-level functions, which was painful; (b) it was invariably
accompanied by the HscEnv. This change tidies up top-level plumbing
without changing anything important.
* Derivable type classes are treated much more like 'deriving' clauses.
Previously, the Ids for the to/from functions lived inside the TyCon,
but now the TyCon simply records their existence (with a simple boolean).
Anyone who wants to use them must look them up in the environment.
This in turn makes it easy to generate the to/from functions (done
in types/Generics) using HsSyn (like TcGenDeriv for ordinary derivings)
instead of CoreSyn, which in turn means that (a) we don't have to figure
out all the type arguments etc; and (b) it'll be type-checked for us.
Generally, the task of generating the code has become easier, which is
good for Manuel, who wants to make it more sophisticated.
* A Name now says what its "parent" is. For example, the parent of a data
constructor is its type constructor; the parent of a class op is its
class. This relationship corresponds exactly to the Avail data type;
there may be other places we can exploit it. (I made the change so that
version comparison in interface files would be a bit easier; but in
fact it tided up other things here and there (see calls to
Name.nameParent). For example, the declaration pool, of declararations
read from interface files, but not yet used, is now keyed only by the 'main'
name of the declaration, not the subordinate names.
* New types OccEnv and OccSet, with the usual operations.
OccNames can be efficiently compared, because they have uniques, thanks
to the hashing implementation of FastStrings.
* The GlobalRdrEnv is now keyed by OccName rather than RdrName. Not only
does this halve the size of the env (because we don't need both qualified
and unqualified versions in the env), but it's also more efficient because
we can use a UniqFM instead of a FiniteMap.
Consequential changes to Provenance, which has moved to RdrName.
* External Core remains a bit of a hack, as it was before, done with a mixture
of HsDecls (so that recursiveness and argument variance is still inferred),
and IfaceExprs (for value declarations). It's not thoroughly tested.
------------------------
Minor things
------------------------
* DataCon fields dcWorkId, dcWrapId combined into a single field
dcIds, that is explicit about whether the data con is a newtype or not.
MkId.mkDataConWorkId and mkDataConWrapId are similarly combined into
MkId.mkDataConIds
* Choosing the boxing strategy is done for *source* type decls only, and
hence is now in TcTyDecls, not DataCon.
* WiredIn names are distinguished by their n_sort field, not by their location,
which was rather strange
* Define Maybes.mapCatMaybes :: (a -> Maybe b) -> [a] -> [b]
and use it here and there
* Much better pretty-printing of interface files (--show-iface)
Many, many other small things.
------------------------
File changes
------------------------
* New iface/ subdirectory
* Much of RnEnv has moved to iface/IfaceEnv
* MkIface and BinIface have moved from main/ to iface/
* types/Variance has been absorbed into typecheck/TcTyDecls
* RnHiFiles and RnIfaces have vanished entirely. Their
work is done by iface/LoadIface
* hsSyn/HsCore has gone, replaced by iface/IfaceSyn
* typecheck/TcIfaceSig has gone, replaced by iface/TcIface
* typecheck/TcMonoType has been renamed to typecheck/TcHsType
* basicTypes/Var.hi-boot and basicTypes/Generics.hi-boot have gone altogether
Diffstat (limited to 'ghc/compiler/main/BinIface.hs')
-rw-r--r-- | ghc/compiler/main/BinIface.hs | 1051 |
1 files changed, 0 insertions, 1051 deletions
diff --git a/ghc/compiler/main/BinIface.hs b/ghc/compiler/main/BinIface.hs deleted file mode 100644 index c507f2e4dc..0000000000 --- a/ghc/compiler/main/BinIface.hs +++ /dev/null @@ -1,1051 +0,0 @@ -{-% DrIFT (Automatic class derivations for Haskell) v1.1 %-} -{-% DrIFT (Automatic class derivations for Haskell) v1.1 %-} --- --- (c) The University of Glasgow 2002 --- --- Binary interface file support. - -module BinIface ( writeBinIface, readBinIface, v_IgnoreHiVersion ) where - -#include "HsVersions.h" - -import HscTypes -import BasicTypes -import NewDemand -import HsTypes -import HsCore -import HsDecls -import HsBinds -import HsPat ( HsConDetails(..) ) -import TyCon -import Class -import VarEnv -import CostCentre -import RdrName ( mkRdrUnqual, mkRdrQual ) -import Name ( Name, nameOccName, nameModule_maybe ) -import NameEnv ( NameEnv, lookupNameEnv, nameEnvElts ) -import Module ( moduleName ) -import OccName ( OccName ) -import RnHsSyn -import DriverState ( v_Build_tag ) -import CmdLineOpts ( opt_HiVersion ) -import Panic -import SrcLoc -import Binary -import Util - -import DATA_IOREF -import EXCEPTION ( throwDyn ) -import Monad ( when ) - -#include "HsVersions.h" - --- --------------------------------------------------------------------------- --- We write out a ModIface, but read it in as a ParsedIface. --- There are some big differences, and some subtle ones. We do most --- of the conversion on the way out, so there is minimal fuss when we --- read it back in again (see RnMonad.lhs) - --- The main difference is that all Names in a ModIface are RdrNames in --- a ParsedIface, so when writing out a Name in binary we make sure it --- is binary-compatible with a RdrName. - --- Other subtle differences: --- - pi_mod is a ModuleName, but mi_mod is a Module. Hence we put --- Modules as ModuleNames. --- - pi_exports and pi_usages, Names have --- to be converted to OccNames. --- - pi_fixity is a NameEnv in ModIface, --- but a list of (Name,Fixity) pairs in ParsedIface. --- - versioning is totally different. --- - deprecations are different. - -writeBinIface :: FilePath -> ModIface -> IO () -writeBinIface hi_path mod_iface - = putBinFileWithDict hi_path (mi_module mod_iface) mod_iface - -readBinIface :: FilePath -> IO ParsedIface -readBinIface hi_path = getBinFileWithDict hi_path - - --- %********************************************************* --- %* * --- All the Binary instances --- %* * --- %********************************************************* - --- BasicTypes -{-! for IPName derive: Binary !-} -{-! for Fixity derive: Binary !-} -{-! for FixityDirection derive: Binary !-} -{-! for NewOrData derive: Binary !-} -{-! for Boxity derive: Binary !-} -{-! for StrictnessMark derive: Binary !-} -{-! for Activation derive: Binary !-} - -instance Binary Name where - -- we must print these as RdrNames, because that's how they will be read in - put_ bh name - = case nameModule_maybe name of - Just mod - | this_mod == mod -> put_ bh (mkRdrUnqual occ) - | otherwise -> put_ bh (mkRdrQual (moduleName mod) occ) - _ -> put_ bh (mkRdrUnqual occ) - where - occ = nameOccName name - (this_mod,_,_,_) = getUserData bh - - get bh = error "can't Binary.get a Name" - --- NewDemand -{-! for Demand derive: Binary !-} -{-! for Demands derive: Binary !-} -{-! for DmdResult derive: Binary !-} -{-! for StrictSig derive: Binary !-} - -instance Binary DmdType where - -- ignore DmdEnv when spitting out the DmdType - put bh (DmdType _ ds dr) = do p <- put bh ds; put bh dr; return (castBin p) - get bh = do ds <- get bh; dr <- get bh; return (DmdType emptyVarEnv ds dr) - --- TyCon -{-! for DataConDetails derive: Binary !-} - --- Class -{-! for DefMeth derive: Binary !-} - --- HsTypes -{-! for HsPred derive: Binary !-} -{-! for HsType derive: Binary !-} -{-! for HsTupCon derive: Binary !-} -{-! for HsTyVarBndr derive: Binary !-} - --- HsCore -{-! for UfExpr derive: Binary !-} -{-! for UfConAlt derive: Binary !-} -{-! for UfBinding derive: Binary !-} -{-! for UfBinder derive: Binary !-} -{-! for HsIdInfo derive: Binary !-} -{-! for UfNote derive: Binary !-} - --- HsDecls -{-! for ConDetails derive: Binary !-} -{-! for BangType derive: Binary !-} - -instance (Binary name) => Binary (TyClDecl name) where - put_ bh (IfaceSig name ty idinfo _) = do - putByte bh 0 - put_ bh name - lazyPut bh ty - lazyPut bh idinfo - put_ bh (ForeignType ae af ag ah) = - error "Binary.put_(TyClDecl): ForeignType" - put_ bh (TyData ai aj ak al am _ (Just generics) _) = do - putByte bh 2 - put_ bh ai - put_ bh aj - put_ bh ak - put_ bh al - put_ bh am - -- ignore Derivs - put_ bh generics -- Record whether generics needed or not - put_ bh (TySynonym aq ar as _) = do - putByte bh 3 - put_ bh aq - put_ bh ar - put_ bh as - put_ bh c@(ClassDecl ctxt nm tyvars fds sigs _ _) = do - putByte bh 4 - put_ bh ctxt - put_ bh nm - put_ bh tyvars - put_ bh fds - put_ bh sigs - -- ignore methods (there should be none) - -- ignore SrcLoc - get bh = do - h <- getByte bh - case h of - 0 -> do - name <- get bh - ty <- lazyGet bh - idinfo <- lazyGet bh - return (IfaceSig name ty idinfo noSrcLoc) - 1 -> error "Binary.get(TyClDecl): ForeignType" - 2 -> do - n_or_d <- get bh - ctx <- get bh - nm <- get bh - tyvars <- get bh - cons <- get bh - generics <- get bh - return (TyData n_or_d ctx nm tyvars cons - Nothing (Just generics) noSrcLoc) - 3 -> do - aq <- get bh - ar <- get bh - as <- get bh - return (TySynonym aq ar as noSrcLoc) - _ -> do - ctxt <- get bh - nm <- get bh - tyvars <- get bh - fds <- get bh - sigs <- get bh - return (ClassDecl ctxt nm tyvars fds sigs - Nothing noSrcLoc) - -instance (Binary name) => Binary (ConDecl name) where - put_ bh (ConDecl aa ac ad ae _) = do - put_ bh aa - put_ bh ac - put_ bh ad - put_ bh ae - -- ignore SrcLoc - get bh = do - aa <- get bh - ac <- get bh - ad <- get bh - ae <- get bh - return (ConDecl aa ac ad ae noSrcLoc) - -instance (Binary name) => Binary (InstDecl name) where - put_ bh (InstDecl aa _ _ ad _) = do - put_ bh aa - -- ignore MonoBinds - -- ignore Sigs - put_ bh ad - -- ignore SrcLoc - get bh = do - aa <- get bh - ad <- get bh - return (InstDecl aa EmptyMonoBinds [{-no sigs-}] ad noSrcLoc) - -instance (Binary name) => Binary (RuleDecl name) where - put_ bh (IfaceRule ag ah ai aj ak al _) = do - put_ bh ag - put_ bh ah - put_ bh ai - put_ bh aj - put_ bh ak - put_ bh al - -- ignore SrcLoc - get bh = do ag <- get bh - ah <- get bh - ai <- get bh - aj <- get bh - ak <- get bh - al <- get bh - return (IfaceRule ag ah ai aj ak al noSrcLoc) - -instance (Binary name) => Binary (DeprecDecl name) where - put_ bh (Deprecation aa ab _) = do - put_ bh aa - put_ bh ab - -- ignore SrcLoc - get bh = do - aa <- get bh - ab <- get bh - return (Deprecation aa ab noSrcLoc) - --- HsBinds -instance Binary name => Binary (Sig name) where - put_ bh (ClassOpSig n def ty _) = do put_ bh n; put_ bh def; put_ bh ty - get bh = do - n <- get bh - def <- get bh - ty <- get bh - return (ClassOpSig n def ty noSrcLoc) - --- CostCentre -{-! for IsCafCC derive: Binary !-} -{-! for IsDupdCC derive: Binary !-} -{-! for CostCentre derive: Binary !-} - - - -instance Binary ModIface where - put_ bh iface = do - build_tag <- readIORef v_Build_tag - put_ bh (show opt_HiVersion ++ build_tag) - p <- put_ bh (moduleName (mi_module iface)) - put_ bh (mi_package iface) - put_ bh (vers_module (mi_version iface)) - put_ bh (mi_orphan iface) - -- no: mi_boot - lazyPut bh (mi_deps iface) - lazyPut bh (map usageToOccName (mi_usages iface)) - put_ bh (vers_exports (mi_version iface), - map exportItemToRdrExportItem (mi_exports iface)) - put_ bh (declsToVersionedDecls (dcl_tycl (mi_decls iface)) - (vers_decls (mi_version iface))) - -- no: mi_globals - put_ bh (collectFixities (mi_fixities iface) - (dcl_tycl (mi_decls iface))) - put_ bh (dcl_insts (mi_decls iface)) - lazyPut bh (vers_rules (mi_version iface), dcl_rules (mi_decls iface)) - lazyPut bh (deprecsToIfaceDeprecs (mi_deprecs iface)) - - -- Read in as a ParsedIface, not a ModIface. See above. - get bh = error "Binary.get: ModIface" - -declsToVersionedDecls :: [RenamedTyClDecl] -> NameEnv Version - -> [(Version, RenamedTyClDecl)] -declsToVersionedDecls decls env - = map add_vers decls - where add_vers d = - case lookupNameEnv env (tyClDeclName d) of - Nothing -> (initialVersion, d) - Just v -> (v, d) - - ---NOT REALLY: deprecsToIfaceDeprecs :: Deprecations -> IfaceDeprecs -deprecsToIfaceDeprecs NoDeprecs = Nothing -deprecsToIfaceDeprecs (DeprecAll txt) = Just (Left txt) -deprecsToIfaceDeprecs (DeprecSome env) = Just (Right (nameEnvElts env)) - - -{-! for GenAvailInfo derive: Binary !-} -{-! for WhatsImported derive: Binary !-} - --- For binary interfaces we need to convert the ImportVersion Names to OccNames -usageToOccName :: Usage Name -> Usage OccName -usageToOccName usg - = usg { usg_entities = [ (nameOccName n, v) | (n,v) <- usg_entities usg ] } - -exportItemToRdrExportItem (mn, avails) - = (mn, map availInfoToRdrAvailInfo avails) - -availInfoToRdrAvailInfo :: AvailInfo -> RdrAvailInfo -availInfoToRdrAvailInfo (Avail n) - = Avail (nameOccName n) -availInfoToRdrAvailInfo (AvailTC n ns) - = AvailTC (nameOccName n) (map nameOccName ns) - --- --------------------------------------------------------------------------- --- Reading a binary interface into ParsedIface - -instance Binary ParsedIface where - put_ bh ParsedIface{ - pi_mod = module_name, - pi_pkg = pkg_name, - pi_vers = module_ver, - pi_orphan = orphan, - pi_usages = usages, - pi_exports = exports, - pi_decls = tycl_decls, - pi_fixity = fixities, - pi_insts = insts, - pi_rules = rules, - pi_deprecs = deprecs } = do - build_tag <- readIORef v_Build_tag - put_ bh (show opt_HiVersion ++ build_tag) - put_ bh module_name - put_ bh pkg_name - put_ bh module_ver - put_ bh orphan - lazyPut bh usages - put_ bh exports - put_ bh tycl_decls - put_ bh fixities - put_ bh insts - lazyPut bh rules - lazyPut bh deprecs - get bh = do - check_ver <- get bh - ignore_ver <- readIORef v_IgnoreHiVersion - build_tag <- readIORef v_Build_tag - let our_ver = show opt_HiVersion ++ build_tag - when (check_ver /= our_ver && not ignore_ver) $ - -- use userError because this will be caught by readIface - -- which will emit an error msg containing the iface module name. - throwDyn (ProgramError ( - "mismatched interface file versions: expected " - ++ our_ver ++ ", found " ++ check_ver)) - module_name <- get bh -- same rep. as Module, so that's ok - pkg_name <- get bh - module_ver <- get bh - orphan <- get bh - deps <- lazyGet bh - usages <- {-# SCC "bin_usages" #-} lazyGet bh - exports <- {-# SCC "bin_exports" #-} get bh - tycl_decls <- {-# SCC "bin_tycldecls" #-} get bh - fixities <- {-# SCC "bin_fixities" #-} get bh - insts <- {-# SCC "bin_insts" #-} get bh - rules <- {-# SCC "bin_rules" #-} lazyGet bh - deprecs <- {-# SCC "bin_deprecs" #-} lazyGet bh - return (ParsedIface { - pi_mod = module_name, - pi_pkg = pkg_name, - pi_vers = module_ver, - pi_orphan = orphan, - pi_deps = deps, - pi_usages = usages, - pi_exports = exports, - pi_decls = tycl_decls, - pi_fixity = fixities, - pi_insts = reverse insts, - pi_rules = rules, - pi_deprecs = deprecs }) - -GLOBAL_VAR(v_IgnoreHiVersion, False, Bool) - --- ---------------------------------------------------------------------------- -{-* Generated by DrIFT-v1.0 : Look, but Don't Touch. *-} - --- Imported from other files :- - -instance Binary Dependencies where - put_ bh deps = do put_ bh (dep_mods deps) - put_ bh (dep_pkgs deps) - put_ bh (dep_orphs deps) - - get bh = do ms <- get bh - ps <- get bh - os <- get bh - return (Deps { dep_mods = ms, dep_pkgs = ps, dep_orphs = os }) - -instance (Binary name) => Binary (GenAvailInfo name) where - put_ bh (Avail aa) = do - putByte bh 0 - put_ bh aa - put_ bh (AvailTC ab ac) = do - putByte bh 1 - put_ bh ab - put_ bh ac - get bh = do - h <- getByte bh - case h of - 0 -> do aa <- get bh - return (Avail aa) - _ -> do ab <- get bh - ac <- get bh - return (AvailTC ab ac) - -instance (Binary name) => Binary (Usage name) where - put_ bh usg = do - put_ bh (usg_name usg) - put_ bh (usg_mod usg) - put_ bh (usg_exports usg) - put_ bh (usg_entities usg) - put_ bh (usg_rules usg) - - get bh = do - nm <- get bh - mod <- get bh - exps <- get bh - ents <- get bh - rules <- get bh - return (Usage { usg_name = nm, usg_mod = mod, - usg_exports = exps, usg_entities = ents, - usg_rules = rules }) - -instance Binary Activation where - put_ bh NeverActive = do - putByte bh 0 - put_ bh AlwaysActive = do - putByte bh 1 - put_ bh (ActiveBefore aa) = do - putByte bh 2 - put_ bh aa - put_ bh (ActiveAfter ab) = do - putByte bh 3 - put_ bh ab - get bh = do - h <- getByte bh - case h of - 0 -> do return NeverActive - 1 -> do return AlwaysActive - 2 -> do aa <- get bh - return (ActiveBefore aa) - _ -> do ab <- get bh - return (ActiveAfter ab) - -instance Binary StrictnessMark where - put_ bh MarkedUserStrict = do - putByte bh 0 - put_ bh MarkedStrict = do - putByte bh 1 - put_ bh MarkedUnboxed = do - putByte bh 2 - put_ bh NotMarkedStrict = do - putByte bh 3 - get bh = do - h <- getByte bh - case h of - 0 -> do return MarkedUserStrict - 1 -> do return MarkedStrict - 2 -> do return MarkedUnboxed - _ -> do return NotMarkedStrict - -instance Binary Boxity where - put_ bh Boxed = do - putByte bh 0 - put_ bh Unboxed = do - putByte bh 1 - get bh = do - h <- getByte bh - case h of - 0 -> do return Boxed - _ -> do return Unboxed - -instance Binary NewOrData where - put_ bh NewType = do - putByte bh 0 - put_ bh DataType = do - putByte bh 1 - get bh = do - h <- getByte bh - case h of - 0 -> do return NewType - _ -> do return DataType - -instance Binary FixityDirection where - put_ bh InfixL = do - putByte bh 0 - put_ bh InfixR = do - putByte bh 1 - put_ bh InfixN = do - putByte bh 2 - get bh = do - h <- getByte bh - case h of - 0 -> do return InfixL - 1 -> do return InfixR - _ -> do return InfixN - -instance Binary Fixity where - put_ bh (Fixity aa ab) = do - put_ bh aa - put_ bh ab - get bh = do - aa <- get bh - ab <- get bh - return (Fixity aa ab) - -instance (Binary name) => Binary (FixitySig name) where - put_ bh (FixitySig aa ab _) = do - put_ bh aa - put_ bh ab - get bh = do - aa <- get bh - ab <- get bh - return (FixitySig aa ab noSrcLoc) - -instance (Binary name) => Binary (IPName name) where - put_ bh (Dupable aa) = do - putByte bh 0 - put_ bh aa - put_ bh (Linear ab) = do - putByte bh 1 - put_ bh ab - get bh = do - h <- getByte bh - case h of - 0 -> do aa <- get bh - return (Dupable aa) - _ -> do ab <- get bh - return (Linear ab) - -instance Binary Demand where - put_ bh Top = do - putByte bh 0 - put_ bh Abs = do - putByte bh 1 - put_ bh (Call aa) = do - putByte bh 2 - put_ bh aa - put_ bh (Eval ab) = do - putByte bh 3 - put_ bh ab - put_ bh (Defer ac) = do - putByte bh 4 - put_ bh ac - put_ bh (Box ad) = do - putByte bh 5 - put_ bh ad - put_ bh Bot = do - putByte bh 6 - get bh = do - h <- getByte bh - case h of - 0 -> do return Top - 1 -> do return Abs - 2 -> do aa <- get bh - return (Call aa) - 3 -> do ab <- get bh - return (Eval ab) - 4 -> do ac <- get bh - return (Defer ac) - 5 -> do ad <- get bh - return (Box ad) - _ -> do return Bot - -instance Binary Demands where - put_ bh (Poly aa) = do - putByte bh 0 - put_ bh aa - put_ bh (Prod ab) = do - putByte bh 1 - put_ bh ab - get bh = do - h <- getByte bh - case h of - 0 -> do aa <- get bh - return (Poly aa) - _ -> do ab <- get bh - return (Prod ab) - -instance Binary DmdResult where - put_ bh TopRes = do - putByte bh 0 - put_ bh RetCPR = do - putByte bh 1 - put_ bh BotRes = do - putByte bh 2 - get bh = do - h <- getByte bh - case h of - 0 -> do return TopRes - 1 -> do return RetCPR -- Really use RetCPR even if -fcpr-off - -- The wrapper was generated for CPR in - -- the imported module! - _ -> do return BotRes - -instance Binary StrictSig where - put_ bh (StrictSig aa) = do - put_ bh aa - get bh = do - aa <- get bh - return (StrictSig aa) - -instance (Binary name) => Binary (HsTyVarBndr name) where - put_ bh (UserTyVar aa) = do - putByte bh 0 - put_ bh aa - put_ bh (IfaceTyVar ab ac) = do - putByte bh 1 - put_ bh ab - put_ bh ac - get bh = do - h <- getByte bh - case h of - 0 -> do aa <- get bh - return (UserTyVar aa) - _ -> do ab <- get bh - ac <- get bh - return (IfaceTyVar ab ac) - -instance Binary HsTupCon where - put_ bh (HsTupCon ab ac) = do - put_ bh ab - put_ bh ac - get bh = do - ab <- get bh - ac <- get bh - return (HsTupCon ab ac) - -instance (Binary name) => Binary (HsTyOp name) where - put_ bh HsArrow = putByte bh 0 - put_ bh (HsTyOp n) = do putByte bh 1 - put_ bh n - - get bh = do h <- getByte bh - case h of - 0 -> return HsArrow - 1 -> do a <- get bh - return (HsTyOp a) - -instance (Binary name) => Binary (HsType name) where - put_ bh (HsForAllTy aa ab ac) = do - putByte bh 0 - put_ bh aa - put_ bh ab - put_ bh ac - put_ bh (HsTyVar ad) = do - putByte bh 1 - put_ bh ad - put_ bh (HsAppTy ae af) = do - putByte bh 2 - put_ bh ae - put_ bh af - put_ bh (HsFunTy ag ah) = do - putByte bh 3 - put_ bh ag - put_ bh ah - put_ bh (HsListTy ai) = do - putByte bh 4 - put_ bh ai - put_ bh (HsPArrTy aj) = do - putByte bh 5 - put_ bh aj - put_ bh (HsTupleTy ak al) = do - putByte bh 6 - put_ bh ak - put_ bh al - put_ bh (HsOpTy am an ao) = do - putByte bh 7 - put_ bh am - put_ bh an - put_ bh ao - put_ bh (HsNumTy ap) = do - putByte bh 8 - put_ bh ap - put_ bh (HsPredTy aq) = do - putByte bh 9 - put_ bh aq - put_ bh (HsKindSig ar as) = do - putByte bh 10 - put_ bh ar - put_ bh as - get bh = do - h <- getByte bh - case h of - 0 -> do aa <- get bh - ab <- get bh - ac <- get bh - return (HsForAllTy aa ab ac) - 1 -> do ad <- get bh - return (HsTyVar ad) - 2 -> do ae <- get bh - af <- get bh - return (HsAppTy ae af) - 3 -> do ag <- get bh - ah <- get bh - return (HsFunTy ag ah) - 4 -> do ai <- get bh - return (HsListTy ai) - 5 -> do aj <- get bh - return (HsPArrTy aj) - 6 -> do ak <- get bh - al <- get bh - return (HsTupleTy ak al) - 7 -> do am <- get bh - an <- get bh - ao <- get bh - return (HsOpTy am an ao) - 8 -> do ap <- get bh - return (HsNumTy ap) - 9 -> do aq <- get bh - return (HsPredTy aq) - _ -> do ar <- get bh - as <- get bh - return (HsKindSig ar as) - -instance (Binary name) => Binary (HsPred name) where - put_ bh (HsClassP aa ab) = do - putByte bh 0 - put_ bh aa - put_ bh ab - put_ bh (HsIParam ac ad) = do - putByte bh 1 - put_ bh ac - put_ bh ad - get bh = do - h <- getByte bh - case h of - 0 -> do aa <- get bh - ab <- get bh - return (HsClassP aa ab) - _ -> do ac <- get bh - ad <- get bh - return (HsIParam ac ad) - -instance (Binary name) => Binary (UfExpr name) where - put_ bh (UfVar aa) = do - putByte bh 0 - put_ bh aa - put_ bh (UfType ab) = do - putByte bh 1 - put_ bh ab - put_ bh (UfTuple ac ad) = do - putByte bh 2 - put_ bh ac - put_ bh ad - put_ bh (UfLam ae af) = do - putByte bh 3 - put_ bh ae - put_ bh af - put_ bh (UfApp ag ah) = do - putByte bh 4 - put_ bh ag - put_ bh ah - put_ bh (UfCase ai aj ak) = do - putByte bh 5 - put_ bh ai - put_ bh aj - put_ bh ak - put_ bh (UfLet al am) = do - putByte bh 6 - put_ bh al - put_ bh am - put_ bh (UfNote an ao) = do - putByte bh 7 - put_ bh an - put_ bh ao - put_ bh (UfLit ap) = do - putByte bh 8 - put_ bh ap - put_ bh (UfFCall as at) = do - putByte bh 9 - put_ bh as - put_ bh at - get bh = do - h <- getByte bh - case h of - 0 -> do aa <- get bh - return (UfVar aa) - 1 -> do ab <- get bh - return (UfType ab) - 2 -> do ac <- get bh - ad <- get bh - return (UfTuple ac ad) - 3 -> do ae <- get bh - af <- get bh - return (UfLam ae af) - 4 -> do ag <- get bh - ah <- get bh - return (UfApp ag ah) - 5 -> do ai <- get bh - aj <- get bh - ak <- get bh - return (UfCase ai aj ak) - 6 -> do al <- get bh - am <- get bh - return (UfLet al am) - 7 -> do an <- get bh - ao <- get bh - return (UfNote an ao) - 8 -> do ap <- get bh - return (UfLit ap) - _ -> do as <- get bh - at <- get bh - return (UfFCall as at) - -instance (Binary name) => Binary (UfConAlt name) where - put_ bh UfDefault = do - putByte bh 0 - put_ bh (UfDataAlt aa) = do - putByte bh 1 - put_ bh aa - put_ bh (UfTupleAlt ab) = do - putByte bh 2 - put_ bh ab - put_ bh (UfLitAlt ac) = do - putByte bh 3 - put_ bh ac - get bh = do - h <- getByte bh - case h of - 0 -> do return UfDefault - 1 -> do aa <- get bh - return (UfDataAlt aa) - 2 -> do ab <- get bh - return (UfTupleAlt ab) - _ -> do ac <- get bh - return (UfLitAlt ac) - -instance (Binary name) => Binary (UfBinding name) where - put_ bh (UfNonRec aa ab) = do - putByte bh 0 - put_ bh aa - put_ bh ab - put_ bh (UfRec ac) = do - putByte bh 1 - put_ bh ac - get bh = do - h <- getByte bh - case h of - 0 -> do aa <- get bh - ab <- get bh - return (UfNonRec aa ab) - _ -> do ac <- get bh - return (UfRec ac) - -instance (Binary name) => Binary (UfBinder name) where - put_ bh (UfValBinder aa ab) = do - putByte bh 0 - put_ bh aa - put_ bh ab - put_ bh (UfTyBinder ac ad) = do - putByte bh 1 - put_ bh ac - put_ bh ad - get bh = do - h <- getByte bh - case h of - 0 -> do aa <- get bh - ab <- get bh - return (UfValBinder aa ab) - _ -> do ac <- get bh - ad <- get bh - return (UfTyBinder ac ad) - -instance (Binary name) => Binary (HsIdInfo name) where - put_ bh (HsArity aa) = do - putByte bh 0 - put_ bh aa - put_ bh (HsStrictness ab) = do - putByte bh 1 - put_ bh ab - put_ bh (HsUnfold ac ad) = do - putByte bh 2 - put_ bh ac - put_ bh ad - put_ bh HsNoCafRefs = do - putByte bh 3 - put_ bh (HsWorker ae af) = do - putByte bh 4 - put_ bh ae - put_ bh af - get bh = do - h <- getByte bh - case h of - 0 -> do aa <- get bh - return (HsArity aa) - 1 -> do ab <- get bh - return (HsStrictness ab) - 2 -> do ac <- get bh - ad <- get bh - return (HsUnfold ac ad) - 3 -> do return HsNoCafRefs - _ -> do ae <- get bh - af <- get bh - return (HsWorker ae af) - -instance (Binary name) => Binary (UfNote name) where - put_ bh (UfSCC aa) = do - putByte bh 0 - put_ bh aa - put_ bh (UfCoerce ab) = do - putByte bh 1 - put_ bh ab - put_ bh UfInlineCall = do - putByte bh 2 - put_ bh UfInlineMe = do - putByte bh 3 - put_ bh (UfCoreNote s) = do - putByte bh 4 - put_ bh s - get bh = do - h <- getByte bh - case h of - 0 -> do aa <- get bh - return (UfSCC aa) - 1 -> do ab <- get bh - return (UfCoerce ab) - 2 -> do return UfInlineCall - 3 -> do return UfInlineMe - _ -> do ac <- get bh - return (UfCoreNote ac) - -instance (Binary name) => Binary (BangType name) where - put_ bh (BangType aa ab) = do - put_ bh aa - put_ bh ab - get bh = do - aa <- get bh - ab <- get bh - return (BangType aa ab) - -instance (Binary name, Binary arg) => Binary (HsConDetails name arg) where - put_ bh (PrefixCon aa) = do - putByte bh 0 - put_ bh aa - put_ bh (InfixCon ab ac) = do - putByte bh 1 - put_ bh ab - put_ bh ac - put_ bh (RecCon ad) = do - putByte bh 2 - put_ bh ad - get bh = do - h <- getByte bh - case h of - 0 -> do aa <- get bh - return (PrefixCon aa) - 1 -> do ab <- get bh - ac <- get bh - return (InfixCon ab ac) - _ -> do ad <- get bh - return (RecCon ad) - -instance (Binary datacon) => Binary (DataConDetails datacon) where - put_ bh (DataCons aa) = do - putByte bh 0 - put_ bh aa - put_ bh Unknown = do - putByte bh 1 - put_ bh (HasCons ab) = do - putByte bh 2 - put_ bh ab - get bh = do - h <- getByte bh - case h of - 0 -> do aa <- get bh - return (DataCons aa) - 1 -> do return Unknown - _ -> do ab <- get bh - return (HasCons ab) - -instance (Binary id) => Binary (DefMeth id) where - put_ bh NoDefMeth = do - putByte bh 0 - put_ bh (DefMeth aa) = do - putByte bh 1 - put_ bh aa - put_ bh GenDefMeth = do - putByte bh 2 - get bh = do - h <- getByte bh - case h of - 0 -> do return NoDefMeth - 1 -> do aa <- get bh - return (DefMeth aa) - _ -> do return GenDefMeth - -instance Binary IsCafCC where - put_ bh CafCC = do - putByte bh 0 - put_ bh NotCafCC = do - putByte bh 1 - get bh = do - h <- getByte bh - case h of - 0 -> do return CafCC - _ -> do return NotCafCC - -instance Binary IsDupdCC where - put_ bh OriginalCC = do - putByte bh 0 - put_ bh DupdCC = do - putByte bh 1 - get bh = do - h <- getByte bh - case h of - 0 -> do return OriginalCC - _ -> do return DupdCC - -instance Binary CostCentre where - put_ bh NoCostCentre = do - putByte bh 0 - put_ bh (NormalCC aa ab ac ad) = do - putByte bh 1 - put_ bh aa - put_ bh ab - put_ bh ac - put_ bh ad - put_ bh (AllCafsCC ae) = do - putByte bh 2 - put_ bh ae - get bh = do - h <- getByte bh - case h of - 0 -> do return NoCostCentre - 1 -> do aa <- get bh - ab <- get bh - ac <- get bh - ad <- get bh - return (NormalCC aa ab ac ad) - _ -> do ae <- get bh - return (AllCafsCC ae) |