Opened 3 years ago

Last modified 3 years ago

#12053 new feature request

Mode for ghc --make which only compiles the files I pass on command line

Reported by: ezyang Owned by: ezyang
Priority: normal Milestone:
Component: Compiler Version: 8.0.1
Keywords: Cc: dcoutts
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: None/Unknown Test Case:
Blocked By: Blocking:
Related Tickets: Differential Rev(s):
Wiki Page:


Here are a few situations where GHC picks up "too many" files when running --make:

  • Suppose a user doesn't add enough modules to exposed-modules/other-modules in Cabal. GHC will happily pick up extra source files, but those files won't get bundled in the sdist or be included in ABI computation. Difficult for Cabal to tell when this has happened.
  • Suppose the user wants to define multiple internal libraries, and give them the same hs-source-dir. This won't work: because GHC sees the source file it will prefer it over the external dependency.

There's a very easy thing that GHC could do to make this better: add a mode to --make which says "only compile the files that are explicitly passed on the command line." Something like ghc --make --only A.hs will only build A.hs, and error if you try to import B.hs.

Seems like this should be fairly easy to do, and would help solve a lot of problems related to GHC slurping up too many files.

(I've assigned myself because this is a blocker for backpack, but if someone wants to take a crack at this be my guest.)

Change History (2)

comment:1 Changed 3 years ago by mgsloan

Something like this would indeed be handy! The linker errors people get when the module isn't in their cabal file can be scary / uninformative.

FYI, the approach that stack takes here is to use -ddump-hi and identify when there are modules / etc unmentioned in the cabal file.

comment:2 Changed 3 years ago by ezyang

Keywords: backpack removed
Note: See TracTickets for help on using tickets.