[commit: ghc] wip/tdammers/T11735-1: Added Note [Nested ForAllCos] according to D4355 (57221a2)

git at git.haskell.org git at git.haskell.org
Tue Jan 30 16:26:26 UTC 2018


Repository : ssh://git@git.haskell.org/ghc

On branch  : wip/tdammers/T11735-1
Link       : http://ghc.haskell.org/trac/ghc/changeset/57221a25018e4f9560d63a87c5282773ee259d36/ghc

>---------------------------------------------------------------

commit 57221a25018e4f9560d63a87c5282773ee259d36
Author: Tobias Dammers <tdammers at gmail.com>
Date:   Tue Jan 30 17:25:41 2018 +0100

    Added Note [Nested ForAllCos] according to D4355


>---------------------------------------------------------------

57221a25018e4f9560d63a87c5282773ee259d36
 compiler/types/Coercion.hs | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/compiler/types/Coercion.hs b/compiler/types/Coercion.hs
index d92b362..7a7918c 100644
--- a/compiler/types/Coercion.hs
+++ b/compiler/types/Coercion.hs
@@ -1757,6 +1757,7 @@ coercionKind co =
     go_app co              args = piResultTys <$> go co <*> (sequenceA $ map go args)
 
     go_forall subst (ForAllCo tv1 k_co co)
+      -- See Note [Nested ForAllCos]
       = mkInvForAllTy <$> Pair tv1 tv2 <*> go_forall subst' co
       where
         Pair _ k2 = go k_co
@@ -1767,6 +1768,23 @@ coercionKind co =
     go_forall subst other_co
       = substTy subst `pLiftSnd` go other_co
 
+{-
+
+Note [Nested ForAllCos]
+~~~~~~~~~~~~~~~~~~~~~~~
+
+Suppose we need `coercionKind (ForAllCo a1 (ForAllCo a2 ... (ForAllCo an
+co)...) )`.   We do not want to perform `n` single-type-variable
+substitutions over the kind of `co`; rather we want to do one substitution
+which substitutes for all of `a1`, `a2` ... simultaneously.  If we do one
+at a time we get the performance hole reported in Trac #11735.
+
+Solution: gather up the type variables for nested `ForAllCos`, and
+substitute for them all at once.  Remarkably, for Trac #11735 this single
+change reduces /total/ compile time by a factor of more than ten.
+
+-}
+
 -- | Apply 'coercionKind' to multiple 'Coercion's
 coercionKinds :: [Coercion] -> Pair [Type]
 coercionKinds tys = sequenceA $ map coercionKind tys



More information about the ghc-commits mailing list