Opened 11 years ago

Closed 11 years ago

Last modified 3 years ago

#2412 closed bug (fixed)

Interaction between type synonyms and .hs-boot causes panic "tcIfaceGlobal (local): not found"

Reported by: batterseapower Owned by: igloo
Priority: normal Milestone: 6.10.1
Component: Compiler Version: 6.9
Keywords: hs-boot Cc:
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: None/Unknown Test Case: T2412
Blocked By: Blocking:
Related Tickets: Differential Rev(s):
Wiki Page:


To reproduce, create the files:


module Main ( main, Baz ) where

import Foo ( Bar )

type Spqr = Bar
data Baz = Baz Spqr

main = putStrLn "Hello"


module Main where

data Baz


module Foo where

import {-# SOURCE #-} Main ( Baz )

type Bar = Baz

Then run this command sequence:

$ ghc Main.hs-boot
$ ghc Foo.hs
$ ghc Main.hs
ghc-6.8.2: panic! (the 'impossible' happened)
  (GHC version 6.8.2 for i386-apple-darwin):
	tcIfaceGlobal (local): not found:
    main:Main.Baz{tc r2T}

Please report this as a GHC bug:

Note the problem does not seem to manifest itself outside of one-shot mode.

The full trace is:

$ ghc Main.hs -ddump-if-trace -ddump-tc-trace
FYI: cannot read old interface file:
    Main.hi: openBinaryFile: does not exist (No such file or directory)
Considering whether to load base:Prelude
Reading interface for base:Prelude; reason: Prelude is directly imported
readIFace /usr/local/lib/ghc-6.8.2/lib/base-
updating EPS_
Considering whether to load main:Foo
Reading interface for main:Foo; reason: Foo is directly imported
readIFace Foo.hi
updating EPS_
updating EPS_
Loading orphan modules: base:GHC.Base
Considering whether to load base:GHC.Base {- SYSTEM -}
Reading interface for base:GHC.Base;
    reason: base:GHC.Base is a orphan-instance module
readIFace /usr/local/lib/ghc-6.8.2/lib/base-
updating EPS_
loadHiBootInterface main:Main
Reading [boot] interface for main:Main;
    reason: Need the hi-boot interface for main:Main to compare against the Real Thing
readIFace Main.hi-boot
Finished typechecking interface for main:MainStarting fork { Declaration for Baz
Loading decl for Main.Baz
updating EPS_
tcIfaceDecl4 Main.Baz
} ending fork Declaration for Baz

Type envt: [(r2T, Type constructor `Main.Baz')]
Main.hs:1:0: Tc2
Main.hs:1:0: tcTyAndCl Main
    kcd1 Spqr [[]] [[]]
    In the type synonym declaration for `Spqr'
    lk1 Bar
    In the type synonym declaration for `Spqr'
Main.hs:5:12:Starting fork { Declaration for Bar
Loading decl for Foo.Bar
updating EPS_
ghc-6.8.2: panic! (the 'impossible' happened)
  (GHC version 6.8.2 for i386-apple-darwin):
	tcIfaceGlobal (local): not found:
    main:Main.Baz{tc r2T}

Please report this as a GHC bug:

This happens because when typechecking the type synonym Main.Spqr, kcTyVar calls tcLookup. This causes GHC to pull on the declaration for Foo.Bar. However, this declaration makes use of Main.Baz via a SOURCE import and we haven't yet got around to type checking Main.Baz!

Hence tcIfaceGlobal dies, unable to find Baz in the type environment.

Note that reversing the order of the declarations of Main.Baz and Main.Spqr doesn't seem to make a difference. I think this is because Baz in turn uses Spqr.

I only have limited knowledge of the type checker, but I think a possible fix to this would be to type check the right hand sides of type synonym declarations lazily so we put Main.Baz into the environment before we go off exploring Foo.Bar. We seem to use a trick to deal with a similar type checking interface data constructors?

Change History (8)

comment:1 Changed 11 years ago by batterseapower

Actually, I've just confirmed that the synonym Main.Spqr is irrelevant: you can replace the use of it in Main.Baz with Foo.Bar itself and get the same behaviour.

A workaround for this bug is to use a newtype rather than a type synonym in Foo.

comment:2 Changed 11 years ago by igloo

difficulty: Unknown
Milestone: 6.10.1

Thanks for a great testcase and explanation of the problem! We'll take a look.

comment:3 Changed 11 years ago by simonpj

Thanks for the report. I've investigated a little, and I think I know what's going on. Needs more thought.

Note to self: the write to tcg_type_env_var (line 783 in TcRnDriver is coming too late).


comment:4 Changed 11 years ago by simonpj

Owner: set to igloo

Fixed by

Mon Aug 11 13:25:23 BST 2008
  * Fix Trac #2412: type synonyms and hs-boot recursion

Ian: I'm not sure how to set up a testsuite test for this. Do you think you could do so? Thanks.


comment:5 Changed 11 years ago by igloo

Resolution: fixed
Status: newclosed
Test Case: T2412

Test T2412 added

comment:6 Changed 11 years ago by simonmar

Architecture: UnknownUnknown/Multiple

comment:7 Changed 11 years ago by simonmar

Operating System: UnknownUnknown/Multiple

comment:8 Changed 3 years ago by ezyang

Keywords: hs-boot added
Type of failure: None/Unknown
Note: See TracTickets for help on using tickets.