Opened 3 years ago

Closed 4 months ago

#10869 closed feature request (fixed)

Option to dump preprocessed source

Reported by: phischu Owned by: RolandSenn
Priority: low Milestone: 8.8.1
Component: Driver Version: 7.10.2
Keywords: easy Cc:
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: None/Unknown Test Case: T10869
Blocked By: Blocking:
Related Tickets: Differential Rev(s): Phab:D4861
Wiki Page:

Description

It would be awesome if GHC had an option -ddump-preprocessed that dumps the source code for each module after preprocessing. I am not sure what the current definition of "preprocessing" is but I mean the output of at least the following tools: happy, alex, c2hs, hsc2hs and cpp. Additionally even if a module was not subject to any preprocessing it should be dumped anyway.

Use case: I want to parse module files from packages from hackage with haskell-src-exts but find it prohibitively difficult to get the preprocessing right. The idea is that after cabal install with ghc options -ddump-preprocessed -ddump-to-file -dumpdir real_modules you get a complete working set of haskell modules that can be parsed directly without any preprocessing in folder real_modules.

Change History (16)

comment:1 Changed 3 years ago by ezyang

Keywords: easy added

comment:2 Changed 3 years ago by mpickering

I'm fairly sure there is already this option? Maybe it's -E..

comment:3 in reply to:  2 Changed 3 years ago by thomie

Resolution: invalid
Status: newclosed

Replying to mpickering:

I'm fairly sure there is already this option? Maybe it's -E..

Exactly, see: https://downloads.haskell.org/~ghc/latest/docs/html/users_guide/modes.html#options-order

The option -E runs just the pre-processing passes of the compiler, dumping the result in a file.

GHC doesn't run happy, alex, c2hs or hsc2hs for you, so I don't think there's anything to do here.

comment:4 Changed 3 years ago by thomie

Or maybe you want --make and -E to work together?

comment:5 Changed 3 years ago by phischu

I am sorry that the request was not clear. -E stops ghc after preprocessing. But I want ghc to work normally but in addition dump the preprocessed source files. So, yes, I kinda want --make and -E to work together.

comment:6 Changed 3 years ago by thomie

Resolution: invalid
Status: closednew

comment:7 Changed 7 months ago by RolandSenn

Owner: set to RolandSenn

I'll try to implement this:

  • A new compiler flag --ddump-preprocessed will be defined and documented.
  • With the new flag set, GHC will generate the <module>.hspp file with the same content as the one created with the GHC option -E.
  • Opposite to the -E processing, GHC will not stop, but continue its processing normally.
  • If you specify both -E and --ddump-preprocessed, there will be the same processing as with only the GHC option -E: GHC will stop after producing the <module>.hspp file. No error/warning message will be issued.
  • A test case will be added.

As usual, if you disagree, please do holler...

comment:8 Changed 7 months ago by RolandSenn

After looking into the code, I decided the following: The requested functionality is not a dump operation. In a dump operation we have information in memory and write (dump) it out to sysout, syserror or to a file. Here, however, we have the information already in a file and we want to keep the file after GHC processing ends. Hence, this is a keep operation, and the flag will be called keep-hspp-file.

comment:9 Changed 6 months ago by RolandSenn

Status: newpatch

comment:10 Changed 6 months ago by RolandSenn

Differential Rev(s): Phab: D4861

comment:11 Changed 6 months ago by RolandSenn

Test Case: T10869

comment:12 Changed 4 months ago by RolandSenn

Flag is now called keep-hscpp-file.

comment:13 Changed 4 months ago by RolandSenn

Milestone: 8.8.1

comment:14 Changed 4 months ago by RolandSenn

Differential Rev(s): Phab: D4861Phab:D4861

comment:15 Changed 4 months ago by Ben Gamari <ben@…>

In ebcbfba/ghc:

Introduce flag -keep-hscpp-files

Test Plan: `make test=T10869`

Reviewers: mpickering, thomie, ezyang, bgamari

Reviewed By: thomie, bgamari

Subscribers: rwbarton, carter

GHC Trac Issues: #10869

Differential Revision: https://phabricator.haskell.org/D4861

comment:16 Changed 4 months ago by bgamari

Resolution: fixed
Status: patchclosed
Note: See TracTickets for help on using tickets.