[commit: ghc] ghc-8.2: Allow unbound Refl binders in a RULE (7087abf)

git at git.haskell.org git at git.haskell.org
Thu Mar 30 00:38:06 UTC 2017


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

On branch  : ghc-8.2
Link       : http://ghc.haskell.org/trac/ghc/changeset/7087abfe2ba944d6609eee399c5ad2ca44cd388c/ghc

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

commit 7087abfe2ba944d6609eee399c5ad2ca44cd388c
Author: Simon Peyton Jones <simonpj at microsoft.com>
Date:   Wed Mar 29 09:00:02 2017 +0100

    Allow unbound Refl binders in a RULE
    
    Trac #13410 was failing because we had a RULE with a binder
       (c :: t~t)
    and the /occurrences/ of c on the LHS were being optimised to Refl,
    leaving a binder that would not be filled in by matching the LHS
    of the rule.
    
    I flirted with trying to ensure that occurrences (c :: t~t) are
    not optimised to Relf, but that turned out to be fragile; it was
    being done, for good reasons, in multiple places, including
      - TyCoRep.substCoVarBndr
      - Simplify.simplCast
      - Corecion.mkCoVarCo
    
    So I fixed it in one place by making Rules.matchN deal happily
    with an unbound binder (c :: t~t).  Quite easy.  See "Coercion
    variables" in Note [Unbound RULE binders] in Rules.
    
    In addition, I needed to make CoreLint be happy with an bound
    RULE binder that is a Relf coercion variable
    
    In debugging this, I was perplexed that occurrences of a variable
    (c :: t~t) mysteriously turned into Refl.  I found out how it
    was happening, and decided to move it:
    
    * In TyCoRep.substCoVarBndr, do not substitute Refl for a
      binder (c :: t~t).
    
    * In mkCoVarCo do not optimise (c :: t~t) to Refl.
    
    Instead, we do this optimisation in optCoercion (specifically
    opt_co4) where, surprisingly, the optimisation was /not/
    being done.  This has no effect on what programs compile;
    it just moves a relatively-expensive optimisation to optCoercion,
    where it seems more properly to belong.  It's actually not clear
    to me which is really "better", but this way round is less
    surprising.
    
    One small simplifying refactoring
    
    * Eliminate TyCoRep.substCoVarBndrCallback, which was only
      called locally.
    
    (cherry picked from commit 8674883c137401873fd53a6963acd33af651c2af)


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

7087abfe2ba944d6609eee399c5ad2ca44cd388c
 compiler/coreSyn/CoreLint.hs                       |  18 ++-
 compiler/specialise/Rules.hs                       |  47 +++++--
 compiler/types/Coercion.hs                         |  33 +++--
 compiler/types/OptCoercion.hs                      |  32 ++++-
 compiler/types/TyCoRep.hs                          |  22 +--
 testsuite/tests/simplCore/should_compile/T13410.hs | 152 +++++++++++++++++++++
 testsuite/tests/simplCore/should_compile/all.T     |   1 +
 7 files changed, 260 insertions(+), 45 deletions(-)

Diff suppressed because of size. To see it, use:

    git diff-tree --root --patch-with-stat --no-color --find-copies-harder --ignore-space-at-eol --cc 7087abfe2ba944d6609eee399c5ad2ca44cd388c


More information about the ghc-commits mailing list