Repository : ssh://darcs.haskell.org//srv/darcs/ghc On branch : master
http://hackage.haskell.org/trac/ghc/changeset/f1f93b21df509a7e7509c6d3ce829504785b38fd >--------------------------------------------------------------- commit f1f93b21df509a7e7509c6d3ce829504785b38fd Author: Simon Peyton Jones <[email protected]> Date: Fri Mar 30 12:35:50 2012 +0100 Comments only >--------------------------------------------------------------- compiler/coreSyn/CoreUtils.lhs | 17 +++++++++++------ compiler/simplCore/SimplUtils.lhs | 1 + compiler/simplCore/Simplify.lhs | 1 + 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/compiler/coreSyn/CoreUtils.lhs b/compiler/coreSyn/CoreUtils.lhs index 44aebb8..df72778 100644 --- a/compiler/coreSyn/CoreUtils.lhs +++ b/compiler/coreSyn/CoreUtils.lhs @@ -400,18 +400,23 @@ trimConArgs (DataAlt dc) args = dropList (dataConUnivTyVars dc) args \begin{code} filterAlts :: [Unique] -- ^ Supply of uniques used in case we have to manufacture a new AltCon -> Type -- ^ Type of scrutinee (used to prune possibilities) - -> [AltCon] -- ^ Constructors known to be impossible due to the form of the scrutinee + -> [AltCon] -- ^ 'imposs_cons': constructors known to be impossible due to the form of the scrutinee -> [(AltCon, [Var], a)] -- ^ Alternatives -> ([AltCon], Bool, [(AltCon, [Var], a)]) -- Returns: - -- 1. Constructors that will never be encountered by the *default* case (if any) - -- 2. Whether we managed to refine the default alternative into a specific constructor (for statistcs only) - -- 3. The new alternatives + -- 1. Constructors that will never be encountered by the + -- *default* case (if any). A superset of imposs_cons + -- 2. Whether we managed to refine the default alternative into a specific constructor (for statistics only) + -- 3. The new alternatives, trimmed by + -- a) remove imposs_cons + -- b) remove constructors which can't match because of GADTs + -- and with the DEFAULT expanded to a DataAlt if there is exactly + -- remaining constructor that can match -- -- NB: the final list of alternatives may be empty: -- This is a tricky corner case. If the data type has no constructors, - -- which GHC allows, then the case expression will have at most a default - -- alternative. + -- which GHC allows, or if the imposs_cons covers all constructors (after taking + -- account of GADTs), then no alternatives can match. -- -- If callers need to preserve the invariant that there is always at least one branch -- in a "case" statement then they will need to manually add a dummy case branch that just diff --git a/compiler/simplCore/SimplUtils.lhs b/compiler/simplCore/SimplUtils.lhs index 59ebeea..0af0b7f 100644 --- a/compiler/simplCore/SimplUtils.lhs +++ b/compiler/simplCore/SimplUtils.lhs @@ -1494,6 +1494,7 @@ of the inner case y, which give us nowhere to go! \begin{code} prepareAlts :: OutExpr -> OutId -> [InAlt] -> SimplM ([AltCon], [InAlt]) +-- The returned alternatives can be empty, none are possible prepareAlts scrut case_bndr' alts = do us <- getUniquesM -- Case binder is needed just for its type. Note that as an diff --git a/compiler/simplCore/Simplify.lhs b/compiler/simplCore/Simplify.lhs index ab195e8..335f86a 100644 --- a/compiler/simplCore/Simplify.lhs +++ b/compiler/simplCore/Simplify.lhs @@ -1946,6 +1946,7 @@ simplAlts :: SimplEnv -> SimplM (OutExpr, OutId, [OutAlt]) -- Includes the continuation -- Like simplExpr, this just returns the simplified alternatives; -- it does not return an environment +-- The returned alternatives can be empty, none are possible simplAlts env scrut case_bndr alts cont' = -- pprTrace "simplAlts" (ppr alts $$ ppr (seTvSubst env)) $ _______________________________________________ Cvs-ghc mailing list [email protected] http://www.haskell.org/mailman/listinfo/cvs-ghc
