summaryrefslogtreecommitdiff
path: root/compiler/coreSyn/CoreUtils.hs
diff options
context:
space:
mode:
authorSimon Peyton Jones <simonpj@microsoft.com>2018-09-23 00:44:14 +0100
committerSimon Peyton Jones <simonpj@microsoft.com>2018-09-23 02:45:23 +0100
commit2dbf88b3558c3b53a1207fb504232c3da67b266e (patch)
treec029b6564ddd8b9558add9d926876e43018fc30b /compiler/coreSyn/CoreUtils.hs
parentab44ff817bcbf81aa5311eb8bb6f2073f521bd26 (diff)
downloadhaskell-2dbf88b3558c3b53a1207fb504232c3da67b266e.tar.gz
Fix get getIdFromTrivialExpr
This bug, discovered by Trac #15325, has been lurking since commit 1c9fd3f1c5522372fcaf250c805b959e8090a62c Author: Simon Peyton Jones <simonpj@microsoft.com> Date: Thu Dec 3 12:57:54 2015 +0000 Case-of-empty-alts is trivial (Trac #11155) I'd forgotttnen to modify getIdFromTrivialExpr when I modified exprIsTrivial. Easy to fix, though.
Diffstat (limited to 'compiler/coreSyn/CoreUtils.hs')
-rw-r--r--compiler/coreSyn/CoreUtils.hs22
1 files changed, 14 insertions, 8 deletions
diff --git a/compiler/coreSyn/CoreUtils.hs b/compiler/coreSyn/CoreUtils.hs
index a1dae9875e..453d984ec4 100644
--- a/compiler/coreSyn/CoreUtils.hs
+++ b/compiler/coreSyn/CoreUtils.hs
@@ -955,6 +955,8 @@ it off at source.
-}
exprIsTrivial :: CoreExpr -> Bool
+-- If you modify this function, you may also
+-- need to modify getIdFromTrivialExpr
exprIsTrivial (Var _) = True -- See Note [Variables are trivial]
exprIsTrivial (Type _) = True
exprIsTrivial (Coercion _) = True
@@ -984,20 +986,24 @@ if the variable actually refers to a literal; thus we use
T12076lit for an example where this matters.
-}
-getIdFromTrivialExpr :: CoreExpr -> Id
+getIdFromTrivialExpr :: HasDebugCallStack => CoreExpr -> Id
getIdFromTrivialExpr e
= fromMaybe (pprPanic "getIdFromTrivialExpr" (ppr e))
(getIdFromTrivialExpr_maybe e)
getIdFromTrivialExpr_maybe :: CoreExpr -> Maybe Id
-- See Note [getIdFromTrivialExpr]
-getIdFromTrivialExpr_maybe e = go e
- where go (Var v) = Just v
- go (App f t) | not (isRuntimeArg t) = go f
- go (Tick t e) | not (tickishIsCode t) = go e
- go (Cast e _) = go e
- go (Lam b e) | not (isRuntimeVar b) = go e
- go _ = Nothing
+-- Th equations for this should line up with those for exprIsTrivial
+getIdFromTrivialExpr_maybe e
+ = go e
+ where
+ go (App f t) | not (isRuntimeArg t) = go f
+ go (Tick t e) | not (tickishIsCode t) = go e
+ go (Cast e _) = go e
+ go (Lam b e) | not (isRuntimeVar b) = go e
+ go (Case e _ _ []) = go e
+ go (Var v) = Just v
+ go _ = Nothing
{-
exprIsBottom is a very cheap and cheerful function; it may return