Skip to content

Commit 907804d

Browse files
committed
WIP
1 parent c8a1d9f commit 907804d

File tree

27 files changed

+8120
-16
lines changed

27 files changed

+8120
-16
lines changed

configure.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,4 +271,4 @@ rm -fr dist*
271271
# cabal configure -fdev --with-compiler=/opt/ghc/9.13.20250316/bin/ghc --allow-newer
272272
# cabal configure -fdev -froundtrip --enable-tests --with-compiler=/opt/ghc/9.13.20250316/bin/ghc --allow-newer
273273
# cabal configure -fdev -froundtrip --enable-tests --with-compiler=/opt/ghc/9.13.20250331/bin/ghc --allow-newer
274-
cabal configure -fdev -froundtrip --enable-tests --with-compiler=/opt/ghc/9.13.20250414/bin/ghc --allow-newer
274+
cabal configure -fdev -froundtrip --enable-tests --with-compiler=/opt/ghc/9.13.20250427/bin/ghc --allow-newer

roundtrip-config/knownfailures.txt

Lines changed: 1808 additions & 6 deletions
Large diffs are not rendered by default.

src/Language/Haskell/GHC/ExactPrint/ExactPrint.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1608,7 +1608,7 @@ instance ExactPrint (ImportDecl GhcPs) where
16081608
= (ideclExt idecl) { ideclAnn = setAnchorEpa (ideclAnn $ ideclExt idecl) anc ts cs} }
16091609

16101610
exact (ImportDecl (XImportDeclPass ann msrc impl)
1611-
modname mpkg src safeflag qualFlag mAs hiding) = do
1611+
modname mpkg src st safeflag qualFlag mAs hiding) = do
16121612

16131613
ann0 <- markLensFun' ann limportDeclAnnImport markEpToken
16141614
let (EpAnn _anc an _cs) = ann0
@@ -1670,7 +1670,7 @@ instance ExactPrint (ImportDecl GhcPs) where
16701670
}
16711671
16721672
return (ImportDecl (XImportDeclPass (EpAnn anc' an2 cs') msrc impl)
1673-
modname' mpkg src safeflag qualFlag mAs' hiding')
1673+
modname' mpkg src st safeflag qualFlag mAs' hiding')
16741674
16751675
16761676
-- ---------------------------------------------------------------------

src/Language/Haskell/GHC/ExactPrint/Parsers.hs

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ import qualified GHC hiding (parseModule)
5959
import qualified Control.Monad.IO.Class as GHC
6060
import qualified GHC.Data.FastString as GHC
6161
import qualified GHC.Data.StringBuffer as GHC
62+
import qualified GHC.Driver.Config.Diagnostic as GHC
6263
import qualified GHC.Driver.Config.Parser as GHC
6364
import qualified GHC.Driver.Env.Types as GHC
6465
import qualified GHC.Driver.Errors.Types as GHC
@@ -117,17 +118,33 @@ runParser parser flags filename str = GHC.unP parser parseState
117118
-- TODO: precompute the macros first, store them in an IORef
118119
-- macros = Nothing
119120
macros = fromMaybe Map.empty macrosFromIORef
120-
parseState0 = GHC.initParserStateWithMacrosString flags Nothing (GHC.initParserOpts flags) buffer location
121+
-- opts0 = GHC.initParserOpts flags
122+
-- opts1 = GHC.enableExtBit GHC.UsePosPragsBit opts0
123+
-- opts = opts1
124+
opts = myInitParserOpts flags
125+
parseState0 = GHC.initParserStateWithMacrosString flags Nothing opts buffer location
121126
parseState = parseState0 { GHC.pp = (GHC.pp parseState0) { GHC.pp_defines = macros }
122127
, GHC.buffer = buffer }
123128

129+
124130
macroIORef :: IORef (Maybe GHC.MacroDefines)
125131
{-# NOINLINE macroIORef #-}
126132
macroIORef = unsafePerformIO (newIORef Nothing)
127133

128134
macrosFromIORef :: Maybe GHC.MacroDefines
129135
macrosFromIORef = unsafePerformIO (readIORef macroIORef)
130136

137+
myInitParserOpts :: GHC.DynFlags -> GHC.ParserOpts
138+
myInitParserOpts =
139+
GHC.mkParserOpts
140+
<$> GHC.extensionFlags
141+
<*> GHC.initDiagOpts
142+
<*> GHC.safeImportsOn
143+
<*> GHC.gopt GHC.Opt_Haddock
144+
<*> GHC.gopt GHC.Opt_KeepRawTokenStream
145+
<*> const False -- do not use LINE/COLUMN to update the internal location
146+
147+
131148
-- ---------------------------------------------------------------------
132149

133150
-- | Provides a safe way to consume a properly initialised set of
@@ -277,13 +294,9 @@ parseModuleEpAnnsWithGhcCppInternal cppOptions dflags file = do
277294
(fileContents, injectedComments, dflags') <-
278295
if useCpp
279296
then do
280-
-- (contents,dflags1) <- getPreprocessedSrcDirect cppOptions file
281-
-- cppComments <- getCppTokensAsComments cppOptions file
282-
-- return (contents,cppComments,dflags1)
283297
txt <- GHC.liftIO $ readFileGhc file
284-
-- let (contents1,lp) = stripLinePragmas txt
285298
let (contents1,lp) = (txt, [])
286-
let no_cpp_dflags = GHC.xopt_unset dflags LangExt.GhcCpp
299+
let no_cpp_dflags = GHC.xopt_unset dflags LangExt.Cpp
287300
return (contents1, lp, GHC.xopt_set no_cpp_dflags LangExt.GhcCpp)
288301
else do
289302
txt <- GHC.liftIO $ readFileGhc file

tests/Test.hs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,9 @@ tt' = do
229229
-- mkParserTest libdir "pre-ghc910" "Utils.hs"
230230
-- mkParserTest libdir "failing" "CppComment.hs"
231231
-- mkParserTest libdir "ghc-cpp" "Scan.hs"
232-
mkParserTest libdir "ghc-cpp" "Test1.hs"
232+
-- mkParserTest libdir "ghc-cpp" "Test1.hs"
233+
-- mkParserTest libdir "ghc-cpp" "WithoutSomeFixpoints.hs"
234+
mkParserTest libdir "ghc-cpp" "HelperMain.hs"
233235

234236
]
235237

tests/Test/Common.hs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,5 +292,11 @@ hhh libdir = ghcWrapper libdir $ do
292292
, " (major1) == 2 && (major2) < 0 || \\"
293293
, " (major1) == 2 && (major2) == 0 && (minor) <= 1)"
294294
, ""
295+
, "#define VERSION_template_haskell \"2.23.0\""
296+
, "#define MIN_VERSION_template_haskell(major1,major2,minor) (\\"
297+
, " (major1) < 2 || \\"
298+
, " (major1) == 2 && (major2) < 23 || \\"
299+
, " (major1) == 2 && (major2) == 23 && (minor) <= 0)"
300+
, ""
295301
]
296302
return $ parseMacroDefines dflags macro_defs

0 commit comments

Comments
 (0)