[GHC] #8198: One-shot mode is buggy w.r.t. hs-boot files

#8198: One-shot mode is buggy w.r.t. hs-boot files -------------------------+------------------------------------------------- Reporter: parcs | Owner: Type: bug | Status: new Priority: | Milestone: 7.8.1 normal | Version: 7.7 Component: | Operating System: Unknown/Multiple Driver | Type of failure: Incorrect warning at Keywords: | compile-time Architecture: | Test Case: Unknown/Multiple | Blocking: Difficulty: | Unknown | Blocked By: | Related Tickets: | -------------------------+------------------------------------------------- Consider === A.hs-boot {{{ #!haskell module A where }}} === B.hs {{{ #!haskell module B where import {-# SOURCE #-} A }}} === Command Line {{{ $ ghc -c A.hs-boot B.hs B.hs:3:1: Bad interface file: A.hi-boot-boot A.hi-boot-boot: openBinaryFile: does not exist (No such file or directory) }}} I expect the modules to get compiled cleanly. Instead I get an error. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8198 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8198: One-shot mode is buggy w.r.t. hs-boot files -------------------------------------------------+------------------------- Reporter: parcs | Owner: parcs Type: bug | Status: new Priority: normal | Milestone: 7.8.1 Component: Driver | Version: 7.7 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Incorrect warning at | Unknown/Multiple compile-time | Difficulty: Test Case: | Unknown Blocking: | Blocked By: | Related Tickets: -------------------------------------------------+------------------------- Changes (by parcs): * owner: => parcs Comment: The problem is that when compiling `A.hs-boot`, module A's hs-boot file is added to the finder cache instead of its corresponding source file. So when the interface file for module A is requested, the finder cache returns "A.hi-boot". It then appends "-boot" to the end of that to get "A .hi-boot-boot". Since it is assumed that every home module location in the finder cache corresponds to a source file, the correct solution is to always add the module's source-file location to the finder cache, even if the current file happens to be an hs-boot file. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8198#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8198: One-shot mode is buggy w.r.t. hs-boot files -------------------------------------------------+------------------------- Reporter: parcs | Owner: parcs Type: bug | Status: new Priority: normal | Milestone: 7.8.1 Component: Driver | Version: 7.7 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Incorrect warning at | Unknown/Multiple compile-time | Difficulty: Test Case: | Unknown Blocking: | Blocked By: | Related Tickets: -------------------------------------------------+------------------------- Changes (by simonpj): * cc: simonmar (added) Comment: Simon M would you care to comment? -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8198#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8198: One-shot mode is buggy w.r.t. hs-boot files -------------------------------------------------+------------------------- Reporter: parcs | Owner: parcs Type: bug | Status: new Priority: normal | Milestone: 7.8.1 Component: Driver | Version: 7.7 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Incorrect warning at | Unknown/Multiple compile-time | Difficulty: Test Case: | Unknown Blocking: | Blocked By: | Related Tickets: -------------------------------------------------+------------------------- Comment (by parcs): Here's a patch of the change I'm proposing. {{{ #!diff diff --git a/compiler/main/DriverPipeline.hs b/compiler/main/DriverPipeline.hs index 44a6fa5..b4f4844 100644 --- a/compiler/main/DriverPipeline.hs +++ b/compiler/main/DriverPipeline.hs @@ -928,7 +928,16 @@ runPhase (RealPhase (Hsc src_flavour)) input_fn dflags0 PipeState{hsc_env=hsc_env'} <- getPipeState -- Tell the finder cache about this module - mod <- liftIO $ addHomeModuleToFinder hsc_env' mod_name location + -- + -- If we're compiling an hs-boot file in one-shot mode, assume that a + -- corresponding source file exists in the same directory and add that into + -- the finder cache instead, to maintain the invariant that locations in the + -- finder cache correspond to a module's source file only. + mod <- do + src_location <- if isHsBoot src_flavour + then getLocation HsSrcFile mod_name + else return location + liftIO $ addHomeModuleToFinder hsc_env' mod_name src_location -- Make the ModSummary to hand to hscMain let }}} -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8198#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8198: One-shot mode is buggy w.r.t. hs-boot files -------------------------------------------------+------------------------- Reporter: parcs | Owner: parcs Type: bug | Status: new Priority: normal | Milestone: 7.8.1 Component: Driver | Version: 7.7 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Incorrect warning at | Unknown/Multiple compile-time | Difficulty: Test Case: | Unknown Blocking: | Blocked By: | Related Tickets: -------------------------------------------------+------------------------- Comment (by simonmar): shouldn't we set `ml_hs_file` to `Nothing` in this case, rather than assuming that it is in the same location as the `hs-boot` file? -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8198#comment:4 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8198: One-shot mode is buggy w.r.t. hs-boot files -------------------------------------------------+------------------------- Reporter: parcs | Owner: parcs Type: bug | Status: new Priority: normal | Milestone: 7.8.1 Component: Driver | Version: 7.7 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Incorrect warning at | Unknown/Multiple compile-time | Difficulty: Test Case: | Unknown Blocking: | Blocked By: | Related Tickets: -------------------------------------------------+------------------------- Comment (by parcs): Replying to [comment:4 simonmar]:
shouldn't we set `ml_hs_file` to `Nothing` in this case, rather than assuming that it is in the same location as the `hs-boot` file?
I think that's a fair assumption since we already assume that hi- boot/o-boot files are in the same directory as their corresponding hi/o files. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8198#comment:5 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8198: One-shot mode is buggy w.r.t. hs-boot files -------------------------------------------------+------------------------- Reporter: parcs | Owner: parcs Type: bug | Status: new Priority: normal | Milestone: 7.8.1 Component: Driver | Version: 7.7 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Incorrect warning at | Unknown/Multiple compile-time | Difficulty: Test Case: | Unknown Blocking: | Blocked By: | Related Tickets: -------------------------------------------------+------------------------- Comment (by simonmar): FC and MLC? I don't think we make that assumption in one-shot mode. Why make the assumption if we don't need to? -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8198#comment:6 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8198: One-shot mode is buggy w.r.t. hs-boot files -------------------------------------------------+------------------------- Reporter: parcs | Owner: parcs Type: bug | Status: new Priority: normal | Milestone: 7.8.1 Component: Driver | Version: 7.7 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Incorrect warning at | Unknown/Multiple compile-time | Difficulty: Test Case: | Unknown Blocking: | Blocked By: | Related Tickets: -------------------------------------------------+------------------------- Comment (by parcs): Sorry, I meant the finder cache and mod location cache. I agree now -- there is no reason to assume that the source module exists in the same directory as the boot module. Does this patch look OK? {{{ #!diff diff --git a/compiler/main/DriverPipeline.hs b/compiler/main/DriverPipeline.hs index 337778e..0ecb5eb 100644 --- a/compiler/main/DriverPipeline.hs +++ b/compiler/main/DriverPipeline.hs @@ -928,7 +928,19 @@ runPhase (RealPhase (Hsc src_flavour)) input_fn dflags0 PipeState{hsc_env=hsc_env'} <- getPipeState -- Tell the finder cache about this module - mod <- liftIO $ addHomeModuleToFinder hsc_env' mod_name location + mod <- do + -- We pass in HsSrcFile unconditionally, even if we're compiling a + -- boot module, because every location in the finder cache + -- corresponds to a module's source files only. + src_location0 <- getLocation HsSrcFile mod_name + + -- However, if we're compiling a boot module then don't make any + -- assumptions about the location of the source module. It could + -- be in a different directory than the boot module. + let src_location1 + | isHsBoot src_flavour = src_location0 { ml_hs_file = Nothing } + | otherwise = src_location0 + liftIO $ addHomeModuleToFinder hsc_env' mod_name src_location1 -- Make the ModSummary to hand to hscMain let }}} -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8198#comment:7 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8198: One-shot mode is buggy w.r.t. hs-boot files -------------------------------------------------+------------------------- Reporter: parcs | Owner: parcs Type: bug | Status: new Priority: normal | Milestone: 7.8.1 Component: Driver | Version: 7.7 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Incorrect warning at | Unknown/Multiple compile-time | Difficulty: Test Case: | Unknown Blocking: | Blocked By: | Related Tickets: -------------------------------------------------+------------------------- Comment (by simonmar): ooh, inline diffs. Funky. It's not true that "every location in the finder cache corresponds to a module's source files only". In one-shot mode, the finder cache is full of locations that only have `.hi` files. See `findHomeModule`, and `hi_exts`. I think we should be calling `mkHiOnlyModLocation` here, because in one- shot mode that is what is normally used to create `ModLocation`s that go in the finder cache. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8198#comment:8 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC