From a5aaceecaa04ce7ea5bade6eb96c0d129109c15a Mon Sep 17 00:00:00 2001
From: Sylvain Henry <sylvain@haskus.fr>
Date: Wed, 19 Aug 2020 20:16:21 +0200
Subject: Use ADTs for parser errors/warnings

Haskell and Cmm parsers/lexers now report errors and warnings using ADTs
defined in GHC.Parser.Errors. They can be printed using functions in
GHC.Parser.Errors.Ppr.

Some of the errors provide hints with a separate ADT (e.g. to suggest to
turn on some extension). For now, however, hints are not consistent
across all messages. For example some errors contain the hints in the
main message. I didn't want to change any message with this patch. I
expect these changes to be discussed and implemented later.

Surprisingly, this patch enhances performance. On CI
(x86_64/deb9/hadrian, ghc/alloc):

   parsing001         -11.5%
   T13719             -2.7%
   MultiLayerModules  -3.5%
   Naperian           -3.1%

Bump haddock submodule

Metric Decrease:
    MultiLayerModules
    Naperian
    T13719
    parsing001
---
 testsuite/tests/regalloc/regalloc_unit_tests.hs | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

(limited to 'testsuite/tests/regalloc')

diff --git a/testsuite/tests/regalloc/regalloc_unit_tests.hs b/testsuite/tests/regalloc/regalloc_unit_tests.hs
index d8176cd644..c6902d48be 100644
--- a/testsuite/tests/regalloc/regalloc_unit_tests.hs
+++ b/testsuite/tests/regalloc/regalloc_unit_tests.hs
@@ -33,6 +33,7 @@ import GHC.Cmm.Pipeline
 import GHC.Cmm.Parser
 import GHC.Cmm.Info
 import GHC.Cmm
+import GHC.Parser.Errors.Ppr
 import GHC.Unit.Module
 import GHC.Cmm.DebugBlock
 import GHC
@@ -109,7 +110,9 @@ compileCmmForRegAllocStats dflags' cmmFile ncgImplF us = do
     hscEnv <- newHscEnv dflags
 
     -- parse the cmm file and output any warnings or errors
-    ((warningMsgs, errorMsgs), parsedCmm) <- parseCmmFile dflags cmmFile
+    (warnings, errors, parsedCmm) <- parseCmmFile dflags cmmFile
+    let warningMsgs = fmap pprWarning warnings
+        errorMsgs   = fmap pprError errors
 
     -- print parser errors or warnings
     mapM_ (printBagOfErrors dflags) [warningMsgs, errorMsgs]
-- 
cgit v1.2.1