[commit: ghc] master: Allow unbound Refl binders in a RULE (8674883)

git at git.haskell.org git at git.haskell.org
Wed Mar 29 13:59:36 UTC 2017


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

On branch  : master
Link       : http://ghc.haskell.org/trac/ghc/changeset/8674883c137401873fd53a6963acd33af651c2af/ghc

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

commit 8674883c137401873fd53a6963acd33af651c2af
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.


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

8674883c137401873fd53a6963acd33af651c2af
 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 8674883c137401873fd53a6963acd33af651c2af


More information about the ghc-commits mailing list