Opened 4 years ago

Closed 4 years ago

Last modified 3 years ago

#11708 closed bug (fixed)

Typechecker hangs when checking type families with -ddump-tc-trace turned on

Reported by: kcsongor Owned by: kcsongor
Priority: normal Milestone: 8.0.1
Component: Compiler (Type checker) Version: 8.1
Keywords: typefamilies trace hangs Cc:
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: None/Unknown Test Case:
Blocked By: Blocking:
Related Tickets: Differential Rev(s): Phab:D2006
Wiki Page:

Description

I have the following code, which is supposed to fail with a type error. However, when compiled with HEAD using the -ddump-tc-trace flag, the type checker hangs.

{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE DataKinds #-}

module Test where

import Data.Proxy

test :: (IsElem a as ~ 'True) => Proxy a -> Proxy as -> Bool
test _ _ = True

x = test (Proxy :: Proxy Int) (Proxy :: Proxy '[])

type family IsElem (x :: k) (xs :: [k]) where
    IsElem x '[] = 'False
    IsElem x (x ': xs) = 'True
    IsElem x (y ': xs) = IsElem x xs

The reason is that in typecheck/TcHsType.hs, the type family tycons are type-checked with knot-tying, however, they are being traced, forcing their evaluation which causes the typechecker to hang.

My proposed fix is to only print the safe values that we know are constructed by the time of tracing.

Attachments (1)

TypeFamilyErrors_4.hs (424 bytes) - added by kcsongor 4 years ago.
Relevant file to reproduce the issue

Download all attachments as: .zip

Change History (7)

Changed 4 years ago by kcsongor

Attachment: TypeFamilyErrors_4.hs added

Relevant file to reproduce the issue

comment:1 Changed 4 years ago by kcsongor

Differential Rev(s): https://phabricator.haskell.org/D2006

comment:2 Changed 4 years ago by mpickering

Differential Rev(s): https://phabricator.haskell.org/D2006Phab:D2006
Status: newpatch

comment:3 Changed 4 years ago by goldfire

I actually hit this bug locally and so merged @kcsongor's patch. Will push in due course.

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

In c5ed41c/ghc:

typechecker: fix trac issue #11708

Summary: Fixes T11708

Reviewers: austin, bgamari, goldfire, simonpj

Reviewed By: goldfire, simonpj

Subscribers: simonpj, goldfire, thomie

Differential Revision: https://phabricator.haskell.org/D2006

GHC Trac Issues: #11708

comment:5 Changed 4 years ago by goldfire

Milestone: 8.0.1
Status: patchmerge

comment:6 Changed 4 years ago by bgamari

Resolution: fixed
Status: mergeclosed
Last edited 3 years ago by bgamari (previous) (diff)
Note: See TracTickets for help on using tickets.