[GHC] #9422: EPT caching on --make can make spurious instances visible

GHC ghc-devs at haskell.org
Thu Aug 7 23:24:36 UTC 2014


#9422: EPT caching on --make can make spurious instances visible
-------------------------------------+-------------------------------------
       Reporter:  ezyang             |                   Owner:
           Type:  bug                |                  Status:  new
       Priority:  normal             |               Milestone:
      Component:  Compiler (Type     |                 Version:  7.9
  checker)                           |        Operating System:
       Keywords:                     |  Unknown/Multiple
   Architecture:  Unknown/Multiple   |         Type of failure:  GHC
     Difficulty:  Unknown            |  accepts invalid program
     Blocked By:                     |               Test Case:
Related Tickets:                     |                Blocking:
                                     |  Differential Revisions:
-------------------------------------+-------------------------------------
 This is perhaps best demonstrated by way of an example.  Suppose we have a
 package a with the following two modules, with A defining a type class and
 data type, and I defining an orphan instance.

 {{{#!hs
 module A where
 data A = A
 class C a where
     cop :: a -> a
 }}}

 {{{#!hs
 module I where
 import A
 instance C A where
     cop = id
 }}}

 Then, when compiling this module:

 {{{#!hs
 module N where
 import A
 x = cop A
 }}}

 I might reasonably expect to be told that the instance `C` is not in scope
 (since I didn't import `I`, nor did any of my dependencies import `I`).
 However, suppose I have another module:

 {{{#!hs
 module M where
 import I
 }}}

 and I use `--make` to compile both of these modules in one go, with `M`
 being compiled first (`ghc --make N.hs M.hs` does that for me), then `N`
 will incorrectly type check and compile! This should not happen.

 The reason for this behavior is that we do not clear the EPT (external
 package table) between compilations of a file in batch compilation mode;
 this saves us from having to repeatedly read instances from the external
 files. Thus, `M`, having loaded the instances into the EPT when type-
 checking, `N` will automatically pick them up. Note that `I` and `A` have
 to be in a separate package; otherwise `--make` puts them in the HPT (home
 package table) and everything works fine. (Note also that one-shot
 compilation puts home modules in the EPT, but since that gets thrown out
 everything is fine as well, although perhaps a user of the GHC API could
 get bitten by this.)

 As for the fix, it's probably not right to clear the EPT either, since we
 get quite good time savings from not having to parse interface files
 repeatedly. Perhaps we could do something clever by partitioning up the
 EPT, but maybe it's not worth it and we should keep this bug as a known
 infelicity until the next time this part of the compiler gets rewritten.
 I'll submit a test-case (marked as failing) anyhoo.

--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/9422>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler


More information about the ghc-tickets mailing list