diff options
author | Ben Gamari <ben@smart-cactus.org> | 2015-08-26 18:24:34 +0200 |
---|---|---|
committer | Ben Gamari <ben@smart-cactus.org> | 2015-10-29 16:14:51 +0100 |
commit | bef2f03e4d56d88a7e9752a7afd6a0a35616da6c (patch) | |
tree | 9ae33978cf43d8268a6c5afa42e7a6c8a7e227a1 /testsuite/tests/roles/should_compile/Roles13.stderr | |
parent | 40e6214c06bc197dbdfcf9f7345dad1ad271922b (diff) | |
download | haskell-bef2f03e4d56d88a7e9752a7afd6a0a35616da6c.tar.gz |
Generate Typeable info at definition sites
This patch implements the idea floated in Trac #9858, namely that we
should generate type-representation information at the data type
declaration site, rather than when solving a Typeable constraint.
However, this turned out quite a bit harder than I expected. I still
think it's the right thing to do, and it's done now, but it was quite
a struggle.
See particularly
* Note [Grand plan for Typeable] in TcTypeable (which is a new module)
* Note [The overall promotion story] in DataCon (clarifies existing stuff)
The most painful bit was that to generate Typeable instances (ie
TyConRepName bindings) for every TyCon is tricky for types in ghc-prim
etc:
* We need to have enough data types around to *define* a TyCon
* Many of these types are wired-in
Also, to minimise the code generated for each data type, I wanted to
generate pure data, not CAFs with unpackCString# stuff floating about.
Performance
~~~~~~~~~~~
Three perf/compiler tests start to allocate quite a bit more. This isn't
surprising, because they all allocate zillions of data types, with
practically no other code, esp. T1969
* T3294: GHC allocates 110% more (filed #11030 to track this)
* T1969: GHC allocates 30% more
* T4801: GHC allocates 14% more
* T5321FD: GHC allocates 13% more
* T783: GHC allocates 12% more
* T9675: GHC allocates 12% more
* T5642: GHC allocates 10% more
* T9961: GHC allocates 6% more
* T9203: Program allocates 54% less
I'm treating this as acceptable. The payoff comes in Typeable-heavy
code.
Remaining to do
~~~~~~~~~~~~~~~
* I think that "TyCon" and "Module" are over-generic names to use for
the runtime type representations used in GHC.Typeable. Better might be
"TrTyCon" and "TrModule". But I have not yet done this
* Add more info the the "TyCon" e.g. source location where it was
defined
* Use the new "Module" type to help with Trac Trac #10068
* It would be possible to generate TyConRepName (ie Typeable
instances) selectively rather than all the time. We'd need to persist
the information in interface files. Lacking a motivating reason I have
not done this, but it would not be difficult.
Refactoring
~~~~~~~~~~~
As is so often the case, I ended up refactoring more than I intended.
In particular
* In TyCon, a type *family* (whether type or data) is repesented by a
FamilyTyCon
* a algebraic data type (including data/newtype instances) is
represented by AlgTyCon This wasn't true before; a data family
was represented as an AlgTyCon. There are some corresponding
changes in IfaceSyn.
* Also get rid of the (unhelpfully named) tyConParent.
* In TyCon define 'Promoted', isomorphic to Maybe, used when things are
optionally promoted; and use it elsewhere in GHC.
* Cleanup handling of knownKeyNames
* Each TyCon, including promoted TyCons, contains its TyConRepName, if
it has one. This is, in effect, the name of its Typeable instance.
Requires update of the haddock submodule.
Differential Revision: https://phabricator.haskell.org/D757
Diffstat (limited to 'testsuite/tests/roles/should_compile/Roles13.stderr')
-rw-r--r-- | testsuite/tests/roles/should_compile/Roles13.stderr | 53 |
1 files changed, 49 insertions, 4 deletions
diff --git a/testsuite/tests/roles/should_compile/Roles13.stderr b/testsuite/tests/roles/should_compile/Roles13.stderr index 5ecdd16e10..4b7b2cb18d 100644 --- a/testsuite/tests/roles/should_compile/Roles13.stderr +++ b/testsuite/tests/roles/should_compile/Roles13.stderr @@ -1,17 +1,62 @@ ==================== Tidy Core ==================== -Result size of Tidy Core = {terms: 5, types: 9, coercions: 5} +Result size of Tidy Core = {terms: 42, types: 18, coercions: 5} + +-- RHS size: {terms: 2, types: 0, coercions: 0} +a :: TrName +[GblId, Caf=NoCafRefs, Str=DmdType] +a = TrNameS "main"# + +-- RHS size: {terms: 2, types: 0, coercions: 0} +a1 :: TrName +[GblId, Caf=NoCafRefs, Str=DmdType] +a1 = TrNameS "Roles13"# + +-- RHS size: {terms: 3, types: 0, coercions: 0} +Roles13.$trModule :: Module +[GblId[ReflectionId], Caf=NoCafRefs, Str=DmdType] +Roles13.$trModule = Module a a1 + +-- RHS size: {terms: 2, types: 0, coercions: 0} +a2 :: TrName +[GblId, Caf=NoCafRefs, Str=DmdType] +a2 = TrNameS "Age"# + +-- RHS size: {terms: 5, types: 0, coercions: 0} +Roles13.$tcAge :: TyCon +[GblId[ReflectionId], Caf=NoCafRefs, Str=DmdType] +Roles13.$tcAge = TyCon 0## 0## Roles13.$trModule a2 + +-- RHS size: {terms: 2, types: 0, coercions: 0} +a3 :: TrName +[GblId, Caf=NoCafRefs, Str=DmdType] +a3 = TrNameS "'MkWrap"# + +-- RHS size: {terms: 5, types: 0, coercions: 0} +Roles13.$tc'MkWrap :: TyCon +[GblId[ReflectionId], Caf=NoCafRefs, Str=DmdType] +Roles13.$tc'MkWrap = TyCon 0## 0## Roles13.$trModule a3 + +-- RHS size: {terms: 2, types: 0, coercions: 0} +a4 :: TrName +[GblId, Caf=NoCafRefs, Str=DmdType] +a4 = TrNameS "Wrap"# + +-- RHS size: {terms: 5, types: 0, coercions: 0} +Roles13.$tcWrap :: TyCon +[GblId[ReflectionId], Caf=NoCafRefs, Str=DmdType] +Roles13.$tcWrap = TyCon 0## 0## Roles13.$trModule a4 -- RHS size: {terms: 2, types: 2, coercions: 0} -a :: Wrap Age -> Wrap Age +a5 :: Wrap Age -> Wrap Age [GblId, Arity=1, Caf=NoCafRefs, Str=DmdType] -a = \ (ds :: Wrap Age) -> ds +a5 = \ (ds :: Wrap Age) -> ds -- RHS size: {terms: 1, types: 0, coercions: 5} convert :: Wrap Age -> Int [GblId, Arity=1, Caf=NoCafRefs, Str=DmdType] convert = - a + a5 `cast` (<Wrap Age>_R -> Roles13.NTCo:Wrap[0] Roles13.NTCo:Age[0] :: (Wrap Age -> Wrap Age) ~R# (Wrap Age -> Int)) |