[GHC] #11201: ghc --make on Haskell and non-Haskell inputs can silently clobber input

GHC ghc-devs at haskell.org
Wed Dec 16 17:39:33 UTC 2015


#11201: ghc --make on Haskell and non-Haskell inputs can silently clobber input
-------------------------------------+-------------------------------------
        Reporter:  ezyang            |                Owner:
            Type:  bug               |               Status:  new
        Priority:  normal            |            Milestone:
       Component:  Compiler          |              Version:  7.11
      Resolution:                    |             Keywords:
Operating System:  Unknown/Multiple  |         Architecture:
 Type of failure:  Incorrect result  |  Unknown/Multiple
  at runtime                         |            Test Case:
      Blocked By:                    |             Blocking:
 Related Tickets:                    |  Differential Rev(s):
       Wiki Page:                    |
-------------------------------------+-------------------------------------

Comment (by ezyang):

 GHC's behavior is deterministic, and to some degree makes sense, but I
 don't think it's very transparent to the user. It goes something like:

 * If hiDir is set, `A.hs` gets compiled to `$hiDir/B.hi` where `B` is the
 `module` declaration inside the file.
 * If hiDir is not set, `A.hs` gets compiled to `A.hi`.

 And then the `.o` files are handled separately (so if you say `ghc --make
 A.hs -odir foo` where `A.hs` defines `module B` then you'll get `foo/B.o`
 and `A.hi`).

 Non-Haskell files operate differently:

 * If oDir is set, `b/a.c` gets compiled to `$odir/b/a.o`.
 * If it is not set, `b/a.c` gets compiled to `$odir/b/a.c`.

 I don't know what the right alternate behavior is. Possibilities:

 1. Simply warn when clobbering can occur
 2. Designate some uses of the command line as "blessed" and give warnings
 if you use it otherwise. For example, it would warn if you specify `hiDir`
 but not `oDir`. Probably should be OK to specify both. I'd like to also
 warn if you use `outputDir` with a file whose filename doesn't match the
 module name, but I'm pretty sure Cabal uses this to build exectuables.
 3. Interface/object files for Haskell should never be based off of the
 internal module name; they should always be based off of the source file
 name. But you have to munge prefixes because you can also have `ghc --make
 src1/Foo.hs src2/Bar.hs -isrc1 -isrc2`, ugh!

 Here is a suggested meta-rule: given an object/interface filename, it
 should be EASY to tell how to build it. I don't know how to achieve that
 and maintain BC.

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


More information about the ghc-tickets mailing list