[GHC] #10942: CPP pragma ignored if top comments and Opt_KeepRawTokenStream

#10942: CPP pragma ignored if top comments and Opt_KeepRawTokenStream -------------------------------------+------------------------------------- Reporter: alanz | Owner: alanz Type: bug | Status: new Priority: normal | Milestone: 8.0.1 Component: Compiler | Version: 7.10.2 Keywords: | Operating System: Unknown/Multiple Architecture: | Type of failure: None/Unknown Unknown/Multiple | Test Case: | Blocked By: Blocking: | Related Tickets: Differential Rev(s): | -------------------------------------+------------------------------------- HaRe sets `Opt_KeepRawTokenStream` to be able to round trip the source code. If we have a module starting {{{#!hs {- A normal comment, to check if we can still pick up the CPP directive after it. -} {-# LANGUAGE FlexibleInstances #-} {-# LANGUAGE CPP #-} -- Check that we can parse a file which requires CPP module BCpp where bob :: Int -> Int -> Int #if __GLASGOW_HASKELL__ > 704 bob x y = x + y #else bob x y = x + y * 2 #endif }}} then the call to `loadTargets` via the GHC API fails with `SourceError (lexical error at character 'i'` which is the normal error when `#if` is hit and CPP is not enabled. If `Opt_KeepRawTokenStream` is not set it loads without problems. Also, files using CPP but not having a top comment load properly too. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10942 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10942: CPP pragma ignored if top comments and Opt_KeepRawTokenStream -------------------------------------+------------------------------------- Reporter: alanz | Owner: alanz Type: bug | Status: new Priority: normal | Milestone: 8.0.1 Component: Compiler | Version: 7.10.2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): -------------------------------------+------------------------------------- Description changed by alanz: Old description:
HaRe sets `Opt_KeepRawTokenStream` to be able to round trip the source code.
If we have a module starting
{{{#!hs {-
A normal comment, to check if we can still pick up the CPP directive after it.
-} {-# LANGUAGE FlexibleInstances #-} {-# LANGUAGE CPP #-} -- Check that we can parse a file which requires CPP module BCpp where bob :: Int -> Int -> Int #if __GLASGOW_HASKELL__ > 704 bob x y = x + y #else bob x y = x + y * 2 #endif
}}}
then the call to `loadTargets` via the GHC API fails with
`SourceError (lexical error at character 'i'` which is the normal error when `#if` is hit and CPP is not enabled.
If `Opt_KeepRawTokenStream` is not set it loads without problems.
Also, files using CPP but not having a top comment load properly too.
New description: HaRe sets `Opt_KeepRawTokenStream` to be able to round trip the source code. If we have a module starting {{{#!hs {- A normal comment, to check if we can still pick up the CPP directive after it. -} {-# LANGUAGE FlexibleInstances #-} {-# LANGUAGE CPP #-} -- Check that we can parse a file which requires CPP module BCpp where bob :: Int -> Int -> Int #if __GLASGOW_HASKELL__ > 704 bob x y = x + y #else bob x y = x + y * 2 #endif }}} then the call to `load LoadAllTargets` via the GHC API fails with `SourceError (lexical error at character 'i'` which is the normal error when `#if` is hit and CPP is not enabled. If `Opt_KeepRawTokenStream` is not set it loads without problems. Also, files using CPP but not having a top comment load properly too. -- -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10942#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10942: CPP pragma ignored if top comments and Opt_KeepRawTokenStream -------------------------------------+------------------------------------- Reporter: alanz | Owner: alanz Type: bug | Status: new Priority: normal | Milestone: 8.0.1 Component: Compiler | Version: 7.10.2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): -------------------------------------+------------------------------------- Comment (by alanz): It seems the simplified parser in `HeaderInfo.getOptions'` needs to to skip over any vanilla comments seen and keep going. Alternatively `Opt_KeepRawTokenStream` must be unset in `HeaderInfo.getOptions` before calling `getToks`. I suspect the latter will be the simplest. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10942#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10942: CPP pragma ignored if top comments and Opt_KeepRawTokenStream -------------------------------------+------------------------------------- Reporter: alanz | Owner: alanz Type: bug | Status: new Priority: normal | Milestone: 8.0.1 Component: Compiler | Version: 7.10.2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): -------------------------------------+------------------------------------- Comment (by alanz): A workaround (as now in HaRe) is to only set the `Opt_KeepRawTokenStream` flag in the cached `DynFlags` in the `ModSummary` before invoking `parseModule` {{{#!hs tweakModSummaryDynFlags :: GHC.ModSummary -> GHC.ModSummary tweakModSummaryDynFlags ms = let df = GHC.ms_hspp_opts ms in ms { GHC.ms_hspp_opts = GHC.gopt_set df GHC.Opt_KeepRawTokenStream } }}} -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10942#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10942: CPP pragma ignored if top comments and Opt_KeepRawTokenStream -------------------------------------+------------------------------------- Reporter: alanz | Owner: alanz Type: bug | Status: new Priority: normal | Milestone: 8.0.1 Component: Compiler | Version: 7.10.2 (Parser) | Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by thomie): * component: Compiler => Compiler (Parser) -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10942#comment:4 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10942: CPP pragma ignored if top comments and Opt_KeepRawTokenStream -------------------------------------+------------------------------------- Reporter: alanz | Owner: alanz Type: bug | Status: patch Priority: normal | Milestone: 8.0.1 Component: Compiler | Version: 7.10.2 (Parser) | Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:D1444 Wiki Page: | -------------------------------------+------------------------------------- Changes (by mpickering): * status: new => patch * differential: => Phab:D1444 -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10942#comment:5 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10942: CPP pragma ignored if top comments and Opt_KeepRawTokenStream -------------------------------------+------------------------------------- Reporter: alanz | Owner: mpickering Type: bug | Status: patch Priority: normal | Milestone: 8.0.1 Component: Compiler | Version: 7.10.2 (Parser) | Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:D1444 Wiki Page: | -------------------------------------+------------------------------------- Changes (by mpickering): * owner: alanz => mpickering -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10942#comment:6 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10942: CPP pragma ignored if top comments and Opt_KeepRawTokenStream
-------------------------------------+-------------------------------------
Reporter: alanz | Owner: mpickering
Type: bug | Status: patch
Priority: normal | Milestone: 8.0.1
Component: Compiler | Version: 7.10.2
(Parser) |
Resolution: | Keywords:
Operating System: Unknown/Multiple | Architecture:
| Unknown/Multiple
Type of failure: None/Unknown | Test Case:
Blocked By: | Blocking:
Related Tickets: | Differential Rev(s): Phab:D1444
Wiki Page: |
-------------------------------------+-------------------------------------
Comment (by Ben Gamari

#10942: CPP pragma ignored if top comments and Opt_KeepRawTokenStream -------------------------------------+------------------------------------- Reporter: alanz | Owner: mpickering Type: bug | Status: closed Priority: normal | Milestone: 8.0.1 Component: Compiler | Version: 7.10.2 (Parser) | Resolution: fixed | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:D1444 Wiki Page: | -------------------------------------+------------------------------------- Changes (by bgamari): * status: patch => closed * resolution: => fixed Comment: Merged. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10942#comment:8 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC