[commit: ghc] wip/tdammers/D4394: Fixed NthCo Note (discussion in D4385) (7ef2f9c)

git at git.haskell.org git at git.haskell.org
Tue Mar 27 14:28:34 UTC 2018


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

On branch  : wip/tdammers/D4394
Link       : http://ghc.haskell.org/trac/ghc/changeset/7ef2f9ccab2fa39537a9af4a6a2a313d84a9b031/ghc

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

commit 7ef2f9ccab2fa39537a9af4a6a2a313d84a9b031
Author: Tobias Dammers <tdammers at gmail.com>
Date:   Wed Feb 7 13:19:33 2018 +0100

    Fixed NthCo Note (discussion in D4385)
    
    https://phabricator.haskell.org/D4385#inline-34161


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

7ef2f9ccab2fa39537a9af4a6a2a313d84a9b031
 compiler/types/TyCoRep.hs | 22 ++++++++++++++--------
 1 file changed, 14 insertions(+), 8 deletions(-)

diff --git a/compiler/types/TyCoRep.hs b/compiler/types/TyCoRep.hs
index 93ec274..cd295f7 100644
--- a/compiler/types/TyCoRep.hs
+++ b/compiler/types/TyCoRep.hs
@@ -1236,14 +1236,20 @@ in the "Safe Coercions" paper (ICFP '14).
 
 Note [NthCo Cached Roles]
 ~~~~~~~~~~~~~~~~~~~~~~~~~
-Looking at coercionKind and coercionRole, we see that in order to find the Role
-for an NthCo, we have to know the kind; unfortunately, calculating the coercion
-kind for a nested NthCo is quadratic in the nesting depth, so we would like to
-avoid doing that as much as possible. To this end, we calculate the Role at
-construction time, and store it in the NthCo itself, thus removing the need to
-do the calculation on the fly.
-
-See Trac #11735 for the discussion that led to this.
+Why do we cache the role of NthCo in the NthCo constructor?
+Because computing role(Nth i co) involves figuring out that
+
+  co :: T tys1 ~ T tys2
+
+using coercionKind, and finding (coercionRole co), and then looking
+at the tyConRoles of T. Avoiding bad asymptotic behaviour here means
+we have to compute the kind and role of a coercion simultaneously,
+which makes the code complicated and inefficient.
+
+This only happens for NthCo. Caching the role solves the problem, and
+allows coercionKind and coercionRole to be simple.
+
+See Trac #11735
 
 Note [InstCo roles]
 ~~~~~~~~~~~~~~~~~~~



More information about the ghc-commits mailing list