Opened 3 years ago

Closed 3 years ago

#13188 closed bug (fixed)

COMPLETE pragma causes compilation to hang forever under certain scenarios

Reported by: RyanGlScott Owned by: mpickering
Priority: high Milestone: 8.2.1
Component: Compiler Version: 8.1
Keywords: PatternSynonyms Cc: mpickering
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: Compile-time performance bug Test Case:
Blocked By: Blocking:
Related Tickets: Differential Rev(s): Phab:D3058
Wiki Page:


This is a really bizarre one. If you have the following program:

{-# LANGUAGE PatternSynonyms #-}
{-# LANGUAGE ViewPatterns #-}
module Main where

class LL f where
  go :: f a -> ()

instance LL [] where
  go _ = ()

pattern GoLL :: LL f => f a
pattern GoLL <- (go -> ())

{-# COMPLETE GoLL :: [] #-}

goLLEx :: [a] -> Int
goLLEx GoLL = 5

main :: IO ()
main = return ()

And you compile it with GHC HEAD in just the right way, GHC hangs forever!

$ ~/Software/ghc3/inplace/bin/ghc-stage2 -no-link Bug.hs
[1 of 1] Compiling Main             ( Bug.hs, Bug.o )
$ ~/Software/ghc3/inplace/bin/ghc-stage2 Bug.hs
# Hangs forever here

That -no-link part is crucial, since if you compile it straight from a source file, it works. Also worth noting:

  • I can reproduce this in GHC HEAD, but not in GHC 8.0.2.
  • The COMPLETE pragma is critical for triggering this bug. If you comment it out, then the issue disappears.

Note that cabal-install installs executables using this -no-link strategy, so this bug effectively prevents me from using cabal-install with code that involves COMPLETE pragmas. Marking as high priority.

I have no idea where to start looking for this one. Matthew, do you have any idea what might be happening here?

Change History (4)

comment:1 Changed 3 years ago by RyanGlScott

Owner: set to mpickering

comment:2 Changed 3 years ago by mpickering

Differential Rev(s): Phab:D3058
Status: newpatch

See Phab:D3058

If you ever run into problems with interface files the best way to debug them is to use one-shot mode (-c) rather than make mode. This ensures that you are actually loading the interface files each time rather than caching the information between modules.

comment:3 Changed 3 years ago by Ben Gamari <ben@…>

In b16239a9/ghc:

Make interface loading for COMPLETE pragmas lazy

Without this additional laziness we will loop forever trying
to find the definitions of the conlikes referenced in the pragma.

Fixes #13188

Reviewers: austin, RyanGlScott, bgamari

Reviewed By: bgamari

Subscribers: thomie

Differential Revision:

GHC Trac Issues: #13188

comment:4 Changed 3 years ago by bgamari

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