diff options
-rw-r--r-- | compiler/deSugar/Check.hs | 18 | ||||
-rw-r--r-- | compiler/main/DynFlags.hs | 5 | ||||
-rw-r--r-- | docs/users_guide/using-optimisation.rst | 9 | ||||
-rw-r--r-- | utils/mkUserGuidePart/Options/Optimizations.hs | 6 |
4 files changed, 27 insertions, 11 deletions
diff --git a/compiler/deSugar/Check.hs b/compiler/deSugar/Check.hs index fe1b4bc9a3..02074e5a3e 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 a79bb3a9b3..e43869ed35 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 5e4995d968..943651001a 100644 --- a/docs/users_guide/using-optimisation.rst +++ b/docs/users_guide/using-optimisation.rst @@ -120,7 +120,7 @@ list. case x of Red -> e1 - _ -> case x of + _ -> case x of Blue -> e2 Green -> e3 @@ -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 dd9ffd9ced..5f46a06e39 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." |