summaryrefslogtreecommitdiff
path: root/compiler/GHC.hs
diff options
context:
space:
mode:
authorMatthew Pickering <matthewtpickering@gmail.com>2021-05-20 10:38:10 +0100
committerMarge Bot <ben+marge-bot@smart-cactus.org>2021-05-24 09:47:52 -0400
commit098c7794953ee11334b6a450e6eda598a7ee09dc (patch)
tree0164e283dff4b13e0bd25b44c6f5b4e78e3d892d /compiler/GHC.hs
parent3e4ef4b2d05ce0bdd70abd96066f0376dc0e13d6 (diff)
downloadhaskell-098c7794953ee11334b6a450e6eda598a7ee09dc.tar.gz
check-{ppr/exact}: Rewrite more directly to just parse files
There was quite a large amount of indirection in these tests, so I have rewritten them to just directly parse the files rather than making a module graph and entering other twisty packages.
Diffstat (limited to 'compiler/GHC.hs')
-rw-r--r--compiler/GHC.hs21
1 files changed, 11 insertions, 10 deletions
diff --git a/compiler/GHC.hs b/compiler/GHC.hs
index 44e09a23ba..0d515a61f6 100644
--- a/compiler/GHC.hs
+++ b/compiler/GHC.hs
@@ -1584,25 +1584,26 @@ pprParenSymName a = parenSymOcc (getOccName a) (ppr (getName a))
-- on whether the module is interpreted or not.
--- Extract the filename, stringbuffer content and dynflags associed to a module
+-- Extract the filename, stringbuffer content and dynflags associed to a ModSummary
+-- Given an initialised GHC session a ModSummary can be retrieved for
+-- a module by using 'getModSummary'
--
-- XXX: Explain pre-conditions
-getModuleSourceAndFlags :: GhcMonad m => Module -> m (String, StringBuffer, DynFlags)
-getModuleSourceAndFlags mod = do
- m <- getModSummary (moduleName mod)
+getModuleSourceAndFlags :: ModSummary -> IO (String, StringBuffer, DynFlags)
+getModuleSourceAndFlags m = do
case ml_hs_file $ ms_location m of
- Nothing -> do dflags <- getDynFlags
- liftIO $ throwIO $ mkApiErr dflags (text "No source available for module " <+> ppr mod)
+ Nothing -> throwIO $ mkApiErr (ms_hspp_opts m) (text "No source available for module " <+> ppr (ms_mod m))
Just sourceFile -> do
- source <- liftIO $ hGetStringBuffer sourceFile
+ source <- hGetStringBuffer sourceFile
return (sourceFile, source, ms_hspp_opts m)
-- | Return module source as token stream, including comments.
--
--- The module must be in the module graph and its source must be available.
+-- A 'Module' can be turned into a 'ModSummary' using 'getModSummary' if
+-- your session is fully initialised.
-- Throws a 'GHC.Driver.Env.SourceError' on parse error.
-getTokenStream :: GhcMonad m => Module -> m [Located Token]
+getTokenStream :: ModSummary -> IO [Located Token]
getTokenStream mod = do
(sourceFile, source, dflags) <- getModuleSourceAndFlags mod
let startLoc = mkRealSrcLoc (mkFastString sourceFile) 1 1
@@ -1613,7 +1614,7 @@ getTokenStream mod = do
-- | Give even more information on the source than 'getTokenStream'
-- This function allows reconstructing the source completely with
-- 'showRichTokenStream'.
-getRichTokenStream :: GhcMonad m => Module -> m [(Located Token, String)]
+getRichTokenStream :: ModSummary -> IO [(Located Token, String)]
getRichTokenStream mod = do
(sourceFile, source, dflags) <- getModuleSourceAndFlags mod
let startLoc = mkRealSrcLoc (mkFastString sourceFile) 1 1