Type-indexed type representations
AbandonedPublic

Authored by bgamari on Mar 16 2016, 6:24 AM.

Details

Reviewers
simonmar
erikd
goldfire
hvr
austin
Commits
rGHC2a7b4e811470: Binary: Simple serialization test works
rGHC8e5addb074e4: Hi
rGHC5e00482b9dc5: Internal: Various cleanups
rGHC01293886816a: TcTypeable: A bit more debug output and fix binder ordering
rGHC2fa2dae3db3a: Message: Fix it
rGHC74b969421932: Binary: More explicit pattern matching
rGHC7d8c0c39b100: More test fixes
rGHC63d611b69f21: TcTypeable: Clarify comment
rGHCace8fd96e339: Finally serialization is both general and correct
rGHCb3ffe518f2ce: Fix rebase
rGHC3bd60ba48f68: Add TRArrow pattern synonym
rGHC8c3cc63af474: Fix T8132
rGHCbfdeae0d5848: Clarify serialization errors
rGHC132fddc0dfc7: Fix kind instantiation
rGHC4b79d997a941: Unpack the fingerprints
rGHC7db1b4784109: CoreLint: Improve debug output
rGHCdd9180748695: Fix warnings
rGHCe6f1b1229d01: Fix withTypeable
rGHC267180280d98: Break recursive loop in serialization
rGHC228dbdb9a7b6: Break recursive loop in serialization
rGHC529bbc9eebba: TcTypeable: Fix kind variable count
rGHCcc90a2937fde: TcTypeable: It compiles GHC.Types!
rGHCa7c39f98af58: HACK: CoreLint: Kill unsaturated unlifted types check
rGHC482e7cd13534: TcInteract: Unused parameter
rGHC5988da0bfde1: Fix it
rGHC76caca2429bd: Note need for mkTrApp
rGHC8bd12185e031: TcTypeable: Look through type synonyms
rGHCd86c376d0419: Begin reintroducing typeRepKind
rGHCff407d59c867: Add mkFunTy
rGHC8d7ed74bd248: TcTypeable: Don't generate bindings for special primitive tycons
rGHC765bc30d85a3: Introduce TrFun
rGHC5f08b9821980: Start implementing library side of TTypeable
rGHCd3cc6209358a: TcInteract: Unused parameter
rGHC541c138e370d: Rename TypeRepX to SomeTypeRep
rGHC26952ca4fa1d: Debug
rGHCa52df0aa973e: Getting there
rGHCbe9f9f2bc780: base: Derive Enum, Bounded for VecCount, VecElem
rGHC81b9058e17ba: Export mkTrFun
rGHC6e9eaffe919e: Message: Import Data.Typeable.TypeRep
rGHCe3242bd82331: Add mkFunTy
rGHC4c178916f5b4: testsuite/TypeRep: Add test for #12409
rGHCb1c0eee272d1: submodule changes
rGHCd53585cd0892: ghc-bin: Bump time bound
rGHCf4a82ef16473: Fix pretty-printer
rGHCa0b139d02057: Fix utils/Binary
rGHCfda1534def24: Fix nofib submodule
rGHC8700769c923c: Kill todo
rGHC0ac9466dc842: Start implementing library side of TTypeable
rGHC4538c794da02: Kill dead TODO
rGHCbe0471d07cd0: Update deepseq submodule
rGHC40b736700394: More test fixes
rGHC7b90d649a192: TcSMonad: Introduce tcLookupId
rGHCf03c84a652cb: Add TRArrow pattern synonym
rGHC57ec619e5037: Fix primitive types
rGHCd5c09aa1e59d: Fix up type printer
rGHC4f27d3dad97e: Fix unique clash
rGHC2fc04db5086c: TcTypeable: Kill tracing
rGHC82897d30effa: Add a TestEquality TypeRep instance
rGHCf03a22726d0f: Give unboxed tuples type representations
rGHC142f89c713b9: Begin work on kind computation
rGHC485cd9ea33d4: Finally serialization is both general and correct
rGHCeef1797c0a02: Implement withTypeable
rGHCf74e8f2cefc8: Enum Vec*
rGHCb106230d7013: Internal: Rename type variable
rGHCf99b787b421d: Simplify treatment of type lits
rGHC5812687c24fe: TcTypeable: Don't generate bindings for special primitive tycons
rGHCa604ce9471ce: Fix up representation pretty-printer
rGHC91e5c2feeb50: Various fixes
rGHCbdff108b9b53: Move special tycons
rGHC49f625d2f7de: Add quick compatibility note
rGHC4034bdfc5ed5: Various fixes
rGHC13e8b88fa7d6: Kill debugShow
rGHCb169b7ebb547: Un-bump time bound
rGHCe68d96155dd7: Another recursive serialization case
rGHCd78b3fdddc86: Add quick compatibility note
rGHC90ad65d3c487: Render type equality more readably
rGHC8833f38d31f6: Fix T8132
rGHCed590f04a326: Fix up rebase
rGHCa901d98a3b7d: Outputable: Refactor handling of CallStacks
rGHCe245e83f4c6a: Fix recursive fingerprints
rGHCf0a6eecd9f10: Reenable Core Lint
rGHCaa8510a6ae8e: Rework Show
rGHC12477d6d47e0: Kill todo
rGHC2bba4e051efa: Add explicit forall to SomeTypeRep
rGHC009b60765d42: testsuite: Add test of Typeable Binary instances
rGHC79d404c7934c: Implement Data.Typeable.funResultTy
rGHC957ac8d8e77e: Inline space
rGHC5c522f95501a: TcSMonad: Introduce tcLookupId
rGHC0a16af4a5b57: Note need for mkTrApp
rGHCe19c41e95b08: Fix primitive types
rGHC10f40d51a1b0: Things
rGHCce229eb96081: Fix up representation pretty-printer
rGHC7c411111ced8: TcTypeable: Fix it
rGHCccd8b09785ae: Fix up Binary instances
rGHC7e16c17a48df: Message: Import Data.Typeable.TypeRep
rGHCdfd90e24ba37: Fix up obviously incorrect comparisons
rGHCb3a9a72894d7: Make TRApp bidirectional
rGHCca6256801ceb: Fix a few TTypeRep references
rGHCeda8b0682053: TcTypeable: Be more careful about non-representable types
rGHCa617532e85f0: Handle literal kinds
rGHCebde9e405701: Implement Data.Typeable.funResultTy
rGHC1a644df32be7: Continue reintroduction of kind representations
rGHC555445542eea: Revert "TcTypeable: Kill tracing"
rGHC622eb750ddeb: Fix showTypeable
rGHCe912ddf6f386: Things
rGHC9453c38a9b71: Another recursive serialization case
rGHC0a6cd5b1a58c: Move special tycons
rGHC73e17b35d31c: Accept easy test output
rGHCc92c1dc498d7: Accept easy test output
rGHC1d16eb5925d8: More serialization
rGHC473288ec7d03: Fix warnings
rGHC14107305c5ab: Bump base to 4.10.0
rGHCb848d6d9dce6: Bump haskeline submodule
rGHCee5a0852c550: Fix serialization
rGHC69ddbb911cb0: Fix serialization
rGHCf83025c82bb7: Internal things
rGHC414aa451ea65: Temporarily override submodule upstream repo paths
rGHC1099a960764c: Fix rebase
rGHCe93b95e58fde: Clean up whitespace
rGHC16e361743ecb: CoreLint: Improve debug output
rGHC660b13e29b2f: More serialization
rGHC4268d6014c5c: Generate Typeable declarations for types in hs-boot files
rGHC80800f05451e: Binary: Compatibility with base<4.10
rGHCac90630d632a: Fixes
rGHCc56580f266b0: Fix hs-boot file
rGHC2db3572fa076: Kill redundant comment
rGHC4daf937fe458: Fix up type printer
rGHCe01ebe48f765: Kill debugShow
rGHC2f88acc72350: Binary: More explicit pattern matching
rGHC979b758ca807: Rip out manual TypeReps
rGHC0eacb1040e8a: TcInteract: Fix something
rGHC4f3c05163b39: Fix serialization
rGHCf6bcb2d96b19: Add reference to precedence note
rGHC0d039facb7e7: Fix up submodules
rGHCfe5bcf68d079: Fix pretty-printer
rGHCeee52b86426d: Kill redundant comment
rGHCf508c8821c49: Fix a few TTypeRep references
rGHC611e199393d9: Begin reverting to Simon's story
rGHC9abac3c18172: Make TRApp bidirectional
rGHC0098ba28c5d6: Fix it
rGHC2c2c2c6a3714: Continue
rGHC3006200420fa: Render TYPE 'PtrRepLifted as *
rGHC947b310cd201: Inline space
rGHC1f0ffda9e636: Internal things
rGHC6371dbaeb0eb: Clarify comments
rGHC06ede7f4ce14: Fix recursive fingerprints
Trac Issues
#11011
Summary

