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

#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

#9422: EPT caching on --make can make spurious instances visible -------------------------------------+------------------------------------- Reporter: ezyang | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.9 (Type checker) | Keywords: Resolution: | Architecture: Unknown/Multiple Operating System: | Difficulty: Unknown Unknown/Multiple | Blocked By: Type of failure: GHC | Related Tickets: accepts invalid program | Test Case: | Blocking: | Differential Revisions: | -------------------------------------+------------------------------------- Comment (by ezyang): In our most recent Backpack information, SPJ described a nice and simple way of solving this problem. Continue to maintain a global EPT, but with every type class instance, record the module it originated from. Now, when we do a lookup into the EPT table, we need to check if that module is transitively reachable from the current module; if it is not, then it is discarded. The transitivity check can be done lazily, so, hopefully, when this bad behavior doesn't occur, we can avoid doing all of the work of slurping in all the imports to figure out what type instances are available and which are not. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9422#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#9422: EPT caching on --make can make spurious instances visible -------------------------------------+------------------------------------- Reporter: ezyang | Owner: Type: bug | Status: closed Priority: normal | Milestone: Component: Compiler | Version: 7.9 (Type checker) | Keywords: Resolution: duplicate | Architecture: Unknown/Multiple Operating System: | Difficulty: Unknown Unknown/Multiple | Blocked By: Type of failure: GHC | Related Tickets: 8427 accepts invalid program | Test Case: | Blocking: | Differential Revisions: | -------------------------------------+------------------------------------- Changes (by ezyang): * status: new => closed * resolution: => duplicate * related: => 8427 -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9422#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC