Ticket #6068 (closed bug: fixed)

Opened 13 months ago

Last modified 12 months ago

Panic in GHCi when using functional dependencies and promoted kinds

Reported by: goldfire Owned by:
Priority: normal Milestone:
Component: GHCi Version: 7.5
Keywords: PolyKinds Cc:
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: GHCi crash Difficulty: Unknown
Test Case: polykinds/T6068 Blocked By:
Blocking: Related Tickets:

Description

Consider the following code:

{-# LANGUAGE PolyKinds, DataKinds, TypeFamilies, GADTs, MultiParamTypeClasses,
             FunctionalDependencies, FlexibleInstances, UndecidableInstances #-}

import Prelude hiding (Maybe, Nothing)

data Maybe :: * -> * where
  Nothing :: Maybe a

data family Sing (a :: k)

data instance Sing (a :: Maybe k) where
  SNothing :: Sing Nothing

data KProxy (a :: *) = KProxy
data Existential (p :: KProxy k) =
  forall (a :: k). Exists (Sing a)

class HasSingleton a (kp :: KProxy k) | a -> kp where
  exists :: a -> Existential kp

instance forall a (mp :: KProxy (Maybe ak)). HasSingleton (Maybe a) mp where
  exists Nothing = Exists SNothing

When I load it into GHCi and ask for

*Main> :t exists Nothing

I get the following:

ghc-stage2: panic! (the 'impossible' happened)
  (GHC version 7.5.20120426 for x86_64-apple-darwin):
	tcTyVarDetails ak{tv avTW} [tv]

When I add foo = exists Nothing to the end of the compiled code, however, the behavior is as expected. I did try adding all relevant GHC extensions to the running instance of GHCi, but that did not solve the problem.

Change History

Changed 12 months ago by simonpj@…

commit 969f8b728be0a2fec8263e8866295776c993394b

Author: Simon Peyton Jones <simonpj@microsoft.com>
Date:   Wed May 16 11:13:52 2012 +0100

    Be careful to instantiate kind variables when dealing with functional dependencies
    
    There were really two bugs
      a) When the fundep fires we must apply the matching
         substitution to the kinds of the remaining type vars
         (This happens in FunDeps.checkClsFD, when we create meta_tvs)
    
      b) When instantiating the un-matched type variables we must
         instantiate their kinds properly
         (This happens in TcSMonad.instFlexiTcS)
    
    This fixes #6068 and #6015 (second reported bug).

 compiler/typecheck/TcInteract.lhs |    6 +--
 compiler/typecheck/TcSMonad.lhs   |    8 +++-
 compiler/types/FunDeps.lhs        |   87 ++++++++++++++++++++++---------------
 3 files changed, 60 insertions(+), 41 deletions(-)

Changed 12 months ago by simonpj

  • status changed from new to closed
  • difficulty set to Unknown
  • resolution set to fixed
  • testcase set to polykinds/T6068

I believe this patch fixes the bug. Thanks for reporting it with a nice small test case. Give it a try

Simon

Note: See TracTickets for help on using tickets.