[commit: ghc] master: Allow (~) in the head of a quantified constraints (bd76875)

git at git.haskell.org git at git.haskell.org
Thu Sep 13 13:01:25 UTC 2018


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

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

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

commit bd76875ae6ad0cdd734564dddfb9ab88a6de9579
Author: Simon Peyton Jones <simonpj at microsoft.com>
Date:   Thu Sep 13 11:23:53 2018 +0100

    Allow (~) in the head of a quantified constraints
    
    Since the introduction of quantified constraints, GHC has rejected
    a quantified constraint with (~) in the head, thus
      f :: (forall a. blah => a ~ ty) => stuff
    
    I am frankly dubious that this is ever useful.  But /is/ necessary for
    Coercible (representation equality version of (~)) and it does no harm
    to allow it for (~) as well.  Plus, our users are asking for it
    (Trac #15359, #15625).
    
    It was really only excluded by accident, so
    this patch lifts the restriction. See TcCanonical
    Note [Equality superclasses in quantified constraints]
    
    There are a number of wrinkles:
    
    * If the context of the quantified constraint is empty, we
      can get trouble when we get down to unboxed equality (a ~# b)
      or (a ~R# b), as Trac #15625 showed. This is even more of
      a corner case, but it produced an outright crash, so I elaborated
      the superclass machinery in TcCanonical.makeStrictSuperClasses
      to add a void argument in this case.  See
      Note [Equality superclasses in quantified constraints]
    
    * The restriction on (~) was in TcValidity.checkValidInstHead.
      In lifting the restriction I discovered an old special case for
      (~), namely
          | clas_nm `elem` [ heqTyConName, eqTyConName]
          , nameModule clas_nm /= this_mod
      This was (solely) to support the strange instance
          instance a ~~ b => a ~ b
      in Data.Type.Equality. But happily that is no longer
      with us, since
         commit f265008fb6f70830e7e92ce563f6d83833cef071
         Refactor (~) to reduce the suerpclass stack
      So I removed the special case.
    
    * I found that the Core invariants on when we could have
           co = <expr>
      were entirely not written down. (Getting this wrong ws
      the proximate source of the crash in Trac #15625.  So
    
      - Documented them better in CoreSyn
          Note [CoreSyn type and coercion invariant],
      - Modified CoreOpt and CoreLint to match
      - Modified CoreUtils.bindNonRec to match
      - Made MkCore.mkCoreLet use bindNonRec, rather
        than duplicate its logic
      - Made Simplify.rebuildCase case-to-let respect
          Note [CoreSyn type and coercion invariant],


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

bd76875ae6ad0cdd734564dddfb9ab88a6de9579
 compiler/coreSyn/CoreLint.hs                      |  6 ++
 compiler/coreSyn/CoreOpt.hs                       | 35 ++++++-----
 compiler/coreSyn/CoreSyn.hs                       | 71 ++++++++++++++--------
 compiler/coreSyn/CoreUtils.hs                     | 18 +++++-
 compiler/coreSyn/MkCore.hs                        |  4 +-
 compiler/simplCore/Simplify.hs                    | 26 ++++++--
 compiler/typecheck/TcCanonical.hs                 | 74 ++++++++++++++++++++---
 compiler/typecheck/TcInteract.hs                  |  9 ++-
 compiler/typecheck/TcValidity.hs                  | 13 +---
 testsuite/tests/quantified-constraints/T15359.hs  | 12 ++++
 testsuite/tests/quantified-constraints/T15359a.hs | 14 +++++
 testsuite/tests/quantified-constraints/T15625.hs  | 16 +++++
 testsuite/tests/quantified-constraints/T15625a.hs | 20 ++++++
 testsuite/tests/quantified-constraints/all.T      |  4 ++
 14 files changed, 249 insertions(+), 73 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 bd76875ae6ad0cdd734564dddfb9ab88a6de9579


More information about the ghc-commits mailing list