Skip to content

Recognise language pragmas generated by custom pre-processors (run with -F)

A custom pre-processor might desugar terms into terms of a particular language extension, requiring a new language pragma. Currently, any language pragmas generated by a pre-processor will be ignored once the pre-processed file is picked up by GHC again.

As a contrived example, consider foo.hs:

{-# OPTIONS -F -pgmF ./preprocess.sh #-}

data Foo a where MkFoo :: Foo a

where preprocess.sh:

{{{ #!/bin/sh ( echo "{-# LANGUAGE GADTs #-}"; cat $2; ) > $3 }}}

Currently we get this behaviour:

bash-3.2$ ghc foo.hs

/tmp/ghc7191_0/ghc7191_0.hspp:4:0:
    Illegal generalised algebraic data declaration for `Foo'
      (Use -XGADTs to allow GADTs)
    In the data type declaration for `Foo'

bash-3.2$ ghc foo.hs -E
bash-3.2$ cat foo.hspp
{-# LANGUAGE GADTs #-}
{-# OPTIONS -F -pgmF ./preprocess.sh #-}

data Foo a where MkFoo :: Foo abash-3.2$ 

It would be nice if GHC noticed the new pragmas, particularly language pragmas, although perhaps not all pragmas should be picked up (maybe not new OPTION pragmas).

Trac metadata
Trac field Value
Version
Type FeatureRequest
TypeOfFailure OtherFailure
Priority normal
Resolution Unresolved
Component Compiler
Test case
Differential revisions
BlockedBy
Related
Blocking
CC
Operating system
Architecture
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information