[commit: ghc] master: Refactor bindHsQTyVars and friends (0257dac)

git at git.haskell.org git at git.haskell.org
Tue Aug 29 08:37:42 UTC 2017


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

On branch  : master
Link       : http://ghc.haskell.org/trac/ghc/changeset/0257dacf228024d0cc6ba247c707130637a25580/ghc

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

commit 0257dacf228024d0cc6ba247c707130637a25580
Author: Simon Peyton Jones <simonpj at microsoft.com>
Date:   Mon Aug 28 14:20:02 2017 +0100

    Refactor bindHsQTyVars and friends
    
    This work was triggered by Trac #13738, which revealed to me that
    the code RnTypes.bindHsQTyVars and bindLHsTyVarBndrs was a huge
    tangled mess -- and outright wrong on occasion as the ticket showed.
    
    The big problem was that bindLHsTyVarBndrs (which is invoked at every
    HsForAll, including nested higher rank ones) was attempting to bind
    implicit kind variables, which it has absolutely no busineess doing.
    Imlicit kind quantification is done at the outside only, in fact
    precisely where we have HsImplicitBndrs or LHsQTyVars (which also
    has implicit binders).
    
    Achieving this move was surprisingly hard, because more and more
    barnacles had accreted aroud the original mistake.  It's much
    much better now.
    
    Summary of changes.  Almost all the action is in RnTypes.
    
    * Implicit kind variables are bound only by
      - By bindHsQTyVars, which deals with LHsQTyVars
      - By rnImplicitBndrs, which deals with HsImplicitBndrs
    
    * bindLHsTyVarBndrs, and bindLHsTyVarBndr are radically simplified.
      They simply does far less, and have lots their forest of
      incomprehensible accumulating parameters.  (To be fair, some of
      the code in bindLHsTyVarBndrs just moved to bindHsQTyVars, but
      in much more perspicuous form.)
    
    * The code that checks if a variable appears in both a kind and
      a type (triggering RnTypes.mixedVarsErr) was bizarre.  E.g.
      we had this in RnTypes.extract_hs_tv_bndrs
           ; check_for_mixed_vars bndr_kvs acc_tvs
           ; check_for_mixed_vars bndr_kvs body_tvs
           ; check_for_mixed_vars body_tvs acc_kvs
           ; check_for_mixed_vars body_kvs acc_tvs
           ; check_for_mixed_vars locals body_kvs
      I cleaned all this up; now we check for mixed use at binding
      sites only.
    
    * Checks for "Variable used as a kind before being bound", like
         data T (a :: k) k = rhs
      now just show up straightforwardly as "k is not in scope".
      See Note [Kind variable ordering]
    
    * There are some knock-on simplifications in RnSource.


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

0257dacf228024d0cc6ba247c707130637a25580
 compiler/rename/RnSource.hs                        |  86 ++--
 compiler/rename/RnTypes.hs                         | 440 +++++++++------------
 testsuite/tests/ghci/scripts/T7873.stderr          |  10 +-
 .../indexed-types/should_fail/SimpleFail6.stderr   |   4 +-
 testsuite/tests/polykinds/BadKindVar.hs            |   9 +
 testsuite/tests/polykinds/BadKindVar.stderr        |   4 +
 testsuite/tests/polykinds/T13738.hs                |  14 +
 testsuite/tests/polykinds/T13738.stderr            |   4 +
 testsuite/tests/polykinds/T7404.stderr             |   5 +-
 testsuite/tests/polykinds/all.T                    |   2 +
 testsuite/tests/rename/should_fail/T11592.stderr   |  21 +-
 .../tests/typecheck/should_fail/T11963.stderr      |   4 +-
 12 files changed, 278 insertions(+), 325 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 0257dacf228024d0cc6ba247c707130637a25580


More information about the ghc-commits mailing list