Opened 6 years ago

Closed 6 years ago

#5581 closed bug (fixed)

ConstraintKinds lets you put the typechecker into a loop

Reported by: pumpkin Owned by: batterseapower
Priority: normal Milestone:
Component: Compiler (Type checker) Version: 7.3
Keywords: ConstraintKinds Cc:
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: Compile-time crash Test Case:
Blocked By: Blocking:
Related Tickets: Differential Rev(s):
Wiki Page:


Ed Kmett was playing with them the other day and Dan Doel and I reduced the issue to this:

{-# LANGUAGE ConstraintKinds, FlexibleContexts, FlexibleInstances, KindSignatures #-}

class C (p :: Constraint)
class D (p :: Constraint)

instance C (D p) => C (D (D p))

-- This works
data E a = E
class F a
instance F (E a) => F (E (E a))

Change History (4)

comment:1 Changed 6 years ago by pumpkin

The bug arises even with

instance C (C p) => C (C (C p))

but we thought it'd be more indicative to include the other class to show that it isn't just caused by creating an instance of yourself.

comment:2 Changed 6 years ago by simonpj

Owner: set to batterseapower

Oops -- thank you for reporting this.

Max, this is for you. The two functions sizeType and sizePred go into an infinite loop on a single type variable (p :: Constraint). Could you fix pls?

While you are at it could you add a Note to explain your reasoning:

  • Why convert to a PredTree (I think it is only because there might be a synonym, and you don't want to count the tuple of the constraints in the size).
  • What precisely you are counting and why (move the Paterson condition notes from higher up, I suggest, or at least copy the bit about size).



comment:3 Changed 6 years ago by batterseapower@…

commit 95d66964bb315f1c500f179ab2da001d8f52e2ac

Author: Max Bolingbroke <>
Date:   Tue Oct 25 10:28:31 2011 +0100

    Fix infinite loop in PredTYpe size checking (#5581)

 compiler/typecheck/TcMType.lhs |   37 +++++++++++++++++++++++++++++++------
 1 files changed, 31 insertions(+), 6 deletions(-)

comment:4 Changed 6 years ago by batterseapower

Resolution: fixed
Status: newclosed

I've added a test, T5581, in commit fbf4be8429efe36984baebd800c31984272db401

I relaxed the size check for tuple predicates while I was at it.

Note: See TracTickets for help on using tickets.