On Fri, Nov 28, 2014 at 3:41 PM, Lars Hupel <lars@hupel.info> wrote:
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.

GHC 8 will have support for Frontend plugins. Frontend plugins enable you to write plugins to replace
GHC major modes.

E.g. instead of saying
    ghc --make A B C

you can now say:

    ghc --frontend TopoSort A B C
You still have to implement TopoSort.hs yourself, using the GHC API to compile A B C in topological order, but some of the plumbing is taken care of by the Frontend plugin infrastructure already.

Take a look at this commit, especially the user's guide section and the test case: https://github.com/ghc/ghc/commit/a3c2a26b3af034f09c960b2dad38f73be7e3a655.