[commit: ghc] master: Add flag to control number of missing patterns in warnings (7005b9f)

git at git.haskell.org git at git.haskell.org
Sun Apr 17 14:10:37 UTC 2016


Repository : ssh://git@git.haskell.org/ghc

On branch  : master
Link       : http://ghc.haskell.org/trac/ghc/changeset/7005b9f7b0f4db0c0401156557bd4988d0efd569/ghc

>---------------------------------------------------------------

commit 7005b9f7b0f4db0c0401156557bd4988d0efd569
Author: David Luposchainsky <dluposchainsky at gmail.com>
Date:   Sun Apr 17 14:41:33 2016 +0200

    Add flag to control number of missing patterns in warnings
    
    Non-exhaustive pattern warnings had their number of patterns to
    show hardcoded in the past. This patch implements the TODO remark
    that this should be made a command line flag.
    
        -fmax-uncovered-patterns=<n>
    
    can now be used to influence the number of patterns to be shown.
    
    Reviewers: hvr, austin, bgamari
    
    Reviewed By: bgamari
    
    Subscribers: thomie
    
    Differential Revision: https://phabricator.haskell.org/D2076


>---------------------------------------------------------------

7005b9f7b0f4db0c0401156557bd4988d0efd569
 compiler/deSugar/Check.hs                      | 18 ++++++++----------
 compiler/main/DynFlags.hs                      |  5 +++++
 docs/users_guide/using-optimisation.rst        |  7 +++++++
 utils/mkUserGuidePart/Options/Optimizations.hs |  6 ++++++
 4 files changed, 26 insertions(+), 10 deletions(-)

diff --git a/compiler/deSugar/Check.hs b/compiler/deSugar/Check.hs
index fe1b4bc..02074e5 100644
--- a/compiler/deSugar/Check.hs
+++ b/compiler/deSugar/Check.hs
@@ -1256,6 +1256,8 @@ dsPmWarn dflags ctx@(DsMatchContext kind loc) pm_result
     flag_u = exhaustive dflags kind
     flag_u_reason = maybe NoReason Reason (exhaustiveWarningFlag kind)
 
+    maxPatterns = maxUncoveredPatterns dflags
+
     -- Print a single clause (for redundant/with-inaccessible-rhs)
     pprEqn q txt = pp_context True ctx (text txt) $ \f -> ppr_eqn f kind q
 
@@ -1266,7 +1268,8 @@ dsPmWarn dflags ctx@(DsMatchContext kind loc) pm_result
                     -> text "Guards do not cover entire pattern space"
            _missing -> let us = map ppr qs
                        in  hang (text "Patterns not matched:") 4
-                                (vcat (take maximum_output us) $$ dots us)
+                                (vcat (take maxPatterns us)
+                                 $$ dots maxPatterns us)
 
 -- | Issue a warning when the predefined number of iterations is exceeded
 -- for the pattern match checker
@@ -1285,9 +1288,10 @@ warnPmIters dflags (DsMatchContext kind loc)
     flag_i = wopt Opt_WarnOverlappingPatterns dflags
     flag_u = exhaustive dflags kind
 
-dots :: [a] -> SDoc
-dots qs | qs `lengthExceeds` maximum_output = text "..."
-        | otherwise                         = empty
+dots :: Int -> [a] -> SDoc
+dots maxPatterns qs
+    | qs `lengthExceeds` maxPatterns = text "..."
+    | otherwise                      = empty
 
 -- | Check whether the exhaustiveness checker should run (exhaustiveness only)
 exhaustive :: DynFlags -> HsMatchContext id -> Bool
@@ -1347,12 +1351,6 @@ ppr_uncovered (expr_vec, complex)
     sdoc_vec = mapM pprPmExprWithParens expr_vec
     (vec,cs) = runPmPprM sdoc_vec (filterComplex complex)
 
