Opened 2 years ago

Closed 23 months ago

#14339 closed bug (fixed)

GHC 8.2.1 regression when combining GND with TypeError (solveDerivEqns: probable loop)

Reported by: RyanGlScott Owned by:
Priority: high Milestone: 8.2.2
Component: Compiler (Type checker) Version: 8.2.1
Keywords: deriving, CustomTypeErrors Cc: kosmikus
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: Compile-time crash or panic Test Case: testsuite/tests/deriving/should_compile/T14339
Blocked By: Blocking:
Related Tickets: Differential Rev(s):
Wiki Page:


This code panics on GHC 8.2.1 and later:

{-# LANGUAGE DataKinds #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE UndecidableInstances #-}
module Bug where

import GHC.TypeLits

newtype Baz = Baz Foo
  deriving Bar

newtype Foo = Foo Int

class Bar a where
  bar :: a

instance (TypeError (Text "Boo")) => Bar Foo where
  bar = undefined
$ /opt/ghc/8.2.1/bin/ghci Bug.hs
GHCi, version 8.2.1:  :? for help
Loaded GHCi configuration from /home/rgscott/.ghci
[1 of 1] Compiling Bug              ( Bug.hs, interpreted )
ghc: panic! (the 'impossible' happened)
  (GHC version 8.2.1 for x86_64-unknown-linux):
        solveDerivEqns: probable loop
    ds_loc       = Bug.hs:9:12-14
    ds_name      = $fBarBaz
    ds_tvs       = []
    ds_cls       = Bar
    ds_tys       = [Baz]
    ds_theta     = [ThetaOrigin
                      to_tvs            = []
                      to_givens         = []
                      to_wanted_origins = [Bar Foo, (Foo :: *) ~R# (Baz :: *)]]
    ds_mechanism = newtype
  Call stack:
      CallStack (from HasCallStack):
        prettyCurrentCallStack, called at compiler/utils/Outputable.hs:1133:58 in ghc:Outputable
        callStackDoc, called at compiler/utils/Outputable.hs:1137:37 in ghc:Outputable
        pprPanic, called at compiler/typecheck/TcDerivInfer.hs:515:9 in ghc:TcDerivInfer

This is a regression since GHC 8.0.2, in which it does compile successfully.

Change History (7)

comment:1 Changed 2 years ago by RyanGlScott

This is technically my fault, since this regression first started happening in 639e702b6129f501c539b158b982ed8489e3d09c (Refactor DeriveAnyClass's instance context inference). That being said, I don't have any inclination as to what part of that patch tickles this panic.

comment:2 Changed 2 years ago by kosmikus

Cc: kosmikus added

comment:3 Changed 2 years ago by Simon Peyton Jones <simonpj@…>

In 13fdca3d/ghc:

Add a missing zonk in TcDerivInfer.simplifyDeriv

I'm astonished that anything worked without this!

Fixes Trac #14339

comment:4 Changed 2 years ago by simonpj

Status: newmerge
Test Case: testsuite/tests/deriving/should_compile/T14339

comment:5 Changed 23 months ago by RyanGlScott


This was marked as merge with no release target, so I'll optimistically assume you meant 8.2.3, if there is one planned.

comment:6 Changed 23 months ago by bgamari


Ahh, good catch RyanGlScott. Actually I think we can sneak it in to 8.2.2.

comment:7 Changed 23 months ago by bgamari

Resolution: fixed
Status: mergeclosed
Note: See TracTickets for help on using tickets.