Allow using tagetContents for modules needing preprocessing
authorDaniel Gröber <dxld@darkboxed.org>
Mon, 20 May 2019 09:58:55 +0000 (11:58 +0200)
committerBen Gamari <ben@well-typed.com>
Tue, 4 Jun 2019 03:42:11 +0000 (23:42 -0400)
commit0f9ec9d1ff703628fefd991f76cd6f594c1b1e87
tree363805eb2f371be17f8990d0024da60b8a1c42ec
parent551c40243dd91a7ee106b71dc5e0877b57ba7807
Allow using tagetContents for modules needing preprocessing

This allows GHC API clients, most notably tooling such as
Haskell-IDE-Engine, to pass unsaved files to GHC more easily.

Currently when targetContents is used but the module requires preprocessing
'preprocessFile' simply throws an error because the pipeline does not
support passing a buffer.

This change extends `runPipeline` to allow passing the input buffer into
the pipeline. Before proceeding with the actual pipeline loop the input
buffer is immediately written out to a new tempfile.

I briefly considered refactoring the pipeline at large to pass around
in-memory buffers instead of files, but this seems needlessly complicated
since no pipeline stages other than Hsc could really support this at the
moment.
compiler/main/DriverPipeline.hs
compiler/main/GhcMake.hs
compiler/main/HscTypes.hs
testsuite/tests/ghc-api/target-contents/TargetContents.hs [new file with mode: 0644]
testsuite/tests/ghc-api/target-contents/TargetContents.stderr [new file with mode: 0644]
testsuite/tests/ghc-api/target-contents/all.T [new file with mode: 0644]