[GHC] #8337: make it possible for the user to force orphanness via a module-level annotation

GHC ghc-devs
Thu Oct 3 16:47:43 UTC 2013


#8337: make it possible for the user to force orphanness via a module-level
annotation
-------------------------------+-------------------------------------------
        Reporter:  errge       |            Owner:
            Type:  bug         |           Status:  patch
        Priority:  normal      |        Milestone:  7.8.1
       Component:  Compiler    |          Version:  7.6.3
      Resolution:              |         Keywords:
Operating System:              |     Architecture:  Unknown/Multiple
  Unknown/Multiple             |       Difficulty:  Easy (less than 1 hour)
 Type of failure:              |       Blocked By:
  None/Unknown                 |  Related Tickets:
       Test Case:              |
        Blocking:  7867        |
-------------------------------+-------------------------------------------

Comment (by errge):

 Yes, annotations are unfortunately local only.

 My usecase:
   - WGet.hs imports TCP.hs
   - TCP.hs defines a commandline flag (via a template haskell function
 called defineFlag)
     - called tcp_connect_timeout
     - this creates a module-level annotation in B.hs, containing all the
 info about the flag
   - Main.hs imports WGet.hs only (doesn't import TCP.hs)
   - Main.hs's main function contains a call to the initProgram splice
     - this gathers all the flags from all the imported modules
 transitively
     - generates a parser
     - generates a --help output
     - at runtime run's the parser or reports the usage
   - TCP and WGet can be in different package, so different compilation
 unit, not one ghc --make

 This assumes that Main.hs can reify annotations and module listings, but
 we're already working on that in #8397 and #8398.

 For this to work, TCP.hs needs to be orphan, otherwise it's not read by
 GHC when compiling Main.hs.

 Now your question: can we somehow figure this out automatically instead of
 depending on this hacky pragma?  The only thing that gives us a clue is
 that there is a module annotation in TCP.hs.  That's all.

 So I see the following options here:
   - I change the patch to make modules orphans if they contain module
 annotations,
   - I change the patch to have a new type of module annotation (I'm not
 sure about the syntax though, because e.g. `{-# ANN module orphan "String"
 #-}` is ambiguous between orphan module annotation of "String" or module
 annotation of (orphan "String")),
   - I make the current approach less confusing by explicit documentation
 and usecase description.

 In any case, I can of course add the documentation to the manual, I just
 wanted to get feedback as soon as possible, since we're a bit tight
 already for 7.8.

 Now that I gave this some thought, I don't really see why would someone
 want to reify annotations of values and types without importing them.  On
 the other hand, I see the use case of "orphan" module annotations, so I
 prefer option 1.  What is your opinion?

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



More information about the ghc-tickets mailing list