[GHC] #13801: Make -main-is work with {thing} from arbitrary installed packages

GHC ghc-devs at haskell.org
Sat Jun 10 03:09:38 UTC 2017


#13801: Make -main-is work with {thing} from arbitrary installed packages
-------------------------------------+-------------------------------------
        Reporter:  SimonHengel       |                Owner:  (none)
            Type:  feature request   |               Status:  new
        Priority:  normal            |            Milestone:
       Component:  Compiler          |              Version:  8.0.2
      Resolution:                    |             Keywords:
Operating System:  Unknown/Multiple  |         Architecture:
                                     |  Unknown/Multiple
 Type of failure:  None/Unknown      |            Test Case:
      Blocked By:                    |             Blocking:
 Related Tickets:                    |  Differential Rev(s):
       Wiki Page:                    |
-------------------------------------+-------------------------------------

Comment (by ezyang):

 So, are you aware that you can already refer to an identifier that is not
 defined in the Main module? The trick is that you have to export any of
 the identifiers you want to use.  Here is a self-contained example:

 {{{
 -- A.hs
 module A where
 f = print "This is A"
 -- Main.hs
 module Main(main, f) where
 import A

 main :: IO ()
 main = return ()
 }}}

 And then: `ghc --make Main.hs -main-is f`.

 Now, there are still things you might want to do...

 **You might want to not have to explicitly export f.**  Then you would
 have to modify `checkMainExported`, and figure out if there was a
 technical reason why we required this (quite possibly because if it isn't
 exported, we will dead code eliminate it.) Maybe you should implicitly
 export any identifier mentioned with `-main-is`. That sounds helpful.

 **You might not want to have to import A.** In this case, you have to
 modify this code:

 {{{
 getMainFun :: DynFlags -> RdrName
 getMainFun dflags = case mainFunIs dflags of
                       Just fn -> mkRdrUnqual (mkVarOccFS (mkFastString
 fn))
                       Nothing -> main_RDR_Unqual
 }}}

 You'll have to take the module name, run it through the module lookup
 mechanism to make a Module, and then make an Orig RdrName.

 **You don't want to have to write main at all.** I think this is what you
 actually were asking for, based on the ticket text. In that case, GHC has
 to know that, if you pass `-main-is` and an empty list of modules, it
 should generate an empty source file (for Main), and then attempt to build
 that. You'd have to implement the previous step before that too.

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


More information about the ghc-tickets mailing list