Opened 10 months ago

Last modified 8 months ago

#16225 merge bug

GHC HEAD-only Core Lint error (Trans coercion mis-match)

Reported by: RyanGlScott Owned by:
Priority: highest Milestone: 8.8.1
Component: Compiler (Type checker) Version: 8.7
Keywords: TypeInType Cc:
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: None/Unknown Test Case: typecheck/should_compile/T16225
Blocked By: Blocking:
Related Tickets: #16188, #16204 Differential Rev(s): https://gitlab.haskell.org/ghc/ghc/merge_requests/207
Wiki Page:

Description

The following code compiles on GHC 8.0.2 through GHC 8.6.3 with -dcore-lint:

{-# LANGUAGE AllowAmbiguousTypes #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeInType #-}
{-# LANGUAGE TypeOperators #-}
module Bug where

import Data.Kind

data family Sing :: k -> Type
data TyFun :: Type -> Type -> Type
type a ~> b = TyFun a b -> Type
infixr 0 ~>
type family Apply (f :: a ~> b) (x :: a) :: b

data TyCon1 :: (k1 -> k2) -> (k1 ~> k2)
type instance Apply (TyCon1 f) x = f x

data SomeApply :: (k ~> Type) -> Type where
  SomeApply :: Apply f a -> SomeApply f

f :: SomeApply (TyCon1 Sing :: k ~> Type)
  -> SomeApply (TyCon1 Sing :: k ~> Type)
f (SomeApply s)
 = SomeApply s

However, it chokes on GHC HEAD:

$ ~/Software/ghc4/inplace/bin/ghc-stage2 --interactive Bug.hs -dcore-lint
GHCi, version 8.7.20190120: https://www.haskell.org/ghc/  :? for help
Loaded GHCi configuration from /home/rgscott/.ghci
[1 of 1] Compiling Bug              ( Bug.hs, interpreted )
*** Core Lint errors : in result of Desugar (before optimization) ***
<no location info>: warning:
    In the expression: SomeApply
                         @ k_a1Dz
                         @ (TyCon1 Sing)
                         @ Any
                         (s_a1Bq
                          `cast` (Sub (D:R:ApplyabTyCon1x[0]
                                           <k_a1Dz>_N
                                           <*>_N
                                           <Sing>_N
                                           <a_a1DB>_N ; Sym (D:R:ApplyabTyCon1x[0]
                                                                 <k_a1Dz>_N <*>_N <Sing>_N <Any>_N))
                                  :: Apply (TyCon1 Sing) a_a1DB ~R# Apply (TyCon1 Sing) Any))
    Trans coercion mis-match: D:R:ApplyabTyCon1x[0]
                                  <k_a1Dz>_N <*>_N <Sing>_N <a_a1DB>_N ; Sym (D:R:ApplyabTyCon1x[0]
                                                                                  <k_a1Dz>_N
                                                                                  <*>_N
                                                                                  <Sing>_N
                                                                                  <Any>_N)
      Apply (TyCon1 Sing) a_a1DB
      Sing a_a1DB
      Sing Any
      Apply (TyCon1 Sing) Any
*** Offending Program ***

<elided>

f :: forall k. SomeApply (TyCon1 Sing) -> SomeApply (TyCon1 Sing)
[LclIdX]
f = \ (@ k_a1Dz) (ds_d1EV :: SomeApply (TyCon1 Sing)) ->
      case ds_d1EV of wild_00 { SomeApply @ a_a1DB s_a1Bq ->
      break<0>(s_a1Bq)
      SomeApply
        @ k_a1Dz
        @ (TyCon1 Sing)
        @ Any
        (s_a1Bq
         `cast` (Sub (D:R:ApplyabTyCon1x[0]
                          <k_a1Dz>_N <*>_N <Sing>_N <a_a1DB>_N ; Sym (D:R:ApplyabTyCon1x[0]
                                                                          <k_a1Dz>_N
                                                                          <*>_N
                                                                          <Sing>_N
                                                                          <Any>_N))
                 :: Apply (TyCon1 Sing) a_a1DB ~R# Apply (TyCon1 Sing) Any))
      }

Note that if I change the definition of Sing to this:

data family Sing (a :: k)

Then the error goes away.

Also, if I extend SomeProxy with an additional proxy field:

data SomeApply :: (k ~> Type) -> Type where
  SomeApply :: proxy a -> Apply f a -> SomeApply f

f :: SomeApply (TyCon1 Sing :: k ~> Type)
  -> SomeApply (TyCon1 Sing :: k ~> Type)
f (SomeApply p s)
 = SomeApply p s

Then the error also goes away. Perhaps a being ambiguous plays an important role here?

Possibly related to #16188 or #16204.

Change History (3)

comment:1 Changed 10 months ago by RyanGlScott

Differential Rev(s): https://gitlab.haskell.org/ghc/ghc/merge_requests/207
Status: newpatch

comment:2 Changed 9 months ago by RyanGlScott

Status: patchmerge
Test Case: typecheck/should_compile/T16225

Landed in 4a4ae70f09009c5d32696445a06eacb273f364b5.

Please merge this into 8.8.

comment:3 Changed 8 months ago by Marge Bot <ben+marge-bot@…>

In 4a4ae70/ghc:

Fix #16188

There was an awful lot of zipping going on in
canDecomposableTyConAppOK, and one of the lists being zipped
was too short, causing the result to be too short. Easily
fixed.

Also fixes #16204 and #16225

test case: typecheck/should_compile/T16188
           typecheck/should_compile/T16204[ab]
           typecheck/should_fail/T16204c
           typecheck/should_compile/T16225
Note: See TracTickets for help on using tickets.