summaryrefslogtreecommitdiff
path: root/compiler/GHC/Core/Predicate.hs
diff options
context:
space:
mode:
authorSimon Peyton Jones <simonpj@microsoft.com>2021-07-23 16:34:23 +0100
committerSimon Peyton Jones <simonpj@microsoft.com>2021-07-26 17:03:30 +0100
commit2e4be92e6bc25901b90d000382b662e147cff785 (patch)
tree94eab96418684d90e90d5afd180f368214a113a3 /compiler/GHC/Core/Predicate.hs
parenta2ae66a2aa3762ee8c264aafeec2f92a4e0b0ac5 (diff)
downloadhaskell-wip/T19918.tar.gz
Eta expand through CallStackswip/T19918
This patch fixes #20103, by treating HasCallStack constraints as cheap when eta-expanding. See Note [Eta expanding through CallStacks] in GHC.Core.Opt.Arity
Diffstat (limited to 'compiler/GHC/Core/Predicate.hs')
-rw-r--r--compiler/GHC/Core/Predicate.hs35
1 files changed, 35 insertions, 0 deletions
diff --git a/compiler/GHC/Core/Predicate.hs b/compiler/GHC/Core/Predicate.hs
index 43f52b9b5c..9601a92138 100644
--- a/compiler/GHC/Core/Predicate.hs
+++ b/compiler/GHC/Core/Predicate.hs
@@ -24,6 +24,7 @@ module GHC.Core.Predicate (
-- Implicit parameters
isIPLikePred, hasIPSuperClasses, isIPTyCon, isIPClass,
+ isCallStackTy, isCallStackPred, isCallStackPredTy,
-- Evidence variables
DictId, isEvVar, isDictId
@@ -44,6 +45,7 @@ import GHC.Builtin.Names
import GHC.Utils.Outputable
import GHC.Utils.Misc
import GHC.Utils.Panic
+import GHC.Data.FastString( FastString )
-- | A predicate in the solver. The solver tries to prove Wanted predicates
@@ -257,6 +259,39 @@ has_ip_super_classes rec_clss cls tys
initIPRecTc :: RecTcChecker
initIPRecTc = setRecTcMaxBound 1 initRecTc
+-- --------------------- CallStack predicates ---------------------------------
+
+isCallStackPredTy :: Type -> Bool
+-- True of HasCallStack, or IP "blah" CallStack
+isCallStackPredTy ty
+ | Just (tc, tys) <- splitTyConApp_maybe ty
+ , Just cls <- tyConClass_maybe tc
+ , Just {} <- isCallStackPred cls tys
+ = True
+ | otherwise
+ = False
+
+-- | Is a 'PredType' a 'CallStack' implicit parameter?
+--
+-- If so, return the name of the parameter.
+isCallStackPred :: Class -> [Type] -> Maybe FastString
+isCallStackPred cls tys
+ | [ty1, ty2] <- tys
+ , isIPClass cls
+ , isCallStackTy ty2
+ = isStrLitTy ty1
+ | otherwise
+ = Nothing
+
+-- | Is a type a 'CallStack'?
+isCallStackTy :: Type -> Bool
+isCallStackTy ty
+ | Just tc <- tyConAppTyCon_maybe ty
+ = tc `hasKey` callStackTyConKey
+ | otherwise
+ = False
+
+
{- Note [Local implicit parameters]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The function isIPLikePred tells if this predicate, or any of its