summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Peyton Jones <simonpj@microsoft.com>2021-03-16 22:56:56 +0000
committerBen Gamari <ben@smart-cactus.org>2021-04-07 18:37:46 -0400
commit8581d01ab42b2321ec69422392038dff1ceca4b3 (patch)
tree91e9dbf23a30c08c70fa8871e103ac0c13236590
parentc5ea48d123c9f47e12b4314b9d81ad70078e1672 (diff)
downloadhaskell-8581d01ab42b2321ec69422392038dff1ceca4b3.tar.gz
Short-circuit warning generation for partial type signatures
This Note says it all: Note [Skip type holes rapidly] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Suppose we have module with a /lot/ of partial type signatures, and we compile it while suppressing partial-type-signature warnings. Then we don't want to spend ages constructing error messages and lists of relevant bindings that we never display! This happened in #14766, in which partial type signatures in a Happy-generated parser cause a huge increase in compile time. The function ignoreThisHole short-circuits the error/warning generation machinery, in cases where it is definitely going to be a no-op. It makes a pretty big difference on the Sigs.hs example in #14766: Compile-time allocation GHC 8.10 5.6G Before this patch 937G With this patch 4.7G Yes, that's more than two orders of magnitude! (cherry picked from commit a9129f9fdfbd358e76aa197ba00bfe75012d6b4f)
-rw-r--r--compiler/GHC/Tc/Errors.hs29
1 files changed, 27 insertions, 2 deletions
diff --git a/compiler/GHC/Tc/Errors.hs b/compiler/GHC/Tc/Errors.hs
index 69d4654316..1f547660c1 100644
--- a/compiler/GHC/Tc/Errors.hs
+++ b/compiler/GHC/Tc/Errors.hs
@@ -65,7 +65,7 @@ import GHC.Data.Maybe
import qualified GHC.LanguageExtensions as LangExt
import GHC.Utils.FV ( fvVarList, unionFV )
-import Control.Monad ( when )
+import Control.Monad ( when, unless )
import Data.Foldable ( toList )
import Data.List ( partition, mapAccumL, nub, sortBy, unfoldr )
@@ -723,10 +723,35 @@ mkSkolReporter ctxt cts
reportHoles :: [Ct] -- other (tidied) constraints
-> ReportErrCtxt -> [Hole] -> TcM ()
reportHoles tidy_cts ctxt
- = mapM_ $ \hole -> do { err <- mkHoleError tidy_cts ctxt hole
+ = mapM_ $ \hole -> unless (ignoreThisHole ctxt hole) $
+ do { err <- mkHoleError tidy_cts ctxt hole
; maybeReportHoleError ctxt hole err
; maybeAddDeferredHoleBinding ctxt err hole }
+ignoreThisHole :: ReportErrCtxt -> Hole -> Bool
+-- See Note [Skip type holes rapidly]
+ignoreThisHole ctxt hole
+ = case hole_sort hole of
+ ExprHole {} -> False
+ TypeHole -> ignore_type_hole
+ where
+ ignore_type_hole = case cec_type_holes ctxt of
+ HoleDefer -> True
+ _ -> False
+
+{- Note [Skip type holes rapidly]
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+Suppose we have module with a /lot/ of partial type signatures, and we
+compile it while suppressing partial-type-signature warnings. Then
+we don't want to spend ages constructing error messages and lists of
+relevant bindings that we never display! This happened in #14766, in
+which partial type signatures in a Happy-generated parser cause a huge
+increase in compile time.
+
+The function ignoreThisHole short-circuits the error/warning generation
+machinery, in cases where it is definitely going to be a no-op.
+-}
+
mkUserTypeErrorReporter :: Reporter
mkUserTypeErrorReporter ctxt
= mapM_ $ \ct -> do { err <- mkUserTypeError ctxt ct