Opened 8 years ago

Closed 8 years ago

#811 closed bug (fixed)

GHC panics when compiling some mutually recursive modules that export something imported

Reported by: guest Owned by:
Priority: normal Milestone:
Component: Compiler Version: 6.4.2
Keywords: Cc:
Operating System: Linux Architecture: powerpc
Type of failure: Difficulty: Unknown
Test Case: Blocked By:
Blocking: Related Tickets:

Description

This happened in my own code, and then I reduced it to a much simpler test-case. I wished to try it in another compiler, if only to make doubly sure that it is correct code, but I couldn't get any to work with (these) mutually recursive modules (for a variety of reasons). So, unless I am quite mistaken, I am unable to compile my Haskell-98 program at this point.

Following are the four files to cause the error, then the command to invoke GHC (6.4.2, but 6.4.1 also failed for me in the same way) and the result.

CausesRecursiveModules.hs:

--This module is what makes MainBug need a .hs-boot file.

module CausesRecursiveModules () where
import {-# SOURCE #-} MainBug ()

ExportsSomething.hs:

-- This module by itself triggers no bug, but is necessary
-- as something for MainBug to externally import.
-- "Something" triggers the bug at least whether it's a thing,
-- a type-alias, or a data definition (with the appropriate
-- capitalization for each). (I tested those, as can be seen
-- in the commented code below.)

module ExportsSomething (Something) where
type Something = ()
--data Something = MkSomething
--something :: (); something = undefined

MainBug.hs:

--The export of "Something" here is necessary to trigger the bug,
--  as well as it being externally imported.
--(Actually the bug still happens if "Something" is not exported
--  here and module ExportsSomething is not imported here at all,
--  but that violates the expectation that the .hs-boot file
--  should be a subset of the main .hs file.)
--Importing CausesRecursiveModules here is necessary
--  to cause recursive modules.
--Rather than import ExportsSomething, it also triggers the bug to re-export
--  something from the Prelude, such as 'id'; as it is, though, the bug
--  still happens with -fno-implicit-prelude.

module MainBug (Something) where
import ExportsSomething (Something)
import CausesRecursiveModules ()

MainBug.hs-boot:

--The export of "Something" here is necessary to trigger the bug,
--  as well as it being externally imported.
--Note that "Something" is not actually and does not need to actually
--  be imported by anyone from module MainBug (although the bug still happens
--  if it is; it's just not the simplest test-case then!)
--Rather than import ExportsSomething, it also triggers the bug to re-export
--  something from the Prelude, such as 'id'; as it is, though, the bug
--  still happens with -fno-implicit-prelude.

module MainBug (Something) where
import ExportsSomething (Something)

I've uploaded those four files at http://isaac.cedarswampstudios.org/2006/GHC6.4.2RecursiveModulesBug.tar.gz for convenience.

This is the exact command and result to reproduce the bug, although variations on command-line arguments as well as trying to compile CausesRecursiveModules.hs instead all seem to produce about the same error. I didn't try figuring out how to do it without --make, though.

$ ghc --make MainBug.hs
Chasing modules from: MainBug.hs
Compiling ExportsSomething ( ./ExportsSomething.hs, ./ExportsSomething.o )
Compiling MainBug[boot]    ( MainBug.hs-boot, MainBug.o-boot )
Compiling CausesRecursiveModules ( ./CausesRecursiveModules.hs, ./CausesRecursiveModules.o )
Compiling MainBug          ( MainBug.hs, MainBug.o )
ghc-6.4.2: panic! (the `impossible' happened, GHC version 6.4.2):
        checkHiBootIface MainBug.Something{tc r18N}

-- Isaac Dupree

P.S. In case licenses matter, I hereby put this post/ticket/whatever-it-is, and the .tar.gz, into the public domain.

Change History (3)

comment:1 Changed 8 years ago by guest

The example that is provided seems to compile ok with the current ghc HEAD.

Andres Loeh

comment:2 Changed 8 years ago by guest

Indeed -- ghc-6.5.20060703 successfully compiles and runs my original code too, unlike ghc-6.4.2, so the difference is not just because of the trivialness of the example I gave (although my program running isn't saying much, since main = compile `seq` putStrLn "herrlowid" at the moment, where compile is just a function imported from one of the many mutually recursive modules :-P)

--Isaac Dupree

comment:3 Changed 8 years ago by simonpj

  • Resolution set to fixed
  • Status changed from new to closed

Good catch. There was a two-character typo in LoadIface?, which I've just fixed.

To work around, if M.hi-boot exports a type T, make sure you define T in M.hi-boot; do not import it from elsewhere.

Note: See TracTickets for help on using tickets.