[GHC] #15568: Kind variables in type family aren't quantified in toposorted order

GHC ghc-devs at haskell.org
Sun Aug 26 13:32:23 UTC 2018


#15568: Kind variables in type family aren't quantified in toposorted order
-------------------------------------+-------------------------------------
        Reporter:  RyanGlScott       |                Owner:  (none)
            Type:  bug               |               Status:  new
        Priority:  normal            |            Milestone:  8.8.1
       Component:  Compiler          |              Version:  8.5
      Resolution:                    |             Keywords:
                                     |  TypeApplications, TypeFamilies
Operating System:  Unknown/Multiple  |         Architecture:
                                     |  Unknown/Multiple
 Type of failure:  None/Unknown      |            Test Case:
      Blocked By:                    |             Blocking:
 Related Tickets:                    |  Differential Rev(s):
       Wiki Page:                    |
-------------------------------------+-------------------------------------

Comment (by RyanGlScott):

 I figured out what caused this regression. The primary culprit is commit
 fa29df02a1b0b926afb2525a258172dcbf0ea460 (Refactor ConDecl: Trac #14529).
 In particular, this commit made a rather suspicious-looking change to
 `bindHsQTyVars`:

 {{{#!diff
 diff --git a/compiler/rename/RnTypes.hs b/compiler/rename/RnTypes.hs
 index dd66cd3..727744d 100644
 --- a/compiler/rename/RnTypes.hs
 +++ b/compiler/rename/RnTypes.hs
 @@ -898,23 +905,24 @@ bindHsQTyVars doc mb_in_doc mb_assoc body_kv_occs
 hsq_bndrs thing_inside

         ; let -- See Note [bindHsQTyVars examples] for what
               -- all these various things are doing
 -             bndrs, kv_occs, implicit_bndr_kvs,
 -                    implicit_body_kvs, implicit_kvs :: [Located RdrName]
 -             bndrs             = map hsLTyVarLocName hs_tv_bndrs
 -             kv_occs           = body_kv_occs ++ bndr_kv_occs
 -             implicit_bndr_kvs = filter_occs rdr_env bndrs bndr_kv_occs
 -             implicit_body_kvs = filter_occs rdr_env (implicit_bndr_kvs
 ++ bndrs) body_kv_occs
 +             bndrs, kv_occs, implicit_kvs :: [Located RdrName]
 +             bndrs        = map hsLTyVarLocName hs_tv_bndrs
 +             kv_occs      = nubL (body_kv_occs ++ bndr_kv_occs)
 +             implicit_kvs = filter_occs rdr_env bndrs kv_occs
                                   -- Deleting bndrs: See Note [Kind-
 variable ordering]
 -             implicit_kvs      = implicit_bndr_kvs ++ implicit_body_kvs
 -
 }}}

 The value of `implicit_kvs` is what's important here, since it determines
 the order in which kind variables appear in type family kind signatures.
 In the commit before, we had:

 {{{#!hs
 implicit_kvs      = implicit_bndr_kvs ++ implicit_body_kvs
 }}}

 Which makes sense, as you'd expect the binder kind variables to appear
 before any kind variables from the body. But after that commit, we now
 have:

 {{{#!hs
 kv_occs      = nubL (body_kv_occs ++ bndr_kv_occs)
 implicit_kvs = filter_occs rdr_env bndrs kv_occs
 }}}

 Now, we're putting all of the body kind variables before the binder ones!

 (Note that the first commit in which you can actually see the `forall k
 j.` order instead of the old `forall j k.` order is actually
 12794287174146f982257cdeffd491e3e23838dc (`Quantify unfixed kind variables
 in CUSKs`), but that's only because that commit changed the way kind
 variables were quantified to use `quantifyTyVars` instead of
 `tyCoVarsOfTypeWellScoped`, causing GHC to be more sensitive to the order
 of the kind variables in `implicit_kvs`.)

 I think fixing this is a simple matter of defining `kv_occs = nubL
 (bndr_kv_occs ++ body_kv_occs)` instead. Patch incoming.

-- 
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/15568#comment:1>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler


More information about the ghc-tickets mailing list