Discovery of source dependencies without --make

Simon Peyton Jones simonpj at microsoft.com
Fri Nov 28 16:08:32 UTC 2014


|  Let's say the hypothetical feature is selected via the GHC flag "--
|  topo-sort". It would add a step before regular compilation and
|  wouldn't affect any other flag:
|  
|    ghc -c --topo-sort fileA.hs fileB.hs ...
|  
|  This would first read in the specified source files and look at their
|  module headers and import statements. It would build a graph of module
|  dependencies _between_ the specified source files (ignoring circular
|  dependencies), perform a topological sort on that graph, and proceed
|  with compiling the source files in that order.

Interesting (and quite different from what I anticipated, so it's a good thing you wrote it down!).

How does that differ from ghc --make?  The only difference I can see is that
  - Modules that --make might find, but not listed on
    the command line, would not be compiled by --topo-sort
 
Simon

|  -----Original Message-----
|  From: Lars Hupel [mailto:lars at hupel.info]
|  Sent: 28 November 2014 14:42
|  To: Simon Peyton Jones
|  Cc: glasgow-haskell-users at haskell.org; Andrey Mokhov
|  Subject: Re: Discovery of source dependencies without --make
|  
|  > Rather than explain by deltas from something else, it might be
|  easier
|  > just to write down precisely what you seek.
|  
|  Let's say the hypothetical feature is selected via the GHC flag "--
|  topo-sort". It would add a step before regular compilation and
|  wouldn't affect any other flag:
|  
|    ghc -c --topo-sort fileA.hs fileB.hs ...
|  
|  This would first read in the specified source files and look at their
|  module headers and import statements. It would build a graph of module
|  dependencies _between_ the specified source files (ignoring circular
|  dependencies), perform a topological sort on that graph, and proceed
|  with compiling the source files in that order.
|  
|  As a consequence, if there is an order in which these modules can be
|  successfully compiled, "--topo-sort" would choose such an order. In
|  that sense, the above invocation would be equivalent to
|  
|    ghc -c fileB.hs fileA.hs ...
|  
|  (using some permutation of the original order specified)
|  
|  Another consequence is that any invocation of GHC in the form of
|  
|    ghc -c flags... sources.hs...
|  
|  with arbitrary flags would still work as usual when adding "--topo-
|  sort".
|  
|  Quoting from the user manual:
|  
|  > In your program, you import a module Foo by saying import Foo. In
|  > --make mode or GHCi, GHC will look for a source file for Foo and
|  > arrange to compile it first. Without --make, GHC will look for the
|  > interface file for Foo, which should have been created by an earlier
|  > compilation of Foo.
|  
|  The hypothetical "--topo-sort" flag would behave in the latter way,
|  i.e.
|  it would not require a source file for an unknown dependency. Hence,
|  "--topo-sort" and "--make" would be conflicting options.
|  
|  I hope that clears up things a bit.
|  
|  Cheers
|  Lars


More information about the Glasgow-haskell-users mailing list