deprecated OPTIONS flag warnings generated during dep chasing?
It would appear that warnings about deprecated flags used in OPTIONS
pragmas get spat out during the early pre-processing and module chasing phase when they would not be generated after pre-processing.
ghc --make
has to scan each module to look for options and language extensions to know if it has to run cpp. At this stage it cannot of course run cpp so it does not necessarily get the full set of options and extensions since some may be conditional. So it should not at this stage generate any warnings since they may be suppressed by later cpp-conditional flags.
Another possible theory is that it generates the warnings before having read all the OPTIONS
flags so the later warning suppression is ineffective. Unfortunately we have to put them in the order we do for compatibility with older versions of ghc.
Here's an example out of Cabal:
{-# OPTIONS -cpp -fffi #-}
-- OPTIONS required for ghc-6.4.x, and must appear first
{-# LANGUAGE CPP, ForeignFunctionInterface #-}
{-# OPTIONS_GHC -cpp -fffi #-}
{-# OPTIONS_NHC98 -cpp #-}
{-# OPTIONS_JHC -fcpp -fffi #-}
#if __GLASGOW_HASKELL__ >= 610
{-# OPTIONS_GHC -fno-warn-deprecated-flags #-}
-- the ghc flag -fffi is deprecated in ghc-6.10. We're
-- supposed to use the LANGUAGE pragmas instead. However
-- we have to maintain compatibility with older ghc versions
-- so we (try to) suppress this warning.
#endif
What we're trying to do here is make it work with ghc-6.4 + and not generate any warnings with the latest ghc. This seems quite tricky to do.
To support ghc-6.4 we have to put the OPTIONS
pragma first, since it apparently only looks at the first couple lines. We then use the compiler-specific OPTIONS
pragmas. In particular these are needed for ghc-6.6. For ghc-6.8 and later we can use the LANGUAGE
pragmas.
In ghc-6.10 the -fffi
option is deprecated. However we cannot conditionally compile the OPTIONS -cpp -fffi
since ghc needs to see the -cpp
to know that it has to cpp the module. Making the OPTIONS -cpp
unconditional and the OPTIONS -cpp -fffi
conditional does not work with ghc-6.4.
So instead we try suppressing the warning. We cannot do that unconditionally since the flag is only present in newer ghc versions. However if we do suppress conditionally then ghc still warns anyway, presumably because it is warning on the first pass rather than in the pass after running cpp.
All in all it's a bit tricky to do right. Indeed I cannot currently see a way to make it work at all without generating warnings. The sledgehammer would be to put a flag in the .cabal file and have it apply to all modules, however that does not prevent the warning happening during Cabal bootstrapping which uses plain ghc --make
.
Trac metadata
Trac field | Value |
---|---|
Version | 6.8.3 |
Type | Bug |
TypeOfFailure | OtherFailure |
Priority | normal |
Resolution | Unresolved |
Component | Compiler |
Test case | |
Differential revisions | |
BlockedBy | |
Related | |
Blocking | |
CC | |
Operating system | |
Architecture |