DriverPipeline/HscMain DynFlags mystery

Ömer Sinan Ağacan omeragacan at gmail.com
Thu Oct 31 18:45:09 UTC 2019


Hi,

We recently did some refactoring in HscMain and DriverPipeline to generate
interfaces after final Cmms are generated (previously interfaces would be
generated after the tidying pass). It's mostly done but there's one thing that I
couldn't figure out after two full days of debugging (I also asked a few people
about it on IRC), so I wanted to ask here in case someone here knows.

Previously the interface value (ModIface) would be generated and written to disk
in `HscMain.finish`. The DynFlags we use to generate the ModIface and to write
it to disk would be the one passed to `HscMain.hscIncrementalCompile`.

In the new implementation part of the interface is still generated in
`HscMain.hscIncrementalCompile` (see mkPartialIface), using the same DynFlags as
before. But more stuff is added after the final Cmms are generated (see
mkFullIface calls in DriverPipeline) using DynFlags in `compileOne'` or
`runPhase` (called by `runPipeline`). It turns out these DynFlags are different
enough from the one passed to `HscMain.hscIncrementalCompile` that some tests
fail (I remember a backpack test, but there may be more).

("Full" interfaces are written to disk right after generation)

See [1] for the hack I added as a workaround. Basically I keep the DynFlags
passed to hscIncrementalCompile so that I can generate the final interfaces
correctly.

The question is what's changing in DynFlags that makes things go wrong. I tried
looking at the fields used by mkFullIface and hscMaybeWriteIface, but as far as
I can see none of the fields used by these functions are different from the
DynFlags passed to hscIncrementalCompile.

If anyone knows what's going on any help would be appreciated.

Thanks,

Ömer

[1]: https://gitlab.haskell.org/ghc/ghc/blob/master/compiler/main/HscTypes.hs#L255-259


More information about the ghc-devs mailing list