diff options
| author | Jakob Bruenker <jakob.bruenker@gmail.com> | 2022-03-30 11:42:47 +0200 |
|---|---|---|
| committer | Jakob Bruenker <jakob.bruenker@gmail.com> | 2022-03-30 19:44:38 +0200 |
| commit | f6fa22cc7ed58732785e27180d33fdf69444815f (patch) | |
| tree | f4398a002aa2a5eb43148851ab9205d80697b7f5 /compiler/GHC | |
| parent | 21894a6318e0daffa0e34041855c3c73ad1f5b6f (diff) | |
| download | haskell-wip/T20803-followup.tar.gz | |
new datatypes for parsedResultActionwip/T20803-followup
Previously, the warnings and errors were given and returned as a tuple
(Messages PsWarnings, Messages PsErrors). Now, it's just PsMessages.
This, together with the HsParsedModule the parser plugin gets and
returns, has been wrapped up as ParsedResult.
Diffstat (limited to 'compiler/GHC')
| -rw-r--r-- | compiler/GHC/Driver/Main.hs | 7 | ||||
| -rw-r--r-- | compiler/GHC/Driver/Plugins.hs | 22 |
2 files changed, 22 insertions, 7 deletions
diff --git a/compiler/GHC/Driver/Main.hs b/compiler/GHC/Driver/Main.hs index 3fa3d581ce..7fd07d31cf 100644 --- a/compiler/GHC/Driver/Main.hs +++ b/compiler/GHC/Driver/Main.hs @@ -493,10 +493,11 @@ hscParse' mod_summary -- apply parse transformation of plugins let applyPluginAction p opts - = uncurry (parsedResultAction p opts mod_summary) + = parsedResultAction p opts mod_summary hsc_env <- getHscEnv - (transformed, (warns, errs)) <- - withPlugins (hsc_plugins hsc_env) applyPluginAction (res, getPsMessages pst) + (ParsedResult transformed (PsMessages warns errs)) <- + withPlugins (hsc_plugins hsc_env) applyPluginAction + (ParsedResult res (uncurry PsMessages $ getPsMessages pst)) logDiagnostics (GhcPsMessage <$> warns) unless (isEmptyMessages errs) $ throwErrors (GhcPsMessage <$> errs) diff --git a/compiler/GHC/Driver/Plugins.hs b/compiler/GHC/Driver/Plugins.hs index 64e82c42b6..67d8422562 100644 --- a/compiler/GHC/Driver/Plugins.hs +++ b/compiler/GHC/Driver/Plugins.hs @@ -12,6 +12,8 @@ module GHC.Driver.Plugins ( , Plugin(..) , defaultPlugin , CommandLineOption + , PsMessages(..) + , ParsedResult(..) -- ** Recompilation checking , purePlugin, impurePlugin, flagRecompile , PluginRecompile(..) @@ -89,6 +91,19 @@ import GHC.Types.Unique.DFM -- are given to you as this type type CommandLineOption = String +-- | Errors and warnings produced by the parser +data PsMessages = PsMessages { psWarnings :: Messages PsWarning + , psErrors :: Messages PsError + } + +-- | Result of running the parser and the parser plugin +data ParsedResult = ParsedResult + { -- | Parsed module, potentially modified by a plugin + parsedResultModule :: HsParsedModule + , -- | Warnings and errors from parser, potentially modified by a plugin + parsedResultMessages :: PsMessages + } + -- | 'Plugin' is the compiler plugin data type. Try to avoid -- constructing one of these directly, and just modify some fields of -- 'defaultPlugin' instead: this is to try and preserve source-code @@ -121,9 +136,8 @@ data Plugin = Plugin { , pluginRecompile :: [CommandLineOption] -> IO PluginRecompile -- ^ Specify how the plugin should affect recompilation. - , parsedResultAction :: [CommandLineOption] -> ModSummary -> HsParsedModule - -> (Messages PsWarning, Messages PsError) - -> Hsc (HsParsedModule, (Messages PsWarning, Messages PsError)) + , parsedResultAction :: [CommandLineOption] -> ModSummary + -> ParsedResult -> Hsc ParsedResult -- ^ Modify the module when it is parsed. This is called by -- "GHC.Driver.Main" when the parser has produced no or only non-fatal -- errors. @@ -237,7 +251,7 @@ defaultPlugin = Plugin { , driverPlugin = const return , pluginRecompile = impurePlugin , renamedResultAction = \_ env grp -> return (env, grp) - , parsedResultAction = \_ _ mod msgs -> return (mod, msgs) + , parsedResultAction = \_ _ -> return , typeCheckResultAction = \_ _ -> return , spliceRunAction = \_ -> return , interfaceLoadAction = \_ -> return |
