[commit: ghc] wip/tdammers/D4394: Fixed NthCo Note (discussion in D4385) (1d74d1e)
git at git.haskell.org
git at git.haskell.org
Tue Mar 20 11:53:55 UTC 2018
Repository : ssh://git@git.haskell.org/ghc
On branch : wip/tdammers/D4394
Link : http://ghc.haskell.org/trac/ghc/changeset/1d74d1ec1be42850b83eca800b80189ab868aa00/ghc
>---------------------------------------------------------------
commit 1d74d1ec1be42850b83eca800b80189ab868aa00
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
>---------------------------------------------------------------
1d74d1ec1be42850b83eca800b80189ab868aa00
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 014dadc..c719b31 100644
--- a/compiler/types/TyCoRep.hs
+++ b/compiler/types/TyCoRep.hs
@@ -1157,14 +1157,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