summaryrefslogtreecommitdiff
path: root/compiler/prelude
diff options
context:
space:
mode:
authorBen Gamari <bgamari.foss@gmail.com>2016-07-20 12:34:54 +0200
committerBen Gamari <ben@smart-cactus.org>2016-07-20 15:58:02 +0200
commit9513fe6bdeafd35ca1a04e17b5f94732516766aa (patch)
tree7a18f5beb24e31e1b0af71d2450f9228685e6ad5 /compiler/prelude
parented4809813fa51524ae73a4475afe33018a67f87d (diff)
downloadhaskell-9513fe6bdeafd35ca1a04e17b5f94732516766aa.tar.gz
Clean up interaction between name cache and built-in syntax
This cleans up various aspects of the handling of built-in syntax in the original name cache (hopefully resulting in a nice reduction in compiler allocations), * Remove tuple types from original name cache: There is really no reason for these to be in the name cache since we already handle them specially in interface files to ensure that we can resolve them directly to Names, avoiding extraneous name cache lookups. * Sadly it's not possible to remove all traces of tuples from the name cache, however. Namely we need to keep the tuple type representations in since otherwise they would need to be wired-in * Remove the special cases for (:), [], and (##) in isBuiltInOcc_maybe and rename it to isTupleOcc_maybe * Split lookupOrigNameCache into two variants, * lookupOrigNameCache': Merely looks up an OccName in the original name cache, making no attempt to resolve tuples * lookupOrigNameCache: Like the above but handles tuples as well. This is given the un-primed name since it does the "obvious" thing from the perspective of an API user, who knows nothing of our special treatment of tuples. Arriving at this design took a significant amount of iteration. The trail of debris leading here can be found in #11357. Thanks to ezyang and Simon for all of their help in coming to this solution. Test Plan: Validate Reviewers: goldfire, simonpj, austin Reviewed By: simonpj Subscribers: thomie, ezyang Differential Revision: https://phabricator.haskell.org/D2414 GHC Trac Issues: #11357
Diffstat (limited to 'compiler/prelude')
-rw-r--r--compiler/prelude/PrelInfo.hs14
-rw-r--r--compiler/prelude/PrelNames.hs3
-rw-r--r--compiler/prelude/TysWiredIn.hs74
3 files changed, 58 insertions, 33 deletions
diff --git a/compiler/prelude/PrelInfo.hs b/compiler/prelude/PrelInfo.hs
index 52493b40f5..0bd09a2e31 100644
--- a/compiler/prelude/PrelInfo.hs
+++ b/compiler/prelude/PrelInfo.hs
@@ -85,7 +85,8 @@ knownKeyNames
, concatMap tycon_kk_names typeNatTyCons
- , concatMap (tycon_kk_names . tupleTyCon Boxed) [2..mAX_TUPLE_SIZE] -- Yuk
+ -- Tuple type representations
+ , tuple_rep_names
, cTupleTyConNames
-- Constraint tuples are known-key but not wired-in
@@ -97,6 +98,17 @@ knownKeyNames
, basicKnownKeyNames ]
where
+ -- We only include the type representation bindings (for both the type and
+ -- promoted data constructors) for tuples, not the TyCons themselves since
+ -- they are handled specially in interface files and by isBuiltInOcc_maybe.
+ -- See Note [Built-in syntax and the OrigNameCache] and Note [Grand plan for
+ -- Typeable].
+ tuple_rep_names =
+ [ rep
+ | tc <- map (tupleTyCon Boxed) [2..mAX_TUPLE_SIZE]
+ , rep <- rep_names tc ++ concatMap (rep_names . promoteDataCon) (tyConDataCons tc)
+ ]
+
-- All of the names associated with a known-key thing.
-- This includes TyCons, DataCons and promoted TyCons.
tycon_kk_names :: TyCon -> [Name]
diff --git a/compiler/prelude/PrelNames.hs b/compiler/prelude/PrelNames.hs
index 5ed31519e9..483006f638 100644
--- a/compiler/prelude/PrelNames.hs
+++ b/compiler/prelude/PrelNames.hs
@@ -87,7 +87,8 @@ This is accomplished through a combination of mechanisms:
b) The known infinite families of names are specially
serialised by BinIface.putName, with that special treatment
detected when we read back to ensure that we get back to the
- correct uniques.
+ correct uniques. See Note [Symbol table representation of names]
+ in BinIface.
Most of the infinite families cannot occur in source code,
so mechanisms (a,b) sufficies to ensure that they always have
diff --git a/compiler/prelude/TysWiredIn.hs b/compiler/prelude/TysWiredIn.hs
index 86f1dde3d4..f7c6720c8a 100644
--- a/compiler/prelude/TysWiredIn.hs
+++ b/compiler/prelude/TysWiredIn.hs
@@ -198,29 +198,29 @@ wiredInTyCons = [ unitTyCon -- Not treated like other tuples, because
-- that it'll pre-populate the name cache, so
-- the special case in lookupOrigNameCache
-- doesn't need to look out for it
- , anyTyCon
- , boolTyCon
- , charTyCon
- , doubleTyCon
- , floatTyCon
- , intTyCon
- , wordTyCon
- , word8TyCon
- , listTyCon
- , maybeTyCon
- , parrTyCon
- , heqTyCon
- , coercibleTyCon
- , typeNatKindCon
- , typeSymbolKindCon
- , runtimeRepTyCon
- , vecCountTyCon
- , vecElemTyCon
- , constraintKindTyCon
- , liftedTypeKindTyCon
- , starKindTyCon
- , unicodeStarKindTyCon
- ]
+ , anyTyCon
+ , boolTyCon
+ , charTyCon
+ , doubleTyCon
+ , floatTyCon
+ , intTyCon
+ , wordTyCon
+ , word8TyCon
+ , listTyCon
+ , maybeTyCon
+ , parrTyCon
+ , heqTyCon
+ , coercibleTyCon
+ , typeNatKindCon
+ , typeSymbolKindCon
+ , runtimeRepTyCon
+ , vecCountTyCon
+ , vecElemTyCon
+ , constraintKindTyCon
+ , liftedTypeKindTyCon
+ , starKindTyCon
+ , unicodeStarKindTyCon
+ ]
mkWiredInTyConName :: BuiltInSyntax -> Module -> FastString -> Unique -> TyCon -> Name
mkWiredInTyConName built_in modu fs unique tycon
@@ -608,6 +608,15 @@ Note [How tuples work] See also Note [Known-key names] in PrelNames
BoxedTuple/UnboxedTuple, and then we used BasicTypes.Boxity to distinguish
E.g. tupleTyCon has a Boxity argument
+* Names of tuple TyCons, DataCons, and DataCon workers have a special encoding
+ in the interface file symbol table. This allows us to eliminate the need for a
+ original-name cache lookup when loading from an interface file. See
+ Note [Symbol table representation of names] and
+ Note [Built-in syntax and the OrigNameCache].
+
+ Unfortunately, Typeable type representations still do need to be included in
+ the name cache for tiresome reasons. See [Grand plan for Typeable].
+
* When looking up an OccName in the original-name cache
(IfaceEnv.lookupOrigNameCache), we spot the tuple OccName to make sure
we get the right wired-in name. This guy can't tell the difference
@@ -641,19 +650,22 @@ decl in GHC.Classes, so I think this part may not work properly. But
it's unused I think.
-}
--- | Built in syntax isn't "in scope" so these OccNames map to wired-in Names
--- with BuiltInSyntax. However, this should only be necessary while resolving
--- names produced by Template Haskell splices since we take care to encode
--- built-in syntax names specially in interface files. See
--- Note [Symbol table representation of names].
+-- | Tuple types aren't included in the original name cache to keep the size of
+-- the cache down. This function is responsible for identifying tuple types and
+-- mapping them to the appropriate 'Name'.
+--
+-- This should only be necessary while resolving names produced by Template
+-- Haskell splices since we take care to encode built-in syntax names specially
+-- in interface files. See Note [Symbol table representation of names].
+-- This function should be able to identify everything in GHC.Tuple
isBuiltInOcc_maybe :: OccName -> Maybe Name
isBuiltInOcc_maybe occ =
case name of
- "[]" -> Just $ choose_ns listTyConName nilDataConName
+ "[]" -> Just $ choose_ns listTyConName nilDataConName
":" -> Just consDataConName
"[::]" -> Just parrTyConName
- "()" -> Just $ tup_name Boxed 0
- "(##)" -> Just $ tup_name Unboxed 0
+ "()" -> Just $ tup_name Boxed 0
+ "(##)" -> Just $ tup_name Unboxed 0
_ | Just rest <- "(" `stripPrefix` name
, (commas, rest') <- BS.span (==',') rest
, ")" <- rest'