[GHC] #7788: Recursive type family causes <<loop>>

GHC ghc-devs at haskell.org
Mon Dec 29 20:24:13 UTC 2014


#7788: Recursive type family causes <<loop>>
-------------------------------------+-------------------------------------
        Reporter:  shachaf           |                   Owner:  simonpj
            Type:  bug               |                  Status:  new
        Priority:  high              |               Milestone:  7.10.1
       Component:  Compiler (Type    |                 Version:  7.6.2
  checker)                           |                Keywords:
      Resolution:                    |            Architecture:
Operating System:  Unknown/Multiple  |  Unknown/Multiple
 Type of failure:  Incorrect result  |               Test Case:
  at runtime                         |                Blocking:
      Blocked By:                    |  Differential Revisions:
 Related Tickets:                    |
-------------------------------------+-------------------------------------

Comment (by goldfire):

 Here's what I'm worried about here.

 This function is clearly very innocent:

 {{{
 id :: a -> a
 id x = x
 }}}

 It compiles, obviously, without complaint.

 But, with 7.10, the following doesn't:

 {{{
 type family F a where
   F a = F a

 id2 :: F a -> F a
 id2 x = x
 }}}

 This is slightly disturbing because `id2` is merely a specialization of
 `id`.

 I think there is an easy solution here, though: allow users to disable the
 optimisation that we've put into !TcFlatten (`try_to_reduce`). If a user
 says `-flazier-type-families`, then we turn off the optimization. Most
 type-family-heavy programs will simply compile much more slowly... but a
 few will compile in finite time that didn't previously.

 As a separate solution here, we probably should also detect when we're
 looping while evaluating a type family by tracking evaluation depth. I'd
 much rather get an error saying we've blown a limited stack size than to
 just loop.

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


More information about the ghc-tickets mailing list