This at long last realizes the ideas for type-indexed Typeable discussed in A
Reflection on Types (Trac #11011). The general sketch of the project is described on
the Wiki (Typeable/BenGamari). The general idea is that we are adding a type
index to TypeRep,

data TypeRep (a :: k)

This index allows the typechecker to reason about the type represented by the TypeRep.
This index representation mechanism is exposed as Type.Reflection, which also provides
a number of patterns for inspecting TypeReps,

pattern TRFun :: forall k (fun :: k). ()
              => forall (r1 :: RuntimeRep) (r2 :: RuntimeRep) (arg :: TYPE r1) (res :: TYPE r2). (k ~ Type, fun ~~ (arg -> res))
              => TypeRep arg
              -> TypeRep res
              -> TypeRep fun

pattern TRApp :: forall k2 (t :: k2). ()
              => forall k1 (a :: k1 -> k2) (b :: k1). (t ~ a b)
              => TypeRep a -> TypeRep b -> TypeRep t

-- | Pattern match on a type constructor.
pattern TRCon :: forall k (a :: k). TyCon -> TypeRep a

-- | Pattern match on a type constructor including its instantiated kind
-- variables.
pattern TRCon' :: forall k (a :: k). TyCon -> [SomeTypeRep] -> TypeRep a

In addition, we give the user access to the kind of a TypeRep (Trac #10343),

typeRepKind :: TypeRep (a :: k) -> TypeRep k

Moreover, all of this plays nicely with 8.2's levity polymorphism, including the
newly levity polymorphic (->) type constructor.

Library changes

The primary change here is the introduction of a Type.Reflection module to base.
This module provides access to the new type-indexed TypeRep introduced in this
patch. We also continue to provide the unindexed Data.Typeable interface, which
is simply a type synonym for the existentially quantified SomeTypeRep,

data SomeTypeRep where SomeTypeRep :: TypeRep a -> SomeTypeRep

Naturally, this change also touched Data.Dynamic, which can now export the
Dynamic data constructor. Moreover, I removed a blanket reexport of
Data.Typeable from Data.Dynamic (which itself doesn't even import Data.Typeable
now).

We also add a kind heterogeneous type equality type, (:~~:), to
Data.Type.Equality.

Implementation

The implementation strategy is described in Note [Grand plan for Typeable] in
TcTypeable. None of it was difficult, but it did exercise a number of parts of
the new levity polymorphism story which had not yet been exercised, which took
some sorting out.

The rough idea is that we augment the TyCon produced for each type constructor
with information about the constructor's kind (which we call a KindRep). This
allows us to reconstruct the monomorphic result kind of an particular
instantiation of a type constructor given its kind arguments.

Unfortunately all of this takes a fair amount of work to generate and send
through the compilation pipeline. In particular, the KindReps can unfortunately
get quite large. Moreover, the simplifier will float out various pieces of them,
resulting in numerous top-level bindings. Consequently we mark the KindRep
bindings as noinline, ensuring that the float-outs don't make it into the
interface file. This is important since there is generally little benefit to
inlining KindReps and they would otherwise strongly affect compiler performance.

Performance

Initially I was hoping to also clear up the remaining holes in Typeable's
coverage by adding support for both unboxed tuples (Trac #12409) and unboxed sums
(Trac #13276). While the former was fairly straightforward, the latter ended up being
quite difficult: while the implementation can support them easily, enabling this
support causes thousands of Typeable bindings to be emitted to the GHC.Types as
each arity-N sum tycon brings with it N promoted datacons, each of which has a
KindRep whose size which itself scales with N. Doing this was simply too
expensive to be practical; consequently I've disabled support for the time
being.

Even after disabling sums this change regresses compiler performance far more
than I would like. In particular there are several testcases in the testsuite
which consist mostly of types which regress by over 30% in compiler allocations.
These include (considering the "bytes allocated" metric),

  • T1969: +10%
  • T10858: +23%
  • T3294: +19%
  • T5631: +41%
  • T6048: +23%
  • T9675: +20%
  • T9872a: +5.2%
  • T9872d: +12%
  • T9233: +10%
  • T10370: +34%
  • T12425: +30%
  • T12234: +16%
  • 13035: +17%
  • T4029: +6.1%

However, despite these rather dire numbers, the effect on real-world code tends
to be significantly smaller. Namely, per-module compiler allocations while compiling
lens and its dependencies increased by ~0.4% on mean (25th percentile of -0.05%,
75th percentile of 0.75%), while compilation time increased by 1.4% (25th percentile
of -2.13%, 75th percentile of 2.3%).

I've spent quite some time chasing down the source of this regression and while
I was able to make som improvements, I think this approach of generating
Typeable bindings at time of type definition is doomed to give us unnecessarily
large compile-time overhead.

In the future I think we should consider moving some of all of the Typeable
binding generation logic back to the solver (where it was prior to
91c6b1f54aea658b0056caec45655475897f1972). I've opened Trac #13261 documenting this
proposal.

Test Plan

validate

Diff Detail

Repository
rGHC Glasgow Haskell Compiler
Branch
wip/ttypeable
Lint
Lint WarningsExcuse: It's okay
SeverityLocationCodeMessage
Warningcompiler/coreSyn/CoreLint.hs:1015TXT3Line Too Long
Warningcompiler/deSugar/DsBinds.hs:1210TXT3Line Too Long
Warningcompiler/deSugar/DsBinds.hs:1213TXT3Line Too Long
Warningcompiler/deSugar/DsBinds.hs:1221TXT3Line Too Long
Warningcompiler/deSugar/DsBinds.hs:1222TXT3Line Too Long
Warningcompiler/prelude/PrelNames.hs:1220TXT3Line Too Long
Warningcompiler/prelude/PrelNames.hs:1221TXT3Line Too Long
Warningcompiler/prelude/PrelNames.hs:1222TXT3Line Too Long
Warningcompiler/prelude/PrelNames.hs:1223TXT3Line Too Long
Warningcompiler/prelude/PrelNames.hs:1224TXT3Line Too Long
Warningcompiler/prelude/PrelNames.hs:1225TXT3Line Too Long
Warningcompiler/prelude/PrelNames.hs:1226TXT3Line Too Long
Warningcompiler/prelude/PrelNames.hs:1227TXT3Line Too Long
Warningcompiler/prelude/PrelNames.hs:1233TXT3Line Too Long
Warningcompiler/prelude/PrelNames.hs:1234TXT3Line Too Long
Warningcompiler/prelude/PrelNames.hs:1235TXT3Line Too Long
Warningcompiler/prelude/PrelNames.hs:1252TXT3Line Too Long
Warningcompiler/prelude/PrelNames.hs:1253TXT3Line Too Long
Warningcompiler/prelude/PrelNames.hs:1255TXT3Line Too Long
Warningcompiler/prelude/PrelNames.hs:1256TXT3Line Too Long
Warningcompiler/prelude/PrelNames.hs:1257TXT3Line Too Long
Warningcompiler/prelude/TysWiredIn.hs:979TXT3Line Too Long
Warningcompiler/typecheck/TcTypeable.hs:247TXT3Line Too Long
Warningcompiler/typecheck/TcTypeable.hs:302TXT3Line Too Long
Warningcompiler/typecheck/TcTypeable.hs:543TXT3Line Too Long
Unit
No Unit Test Coverage
Build Status
Buildable 13923
Build 20910: [GHC] Linux/amd64: Patch building
Build 20909: [GHC] OSX/amd64: Continuous Integration
Build 20908: [GHC] Windows/amd64: Continuous Integration
Build 20907: arc lint + arc unit
There are a very large number of changes, so older changes are hidden. Show Older Changes

There are a number of tasks outstanding:

  • Fix representation pretty-printer to correctly handle tuples, lists, arrows, and precedence
  • Look at the testsuite failures:
    • several are easy output changes
    • others are testcases which appear to use internal Typeable interfaces that have changed: T8132, dynamic002
    • others seems to involve stack overflows: T10294, plugins01, T5550, annrun01, ann01, annth_make,
    • others are Core lint violations: T11120
    • others appear to be performance changes (even some improvements, perplexingly) that need to be examined
  • Carefully check Data.Typeable for deviations from the previous interface and fill in gaps where possible
  • Evaluate serialization/deserization performance; perhaps it would be worth offering unsafe interface without runtime checks?
  • Examine whether the primitive TypeReps (e.g. trTYPE, trArrow) should be INLINEABLE; we perform a number of runtime checks during serialization/deserialization so being able to inline these fingerprints may be helpful.
  • Evaluate whether we want to try harder to preserve the re-exports that have been dropped from Data.Dynamic.
bgamari added a comment.EditedMar 16 2016, 9:57 AM

Also, I've recently been considering another plan for handling the representations for primitive types (e.g. TYPE, Levity, and (->)), which are currently tricky due to their recursive kind relationships. Currently I go to great length to construct knot-tied representations manually. While this allows me to handle these types consistently with "normal" types internally, this consistency is a bit misleading as these cases do actually require special treatment to avoid bottoming in some cases. It might be easier to instead handle these types by directly encoding them in TypeRep.

bgamari updated this revision to Diff 6947.Mar 16 2016, 4:22 PM
bgamari edited edge metadata.

It works!

The remaining testsuite issues are,

TEST="T11702 break024 print019 break011 allocLimit4 TypeOf T11120 dynamic002 T11334 T5962 dynamic004 annth_compunits TcStaticPointersFail02 T11145 GoodImport03 T8132 lazy-bs-alloc haddock.base T5837"
bgamari updated this revision to Diff 6948.Mar 16 2016, 6:10 PM
bgamari edited edge metadata.

Fix a few more issues

bgamari planned changes to this revision.May 10 2016, 8:53 AM

There is still more work to be done here. See the status page for details.

bgamari updated this revision to Diff 8177.Jul 10 2016, 3:54 AM
bgamari edited edge metadata.
  • HACK: CoreLint: Kill unsaturated unlifted types check
  • TcSMonad: Introduce tcLookupId
  • Outputable: Refactor handling of CallStacks
  • CoreLint: Improve debug output
  • Start implementing library side of TTypeable
  • Fix rebase
  • Add quick compatibility note
  • Fix warnings
  • Various fixes
  • Fix serialization
  • Implement Data.Typeable.funResultTy
  • Binary: More explicit pattern matching
  • More serialization
  • Message: Import Data.Typeable.TypeRep
  • TcInteract: Unused parameter
  • Fix a few TTypeRep references
  • Fix recursive fingerprints
  • Finally serialization is both general and correct
  • Break recursive loop in serialization
  • Kill todo
  • Fix up representation pretty-printer
  • Another recursive serialization case
  • TcTypeable: Don't generate bindings for special primitive tycons
  • Move special tycons
  • Internal things
  • Fix primitive types
  • Fix pretty-printer
  • Kill debugShow
  • Inline space
  • Accept easy test output
  • Add mkFunTy
  • More test fixes
  • Fix T8132
  • Render TYPE 'PtrRepLifted as *
  • Internal: Rename type variable
  • Implement withTypeable
  • Bump base to 4.10.0
  • Fix withTypeable
  • Bump base
  • testsuite: Bump base version
  • Rework Show
  • Testsuite updates
  • Clarify serialization errors
  • Kill redundant comment
  • Note need for mkTrApp
  • Make TRApp bidirectional
  • Add TRArrow pattern synonym
  • Fix up type printer
  • submodule changes

Rebased but there is still more work to be done here. See the status page for details.

bgamari planned changes to this revision.Jul 10 2016, 3:55 AM
bgamari updated this revision to Diff 8853.Oct 2 2016, 2:01 PM
bgamari edited edge metadata.
  • HACK: CoreLint: Kill unsaturated unlifted types check
  • TcSMonad: Introduce tcLookupId
  • CoreLint: Improve debug output
  • Start implementing library side of TTypeable
  • Fix rebase
  • Add quick compatibility note
  • Fix warnings
  • Various fixes
  • Fix serialization
  • Implement Data.Typeable.funResultTy
  • Binary: More explicit pattern matching
  • More serialization
  • Message: Import Data.Typeable.TypeRep
  • TcInteract: Unused parameter
  • Fix a few TTypeRep references
  • Fix recursive fingerprints
  • Finally serialization is both general and correct
  • Break recursive loop in serialization
  • Kill todo
  • Fix up representation pretty-printer
  • Another recursive serialization case
  • TcTypeable: Don't generate bindings for special primitive tycons
  • Move special tycons
  • Internal things
  • Fix primitive types
  • Fix pretty-printer
  • Kill debugShow
  • Inline space
  • Accept easy test output
  • Add mkFunTy
  • More test fixes
  • Fix T8132
  • Render TYPE 'PtrRepLifted as *
  • Internal: Rename type variable
  • Implement withTypeable
  • Bump base to 4.10.0
  • Fix withTypeable
  • Bump base
  • testsuite: Bump base version
  • Rework Show
  • Testsuite updates
  • Clarify serialization errors
  • Kill redundant comment
  • Note need for mkTrApp
  • Make TRApp bidirectional
  • Add TRArrow pattern synonym
  • Fix up type printer
  • TcInteract: Fix something
  • Fix showTypeable
  • Fix serialization
  • Clarify comments
  • Binary: Simple serialization test works
  • Give unboxed tuples type representations
  • testsuite/TypeRep: Add test for Trac #12409
  • testsuite: Add test of Typeable Binary instances
  • TcTypeable: Clarify comment
  • Update submodules
  • Temporarily override submodule upstream repo paths
  • Add a TestEquality TypeRep instance
  • Debug
  • Fix submodules
  • Add reference to precedence note
simonmar added inline comments.Oct 3 2016, 11:01 AM
libraries/base/Data/Typeable/Internal.hs
173

don't forget to UNPACK the fingerprints

175

Here too

libraries/ghci/GHCi/TH/Binary.hs
113

What type of TyCon is being created here? Looks like it is ambiguous, so I must be misunderstanding something.

bgamari retitled this revision from Type-indexed type representation to Type-indexed type representations.Oct 3 2016, 8:27 PM
bgamari edited edge metadata.
bgamari planned changes to this revision.Dec 6 2016, 12:04 AM

This is still a work in progress.

dfeuer added a subscriber: dfeuer.Jan 23 2017, 1:18 AM
dfeuer added inline comments.
libraries/base/Data/Typeable/Internal.hs
200

Can you add a comment explaining why unsafeCoerce# is necessary? I'd have expected to see

... = unsafeCoerce Just Refl

Is this way easier on the inliner? If you want, you can go all out and inline absolutely everything by hand, which should make it extremely unlikely that Just constructors will escape simplification.

instance TestEquality TypeRep where
  testEquality (TrTyCon af _ _) (TrTyCon bf _ _)
    | af == bf = Just (unsafeCoerce# Refl)
    | otherwise = Nothing
  {-# INLINE testEquality #-}
356

The same question about unsafeCoerce# applies here too.

bgamari updated this revision to Diff 10771.Jan 28 2017, 2:17 AM
  • TcSMonad: Introduce tcLookupId
  • CoreLint: Improve debug output
  • Start implementing library side of TTypeable
  • Fix rebase
  • Add quick compatibility note
  • Fix warnings
  • Various fixes
  • Fix serialization
  • Implement Data.Typeable.funResultTy
  • Binary: More explicit pattern matching
  • More serialization
  • Message: Import Data.Typeable.TypeRep
  • TcInteract: Unused parameter
  • Fix a few TTypeRep references
  • Fix recursive fingerprints
  • Finally serialization is both general and correct
  • Break recursive loop in serialization
  • Kill todo
  • Fix up representation pretty-printer
  • Another recursive serialization case
  • TcTypeable: Don't generate bindings for special primitive tycons
  • Move special tycons
  • Internal things
  • Fix primitive types
  • Fix pretty-printer
  • Kill debugShow
  • Inline space
  • Accept easy test output
  • Add mkFunTy
  • More test fixes
  • Fix T8132
  • Render TYPE 'PtrRepLifted as *
  • Internal: Rename type variable
  • Implement withTypeable
  • Bump base to 4.10.0
  • Fix withTypeable
  • Rework Show
  • Clarify serialization errors
  • Kill redundant comment
  • Note need for mkTrApp
  • Make TRApp bidirectional
  • Add TRArrow pattern synonym
  • Fix up type printer
  • TcInteract: Fix something
  • Fix showTypeable
  • Fix serialization
  • Clarify comments
  • Binary: Simple serialization test works
  • Give unboxed tuples type representations
  • testsuite/TypeRep: Add test for Trac #12409
  • testsuite: Add test of Typeable Binary instances
  • TcTypeable: Clarify comment
  • Temporarily override submodule upstream repo paths
  • Add a TestEquality TypeRep instance
  • Debug
  • Add reference to precedence note
  • Unpack the fingerprints
  • Fix it
  • Introduce TrFun
  • Things
  • Rename TypeRepX to SomeTypeRep
  • Begin reverting to Simon's story
  • Begin reintroducing typeRepKind
  • Continue reintroduction of kind representations
  • Continue
  • Rip out manual TypeReps
  • base: Derive Enum, Bounded for VecCount, VecElem
  • Getting there
  • Enum Vec*
  • TcTypeable: Fix it
  • Fix up submodules
  • TcTypeable: It compiles GHC.Types!
  • TcTypeable: Kill tracing
  • Message: Fix it
  • ghc-bin: Bump time bound
  • Fix it
  • Things
  • Fixes
  • Revert "TcTypeable: Kill tracing"
  • Fix up rebase
  • Un-bump time bound
  • Fix unique clash
  • Fix hs-boot file
  • Fix up Binary instances
  • Add explicit forall to SomeTypeRep
  • TcTypeable: Look through type synonyms
  • Fix utils/Binary
  • Begin work on kind computation
  • Binary: Compatibility with base<4.10
  • TcTypeable: Fix kind variable count
  • TcTypeable: A bit more debug output and fix binder ordering
  • Internal: Various cleanups
  • Hi
bgamari updated this revision to Diff 10785.Jan 29 2017, 12:06 AM
bgamari edited edge metadata.
  • Reenable Core Lint
  • Fix up obviously incorrect comparisons
  • Clean up whitespace
  • Fix kind instantiation
  • Export mkTrFun
  • Kill dead TODO
  • TcTypeable: Be more careful about non-representable types
  • Handle literal kinds
  • Generate Typeable declarations for types in hs-boot files
  • Simplify treatment of type lits
bgamari updated this revision to Diff 10786.Jan 29 2017, 12:09 AM
bgamari edited edge metadata.

Fix base commit

bgamari updated this revision to Diff 10800.Jan 29 2017, 11:59 PM
bgamari edited edge metadata.
  • Revert OccName changes
  • Clean up build issues
  • Clean up Data.Dynamic
  • fixup! Clean up build issues
  • RnSource: Turn comment into Haddock comment
  • RnModIface: Rename typeable bindings as never-exported
  • OccName: Account for module bindings as well
  • Fix instantiation of tyconapps
  • Clean up debug output
  • Add a bit of a tricky testcase
  • Fix a few tests
  • Kill debug output
  • Update more testsuite output
  • More testsuite output
  • GoodImport03: Update
  • dynamic002: Fix import
  • More testsuite updates
  • fixup! dynamic002: Fix import
  • Generate TyCons for sums
  • Add Binary TypeLitSort instance
  • KnownUniques: Handle invalid tag case
  • Fix pretty-printer
  • lazy-bs-alloc: Bump down allocations
  • Uncomment funResultTy definition
  • Fix warning
  • Refactor funResultTy
  • Fix up more testsuite output
bgamari updated this object.Feb 1 2017, 11:37 PM
bgamari edited edge metadata.
bgamari updated this revision to Diff 10879.Feb 2 2017, 12:52 AM
bgamari marked an inline comment as done.
bgamari updated this object.

Squash and begin cleanup

bgamari updated this revision to Diff 10880.Feb 2 2017, 12:57 AM
bgamari edited edge metadata.
  • Fix Binary instances
bgamari updated this revision to Diff 10882.Feb 2 2017, 1:23 AM
bgamari edited edge metadata.
  • Type-indexed Typeable
  • Add catchalls
bgamari updated this revision to Diff 10895.Feb 2 2017, 11:45 AM
bgamari edited edge metadata.
  • TcInteract: Cleanup imports
  • Fix warning
  • Comments
bgamari added inline comments.
compiler/typecheck/TcTypeable.hs
411

@goldfire, @simonpj, I would appreciate some feedback on this function. I believe it captures the conditions we want to require for Typeable types, however I can't help but wonder whether there's an easier way to accomplish this. Moreover, I'm not entirely confident in the CastTy check; it seems awfully indirect.

bgamari updated this revision to Diff 11130.Feb 12 2017, 7:39 PM
  • Type-indexed Typeable
  • Move Typeable Binary instances to binary package
  • Disable Typeable binding generation for unboxed tuples
  • Mark KindReps as noinline
  • Plop kindreps in another binding
  • Make unboxed sums not Typeable
  • Fix tests
  • More notes
  • Documentation
bgamari edited the summary of this revision. (Show Details)Feb 12 2017, 7:39 PM
dfeuer added inline comments.Feb 12 2017, 11:39 PM
compiler/prelude/PrelNames.hs
2009

That's a lot of keys! Does this have some benefit for performance over just inserting names? I can't seem to find anything explaining that.

compiler/types/Kind.hs
25

Everybody hates SOURCE. Could you maybe add a comment explaining why these are required, so people will understand why they can't eliminate them?

libraries/base/Data/Typeable/Internal.hs
162

rnfTyCon and rnfKindRep smell much more expensive than I'd have expected. Is it possible that forcing the strings will ever fail or cost more than a small constant times their length? If not, it would probably be better for rnf to perform a shallow forcing operation instead. Don't slow down the default (generic) definition of rnf unless you have to!

212

Could you add a comment explaining why SomeTypeRep is not a strict constructor, or make it strict?

352

Why not use a strict foldl'? foldl' applyTy tycon_app ty_args

520

Should this use errorWithoutStackTrace?

571

I'm scared of catch-all patterns. How expensive would it be to list them all?

libraries/base/GHC/Show.hs
3

Why do we now need PolyKinds here?

libraries/base/changelog.md
60

How about reordering:

A new module, Type.Reflection, exposes GHC's new type-indexed type representation mechanism.

66

How about "type equality evidence type" or something? "Type equality type" sounds a bit odd to my ears.

libraries/base/tests/dynamic002.hs
9

Why the CPP?

libraries/ghc-boot/GHC/Serialized.hs
34

What's this change for?

libraries/ghc-prim/GHC/Types.hs
460

I count 7 constructors. IIRC, that's the limit for pointer tagging. It may make sense to add a comment mentioning the potential performancy impact of adding additional constructors, and what order those should be added in.

libraries/ghci/GHCi/TH/Binary.hs
6

It's a bit surprising to see a bunch of code go away and a bunch of language extensions added.

bgamari edited the summary of this revision. (Show Details)Feb 13 2017, 8:38 AM

Why are unboxed sums particularly problematic? If the problematic types are ones that GHC produces under the hood, that are not visible to users, then are their Typeable instances even useful? Would it make sense to simply skip over non-user-visible generated types?

dfeuer added inline comments.Feb 13 2017, 6:44 PM
libraries/base/Data/Typeable/Internal.hs
175

Using [SomeTypeRep] in TrTyCon smells very strange to me. It has an extra indirection per element. Why not put the typereps into a custom list type? I'm not sure what strictness you want for each element, but here's a first approximation.

data TRList where
  TRCons :: forall k (a :: k). TypeRep a -> TRList -> TRList
  TRNil :: TRList
bgamari abandoned this revision.Feb 18 2017, 8:54 PM

This was merged in 8fa4bf9ab3f4ea4b208f4a43cc90857987e6d497