Commit 8e51bfc3 authored by Ben Gamari's avatar Ben Gamari Committed by Ben Gamari
Browse files

Introduce -fcatch-bottoms

This flag instructs the simplifier to emit ``error`` expressions in the
continutation of empty case analyses (which should bottom and
consequently not return). This is helpful when debugging demand analysis
bugs which can sometimes manifest as segmentation faults.

Test Plan: Validate

Reviewers: simonpj, austin

Subscribers: niteria, rwbarton, thomie

Differential Revision: https://phabricator.haskell.org/D3736
parent eeb141df
......@@ -645,8 +645,21 @@ cpeRhsE env (Case scrut bndr ty alts)
; let bndr1 = bndr `setIdUnfolding` evaldUnfolding
-- Record that the case binder is evaluated in the alternatives
; (env', bndr2) <- cpCloneBndr env bndr1
; alts' <- mapM (sat_alt env') alts
; return (floats, Case scrut' bndr2 ty alts') }
; let alts'
-- This flag is intended to aid in debugging strictness
-- analysis bugs. These are particularly nasty to chase down as
-- they may manifest as segmentation faults. When this flag is
-- enabled we instead produce an 'error' expression to catch
-- the case where a function we think should bottom
-- unexpectedly returns.
| gopt Opt_CatchBottoms (cpe_dynFlags env)
, not (altsAreExhaustive alts)
= addDefault alts (Just err)
| otherwise = alts
where err = mkRuntimeErrorApp rUNTIME_ERROR_ID ty
"Bottoming expression returned"
; alts'' <- mapM (sat_alt env') alts'
; return (floats, Case scrut' bndr2 ty alts'') }
where
sat_alt env (con, bs, rhs)
= do { (env2, bs') <- cpCloneBndrs env bs
......
......@@ -30,6 +30,7 @@ module CoreUtils (
exprIsBig, exprIsConLike,
rhsIsStatic, isCheapApp, isExpandableApp,
exprIsLiteralString, exprIsTopLevelBindable,
altsAreExhaustive,
-- * Equality
cheapEqExpr, cheapEqExpr', eqExpr,
......
......@@ -470,6 +470,7 @@ data GeneralFlag
| Opt_CprAnal
| Opt_WorkerWrapper
| Opt_SolveConstantDicts
| Opt_CatchBottoms
-- Interface files
| Opt_IgnoreInterfacePragmas
......@@ -3778,6 +3779,7 @@ fFlagsDeps = [
flagSpec "version-macros" Opt_VersionMacros,
flagSpec "worker-wrapper" Opt_WorkerWrapper,
flagSpec "solve-constant-dicts" Opt_SolveConstantDicts,
flagSpec "catch-bottoms" Opt_CatchBottoms,
flagSpec "show-warning-groups" Opt_ShowWarnGroups,
flagSpec "hide-source-paths" Opt_HideSourcePaths,
flagSpec "show-hole-constraints" Opt_ShowHoleConstraints,
......
......@@ -389,6 +389,13 @@ Checking for consistency
instead of ``undef`` in calls. This makes it easier to catch subtle
code generator and runtime system bugs (e.g. see :ghc-ticket:`11487`).
.. ghc-flag:: -fcatch-bottoms
Instructs the simplifier to emit ``error`` expressions in the continuation
of empty case analyses (which should bottom and consequently not return).
This is helpful when debugging demand analysis bugs which can sometimes
manifest as segmentation faults.
.. _checking-determinism:
Checking for determinism
......
......@@ -278,4 +278,10 @@ compilerDebuggingOptions =
"Takes a string argument."
, flagType = DynamicFlag
}
, flag { flagName = "-fcatch-bottoms"
, flagDescription =
"Insert ``error`` expressions after bottoming expressions; useful "++
"when debugging the compiler."
, flagType = DynamicFlag
}
]
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment