Opened 5 years ago

Closed 5 years ago

Last modified 4 years ago

#10139 closed bug (fixed)

Coercible causes ghc to hang

Reported by: nitromaster101 Owned by:
Priority: normal Milestone: 8.0.1
Component: Compiler Version: 7.10.1-rc2
Keywords: Cc:
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: None/Unknown Test Case: indexed-types/should_compile/T10139
Blocked By: Blocking:
Related Tickets: Differential Rev(s):
Wiki Page:


Consider my two instance declarations. The second one will hang ghc. If I change (coerce) to (coerce :: Normal a -> Sized a) it compiles fine. The first declaration also works fine.

{-# LANGUAGE TypeFamilies, FlexibleInstances #-}

import qualified Data.FingerTree as FT
import GHC.Exts

class DOps a where
  plus :: a -> D a -> a

type family D a :: *
type instance D (FT.FingerTree (Size Int, v) (Sized a)) = [Diff (Normal a)]

type family Normal a :: *

data Diff a = Add Int a

newtype Sized a = Sized a
newtype Size a = Size a

-- This works:
instance (FT.Measured (Size Int, v) (Sized a), Coercible (Normal a) (Sized a)) => DOps (FT.FingerTree (Size Int, v) (Sized a)) where
  plus = foldr (\(Add index val) seq -> FT.singleton ((coerce) val))

-- This hangs:
instance (FT.Measured (Size Int, v) (Sized a), Coercible (Normal a) (Sized a)) => DOps (FT.FingerTree (Size Int, v) (Sized a)) where
  plus = foldr (flip f)
    where f seq x = case x of
            Add index val -> FT.singleton ((coerce) val)
$ ~/downloads/ghc- --version
The Glorious Glasgow Haskell Compilation System, version

Change History (4)

comment:1 Changed 5 years ago by goldfire

This is presumably related to #10079 and #7788. Fix is forthcoming in the next few days.

Thanks for reporting!

comment:2 Changed 5 years ago by Richard Eisenberg <eir@…>

In c1edbdfd9148ad9f74bfe41e76c524f3e775aaaa/ghc:

Do proper depth checking in the flattener to avoid looping.

This implements (roughly) the plan put forward in comment:14:ticket:7788,
fixing #7788, #8550, #9554, #10139, and addressing concerns raised in #10079.
There are some regressions w.r.t. GHC 7.8, but only with pathological type
families (like F a = F a). This also (hopefully -- don't have a test case)
fixes #10158. Unsolved problems include #10184 and #10185, which are both
known deficiencies of the approach used here.

As part of this change, the plumbing around detecting infinite loops has
changed. Instead of -fcontext-stack and -ftype-function-depth, we now have
one combined -freduction-depth parameter. Setting it to 0 disbales the
check, which is now the recommended way to get (terminating) code to
typecheck in releases. (The number of reduction steps may well change between
minor GHC releases!)

This commit also introduces a new IntWithInf type in BasicTypes
that represents an integer+infinity. This type is used in a few
places throughout the code.

Tests in
  typecheck/should_compile/T10184  (expected broken)
  typecheck/should_compile/T10185  (expected broken)

This commit also changes performance testsuite numbers, for the better.

comment:3 Changed 5 years ago by goldfire

Resolution: fixed
Status: newclosed
Test Case: indexed-types/should_compile/T10139

comment:4 Changed 4 years ago by thomie

Milestone: 8.0.1
Note: See TracTickets for help on using tickets.