--- | This variable shows the maximum number of lines of output generated for
--- warnings. It will limit the number of patterns/equations displayed to
--- maximum_output. (TODO: add command-line option?)
-maximum_output :: Int
-maximum_output = 4
-
 {- Note [Representation of Term Equalities]
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 In the paper, term constraints always take the form (x ~ e). Of course, a more
diff --git a/compiler/main/DynFlags.hs b/compiler/main/DynFlags.hs
index a79bb3a..e43869e 100644
--- a/compiler/main/DynFlags.hs
+++ b/compiler/main/DynFlags.hs
@@ -664,6 +664,8 @@ data DynFlags = DynFlags {
 
   maxRelevantBinds      :: Maybe Int,   -- ^ Maximum number of bindings from the type envt
                                         --   to show in type error messages
+  maxUncoveredPatterns  :: Int,         -- ^ Maximum number of unmatched patterns to show
+                                        --   in non-exhaustiveness warnings
   simplTickFactor       :: Int,         -- ^ Multiplier for simplifier ticks
   specConstrThreshold   :: Maybe Int,   -- ^ Threshold for SpecConstr
   specConstrCount       :: Maybe Int,   -- ^ Max number of specialisations for any one function
@@ -1448,6 +1450,7 @@ defaultDynFlags mySettings =
         maxPmCheckIterations    = 2000000,
         ruleCheck               = Nothing,
         maxRelevantBinds        = Just 6,
+        maxUncoveredPatterns    = 4,
         simplTickFactor         = 100,
         specConstrThreshold     = Just 2000,
         specConstrCount         = Just 3,
@@ -2837,6 +2840,8 @@ dynamic_flags_deps = [
       (intSuffix (\n d -> d { maxRelevantBinds = Just n }))
   , make_ord_flag defFlag "fno-max-relevant-binds"
       (noArg (\d -> d { maxRelevantBinds = Nothing }))
+  , make_ord_flag defFlag "fmax-uncovered-patterns"
+      (intSuffix (\n d -> d { maxUncoveredPatterns = n }))
   , make_ord_flag defFlag "fsimplifier-phases"
       (intSuffix (\n d -> d { simplPhases = n }))
   , make_ord_flag defFlag "fmax-simplifier-iterations"
diff --git a/docs/users_guide/using-optimisation.rst b/docs/users_guide/using-optimisation.rst
index 5e4995d..9436510 100644
--- a/docs/users_guide/using-optimisation.rst
+++ b/docs/users_guide/using-optimisation.rst
@@ -353,6 +353,13 @@ list.
     they may be numerous), but ``-fno-max-relevant-bindings`` includes
     them too.
 
+.. ghc-flag:: -fmax-uncovered-patterns=<n>
+
+    :default: 4
+
+    Maximum number of unmatched patterns to be shown in warnings generated by
+    :ghc-flag:`-Wincomplete-patterns` and :ghc-flag:`-Wincomplete-uni-patterns`.
+
 .. ghc-flag:: -fmax-simplifier-iterations=<n>
 
     :default: 4
diff --git a/utils/mkUserGuidePart/Options/Optimizations.hs b/utils/mkUserGuidePart/Options/Optimizations.hs
index dd9ffd9..5f46a06 100644
--- a/utils/mkUserGuidePart/Options/Optimizations.hs
+++ b/utils/mkUserGuidePart/Options/Optimizations.hs
@@ -178,6 +178,12 @@ optimizationsOptions =
          , flagType = DynamicFlag
          , flagReverse = "-fno-max-relevant-bindings"
          }
+  , flag { flagName = "-fmax-uncovered-patterns=⟨n⟩"
+         , flagDescription =
+           "*default: 4.* Set the maximum number of patterns to display in "++
+           "warnings about non-exhaustive ones."
+         , flagType = DynamicFlag
+         }
   , flag { flagName = "-fmax-simplifier-iterations=⟨n⟩"
          , flagDescription =
            "*default: 4.* Set the max iterations for the simplifier."



More information about the ghc-commits mailing list