[commit: base] master: Typeable overhaul (see #5275) (903c1af)
Simon Marlow
marlowsd at gmail.com
Tue Jul 12 12:37:47 CEST 2011
Repository : ssh://darcs.haskell.org//srv/darcs/packages/base
On branch : master
http://hackage.haskell.org/trac/ghc/changeset/903c1afa3bdd205dc5473c0fca1065d598145311
>---------------------------------------------------------------
commit 903c1afa3bdd205dc5473c0fca1065d598145311
Author: Simon Marlow <marlowsd at gmail.com>
Date: Fri Jul 8 10:39:24 2011 +0100
Typeable overhaul (see #5275)
Instances of Typeable used to call mkTyCon:
mkTyCon :: String -> TyCon
which internally kept a table mapping Strings to Ints, so that each
TyCon could be given a unique Int for fast comparison. This meant the
String has to be unique across all types in the program. However,
derived instances of typeable used the qualified original
name (e.g. "GHC.Types.Int") which is not necessarily unique, is
non-portable, and exposes implementation details.
The String passed to mkTyCon is returned by
tyConString :: TyCon -> String
which let the user get at this non-portable representation (also the
Show instance returns this String).
Now we store three Strings in TyCon. The internal representation is
this:
data TyCon = TyCon {
tyConHash :: {-# UNPACK #-} !Fingerprint,
tyConPackage :: String,
tyConModule :: String,
tyConName :: String
}
(internal representations are now provided by Data.Typeable.Internal)
The fields of TyCon are not exposed via the public API. Together the
three fields tyConPackage, tyConModule and tyConName uniquely identify
a TyCon, and the Fingerprint is a hash of the concatenation of these
three Strings (so no more internal cache to map strings to unique
Ids). tyConString now returns the value of tyConName only, so is
therefore portable (but the String returned does not uniquely
identify the TyCon).
I've measured the performance impact of this change, and performance
seems to be uniformly better. This should improve things for SYB in
particular. Also, the size of the code generated for deriving
Typeable is less than half as much as before.
== API changes ==
=== mkTyCon is DEPRECATED ==
mkTyCon is used by some hand-written instances of Typeable. It still
works as before, but is deprecated in favour of...
=== Add mkTyCon3 ===
mkTyCon3 :: String -> String -> String -> TyCon
mkTyCon3 takes the package, module, and name of the TyCon respectively.
Most users can just derive Typeable, there's no need to use mkTyCon3.
In due course we can rename mkTyCon3 back to mkTyCon.
=== typeRepKey changed ===
Previously we had
typeRepKey :: TypeRep -> IO Int
but since we don't assign unique Ints to TypeReps any more, this is
difficult to implement. Instead we provide an abstract key type which
is an instance of Eq and Ord, and internally is implemented by the
fingerprint:
data TypeRepKey -- abstract, instance of Eq, Ord
typeRepKey :: TypeRep -> IO TypeRepKey
typeRepKey is still in the IO monad, because the Ord instance is
implementation-defined.
Data/Typeable.hs | 178 ++++++++----------------------
Data/Typeable.hs-boot | 5 +-
Data/Typeable/Internal.hs | 59 ++++++++++
Data/Typeable/Internal.hs-boot | 19 +++
Foreign/C/Types.hs | 2 +
GHC/Exception.lhs | 1 +
GHC/Fingerprint.hs | 97 ++++++++++++++++
GHC/Fingerprint.hs-boot | 12 ++
GHC/Fingerprint/Type.hs | 19 +++
base.cabal | 6 +-
cbits/md5.c | 238 ++++++++++++++++++++++++++++++++++++++++
configure.ac | 3 +
include/md5.h | 24 ++++
13 files changed, 526 insertions(+), 137 deletions(-)
Diff suppressed because of size. To see it, use:
git show 903c1afa3bdd205dc5473c0fca1065d598145311
More information about the Cvs-libraries
mailing list