Opened 8 years ago

Closed 8 years ago

Last modified 7 years ago

#1186 closed bug (fixed)

GHC as a library panic on loading second module

Reported by: ArthurVanLeeuwen Owned by: simonmar
Priority: high Milestone: 6.8.1
Component: GHC API Version: 6.6
Keywords: Cc:
Operating System: Unknown/Multiple Architecture: powerpc
Type of failure: Test Case:
Blocked By: Blocking:
Related Tickets: Differential Revisions:

Description

Given the following two modules:

module GHCLibTest where

import GHC
import PackageConfig
import DynFlags

main = do session <- newSession JustTypecheck (Just "/usr/local/lib/ghc-6.6")
          f <- getSessionDynFlags session
          f' <- parseDynamicFlags f ["-isrc","-ilib","-ilib/DData","-fglasgow-ex
ts","-package wx"]
          setSessionDynFlags session (fst f'){hscTarget = HscInterpreted}
          let preludeModule = mkModule (stringToPackageId "base") (mkModuleName
"Prelude")
          setContext session [] [preludeModule]
          t <- guessTarget "src/Main.hs" Nothing
          addTarget session t
          load session LoadAllTargets

and

module OtherModule where

import Data.List

type Nummer = String

data Beademing = HFO | CPAP | IPPV | Geen       
    deriving (Show, Read, Eq)
data Bloeddruk = Hypertensie | Hypotensie | TensieNormaal       
    deriving (Show, Read, Eq)
data Partus = PartusTeVroeg | PartusNormaal     
    deriving (Show, Read, Eq)

the following results:

harlan:~/Werk/dss/software/ghclib arthurvl$ echo "main" | ghci -package ghc ghclibtest.hs
   ___         ___ _
  / _ \ /\  /\/ __(_)
 / /_\// /_/ / /  | |      GHC Interactive, version 6.6, for Haskell 98.
/ /_\\/ __  / /___| |      http://www.haskell.org/ghc/
\____/\/ /_/\____/|_|      Type :? for help.

Loading package base ... linking ... done.
Loading package template-haskell ... linking ... done.
Loading package readline-1.0 ... linking ... done.
Loading package unix-1.0 ... linking ... done.
Loading package Cabal-1.1.6 ... linking ... done.
Loading package regex-base-0.71 ... linking ... done.
Loading package regex-posix-0.71 ... linking ... done.
Loading package regex-compat-0.71 ... linking ... done.
Loading package haskell98 ... linking ... done.
Loading package ghc-6.6 ... linking ... done.
[1 of 2] Compiling OtherModule      ( OtherModule.hs, interpreted )
[2 of 2] Compiling GHCLibTest       ( ghclibtest.hs, interpreted )
Ok, modules loaded: OtherModule, GHCLibTest.
*GHCLibTest> ghc-6.6: panic! (the 'impossible' happened)
  (GHC version 6.6 for powerpc-apple-darwin):
        lookup_dfun main:OtherModule.$f1{v r5ig} [lid]

Please report this as a GHC bug:  http://www.haskell.org/ghc/reportabug

*GHCLibTest> Leaving GHCi.
harlan:~/Werk/dss/software/ghclib arthurvl$ 

This does not just occur for this recursive case, but
also for cases where the main module is from some
completely different program.

Change History (10)

comment:1 Changed 8 years ago by thorkilnaur

I have tried this on a PPC Mac OS X 10.4 and got:

Thorkil-Naurs-Computer:~/tn/test/GHC/trac/1186/work thorkilnaur$ diff ghclibtest.hs ../original/ghclibtest.hs 
7c7
< main = do session <- newSession JustTypecheck (Just "/Users/thorkilnaur/tn/install/ghc-6.6-for-buildbot-20070221_1000/lib/ghc-6.6.20070220")
---
> main = do session <- newSession JustTypecheck (Just "/usr/local/lib/ghc-6.6")
Thorkil-Naurs-Computer:~/tn/test/GHC/trac/1186/work thorkilnaur$ echo main | ghci -package ghc ghclibtest.hs 
   ___         ___ _
  / _ \ /\  /\/ __(_)
 / /_\// /_/ / /  | |      GHC Interactive, version 6.6.20070220, for Haskell 98.
/ /_\\/ __  / /___| |      http://www.haskell.org/ghc/
\____/\/ /_/\____/|_|      Type :? for help.

Loading package base ... linking ... done.
Loading package template-haskell ... linking ... done.
Loading package readline-1.0 ... linking ... done.
Loading package unix-1.0 ... linking ... done.
Loading package Cabal-1.1.6 ... linking ... done.
Loading package regex-base-0.71 ... linking ... done.
Loading package regex-posix-0.71 ... linking ... done.
Loading package regex-compat-0.71 ... linking ... done.
Loading package haskell98 ... linking ... done.
Loading package ghc-6.6.20070220 ... linking ... done.
[1 of 1] Compiling GHCLibTest       ( ghclibtest.hs, interpreted )
Ok, modules loaded: GHCLibTest.
*GHCLibTest> unknown package: wx
*GHCLibTest> Leaving GHCi.
Thorkil-Naurs-Computer:~/tn/test/GHC/trac/1186/work thorkilnaur$ 

I am wondering: Where, in your case, is the OtherModule referenced? I cannot seem to find any reference to it in ghclibtest.hs. Please supply some additional details.

Thanks and regards
Thorkil

comment:2 Changed 8 years ago by ArthurVanLeeuwen

Just to check my sanity (the bugreport was an attempted pare-down of the original problem):

harlan:~/Werk/dss/software/ghclib arthurvl$ uname -a
Darwin harlan.cs.uu.nl 8.8.0 Darwin Kernel Version 8.8.0: Fri Sep  8 17:18:57 PDT 2006; root:xnu-792.12.6.obj~1/RELEASE_PPC Power Macintosh powerpc
harlan:~/Werk/dss/software/ghclib arthurvl$ echo "setupsession >>= loadsession" | ghci -package ghc ghclibtest.hs
   ___         ___ _
  / _ \ /\  /\/ __(_)
 / /_\// /_/ / /  | |      GHC Interactive, version 6.6, for Haskell 98.
/ /_\\/ __  / /___| |      http://www.haskell.org/ghc/
\____/\/ /_/\____/|_|      Type :? for help.

Loading package base ... linking ... done.
Loading package template-haskell ... linking ... done.
Loading package readline-1.0 ... linking ... done.
Loading package unix-1.0 ... linking ... done.
Loading package Cabal-1.1.6 ... linking ... done.
Loading package regex-base-0.71 ... linking ... done.
Loading package regex-posix-0.71 ... linking ... done.
Loading package regex-compat-0.71 ... linking ... done.
Loading package haskell98 ... linking ... done.
Loading package ghc-6.6 ... linking ... done.
[1 of 2] Compiling OtherModule      ( OtherModule.hs, interpreted )
[2 of 2] Compiling GHCLibTest       ( ghclibtest.hs, interpreted )
Ok, modules loaded: OtherModule, GHCLibTest.
*GHCLibTest> ghc-6.6: panic! (the 'impossible' happened)
  (GHC version 6.6 for powerpc-apple-darwin):
        lookup_dfun main:OtherModule.$f1{v r5x8} [lid]

Please report this as a GHC bug:  http://www.haskell.org/ghc/reportabug

*GHCLibTest> Leaving GHCi.
harlan:~/Werk/dss/software/ghclib arthurvl$ lsOtherModule.hs  ghclibtest.hs
harlan:~/Werk/dss/software/ghclib arthurvl$ cat OtherModule.hs 
module OtherModule where

import Data.List

type Nummer = String

data Beademing = HFO | CPAP | IPPV | Geen
    deriving (Show, Read, Eq)
data Bloeddruk = Hypertensie | Hypotensie | TensieNormaal
    deriving (Show, Read, Eq)
data Partus = PartusTeVroeg | PartusNormaal
    deriving (Show, Read, Eq)
harlan:~/Werk/dss/software/ghclib arthurvl$ cat ghclibtest.hs 
module GHCLibTest (setupsession,loadsession) where

import GHC
import PackageConfig
import DynFlags
import OtherModule

main = setupsession >>= loadsession

setupsession = 
    do session <- newSession JustTypecheck (Just "/usr/local/lib/ghc-6.6")
       f <- getSessionDynFlags session
       f' <- parseDynamicFlags f ["-package ghc"]
       setSessionDynFlags session (fst f'){hscTarget = HscInterpreted}
       let preludeModule = mkModule (stringToPackageId "base") (mkModuleName "Prelude")
       setContext session [] [preludeModule]
       t <- guessTarget "ghclibtest.hs" Nothing
       addTarget session t
       return session

loadsession session = load session LoadAllTargets

other = 12

I did note however, that *compiling* this does not seem to evoke the bug:

harlan:~/Werk/dss/software/ghclib arthurvl$ ghc -package ghc --make -main-is GHCLibTest.main ghclibtest.hs 
[1 of 2] Compiling OtherModule      ( OtherModule.hs, OtherModule.o )
[2 of 2] Compiling GHCLibTest       ( ghclibtest.hs, ghclibtest.o )
Linking ghclibtest ...
harlan:~/Werk/dss/software/ghclib arthurvl$ ./ghclibtest 
harlan:~/Werk/dss/software/ghclib arthurvl$ ls
OtherModule.hi  OtherModule.o   ghclibtest.hi   ghclibtest.o
OtherModule.hs  ghclibtest      ghclibtest.hs

And then using the compiled modules with ghci doesn't break things anymore either!

harlan:~/Werk/dss/software/ghclib arthurvl$ echo "setupsession >>= loadsession" | ghci -package ghc ghclibtest.hs
   ___         ___ _
  / _ \ /\  /\/ __(_)
 / /_\// /_/ / /  | |      GHC Interactive, version 6.6, for Haskell 98.
/ /_\\/ __  / /___| |      http://www.haskell.org/ghc/
\____/\/ /_/\____/|_|      Type :? for help.

Loading package base ... linking ... done.
Loading package template-haskell ... linking ... done.
Loading package readline-1.0 ... linking ... done.
Loading package unix-1.0 ... linking ... done.
Loading package Cabal-1.1.6 ... linking ... done.
Loading package regex-base-0.71 ... linking ... done.
Loading package regex-posix-0.71 ... linking ... done.
Loading package regex-compat-0.71 ... linking ... done.
Loading package haskell98 ... linking ... done.
Loading package ghc-6.6 ... linking ... done.
Ok, modules loaded: OtherModule, GHCLibTest.
Prelude GHCLibTest> Prelude GHCLibTest> Leaving GHCi.
harlan:~/Werk/dss/software/ghclib arthurvl$ 

Maybe the intermediate code for interpreted modules isn't re-entrant enough? :)

comment:3 Changed 8 years ago by thorkilnaur

Thanks a lot, I can repeat it now.

comment:4 Changed 8 years ago by simonmar

  • Milestone set to 6.6.2

comment:5 Changed 8 years ago by simonmar

  • Milestone changed from 6.6.2 to 6.8
  • Priority changed from normal to high

comment:6 Changed 8 years ago by simonmar

  • Owner set to simonmar

I can't repeat this with either 6.6, 6.6.1 or HEAD. It always seems to complete successfully and exit for me. Did I do something wrong?

> echo "main" | ghci-6.6 -package ghc ghclibtest.hs
   ___         ___ _
  / _ \ /\  /\/ __(_)
 / /_\// /_/ / /  | |      GHC Interactive, version 6.6, for Haskell 98.
/ /_\\/ __  / /___| |      http://www.haskell.org/ghc/
\____/\/ /_/\____/|_|      Type :? for help.

Loading package base ... linking ... done.
Loading package template-haskell ... linking ... done.
Loading package readline-1.0 ... linking ... done.
Loading package unix-1.0 ... linking ... done.
Loading package Cabal-1.1.6 ... linking ... done.
Loading package regex-base-0.71 ... linking ... done.
Loading package regex-posix-0.71 ... linking ... done.
Loading package regex-compat-0.71 ... linking ... done.
Loading package haskell98 ... linking ... done.
Loading package ghc-6.6 ... linking ... done.
[1 of 2] Compiling OtherModule      ( OtherModule.hs, interpreted )
[2 of 2] Compiling GHCLibTest       ( ghclibtest.hs, interpreted )
Ok, modules loaded: OtherModule, GHCLibTest.
*GHCLibTest> [1 of 2] Compiling OtherModule      ( OtherModule.hs, nothing )
[2 of 2] Compiling GHCLibTest       ( ghclibtest.hs, nothing )
*GHCLibTest> Leaving GHCi.

Here's my ghclibtest.hs:

module GHCLibTest (setupsession,loadsession) where

import GHC
import PackageConfig
import DynFlags
import OtherModule

main = setupsession >>= loadsession

setupsession = 
    do session <- newSession JustTypecheck (Just "/home/simonmar/fp/lib/x86_64-unknown-linux/ghc-6.6")
       f <- getSessionDynFlags session
       f' <- parseDynamicFlags f ["-package ghc", "-v1"]
       setSessionDynFlags session (fst f'){hscTarget = HscNothing}
       let preludeModule = mkModule (stringToPackageId "base") (mkModuleName "Prelude")
       setContext session [] [preludeModule]
       t <- guessTarget "ghclibtest.hs" Nothing
       addTarget session t
       return session

loadsession session = load session LoadAllTargets

other = 12

and to run it with HEAD, you'll need some more modifications:

module GHCLibTest (setupsession,loadsession) where

import GHC
import PackageConfig
import DynFlags
import OtherModule

main = setupsession >>= loadsession

setupsession = 
    do session <- newSession (Just "/home/simonmar/builds/debugger")
       parseStaticFlags []
       f <- getSessionDynFlags session
       f' <- parseDynamicFlags f ["-package ghc", "-v1"]
       setSessionDynFlags session (fst f'){hscTarget = HscNothing}
       let preludeModule = mkModule (stringToPackageId "base") (mkModuleName "Prelude")
       setContext session [] [preludeModule]
       t <- guessTarget "ghclibtest.hs" Nothing
       addTarget session t
       return session

loadsession session = load session LoadAllTargets

other = 12

comment:7 Changed 8 years ago by thorkilnaur

I must confess close to total ignorance to the involved matters, so this may be irrelevant: With GHCLibTest.hs differing from the one for 6.6 and 6.6.1 given by simonmar above as follows:

$ diff ../simonmar/6.6/ghclibtest.hs GHCLibTest.hs 
11c11
<     do session <- newSession JustTypecheck (Just "/home/simonmar/fp/lib/x86_64-unknown-linux/ghc-6.6")
---
>     do session <- newSession JustTypecheck (Just "/Users/thorkilnaur/tn/install/ghc-6.6-for-buildbot-20070221_1000/lib/ghc-6.6.20070220")
14c14
<        setSessionDynFlags session (fst f'){hscTarget = HscNothing}
---
>        setSessionDynFlags session (fst f'){hscTarget = HscInterpreted}
23a24
> 
$ 

And with:

$ ghc --version
The Glorious Glasgow Haskell Compilation System, version 6.6.20070220
$ 

which I would perhaps denote GHC 6.6.(three quaters), I can do this:

$ echo main | ghci -package ghc GHCLibTest
   ___         ___ _
  / _ \ /\  /\/ __(_)
 / /_\// /_/ / /  | |      GHC Interactive, version 6.6.20070220, for Haskell 98.
/ /_\\/ __  / /___| |      http://www.haskell.org/ghc/
\____/\/ /_/\____/|_|      Type :? for help.

Loading package base ... linking ... done.
Loading package template-haskell ... linking ... done.
Loading package readline-1.0 ... linking ... done.
Loading package unix-1.0 ... linking ... done.
Loading package Cabal-1.1.6 ... linking ... done.
Loading package regex-base-0.71 ... linking ... done.
Loading package regex-posix-0.71 ... linking ... done.
Loading package regex-compat-0.71 ... linking ... done.
Loading package haskell98 ... linking ... done.
Loading package ghc-6.6.20070220 ... linking ... done.
[1 of 2] Compiling OtherModule      ( OtherModule.hs, interpreted )
[2 of 2] Compiling GHCLibTest       ( GHCLibTest.hs, interpreted )
Ok, modules loaded: OtherModule, GHCLibTest.
*GHCLibTest> [1 of 2] Compiling OtherModule      ( OtherModule.hs, interpreted )
ghc-6.6.20070220: panic! (the 'impossible' happened)
  (GHC version 6.6.20070220 for powerpc-apple-darwin):
        lookup_dfun main:OtherModule.$f1{v r5xc} [lid]

Please report this as a GHC bug:  http://www.haskell.org/ghc/reportabug

*GHCLibTest> Leaving GHCi.
$ 

I have difficulties these days installing a GHC HEAD and don't exactly see how to do this with a ghc-inplace, so I have not been able to try this (or rather: The changed version) on a recent HEAD.

comment:8 Changed 8 years ago by simonmar

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

I did finally reproduce this with 6.6.1 here, and I can confirm that it doesn't happen with HEAD, so I'm closing the bug.

comment:9 Changed 8 years ago by igloo

  • Milestone changed from 6.8 branch to 6.8.1

comment:10 Changed 7 years ago by simonmar

  • Operating System changed from Unknown to Unknown/Multiple
Note: See TracTickets for help on using tickets.