diff options
author | Simon Peyton Jones <simonpj@microsoft.com> | 2012-05-02 15:44:14 +0100 |
---|---|---|
committer | Simon Peyton Jones <simonpj@microsoft.com> | 2012-05-02 15:44:14 +0100 |
commit | ac230c5ef652e27f61d954281ae6a3195e1f9970 (patch) | |
tree | 4cd59d3ca670916f64bcfe9c0c3f72f21a272e42 /compiler/stgSyn | |
parent | b04c0beb951b2e69f76f724a4e72b98c896b468a (diff) | |
download | haskell-ac230c5ef652e27f61d954281ae6a3195e1f9970.tar.gz |
Allow cases with empty alterantives
This patch allows, for the first time, case expressions with an empty
list of alternatives. Max suggested the idea, and Trac #6067 showed
that it is really quite important.
So I've implemented the idea, fixing #6067. Main changes
* See Note [Empty case alternatives] in CoreSyn
* Various foldr1's become foldrs
* IfaceCase does not record the type of the alternatives.
I added IfaceECase for empty-alternative cases.
* Core Lint does not complain about empty cases
* MkCore.castBottomExpr constructs an empty-alternative case
expression (case e of ty {})
* CoreToStg converts '(case e of {})' to just 'e'
Diffstat (limited to 'compiler/stgSyn')
-rw-r--r-- | compiler/stgSyn/CoreToStg.lhs | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/compiler/stgSyn/CoreToStg.lhs b/compiler/stgSyn/CoreToStg.lhs index 71bdfe97c9..c4f289c68e 100644 --- a/compiler/stgSyn/CoreToStg.lhs +++ b/compiler/stgSyn/CoreToStg.lhs @@ -363,6 +363,18 @@ coreToStgExpr (Cast expr _) -- Cases require a little more real work. +coreToStgExpr (Case scrut _ _ []) + = coreToStgExpr scrut + -- See Note [Empty case alternatives] in CoreSyn If the case + -- alternatives are empty, the scrutinee must diverge or raise an + -- exception, so we can just dive into it. + -- + -- Of course this may seg-fault if the scrutinee *does* return. A + -- belt-and-braces approach would be to move this case into the + -- code generator, and put a return point anyway that calls a + -- runtime system error function. + + coreToStgExpr (Case scrut bndr _ alts) = do (alts2, alts_fvs, alts_escs) <- extendVarEnvLne [(bndr, LambdaBound)] $ do |