[commit: ghc] wip/tdammers/D4394: Fixed NthCo Note (discussion in D4385) (28b59e4)
git at git.haskell.org
git at git.haskell.org
Thu Mar 22 11:02:37 UTC 2018
Repository : ssh://git@git.haskell.org/ghc
On branch : wip/tdammers/D4394
Link : http://ghc.haskell.org/trac/ghc/changeset/28b59e41de0932958179a64985cff5557fe1fa0a/ghc
>---------------------------------------------------------------
commit 28b59e41de0932958179a64985cff5557fe1fa0a
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
>---------------------------------------------------------------
28b59e41de0932958179a64985cff5557fe1fa0a
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 4614eae..b6ccc93 100644
--- a/compiler/types/TyCoRep.hs
+++ b/compiler/types/TyCoRep.hs
@@ -1181,14 +1181,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