Ticket #2847 (closed bug: fixed)

Opened 3 years ago

Last modified 3 years ago

Failure on OPTION_* pramgas other than GHC

Reported by: NeilMitchell Owned by: igloo
Priority: high Milestone: 6.10.2
Component: Compiler Version: 6.10.1
Keywords: Cc: ndmitchell@…
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: Difficulty: Unknown
Test Case: Blocked By:
Blocking: Related Tickets:

Description

GHC should not attempt to look at other peoples pragmas. For example:

{-# OPTIONS_DERIVE --derive=Data,Typeable,Eq,Ord #-}
module Example where
data Foo = Bar

This worked fine with GHC 6.8, but doesn't with GHC 6.10. It says:

C:\Neil\derive>ghc Example.hs -c
Example.hs:1:11-48:
    unknown flag in  {-# OPTIONS #-} pragma: _DERIVE
Example.hs:1:11-48:
    unknown flag in  {-# OPTIONS #-} pragma: --derive=Data,Typeable,Eq,Ord

I consider this to be a major regression, as it breaks (amongst other things) the Yhc compiler, the Derive tool, and my thesis. I suspect it will also break anything Malcolm has set up with OPTION_YHC or OPTION_NHC pragmas.

Change History

  Changed 3 years ago by igloo

  • difficulty set to Unknown
  • milestone set to 6.10.2

Thanks for the report.

  Changed 3 years ago by simonmar

  • priority changed from normal to high

regression

  Changed 3 years ago by duncan

I cannot reproduce this with 6.10.1. The Cabal sources contain many instances of things like:

{-# OPTIONS_NHC98 -cpp #-}
{-# OPTIONS_JHC -fcpp #-}

and we get no warnings for these at all (and we're using -Wall and no flags to suppress any kinds of warnings).

  Changed 3 years ago by NeilMitchell

But if you have:

{-# OPTIONS_NHC -cpp #-}

Then suddenly it stops working and gives an error. It seems somewhere in GHC there is a central registry of what Haskell compilers there are...

  Changed 3 years ago by NeilMitchell

OPTIONS_YHC also fails, so that central registry lacks Yhc at the very least.

follow-up: ↓ 7   Changed 3 years ago by duncan

See ghc/compiler/parser/Lexer.x line 267:

"{-#" $whitechar* (OPTIONS_HUGS|options_hugs|OPTIONS_NHC98|options_nhc98|OPTIONS_JHC|options_jhc|CFILES|cfiles)

Clearly this is not the right approach.

in reply to: ↑ 6 ; follow-up: ↓ 11   Changed 3 years ago by igloo

Replying to duncan:

See ghc/compiler/parser/Lexer.x line 267: {{{ "{-#" $whitechar* (OPTIONS_HUGS|options_hugs|OPTIONS_NHC98|options_nhc98|OPTIONS_JHC|options_jhc|CFILES|cfiles) }}} Clearly this is not the right approach.

We need this to be able to warn about unrecognised pragmas.

But we also need to not parse OPTIONS_foo as an OPTIONS pragma, so we don't try to treat _foo and the pragma contents as a flag.

follow-up: ↓ 9   Changed 3 years ago by NeilMitchell

Surely OPTIONS_* where * is not GHC should be treated as a valid pragma aimed at someone else? I don't want users of Derive or Yhc being told that their pragma is invalid.

I also have a CATCH pragma that I've used in a few places. I realise that GHC wants to give good error reporting, but it seems a shame that I have to centrally register pragmas. Could there be a {-# KNOWN_PRAGMA Catch #-} style pragma?

in reply to: ↑ 8   Changed 3 years ago by igloo

Replying to NeilMitchell:

Surely OPTIONS_* where * is not GHC should be treated as a valid pragma aimed at someone else?

I'd certainly want a warning for OPTIONS_HGC, OPTIONS_FGX, etc.

I don't want users of Derive or Yhc being told that their pragma is invalid.

They are told their pragma is "unrecognised", not "invalid".

I also have a CATCH pragma that I've used in a few places. I realise that GHC wants to give good error reporting, but it seems a shame that I have to centrally register pragmas. Could there be a {-# KNOWN_PRAGMA Catch #-} style pragma?

We could do that. We might have to jiggle things around a bit to make it all work out.

  Changed 3 years ago by NeilMitchell

I wouldn't want a warning for OPTIONS_HGC, I don't think its sensible to make GHC have a registry of what is good vs bad compiler names. If however, you do want to keep a closed list of possible values, can OPTIONS_DERIVE and OPTIONS_YHC and OPTIONS_CATCH all be added to the "good" list.

The KNOWN_PRAGMA thing is less important, but might still be nice.

in reply to: ↑ 7 ; follow-up: ↓ 12   Changed 3 years ago by simonmar

Replying to igloo:

Replying to duncan:

See ghc/compiler/parser/Lexer.x line 267: {{{ "{-#" $whitechar* (OPTIONS_HUGS|options_hugs|OPTIONS_NHC98|options_nhc98|OPTIONS_JHC|options_jhc|CFILES|cfiles) }}} Clearly this is not the right approach.

We need this to be able to warn about unrecognised pragmas. But we also need to not parse OPTIONS_foo as an OPTIONS pragma, so we don't try to treat _foo and the pragma contents as a flag.

Right, all the pragmas should require whitespace after the pragma name.

I find it strange that OPTIONS_HUGS is not an unrecognised pragma, but OPTIONS_YHC is, surely we should be consistent here, where the only consistent thing to do is treat them both as unrecognised from the point of view of GHC. I can see that this might cause difficulties for people who want to use -Werror -Wall and use compiler-specific pragmas, though.

in reply to: ↑ 11   Changed 3 years ago by duncan

Replying to simonmar:

I can see that this might cause difficulties for people who want to use -Werror -Wall and use compiler-specific pragmas, though.

Which surely includes the core libraries since ghc likes to build them with -Werror during validate.

  Changed 3 years ago by igloo

  • owner set to igloo

  Changed 3 years ago by igloo

  • status changed from new to closed
  • resolution set to fixed

Fixed in the HEAD by:

Tue Dec  9 19:03:18 GMT 2008  Ian Lynagh <igloo@earth.li>
  * Parse pragma names better; trac #2847
  We require that pragma names are not followed by pragma character,
  defined as
      isAlphaNum c || c == '_'

and

Tue Dec  9 19:17:24 GMT 2008  Ian Lynagh <igloo@earth.li>
  * Add OPTIONS_CATCH,DERIVE,YHC to those that GHC knows about; trac #2847

and in the 6.10 branch by:

Tue Dec  9 21:18:54 GMT 2008  Ian Lynagh <igloo@earth.li>
  * Merge some of the #2847 fixes to the 6.10 branch
  The patches didn't merge cleanly. I've only made the
      notFollowedByPragmaChar
  fix to the OPTIONS pragma.

I've opened #2867 for the KNOWN_PRAGMA suggestion.

Note: See TracTickets for help on using tickets.