module GHC.Tc.Types.CtLoc (
CtLoc(..), ctLocSpan, ctLocEnv, ctLocLevel, ctLocOrigin,
ctLocTypeOrKind_maybe, toInvisibleLoc,
ctLocDepth, bumpCtLocDepth, resetCtLocDepth,
isGivenLoc, mkGivenLoc, mkKindEqLoc,
setCtLocOrigin, updateCtLocOrigin, setCtLocEnv, setCtLocSpan,
pprCtLoc, adjustCtLoc, adjustCtLocTyConBinder,
CtLocEnv(..),
getCtLocEnvLoc, setCtLocEnvLoc, setCtLocRealLoc,
getCtLocEnvLvl, setCtLocEnvLvl,
ctLocEnvInGeneratedCode,
SubGoalDepth, initialSubGoalDepth, maxSubGoalDepth,
bumpSubGoalDepth, subGoalDepthExceeded,
CtExplanations(..), ctLocExplanations, updCtLocExplanations,
outOfScopeNT, stuckDataFamApp, nullCtExplanations,
RoleExplanation(..),
tyConAppRoleExplanation, appTyRoleExplanation
) where
import GHC.Prelude
import GHC.Tc.Types.BasicTypes
import GHC.Tc.Types.ErrCtxt
import GHC.Tc.Types.Origin
import GHC.Tc.Utils.TcType
import GHC.Types.Basic( IntWithInf, mkIntWithInf, TypeOrKind(..) )
import GHC.Types.SrcLoc
import GHC.Types.Name.Reader
import GHC.Types.Unique.Map ( UniqMap, emptyUniqMap, plusUniqMap_C, unitUniqMap, isNullUniqMap )
import GHC.Types.Unique.Set ( UniqSet, emptyUniqSet, unionUniqSets, unitUniqSet, isEmptyUniqSet )
import GHC.Core.DataCon ( DataCon )
import GHC.Core.TyCon
( Role(..), TyCon, TyConBinder
, isVisibleTyConBinder, isNamedTyConBinder
)
import GHC.Utils.Outputable
import qualified Data.Semigroup as S
import qualified GHC.Data.List.NonEmpty as NE
newtype SubGoalDepth = SubGoalDepth Int
deriving (SubGoalDepth -> SubGoalDepth -> Bool
(SubGoalDepth -> SubGoalDepth -> Bool)
-> (SubGoalDepth -> SubGoalDepth -> Bool) -> Eq SubGoalDepth
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: SubGoalDepth -> SubGoalDepth -> Bool
== :: SubGoalDepth -> SubGoalDepth -> Bool
$c/= :: SubGoalDepth -> SubGoalDepth -> Bool
/= :: SubGoalDepth -> SubGoalDepth -> Bool
Eq, Eq SubGoalDepth
Eq SubGoalDepth =>
(SubGoalDepth -> SubGoalDepth -> Ordering)
-> (SubGoalDepth -> SubGoalDepth -> Bool)
-> (SubGoalDepth -> SubGoalDepth -> Bool)
-> (SubGoalDepth -> SubGoalDepth -> Bool)
-> (SubGoalDepth -> SubGoalDepth -> Bool)
-> (SubGoalDepth -> SubGoalDepth -> SubGoalDepth)
-> (SubGoalDepth -> SubGoalDepth -> SubGoalDepth)
-> Ord SubGoalDepth
SubGoalDepth -> SubGoalDepth -> Bool
SubGoalDepth -> SubGoalDepth -> Ordering
SubGoalDepth -> SubGoalDepth -> SubGoalDepth
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: SubGoalDepth -> SubGoalDepth -> Ordering
compare :: SubGoalDepth -> SubGoalDepth -> Ordering
$c< :: SubGoalDepth -> SubGoalDepth -> Bool
< :: SubGoalDepth -> SubGoalDepth -> Bool
$c<= :: SubGoalDepth -> SubGoalDepth -> Bool
<= :: SubGoalDepth -> SubGoalDepth -> Bool
$c> :: SubGoalDepth -> SubGoalDepth -> Bool
> :: SubGoalDepth -> SubGoalDepth -> Bool
$c>= :: SubGoalDepth -> SubGoalDepth -> Bool
>= :: SubGoalDepth -> SubGoalDepth -> Bool
$cmax :: SubGoalDepth -> SubGoalDepth -> SubGoalDepth
max :: SubGoalDepth -> SubGoalDepth -> SubGoalDepth
$cmin :: SubGoalDepth -> SubGoalDepth -> SubGoalDepth
min :: SubGoalDepth -> SubGoalDepth -> SubGoalDepth
Ord, SubGoalDepth -> SDoc
(SubGoalDepth -> SDoc) -> Outputable SubGoalDepth
forall a. (a -> SDoc) -> Outputable a
$cppr :: SubGoalDepth -> SDoc
ppr :: SubGoalDepth -> SDoc
Outputable)
initialSubGoalDepth :: SubGoalDepth
initialSubGoalDepth :: SubGoalDepth
initialSubGoalDepth = Int -> SubGoalDepth
SubGoalDepth Int
0
bumpSubGoalDepth :: SubGoalDepth -> SubGoalDepth
bumpSubGoalDepth :: SubGoalDepth -> SubGoalDepth
bumpSubGoalDepth (SubGoalDepth Int
n) = Int -> SubGoalDepth
SubGoalDepth (Int
n Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1)
maxSubGoalDepth :: SubGoalDepth -> SubGoalDepth -> SubGoalDepth
maxSubGoalDepth :: SubGoalDepth -> SubGoalDepth -> SubGoalDepth
maxSubGoalDepth (SubGoalDepth Int
n) (SubGoalDepth Int
m) = Int -> SubGoalDepth
SubGoalDepth (Int
n Int -> Int -> Int
forall a. Ord a => a -> a -> a
`max` Int
m)
subGoalDepthExceeded :: IntWithInf -> SubGoalDepth -> Bool
subGoalDepthExceeded :: IntWithInf -> SubGoalDepth -> Bool
subGoalDepthExceeded IntWithInf
reductionDepth (SubGoalDepth Int
d)
= Int -> IntWithInf
mkIntWithInf Int
d IntWithInf -> IntWithInf -> Bool
forall a. Ord a => a -> a -> Bool
> IntWithInf
reductionDepth
data CtLoc = CtLoc { CtLoc -> CtOrigin
ctl_origin :: CtOrigin
, CtLoc -> CtLocEnv
ctl_env :: CtLocEnv
, CtLoc -> Maybe TypeOrKind
ctl_t_or_k :: Maybe TypeOrKind
, CtLoc -> CtExplanations
ctl_expln :: CtExplanations
, CtLoc -> SubGoalDepth
ctl_depth :: !SubGoalDepth
}
data CtExplanations
= CtExplanations
{ CtExplanations -> [RoleExplanation]
ctexpl_roleExplanations :: [RoleExplanation]
, CtExplanations -> UniqSet DataCon
ctexpl_outOfScopeNTs :: UniqSet DataCon
, CtExplanations -> UniqMap TyCon (NonEmpty [Type])
ctexpl_stuckDataFamApps :: UniqMap TyCon (NE.NonEmpty [Type])
}
outOfScopeNT :: DataCon -> CtExplanations
outOfScopeNT :: DataCon -> CtExplanations
outOfScopeNT DataCon
nt =
CtExplanations
forall a. Monoid a => a
mempty { ctexpl_outOfScopeNTs = unitUniqSet nt }
stuckDataFamApp :: TyCon -> [Type] -> CtExplanations
stuckDataFamApp :: TyCon -> [Type] -> CtExplanations
stuckDataFamApp TyCon
tc [Type]
tys =
CtExplanations
forall a. Monoid a => a
mempty { ctexpl_stuckDataFamApps = unitUniqMap tc (NE.singleton tys) }
nullCtExplanations :: CtExplanations -> Bool
nullCtExplanations :: CtExplanations -> Bool
nullCtExplanations (CtExplanations [RoleExplanation]
a UniqSet DataCon
b UniqMap TyCon (NonEmpty [Type])
c) =
[RoleExplanation] -> Bool
forall a. [a] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [RoleExplanation]
a Bool -> Bool -> Bool
&& UniqSet DataCon -> Bool
forall a. UniqSet a -> Bool
isEmptyUniqSet UniqSet DataCon
b Bool -> Bool -> Bool
&& UniqMap TyCon (NonEmpty [Type]) -> Bool
forall k a. UniqMap k a -> Bool
isNullUniqMap UniqMap TyCon (NonEmpty [Type])
c
instance Outputable CtExplanations where
ppr :: CtExplanations -> SDoc
ppr (CtExplanations [RoleExplanation]
ns UniqSet DataCon
cs UniqMap TyCon (NonEmpty [Type])
dfs) =
SDoc -> Int -> SDoc -> SDoc
hang (String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"CtExplanations")
Int
2 (SDoc -> SDoc) -> SDoc -> SDoc
forall a b. (a -> b) -> a -> b
$ [SDoc] -> SDoc
forall doc. IsDoc doc => [doc] -> doc
vcat
[ String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"nominal reasons:" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> [RoleExplanation] -> SDoc
forall a. Outputable a => a -> SDoc
ppr [RoleExplanation]
ns
, String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"out of scope newtype constructors:" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> UniqSet DataCon -> SDoc
forall a. Outputable a => a -> SDoc
ppr UniqSet DataCon
cs
, String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"stuck data-fam apps:" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> UniqMap TyCon (NonEmpty [Type]) -> SDoc
forall a. Outputable a => a -> SDoc
ppr UniqMap TyCon (NonEmpty [Type])
dfs
]
instance Semigroup CtExplanations where
CtExplanations [RoleExplanation]
n1 UniqSet DataCon
c1 UniqMap TyCon (NonEmpty [Type])
dfs1 <> :: CtExplanations -> CtExplanations -> CtExplanations
<> CtExplanations [RoleExplanation]
n2 UniqSet DataCon
c2 UniqMap TyCon (NonEmpty [Type])
dfs2 =
[RoleExplanation]
-> UniqSet DataCon
-> UniqMap TyCon (NonEmpty [Type])
-> CtExplanations
CtExplanations
([RoleExplanation]
n1 [RoleExplanation] -> [RoleExplanation] -> [RoleExplanation]
forall a. [a] -> [a] -> [a]
++ [RoleExplanation]
n2)
(UniqSet DataCon
c1 UniqSet DataCon -> UniqSet DataCon -> UniqSet DataCon
forall a. UniqSet a -> UniqSet a -> UniqSet a
`unionUniqSets` UniqSet DataCon
c2)
((NonEmpty [Type] -> NonEmpty [Type] -> NonEmpty [Type])
-> UniqMap TyCon (NonEmpty [Type])
-> UniqMap TyCon (NonEmpty [Type])
-> UniqMap TyCon (NonEmpty [Type])
forall a k.
(a -> a -> a) -> UniqMap k a -> UniqMap k a -> UniqMap k a
plusUniqMap_C NonEmpty [Type] -> NonEmpty [Type] -> NonEmpty [Type]
forall a. Semigroup a => a -> a -> a
(S.<>) UniqMap TyCon (NonEmpty [Type])
dfs1 UniqMap TyCon (NonEmpty [Type])
dfs2)
instance Monoid CtExplanations where
mempty :: CtExplanations
mempty = [RoleExplanation]
-> UniqSet DataCon
-> UniqMap TyCon (NonEmpty [Type])
-> CtExplanations
CtExplanations [] UniqSet DataCon
forall a. UniqSet a
emptyUniqSet UniqMap TyCon (NonEmpty [Type])
forall k a. UniqMap k a
emptyUniqMap
data RoleExplanation
= TyConArg
TyCon
Int
Role
| NominalAppTy Type
instance Outputable RoleExplanation where
ppr :: RoleExplanation -> SDoc
ppr = \case
TyConArg TyCon
tc Int
i Role
r ->
String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"NominalTyConArg" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> TyCon -> SDoc
forall a. Outputable a => a -> SDoc
ppr TyCon
tc SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> Int -> SDoc
forall a. Outputable a => a -> SDoc
ppr Int
i SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> Role -> SDoc
forall a. Outputable a => a -> SDoc
ppr Role
r
NominalAppTy Type
f ->
String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"NominalAppTy" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> Type -> SDoc
forall a. Outputable a => a -> SDoc
ppr Type
f
addRoleExplanation :: RoleExplanation -> CtExplanations -> CtExplanations
addRoleExplanation :: RoleExplanation -> CtExplanations -> CtExplanations
addRoleExplanation RoleExplanation
rea CtExplanations
expln =
CtExplanations
expln { ctexpl_roleExplanations = rea : ctexpl_roleExplanations expln }
mkKindEqLoc :: TcType -> TcType
-> CtLoc -> CtLoc
mkKindEqLoc :: Type -> Type -> CtLoc -> CtLoc
mkKindEqLoc Type
s1 Type
s2 CtLoc
ctloc
| CtLoc { ctl_t_or_k :: CtLoc -> Maybe TypeOrKind
ctl_t_or_k = Maybe TypeOrKind
t_or_k, ctl_origin :: CtLoc -> CtOrigin
ctl_origin = CtOrigin
origin } <- CtLoc
ctloc
= CtLoc
ctloc { ctl_origin = KindEqOrigin s1 s2 origin t_or_k
, ctl_t_or_k = Just KindLevel }
adjustCtLocTyConBinder :: Maybe TyConBinder -> Maybe RoleExplanation -> CtLoc -> CtLoc
adjustCtLocTyConBinder :: Maybe TyConBinder -> Maybe RoleExplanation -> CtLoc -> CtLoc
adjustCtLocTyConBinder Maybe TyConBinder
mb_tc_bndr Maybe RoleExplanation
mb_repr CtLoc
loc
= Maybe InvisibleBit
-> Bool -> Maybe RoleExplanation -> CtLoc -> CtLoc
adjustCtLoc Maybe InvisibleBit
mb_invis_kind Bool
is_kind Maybe RoleExplanation
mb_repr CtLoc
loc
where
mb_invis_kind :: Maybe InvisibleBit
mb_invis_kind
| Just TyConBinder
tc_bndr <- Maybe TyConBinder
mb_tc_bndr
, Bool -> Bool
not (Bool -> Bool) -> Bool -> Bool
forall a b. (a -> b) -> a -> b
$ TyConBinder -> Bool
forall tv. VarBndr tv TyConBndrVis -> Bool
isVisibleTyConBinder TyConBinder
tc_bndr
= InvisibleBit -> Maybe InvisibleBit
forall a. a -> Maybe a
Just InvisibleBit
InvisibleKind
| Bool
otherwise
= Maybe InvisibleBit
forall a. Maybe a
Nothing
is_kind :: Bool
is_kind = Bool -> (TyConBinder -> Bool) -> Maybe TyConBinder -> Bool
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Bool
False TyConBinder -> Bool
isNamedTyConBinder Maybe TyConBinder
mb_tc_bndr
tyConAppRoleExplanation :: Role -> TyCon -> (Int, Role) -> Maybe RoleExplanation
tyConAppRoleExplanation :: Role -> TyCon -> (Int, Role) -> Maybe RoleExplanation
tyConAppRoleExplanation Role
role TyCon
tc (Int
arg_no, Role
arg_role) =
if Role
arg_role Role -> Role -> Bool
forall a. Ord a => a -> a -> Bool
< Role
role
then RoleExplanation -> Maybe RoleExplanation
RoleExplanation -> Maybe RoleExplanation
forall a. a -> Maybe a
Just (RoleExplanation -> Maybe RoleExplanation)
-> RoleExplanation -> Maybe RoleExplanation
forall a b. (a -> b) -> a -> b
$ TyCon -> Int -> Role -> RoleExplanation
TyConArg TyCon
tc Int
arg_no Role
arg_role
else Maybe RoleExplanation
forall a. Maybe a
Nothing
appTyRoleExplanation :: Type -> CtOrigin -> Maybe RoleExplanation
appTyRoleExplanation :: Type -> CtOrigin -> Maybe RoleExplanation
appTyRoleExplanation Type
s CtOrigin
orig
| (CtOrigin, (Type, Type))
_ : [(CtOrigin, (Type, Type))]
_ <- CtOrigin -> [(CtOrigin, (Type, Type))]
defaultReprEqOrigins CtOrigin
orig
= RoleExplanation -> Maybe RoleExplanation
RoleExplanation -> Maybe RoleExplanation
forall a. a -> Maybe a
Just (RoleExplanation -> Maybe RoleExplanation)
-> RoleExplanation -> Maybe RoleExplanation
forall a b. (a -> b) -> a -> b
$ Type -> RoleExplanation
NominalAppTy Type
s
| Bool
otherwise
= Maybe RoleExplanation
forall a. Maybe a
Nothing
adjustCtLoc :: Maybe InvisibleBit
-> Bool
-> Maybe RoleExplanation
-> CtLoc -> CtLoc
adjustCtLoc :: Maybe InvisibleBit
-> Bool -> Maybe RoleExplanation -> CtLoc -> CtLoc
adjustCtLoc Maybe InvisibleBit
mb_invis Bool
is_kind Maybe RoleExplanation
mb_repr CtLoc
loc
= CtLoc
loc3
where
loc1 :: CtLoc
loc1 | Bool
is_kind = CtLoc -> CtLoc
toKindLoc CtLoc
loc
| Bool
otherwise = CtLoc
loc
loc2 :: CtLoc
loc2 =
case Maybe InvisibleBit
mb_invis of
Maybe InvisibleBit
Nothing -> CtLoc
loc1
Just InvisibleBit
invis -> InvisibleBit -> CtLoc -> CtLoc
toInvisibleLoc InvisibleBit
invis CtLoc
loc1
loc3 :: CtLoc
loc3 | Just RoleExplanation
repr_loc <- Maybe RoleExplanation
mb_repr
= (CtExplanations -> CtExplanations) -> CtLoc -> CtLoc
updCtLocExplanations (RoleExplanation -> CtExplanations -> CtExplanations
addRoleExplanation RoleExplanation
repr_loc) CtLoc
loc2
| Bool
otherwise
= CtLoc
loc2
toKindLoc :: CtLoc -> CtLoc
toKindLoc :: CtLoc -> CtLoc
toKindLoc CtLoc
loc = CtLoc
loc { ctl_t_or_k = Just KindLevel }
toInvisibleLoc :: InvisibleBit -> CtLoc -> CtLoc
toInvisibleLoc :: InvisibleBit -> CtLoc -> CtLoc
toInvisibleLoc InvisibleBit
invis CtLoc
loc = CtLoc -> (CtOrigin -> CtOrigin) -> CtLoc
updateCtLocOrigin CtLoc
loc (InvisibleBit -> CtOrigin -> CtOrigin
toInvisibleOrigin InvisibleBit
invis)
mkGivenLoc :: TcLevel -> SkolemInfoAnon -> CtLocEnv -> CtLoc
mkGivenLoc :: TcLevel -> SkolemInfoAnon -> CtLocEnv -> CtLoc
mkGivenLoc TcLevel
tclvl SkolemInfoAnon
skol_info CtLocEnv
env
= CtLoc { ctl_origin :: CtOrigin
ctl_origin = SkolemInfoAnon -> CtOrigin
GivenOrigin SkolemInfoAnon
skol_info
, ctl_env :: CtLocEnv
ctl_env = CtLocEnv -> TcLevel -> CtLocEnv
setCtLocEnvLvl CtLocEnv
env TcLevel
tclvl
, ctl_t_or_k :: Maybe TypeOrKind
ctl_t_or_k = Maybe TypeOrKind
forall a. Maybe a
Nothing
, ctl_expln :: CtExplanations
ctl_expln = CtExplanations
forall a. Monoid a => a
mempty
, ctl_depth :: SubGoalDepth
ctl_depth = SubGoalDepth
initialSubGoalDepth }
ctLocEnv :: CtLoc -> CtLocEnv
ctLocEnv :: CtLoc -> CtLocEnv
ctLocEnv = CtLoc -> CtLocEnv
ctl_env
ctLocLevel :: CtLoc -> TcLevel
ctLocLevel :: CtLoc -> TcLevel
ctLocLevel CtLoc
loc = CtLocEnv -> TcLevel
getCtLocEnvLvl (CtLoc -> CtLocEnv
ctLocEnv CtLoc
loc)
ctLocDepth :: CtLoc -> SubGoalDepth
ctLocDepth :: CtLoc -> SubGoalDepth
ctLocDepth = CtLoc -> SubGoalDepth
ctl_depth
ctLocOrigin :: CtLoc -> CtOrigin
ctLocOrigin :: CtLoc -> CtOrigin
ctLocOrigin = CtLoc -> CtOrigin
ctl_origin
ctLocExplanations :: CtLoc -> CtExplanations
ctLocExplanations :: CtLoc -> CtExplanations
ctLocExplanations = CtLoc -> CtExplanations
ctl_expln
updCtLocExplanations :: (CtExplanations -> CtExplanations) -> CtLoc -> CtLoc
updCtLocExplanations :: (CtExplanations -> CtExplanations) -> CtLoc -> CtLoc
updCtLocExplanations CtExplanations -> CtExplanations
f CtLoc
loc = CtLoc
loc { ctl_expln = f $ ctl_expln loc }
ctLocSpan :: CtLoc -> RealSrcSpan
ctLocSpan :: CtLoc -> RealSrcSpan
ctLocSpan (CtLoc { ctl_env :: CtLoc -> CtLocEnv
ctl_env = CtLocEnv
lcl}) = CtLocEnv -> RealSrcSpan
getCtLocEnvLoc CtLocEnv
lcl
ctLocTypeOrKind_maybe :: CtLoc -> Maybe TypeOrKind
ctLocTypeOrKind_maybe :: CtLoc -> Maybe TypeOrKind
ctLocTypeOrKind_maybe = CtLoc -> Maybe TypeOrKind
ctl_t_or_k
setCtLocSpan :: CtLoc -> RealSrcSpan -> CtLoc
setCtLocSpan :: CtLoc -> RealSrcSpan -> CtLoc
setCtLocSpan ctl :: CtLoc
ctl@(CtLoc { ctl_env :: CtLoc -> CtLocEnv
ctl_env = CtLocEnv
lcl }) RealSrcSpan
loc = CtLoc -> CtLocEnv -> CtLoc
setCtLocEnv CtLoc
ctl (CtLocEnv -> RealSrcSpan -> CtLocEnv
setCtLocRealLoc CtLocEnv
lcl RealSrcSpan
loc)
bumpCtLocDepth :: CtLoc -> CtLoc
bumpCtLocDepth :: CtLoc -> CtLoc
bumpCtLocDepth loc :: CtLoc
loc@(CtLoc { ctl_depth :: CtLoc -> SubGoalDepth
ctl_depth = SubGoalDepth
d }) = CtLoc
loc { ctl_depth = bumpSubGoalDepth d }
resetCtLocDepth :: CtLoc -> CtLoc
resetCtLocDepth :: CtLoc -> CtLoc
resetCtLocDepth CtLoc
loc = CtLoc
loc { ctl_depth = initialSubGoalDepth }
setCtLocOrigin :: CtLoc -> CtOrigin -> CtLoc
setCtLocOrigin :: CtLoc -> CtOrigin -> CtLoc
setCtLocOrigin CtLoc
ctl CtOrigin
orig = CtLoc
ctl { ctl_origin = orig }
updateCtLocOrigin :: CtLoc -> (CtOrigin -> CtOrigin) -> CtLoc
updateCtLocOrigin :: CtLoc -> (CtOrigin -> CtOrigin) -> CtLoc
updateCtLocOrigin ctl :: CtLoc
ctl@(CtLoc { ctl_origin :: CtLoc -> CtOrigin
ctl_origin = CtOrigin
orig }) CtOrigin -> CtOrigin
upd
= CtLoc
ctl { ctl_origin = upd orig }
setCtLocEnv :: CtLoc -> CtLocEnv -> CtLoc
setCtLocEnv :: CtLoc -> CtLocEnv -> CtLoc
setCtLocEnv CtLoc
ctl CtLocEnv
env = CtLoc
ctl { ctl_env = env }
isGivenLoc :: CtLoc -> Bool
isGivenLoc :: CtLoc -> Bool
isGivenLoc CtLoc
loc = CtOrigin -> Bool
isGivenOrigin (CtLoc -> CtOrigin
ctLocOrigin CtLoc
loc)
pprCtLoc :: CtLoc -> SDoc
pprCtLoc :: CtLoc -> SDoc
pprCtLoc (CtLoc { ctl_origin :: CtLoc -> CtOrigin
ctl_origin = CtOrigin
o, ctl_env :: CtLoc -> CtLocEnv
ctl_env = CtLocEnv
lcl})
= [SDoc] -> SDoc
forall doc. IsLine doc => [doc] -> doc
sep [ CtOrigin -> SDoc
pprCtOrigin CtOrigin
o
, String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"at" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> RealSrcSpan -> SDoc
forall a. Outputable a => a -> SDoc
ppr (CtLocEnv -> RealSrcSpan
getCtLocEnvLoc CtLocEnv
lcl)]
data CtLocEnv = CtLocEnv { CtLocEnv -> [ErrCtxt]
ctl_ctxt :: ![ErrCtxt]
, CtLocEnv -> RealSrcSpan
ctl_loc :: !RealSrcSpan
, CtLocEnv -> TcBinderStack
ctl_bndrs :: !TcBinderStack
, CtLocEnv -> TcLevel
ctl_tclvl :: !TcLevel
, CtLocEnv -> Bool
ctl_in_gen_code :: !Bool
, CtLocEnv -> LocalRdrEnv
ctl_rdr :: !LocalRdrEnv }
getCtLocEnvLoc :: CtLocEnv -> RealSrcSpan
getCtLocEnvLoc :: CtLocEnv -> RealSrcSpan
getCtLocEnvLoc = CtLocEnv -> RealSrcSpan
ctl_loc
getCtLocEnvLvl :: CtLocEnv -> TcLevel
getCtLocEnvLvl :: CtLocEnv -> TcLevel
getCtLocEnvLvl = CtLocEnv -> TcLevel
ctl_tclvl
setCtLocEnvLvl :: CtLocEnv -> TcLevel -> CtLocEnv
setCtLocEnvLvl :: CtLocEnv -> TcLevel -> CtLocEnv
setCtLocEnvLvl CtLocEnv
env TcLevel
lvl = CtLocEnv
env { ctl_tclvl = lvl }
setCtLocRealLoc :: CtLocEnv -> RealSrcSpan -> CtLocEnv
setCtLocRealLoc :: CtLocEnv -> RealSrcSpan -> CtLocEnv
setCtLocRealLoc CtLocEnv
env RealSrcSpan
ss = CtLocEnv
env { ctl_loc = ss }
setCtLocEnvLoc :: CtLocEnv -> SrcSpan -> CtLocEnv
setCtLocEnvLoc :: CtLocEnv -> SrcSpan -> CtLocEnv
setCtLocEnvLoc CtLocEnv
env (RealSrcSpan RealSrcSpan
loc Maybe BufSpan
_)
= CtLocEnv
env { ctl_loc = loc, ctl_in_gen_code = False }
setCtLocEnvLoc CtLocEnv
env loc :: SrcSpan
loc@(UnhelpfulSpan UnhelpfulSpanReason
_)
| SrcSpan -> Bool
isGeneratedSrcSpan SrcSpan
loc
= CtLocEnv
env { ctl_in_gen_code = True }
| Bool
otherwise
= CtLocEnv
env
ctLocEnvInGeneratedCode :: CtLocEnv -> Bool
ctLocEnvInGeneratedCode :: CtLocEnv -> Bool
ctLocEnvInGeneratedCode = CtLocEnv -> Bool
ctl_in_gen_code