[commit: ghc] wip/rae: Fix #12919 by making the flattener homegeneous. (dd069c1)

git at git.haskell.org git at git.haskell.org
Fri Sep 29 01:06:11 UTC 2017


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

On branch  : wip/rae
Link       : http://ghc.haskell.org/trac/ghc/changeset/dd069c16d675e4fed67ba5575d8113ef90c5ffba/ghc

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

commit dd069c16d675e4fed67ba5575d8113ef90c5ffba
Author: Richard Eisenberg <rae at cs.brynmawr.edu>
Date:   Thu Aug 3 15:18:39 2017 -0400

    Fix #12919 by making the flattener homegeneous.
    
    This changes a key invariant of the flattener. Previously,
    flattening a type meant flattening its kind as well. But now,
    flattening is always homogeneous -- that is, the kind of the
    flattened type is the same as the kind of the input type.
    This is achieved by various wizardry in the TcFlatten.flatten_many
    function, as described in Note [flatten_many].
    
    There are several knock-on effects, including some refactoring
    in the canonicalizer to take proper advantage of the flattener's
    changed behavior. In particular, the tyvar case of can_eq_nc' no
    longer needs to take casts into account.
    
    Another effect is that flattening a tyconapp might change it
    into a casted tyconapp. This might happen if the result kind
    of the tycon contains a variable, and that variable changes
    during flattening. Because the flattener is homogeneous, it tacks
    on a cast to keep the tyconapp kind the same. However, this
    is problematic when flattening CFunEqCans, which need to have
    an uncasted tyconapp on the LHS and must remain homogeneous.
    The solution is a more involved canCFunEqCan, described in
    Note [canCFunEqCan].
    
    This patch fixes #13643 (as tested in typecheck/should_compile/T13643)
    and the panic in typecheck/should_compile/T13822 (as reported in #14024).
    Actually, there were two bugs in T13822: the first was just some
    incorrect logic in tryFill (part of the unflattener) -- also fixed
    in this patch -- and the other was the main bug fixed in this ticket.
    
    The changes in this patch exposed a long-standing flaw in OptCoercion,
    in that breaking apart an AppCo sometimes has unexpected effects on
    kinds. See new Note [EtaAppCo] in OptCoercion, which explains the
    problem and fix.
    
    Also here is a reversion of the major change in
    09bf135ace55ce2572bf4168124d631e386c64bb, affecting ctEvCoercion.
    It turns out that making the flattener homogeneous changes the
    invariants on the algorithm, making the change in that patch
    no longer necessary.
    
    This patch also fixes #14038, and hence #13910 and #13938.


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

dd069c16d675e4fed67ba5575d8113ef90c5ffba
 compiler/typecheck/TcCanonical.hs                  | 317 +++++---
 compiler/typecheck/TcFlatten.hs                    | 795 ++++++++++++++-------
 compiler/typecheck/TcInteract.hs                   |  51 +-
 compiler/typecheck/TcMType.hs                      |  11 +-
 compiler/typecheck/TcRnTypes.hs                    |  15 +-
 compiler/typecheck/TcSMonad.hs                     |  26 +-
 compiler/typecheck/TcType.hs                       |   2 +-
 compiler/types/Coercion.hs                         | 235 +++---
 compiler/types/Coercion.hs-boot                    |   1 +
 compiler/types/OptCoercion.hs                      | 110 ++-
 compiler/types/TyCoRep.hs                          |  83 ++-
 compiler/types/Type.hs                             |  84 +--
 testsuite/tests/dependent/should_compile/all.T     |   6 +-
 .../tests/dependent/should_fail/RAE_T32a.stderr    |  25 +-
 testsuite/tests/dependent/should_fail/all.T        |   2 +-
 testsuite/tests/typecheck/should_compile/T13643.hs |  22 +
 testsuite/tests/typecheck/should_compile/all.T     |   3 +-
 .../tests/typecheck/should_fail/T12373.stderr      |   8 +-
 18 files changed, 1143 insertions(+), 653 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 dd069c16d675e4fed67ba5575d8113ef90c5ffba


More information about the ghc-commits mailing list