Open jrp2014 opened 4 years ago
To answer my own issue, the problem seem to be with the dflags
that are set in initDynFlagsPure
(perhaps when some language extensions are set in the cabal file, supplemented by language extensions in the source file). If I use the ModSummary
dflags
but also set Opt_KeepRawTokenStream
with parseModuleFromStringInternal
it all works OK.
I suspect that the fix to https://gitlab.haskell.org/ghc/ghc/issues/10942 is what is causing the comments to disappear without setting Opt_KeepRawTokenStream
.
I have not tried the other adjustments that initDynFlagsPure
makes, such as -hide-all-packages
, without apparent ill effect.
So there does seem to be an underlying bug here, but it's not clear to me what the fix is.
I am using
ghx-exactprint
to write ghc type-checked plugin, with ghc-8.10.1. I am testing it over theagda
codebase (https://github.com/agda/agda) as it uses a range of GHC features.ghc-exactprint
generally does a great job, but there are a couple of cases where it seems not to respect the language extensions, when parsing a file usingparseModuleFromString
. If instead, I useparseModuleFromStringInternal
with thedflags
thatghc
provides to a plug-in, everything seems to work well.So I have a work-around, but thought that I'd report the issue, in case there is an underlying problem, rather than a misuse of
ghc-exactprint
For example,
parseModulefromString
doesn't seem to like thisThe language extentions in use are:
A further case is:
with language extensions (
extensions dflags
)As I am writing a type-checked phase plugin, ghc has parsed the code without complaint. In fact, I am feeding
parseModuleFromString
with a string generated bylexemeToString
applied toms_hspp_buf modSummary
(ie, the pre-processed source).As I say, the issue appears to be with the
DynFlags
thatparseModuleFromString
conjures up. When I use those provided to the plugin (viagetDynFlags
andparseModuleFromStringInternal
) all seems well. Maybe this can be fixed, or the documentation of the contexts in whichparseModuleFromString
could be supplemented.[Later] Maybe spoke too soon. Source comments appear to be discarded when I use
parseModulefromStringIntenal
Anyway thanks for the package.
PS: I assume that the a key reason for having
ghc-exactprint
is that GHC does not retain enough source code annotations, hence the need to reparse the source.