RE: state of the cabal (preprocessors)

To hopefully wind up this discussion, I'd like to make three proposals: 1. That if a compiler understands an in-file pragma specifying options, it should take the form {-# OPTIONS_<compiler> ... #-}. 2. We introduce a new pragma to specify the language extensions in force for the current source file. I suggest: {-# LANGUAGE <ext1>,...,<extn> #-} where <ext> is taken from the list of extensions understood by Cabal in the 'extensions' field of a package description (eg. OverlappingInstances, RecursiveDo, etc.). 3. We add CPP to the list of extensions in Cabal, so you can say {-# LANGUAGE CPP #-} to get C preprocessing in the current file, or add CPP to the list of extensions in the package description to get CPP on every file. That doesn't preclude also using a .cpp extension, but it means you don't have to. Hmm, I've just realised some problems with this. Hugs probably won't be implementing {-# LANGUAGE #-} any time soon (I imagine?) so it wouldn't be portable. Also old compilers don't implement it, so we have a difficult migration path. Perhaps for the time being we just do 1 & 3, and use the package-wide list of extensions for portability. Cheers, Simon

Hi all,
To hopefully wind up this discussion, I'd like to make three proposals:
Basically looks good to me.
1. That if a compiler understands an in-file pragma specifying options, it should take the form {-# OPTIONS_<compiler> ... #-}.
Of course, it is really up to each implementation to decide how to handle its own OPTIONS pragmas. But to avoid confusion, it would be helpful if the implementors could agree to process these pragmas in a reasonably similar way. The GHC approach seems good, which I understand as follows: * Options are collected from one or more OPTIONS pragmas in order * The in-file options are prepended to the command-line options. An additional issue is *where* OPTIONS pragmas get recognized. The current GHC approach is as follows: OPTIONS pragmas are only looked for at the top of your source file, up to the first (non-literate, non-empty) line not containing OPTIONS. In view of there now being OPTIONS pragmas for a number of different compilers this approach would have to be refined, or all but one system would not be able to find their options! Also, when/if the LANGUAGE pragma is added, it would be sensible if exactly the same rules applied to that. One could refine the above rule in such a way that it would work for all forms of OPTION/LANGUAGE pragmas and in such a way that that the interleaving with option pragmas for other compilers do not interfere. However, at least superficially, it would seem simpler (and more flexible, since normal comments would not interfere) to simply require that all OPTIONS/LANGUAGE pragmas must occur before the keyword "module". But maybe that is hard to implement, or undesirable for some other reason?
2. We introduce a new pragma to specify the language extensions in force for the current source file. I suggest: {-# LANGUAGE <ext1>,...,<extn> #-} where <ext> is taken from the list of extensions understood by Cabal in the 'extensions' field of a package description (eg. OverlappingInstances, RecursiveDo, etc.).
Yes, I like this. Do we have to worry about how LANGUAGE, OPTIONS_XXX and command line options (some of which may have originated from global Cabal language extension specifications, presumably) interact? I suspect *not*, since all language extension specifiers seem to turn ON the specified feature. If that is the case, simply taking the union of all specifiers (not worrying about order) should do?
3. We add CPP to the list of extensions in Cabal, so you can say {-# LANGUAGE CPP #-} to get C preprocessing in the current file, or add CPP to the list of extensions in the package description to get CPP on > every file. That doesn't preclude also using a .cpp extension, but it means you don't have to.
Sounds good.
Hmm, I've just realised some problems with this. Hugs probably won't be implementing {-# LANGUAGE #-} any time soon (I imagine?) so it wouldn't be portable. Also old compilers don't implement it, so we have a difficult migration path.
I assume that Hugs and old compilers just would ignore {-# LANGUAGE #-} since the Haskell report explicitly requires an implementation to ignore pragmas it does not understand. If so, the build-system could lend a helping hand to Hugs and other systems that do not understand LANGUAGE by looking for LANGUAGE pragmas on behalf of the compiler and invoke it with the appropriate flags. Not sure that would be much fun to implement in a make-based system, but I should think it would be fairly easy to implement in the context of Cabal's simple build system, in particular since there must be some mechanism to translate language extension specifications into compiler-specific options already. When it comes to the CPP "extension" (and Arrows, and maybe other preprocessors), it would seem as if the build system HAS to look for any LANGUAGE pragmas anyway when dealing with Hugs since there was consensus that preprocessing should happen only once, and preprocessed sources are what should get installed. As to backwards compatibility in general, would there be a problem if GHC and NHC continue to support their respective OPTIONS variants as a deprecated feature? Then no old code should break. Best, /Henrik -- Henrik Nilsson School of Computer Science and Information Technology The University of Nottingham nhn@cs.nott.ac.uk This message has been scanned but we cannot guarantee that it and any attachments are free from viruses or other damaging content: you are advised to perform your own checks. Email communications with the University of Nottingham may be monitored as permitted by UK legislation.

"Simon Marlow"
3. We add CPP to the list of extensions in Cabal, so you can say {-# LANGUAGE CPP #-} to get C preprocessing in the current file, or add CPP to the list of extensions in the package description to get CPP on every file. That doesn't preclude also using a .cpp extension, but it means you don't have to.
For hugs this would mean preprocessing all files and putting the new .hs files into a temp directory and compiling these. Hopefully, there will be directives in the preprocessed sources to refer back to the original source, and hugs should report errors against the original source lines rather than the preprocessed source lines. Is hugs able to do this already? For GHC and NHC, this just means we use the -cpp flag. Is this correct? If so, that's fine by me (and I speak for the cabal ;) ) peace, isaac

Isaac Jones writes:
For hugs this would mean preprocessing all files and putting the new .hs files into a temp directory and compiling these.
I thought it would mean that the build system (Cabal's builtin one, a make-based one, ...) would run the sources through CPP prior to installing the preprocessed sources wherever the library/application in question should be installed? This was discussed a week or so ago, and my impression was that people agreed that this is the best approach to preprocessing for Hugs. This also happens to be how the Yampa/Yale make-based build system handles preprocessing for Hugs, and it works quite well. So why a "temp" directory? And did you really mean "interpreting" rather than "compiling"?
Hopefully, there will be directives in the preprocessed sources to refer back to the original source,
That depends on which CPP is used, and how CPP is invoked, so it would really be up to the build system. E.g. the man page for CPP on my system says that "-P" inhibits the generation of linemarkers in the output.
and hugs should report errors against the original source lines rather than the preprocessed source lines. Is hugs able to do this already?
At least in the Yampa/Yale build system we invoked CPP with "-P" when preprocessing sources for Hugs to keep Hugs happy. So at least a year or so ago, Hugs did not understand line directives, as far as I can tell. Maybe that has now changed? All the best, /Henrik -- Henrik Nilsson School of Computer Science and Information Technology The University of Nottingham nhn@cs.nott.ac.uk This message has been scanned but we cannot guarantee that it and any attachments are free from viruses or other damaging content: you are advised to perform your own checks. Email communications with the University of Nottingham may be monitored as permitted by UK legislation.

On Tue, Oct 26, 2004 at 05:33:41PM -0400, Isaac Jones wrote:
"Simon Marlow"
writes: 3. We add CPP to the list of extensions in Cabal, so you can say {-# LANGUAGE CPP #-} to get C preprocessing in the current file, or add CPP to the list of extensions in the package description to get CPP on every file. That doesn't preclude also using a .cpp extension, but it means you don't have to.
For hugs this would mean preprocessing all files and putting the new .hs files into a temp directory and compiling these.
When you get to .hs, you're done (except for compiling ffi stubs) -- these are libraries ready for Hugs.
Hopefully, there will be directives in the preprocessed sources to refer back to the original source, and hugs should report errors against the original source lines rather than the preprocessed source lines. Is hugs able to do this already?
No, it doesn't understand LINE pragmas (nor #line).
participants (4)
-
Henrik Nilsson
-
Isaac Jones
-
ross@soi.city.ac.uk
-
Simon Marlow