{-# LANGUAGE CPP, GADTs, DataKinds, KindSignatures #-}
{-# LANGUAGE TupleSections #-}
{-# LANGUAGE ViewPatterns #-}
module Check (
checkSingle, checkMatches, checkGuardMatches, isAnyPmCheckEnabled,
genCaseTmCs1, genCaseTmCs2
) where
#include "HsVersions.h"
import GhcPrelude
import TmOracle
import Unify( tcMatchTy )
import DynFlags
import HsSyn
import TcHsSyn
import Id
import ConLike
import Name
import FamInstEnv
import TysPrim (tYPETyCon)
import TysWiredIn
import TyCon
import SrcLoc
import Util
import Outputable
import FastString
import DataCon
import PatSyn
import HscTypes (CompleteMatch(..))
import BasicTypes (Boxity(..))
import DsMonad
import TcSimplify (tcCheckSatisfiability)
import TcType (isStringTy)
import Bag
import ErrUtils
import Var (EvVar)
import TyCoRep
import Type
import UniqSupply
import DsUtils (isTrueLHsExpr)
import Maybes (expectJust)
import qualified GHC.LanguageExtensions as LangExt
import Data.List (find)
import Data.Maybe (catMaybes, isJust, fromMaybe)
import Control.Monad (forM, when, forM_, zipWithM)
import Coercion
import TcEvidence
import TcSimplify (tcNormalise)
import IOEnv
import qualified Data.Semigroup as Semi
import ListT (ListT(..), fold, select)
type PmM a = ListT DsM a
liftD :: DsM a -> PmM a
liftD :: DsM a -> PmM a
liftD m :: DsM a
m = (forall r. (a -> DsM r -> DsM r) -> DsM r -> DsM r) -> PmM a
forall (m :: * -> *) a.
(forall r. (a -> m r -> m r) -> m r -> m r) -> ListT m a
ListT ((forall r. (a -> DsM r -> DsM r) -> DsM r -> DsM r) -> PmM a)
-> (forall r. (a -> DsM r -> DsM r) -> DsM r -> DsM r) -> PmM a
forall a b. (a -> b) -> a -> b
$ \sk :: a -> DsM r -> DsM r
sk fk :: DsM r
fk -> DsM a
m DsM a -> (a -> DsM r) -> DsM r
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \a :: a
a -> a -> DsM r -> DsM r
sk a
a DsM r
fk
getResult :: PmM PmResult -> DsM PmResult
getResult :: PmM PmResult -> DsM PmResult
getResult ls :: PmM PmResult
ls
= do { Maybe PmResult
res <- PmM PmResult
-> (PmResult -> DsM (Maybe PmResult) -> DsM (Maybe PmResult))
-> DsM (Maybe PmResult)
-> DsM (Maybe PmResult)
forall (m :: * -> *) a r.
ListT m a -> (a -> m r -> m r) -> m r -> m r
fold PmM PmResult
ls PmResult -> DsM (Maybe PmResult) -> DsM (Maybe PmResult)
goM (Maybe PmResult -> DsM (Maybe PmResult)
forall (f :: * -> *) a. Applicative f => a -> f a
pure Maybe PmResult
forall a. Maybe a
Nothing)
; case Maybe PmResult
res of
Nothing -> String -> DsM PmResult
forall a. String -> a
panic "getResult is empty"
Just a :: PmResult
a -> PmResult -> DsM PmResult
forall (m :: * -> *) a. Monad m => a -> m a
return PmResult
a }
where
goM :: PmResult -> DsM (Maybe PmResult) -> DsM (Maybe PmResult)
goM :: PmResult -> DsM (Maybe PmResult) -> DsM (Maybe PmResult)
goM mpm :: PmResult
mpm dpm :: DsM (Maybe PmResult)
dpm = do { Maybe PmResult
pmr <- DsM (Maybe PmResult)
dpm
; Maybe PmResult -> DsM (Maybe PmResult)
forall (m :: * -> *) a. Monad m => a -> m a
return (Maybe PmResult -> DsM (Maybe PmResult))
-> Maybe PmResult -> DsM (Maybe PmResult)
forall a b. (a -> b) -> a -> b
$ PmResult -> Maybe PmResult
forall a. a -> Maybe a
Just (PmResult -> Maybe PmResult) -> PmResult -> Maybe PmResult
forall a b. (a -> b) -> a -> b
$ Maybe PmResult -> PmResult -> PmResult
go Maybe PmResult
pmr PmResult
mpm }
go :: Maybe PmResult -> PmResult -> PmResult
go :: Maybe PmResult -> PmResult -> PmResult
go Nothing rs :: PmResult
rs = PmResult
rs
go (Just old :: PmResult
old@(PmResult prov :: Provenance
prov rs :: [Located [LPat GhcTc]]
rs (UncoveredPatterns us :: Uncovered
us) is :: [Located [LPat GhcTc]]
is)) new :: PmResult
new
| Uncovered -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null Uncovered
us Bool -> Bool -> Bool
&& [Located [LPat GhcTc]] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [Located [LPat GhcTc]]
rs Bool -> Bool -> Bool
&& [Located [LPat GhcTc]] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [Located [LPat GhcTc]]
is = PmResult
old
| Bool
otherwise =
let PmResult prov' :: Provenance
prov' rs' :: [Located [LPat GhcTc]]
rs' (UncoveredPatterns us' :: Uncovered
us') is' :: [Located [LPat GhcTc]]
is' = PmResult
new
in case Uncovered -> Uncovered -> Ordering
forall a b. [a] -> [b] -> Ordering
compareLength Uncovered
us Uncovered
us'
Ordering -> Ordering -> Ordering
forall a. Monoid a => a -> a -> a
`mappend` ([Located [LPat GhcTc]] -> [Located [LPat GhcTc]] -> Ordering
forall a b. [a] -> [b] -> Ordering
compareLength [Located [LPat GhcTc]]
is [Located [LPat GhcTc]]
is')
Ordering -> Ordering -> Ordering
forall a. Monoid a => a -> a -> a
`mappend` ([Located [LPat GhcTc]] -> [Located [LPat GhcTc]] -> Ordering
forall a b. [a] -> [b] -> Ordering
compareLength [Located [LPat GhcTc]]
rs [Located [LPat GhcTc]]
rs')
Ordering -> Ordering -> Ordering
forall a. Monoid a => a -> a -> a
`mappend` (Provenance -> Provenance -> Ordering
forall a. Ord a => a -> a -> Ordering
compare Provenance
prov Provenance
prov') of
GT -> PmResult
new
EQ -> PmResult
new
LT -> PmResult
old
go (Just (PmResult _ _ (TypeOfUncovered _) _)) _new :: PmResult
_new
= String -> PmResult
forall a. String -> a
panic "getResult: No inhabitation candidates"
data PatTy = PAT | VA
data PmPat :: PatTy -> * where
PmCon :: { PmPat t -> ConLike
pm_con_con :: ConLike
, PmPat t -> [Type]
pm_con_arg_tys :: [Type]
, PmPat t -> [TyVar]
pm_con_tvs :: [TyVar]
, PmPat t -> [TyVar]
pm_con_dicts :: [EvVar]
, PmPat t -> [PmPat t]
pm_con_args :: [PmPat t] } -> PmPat t
PmVar :: { PmPat t -> TyVar
pm_var_id :: Id } -> PmPat t
PmLit :: { PmPat t -> PmLit
pm_lit_lit :: PmLit } -> PmPat t
PmNLit :: { PmPat 'VA -> TyVar
pm_lit_id :: Id
, PmPat 'VA -> [PmLit]
pm_lit_not :: [PmLit] } -> PmPat 'VA
PmGrd :: { PmPat 'PAT -> PatVec
pm_grd_pv :: PatVec
, PmPat 'PAT -> PmExpr
pm_grd_expr :: PmExpr } -> PmPat 'PAT
instance Outputable (PmPat a) where
ppr :: PmPat a -> SDoc
ppr = PmPat a -> SDoc
forall (a :: PatTy). PmPat a -> SDoc
pprPmPatDebug
type Pattern = PmPat 'PAT
type ValAbs = PmPat 'VA
type PatVec = [Pattern]
data ValVec = ValVec [ValAbs] Delta
data Delta = MkDelta { Delta -> Bag TyVar
delta_ty_cs :: Bag EvVar
, Delta -> TmState
delta_tm_cs :: TmState }
type ValSetAbs = [ValVec]
type Uncovered = ValSetAbs
data Covered = Covered | NotCovered
deriving Int -> Covered -> ShowS
[Covered] -> ShowS
Covered -> String
(Int -> Covered -> ShowS)
-> (Covered -> String) -> ([Covered] -> ShowS) -> Show Covered
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Covered] -> ShowS
$cshowList :: [Covered] -> ShowS
show :: Covered -> String
$cshow :: Covered -> String
showsPrec :: Int -> Covered -> ShowS
$cshowsPrec :: Int -> Covered -> ShowS
Show
instance Outputable Covered where
ppr :: Covered -> SDoc
ppr (Covered
Covered) = String -> SDoc
text "Covered"
ppr (Covered
NotCovered) = String -> SDoc
text "NotCovered"
instance Semi.Semigroup Covered where
Covered <> :: Covered -> Covered -> Covered
<> _ = Covered
Covered
_ <> Covered = Covered
Covered
NotCovered <> NotCovered = Covered
NotCovered
instance Monoid Covered where
mempty :: Covered
mempty = Covered
NotCovered
mappend :: Covered -> Covered -> Covered
mappend = Covered -> Covered -> Covered
forall a. Semigroup a => a -> a -> a
(Semi.<>)
data Diverged = Diverged | NotDiverged
deriving Int -> Diverged -> ShowS
[Diverged] -> ShowS
Diverged -> String
(Int -> Diverged -> ShowS)
-> (Diverged -> String) -> ([Diverged] -> ShowS) -> Show Diverged
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Diverged] -> ShowS
$cshowList :: [Diverged] -> ShowS
show :: Diverged -> String
$cshow :: Diverged -> String
showsPrec :: Int -> Diverged -> ShowS
$cshowsPrec :: Int -> Diverged -> ShowS
Show
instance Outputable Diverged where
ppr :: Diverged -> SDoc
ppr Diverged = String -> SDoc
text "Diverged"
ppr NotDiverged = String -> SDoc
text "NotDiverged"
instance Semi.Semigroup Diverged where
Diverged <> :: Diverged -> Diverged -> Diverged
<> _ = Diverged
Diverged
_ <> Diverged = Diverged
Diverged
NotDiverged <> NotDiverged = Diverged
NotDiverged
instance Monoid Diverged where
mempty :: Diverged
mempty = Diverged
NotDiverged
mappend :: Diverged -> Diverged -> Diverged
mappend = Diverged -> Diverged -> Diverged
forall a. Semigroup a => a -> a -> a
(Semi.<>)
data Provenance =
FromBuiltin
| FromComplete
deriving (Int -> Provenance -> ShowS
[Provenance] -> ShowS
Provenance -> String
(Int -> Provenance -> ShowS)
-> (Provenance -> String)
-> ([Provenance] -> ShowS)
-> Show Provenance
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Provenance] -> ShowS
$cshowList :: [Provenance] -> ShowS
show :: Provenance -> String
$cshow :: Provenance -> String
showsPrec :: Int -> Provenance -> ShowS
$cshowsPrec :: Int -> Provenance -> ShowS
Show, Provenance -> Provenance -> Bool
(Provenance -> Provenance -> Bool)
-> (Provenance -> Provenance -> Bool) -> Eq Provenance
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Provenance -> Provenance -> Bool
$c/= :: Provenance -> Provenance -> Bool
== :: Provenance -> Provenance -> Bool
$c== :: Provenance -> Provenance -> Bool
Eq, Eq Provenance
Eq Provenance =>
(Provenance -> Provenance -> Ordering)
-> (Provenance -> Provenance -> Bool)
-> (Provenance -> Provenance -> Bool)
-> (Provenance -> Provenance -> Bool)
-> (Provenance -> Provenance -> Bool)
-> (Provenance -> Provenance -> Provenance)
-> (Provenance -> Provenance -> Provenance)
-> Ord Provenance
Provenance -> Provenance -> Bool
Provenance -> Provenance -> Ordering
Provenance -> Provenance -> Provenance
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
min :: Provenance -> Provenance -> Provenance
$cmin :: Provenance -> Provenance -> Provenance
max :: Provenance -> Provenance -> Provenance
$cmax :: Provenance -> Provenance -> Provenance
>= :: Provenance -> Provenance -> Bool
$c>= :: Provenance -> Provenance -> Bool
> :: Provenance -> Provenance -> Bool
$c> :: Provenance -> Provenance -> Bool
<= :: Provenance -> Provenance -> Bool
$c<= :: Provenance -> Provenance -> Bool
< :: Provenance -> Provenance -> Bool
$c< :: Provenance -> Provenance -> Bool
compare :: Provenance -> Provenance -> Ordering
$ccompare :: Provenance -> Provenance -> Ordering
$cp1Ord :: Eq Provenance
Ord)
instance Outputable Provenance where
ppr :: Provenance -> SDoc
ppr = String -> SDoc
text (String -> SDoc) -> (Provenance -> String) -> Provenance -> SDoc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Provenance -> String
forall a. Show a => a -> String
show
instance Semi.Semigroup Provenance where
FromComplete <> :: Provenance -> Provenance -> Provenance
<> _ = Provenance
FromComplete
_ <> FromComplete = Provenance
FromComplete
_ <> _ = Provenance
FromBuiltin
instance Monoid Provenance where
mempty :: Provenance
mempty = Provenance
FromBuiltin
mappend :: Provenance -> Provenance -> Provenance
mappend = Provenance -> Provenance -> Provenance
forall a. Semigroup a => a -> a -> a
(Semi.<>)
data PartialResult = PartialResult {
PartialResult -> Provenance
presultProvenance :: Provenance
, PartialResult -> Covered
presultCovered :: Covered
, PartialResult -> Uncovered
presultUncovered :: Uncovered
, PartialResult -> Diverged
presultDivergent :: Diverged }
instance Outputable PartialResult where
ppr :: PartialResult -> SDoc
ppr (PartialResult prov :: Provenance
prov c :: Covered
c vsa :: Uncovered
vsa d :: Diverged
d)
= String -> SDoc
text "PartialResult" SDoc -> SDoc -> SDoc
<+> Provenance -> SDoc
forall a. Outputable a => a -> SDoc
ppr Provenance
prov SDoc -> SDoc -> SDoc
<+> Covered -> SDoc
forall a. Outputable a => a -> SDoc
ppr Covered
c
SDoc -> SDoc -> SDoc
<+> Diverged -> SDoc
forall a. Outputable a => a -> SDoc
ppr Diverged
d SDoc -> SDoc -> SDoc
<+> Uncovered -> SDoc
forall a. Outputable a => a -> SDoc
ppr Uncovered
vsa
instance Semi.Semigroup PartialResult where
(PartialResult prov1 :: Provenance
prov1 cs1 :: Covered
cs1 vsa1 :: Uncovered
vsa1 ds1 :: Diverged
ds1)
<> :: PartialResult -> PartialResult -> PartialResult
<> (PartialResult prov2 :: Provenance
prov2 cs2 :: Covered
cs2 vsa2 :: Uncovered
vsa2 ds2 :: Diverged
ds2)
= Provenance -> Covered -> Uncovered -> Diverged -> PartialResult
PartialResult (Provenance
prov1 Provenance -> Provenance -> Provenance
forall a. Semigroup a => a -> a -> a
Semi.<> Provenance
prov2)
(Covered
cs1 Covered -> Covered -> Covered
forall a. Semigroup a => a -> a -> a
Semi.<> Covered
cs2)
(Uncovered
vsa1 Uncovered -> Uncovered -> Uncovered
forall a. Semigroup a => a -> a -> a
Semi.<> Uncovered
vsa2)
(Diverged
ds1 Diverged -> Diverged -> Diverged
forall a. Semigroup a => a -> a -> a
Semi.<> Diverged
ds2)
instance Monoid PartialResult where
mempty :: PartialResult
mempty = Provenance -> Covered -> Uncovered -> Diverged -> PartialResult
PartialResult Provenance
forall a. Monoid a => a
mempty Covered
forall a. Monoid a => a
mempty [] Diverged
forall a. Monoid a => a
mempty
mappend :: PartialResult -> PartialResult -> PartialResult
mappend = PartialResult -> PartialResult -> PartialResult
forall a. Semigroup a => a -> a -> a
(Semi.<>)
data PmResult =
PmResult {
PmResult -> Provenance
pmresultProvenance :: Provenance
, PmResult -> [Located [LPat GhcTc]]
pmresultRedundant :: [Located [LPat GhcTc]]
, PmResult -> UncoveredCandidates
pmresultUncovered :: UncoveredCandidates
, PmResult -> [Located [LPat GhcTc]]
pmresultInaccessible :: [Located [LPat GhcTc]] }
data UncoveredCandidates = UncoveredPatterns Uncovered
| TypeOfUncovered Type
emptyPmResult :: PmResult
emptyPmResult :: PmResult
emptyPmResult = Provenance
-> [Located [LPat GhcTc]]
-> UncoveredCandidates
-> [Located [LPat GhcTc]]
-> PmResult
PmResult Provenance
FromBuiltin [] (Uncovered -> UncoveredCandidates
UncoveredPatterns []) []
uncoveredWithTy :: Type -> PmResult
uncoveredWithTy :: Type -> PmResult
uncoveredWithTy ty :: Type
ty = Provenance
-> [Located [LPat GhcTc]]
-> UncoveredCandidates
-> [Located [LPat GhcTc]]
-> PmResult
PmResult Provenance
FromBuiltin [] (Type -> UncoveredCandidates
TypeOfUncovered Type
ty) []
checkSingle :: DynFlags -> DsMatchContext -> Id -> Pat GhcTc -> DsM ()
checkSingle :: DynFlags -> DsMatchContext -> TyVar -> LPat GhcTc -> DsM ()
checkSingle dflags :: DynFlags
dflags ctxt :: DsMatchContext
ctxt@(DsMatchContext _ locn :: SrcSpan
locn) var :: TyVar
var p :: LPat GhcTc
p = do
String -> SDoc -> DsM ()
tracePmD "checkSingle" ([SDoc] -> SDoc
vcat [DsMatchContext -> SDoc
forall a. Outputable a => a -> SDoc
ppr DsMatchContext
ctxt, TyVar -> SDoc
forall a. Outputable a => a -> SDoc
ppr TyVar
var, LPat GhcTc -> SDoc
forall a. Outputable a => a -> SDoc
ppr LPat GhcTc
p])
Either IOEnvFailure PmResult
mb_pm_res <- DsM PmResult
-> IOEnv (Env DsGblEnv DsLclEnv) (Either IOEnvFailure PmResult)
forall env r. IOEnv env r -> IOEnv env (Either IOEnvFailure r)
tryM (PmM PmResult -> DsM PmResult
getResult (SrcSpan -> TyVar -> LPat GhcTc -> PmM PmResult
checkSingle' SrcSpan
locn TyVar
var LPat GhcTc
p))
case Either IOEnvFailure PmResult
mb_pm_res of
Left _ -> DynFlags -> DsMatchContext -> DsM ()
warnPmIters DynFlags
dflags DsMatchContext
ctxt
Right res :: PmResult
res -> DynFlags -> DsMatchContext -> PmResult -> DsM ()
dsPmWarn DynFlags
dflags DsMatchContext
ctxt PmResult
res
checkSingle' :: SrcSpan -> Id -> Pat GhcTc -> PmM PmResult
checkSingle' :: SrcSpan -> TyVar -> LPat GhcTc -> PmM PmResult
checkSingle' locn :: SrcSpan
locn var :: TyVar
var p :: LPat GhcTc
p = do
DsM () -> PmM ()
forall a. DsM a -> PmM a
liftD DsM ()
resetPmIterDs
FamInstEnvs
fam_insts <- DsM FamInstEnvs -> PmM FamInstEnvs
forall a. DsM a -> PmM a
liftD DsM FamInstEnvs
dsGetFamInstEnvs
PatVec
clause <- DsM PatVec -> PmM PatVec
forall a. DsM a -> PmM a
liftD (DsM PatVec -> PmM PatVec) -> DsM PatVec -> PmM PatVec
forall a b. (a -> b) -> a -> b
$ FamInstEnvs -> LPat GhcTc -> DsM PatVec
translatePat FamInstEnvs
fam_insts LPat GhcTc
p
Uncovered
missing <- [TyVar] -> PmM Uncovered
mkInitialUncovered [TyVar
var]
String -> SDoc -> PmM ()
tracePm "checkSingle: missing" ([SDoc] -> SDoc
vcat ((ValVec -> SDoc) -> Uncovered -> [SDoc]
forall a b. (a -> b) -> [a] -> [b]
map ValVec -> SDoc
pprValVecDebug Uncovered
missing))
PartialResult prov :: Provenance
prov cs :: Covered
cs us :: Uncovered
us ds :: Diverged
ds <- (ValVec -> PmM PartialResult) -> Uncovered -> PmM PartialResult
runMany (PatVec -> [PatVec] -> ValVec -> PmM PartialResult
pmcheckI PatVec
clause []) Uncovered
missing
let us' :: UncoveredCandidates
us' = Uncovered -> UncoveredCandidates
UncoveredPatterns Uncovered
us
PmResult -> PmM PmResult
forall (m :: * -> *) a. Monad m => a -> m a
return (PmResult -> PmM PmResult) -> PmResult -> PmM PmResult
forall a b. (a -> b) -> a -> b
$ case (Covered
cs,Diverged
ds) of
(Covered, _ ) -> Provenance
-> [Located [LPat GhcTc]]
-> UncoveredCandidates
-> [Located [LPat GhcTc]]
-> PmResult
PmResult Provenance
prov [] UncoveredCandidates
us' []
(NotCovered, NotDiverged) -> Provenance
-> [Located [LPat GhcTc]]
-> UncoveredCandidates
-> [Located [LPat GhcTc]]
-> PmResult
PmResult Provenance
prov [Located [LPat GhcTc]]
m UncoveredCandidates
us' []
(NotCovered, Diverged ) -> Provenance
-> [Located [LPat GhcTc]]
-> UncoveredCandidates
-> [Located [LPat GhcTc]]
-> PmResult
PmResult Provenance
prov [] UncoveredCandidates
us' [Located [LPat GhcTc]]
m
where m :: [Located [LPat GhcTc]]
m = [SrcSpan
-> SrcSpanLess (Located [LPat GhcTc]) -> Located [LPat GhcTc]
forall a. HasSrcSpan a => SrcSpan -> SrcSpanLess a -> a
cL SrcSpan
locn [SrcSpan -> SrcSpanLess (LPat GhcTc) -> LPat GhcTc
forall a. HasSrcSpan a => SrcSpan -> SrcSpanLess a -> a
cL SrcSpan
locn SrcSpanLess (LPat GhcTc)
LPat GhcTc
p]]
checkGuardMatches :: HsMatchContext Name
-> GRHSs GhcTc (LHsExpr GhcTc)
-> DsM ()
checkGuardMatches :: HsMatchContext Name -> GRHSs GhcTc (LHsExpr GhcTc) -> DsM ()
checkGuardMatches hs_ctx :: HsMatchContext Name
hs_ctx guards :: GRHSs GhcTc (LHsExpr GhcTc)
guards@(GRHSs _ grhss :: [LGRHS GhcTc (LHsExpr GhcTc)]
grhss _) = do
DynFlags
dflags <- IOEnv (Env DsGblEnv DsLclEnv) DynFlags
forall (m :: * -> *). HasDynFlags m => m DynFlags
getDynFlags
let combinedLoc :: SrcSpan
combinedLoc = (SrcSpan -> SrcSpan -> SrcSpan) -> [SrcSpan] -> SrcSpan
forall (t :: * -> *) a. Foldable t => (a -> a -> a) -> t a -> a
foldl1 SrcSpan -> SrcSpan -> SrcSpan
combineSrcSpans ((LGRHS GhcTc (LHsExpr GhcTc) -> SrcSpan)
-> [LGRHS GhcTc (LHsExpr GhcTc)] -> [SrcSpan]
forall a b. (a -> b) -> [a] -> [b]
map LGRHS GhcTc (LHsExpr GhcTc) -> SrcSpan
forall a. HasSrcSpan a => a -> SrcSpan
getLoc [LGRHS GhcTc (LHsExpr GhcTc)]
grhss)
dsMatchContext :: DsMatchContext
dsMatchContext = HsMatchContext Name -> SrcSpan -> DsMatchContext
DsMatchContext HsMatchContext Name
hs_ctx SrcSpan
combinedLoc
match :: LMatch GhcTc (LHsExpr GhcTc)
match = SrcSpan
-> SrcSpanLess (LMatch GhcTc (LHsExpr GhcTc))
-> LMatch GhcTc (LHsExpr GhcTc)
forall a. HasSrcSpan a => SrcSpan -> SrcSpanLess a -> a
cL SrcSpan
combinedLoc (SrcSpanLess (LMatch GhcTc (LHsExpr GhcTc))
-> LMatch GhcTc (LHsExpr GhcTc))
-> SrcSpanLess (LMatch GhcTc (LHsExpr GhcTc))
-> LMatch GhcTc (LHsExpr GhcTc)
forall a b. (a -> b) -> a -> b
$
Match :: forall p body.
XCMatch p body
-> HsMatchContext (NameOrRdrName (IdP p))
-> [LPat p]
-> GRHSs p body
-> Match p body
Match { m_ext :: XCMatch GhcTc (LHsExpr GhcTc)
m_ext = XCMatch GhcTc (LHsExpr GhcTc)
NoExt
noExt
, m_ctxt :: HsMatchContext (NameOrRdrName (IdP GhcTc))
m_ctxt = HsMatchContext Name
HsMatchContext (NameOrRdrName (IdP GhcTc))
hs_ctx
, m_pats :: [LPat GhcTc]
m_pats = []
, m_grhss :: GRHSs GhcTc (LHsExpr GhcTc)
m_grhss = GRHSs GhcTc (LHsExpr GhcTc)
guards }
DynFlags
-> DsMatchContext
-> [TyVar]
-> [LMatch GhcTc (LHsExpr GhcTc)]
-> DsM ()
checkMatches DynFlags
dflags DsMatchContext
dsMatchContext [] [LMatch GhcTc (LHsExpr GhcTc)
match]
checkGuardMatches _ (XGRHSs _) = String -> DsM ()
forall a. String -> a
panic "checkGuardMatches"
checkMatches :: DynFlags -> DsMatchContext
-> [Id] -> [LMatch GhcTc (LHsExpr GhcTc)] -> DsM ()
checkMatches :: DynFlags
-> DsMatchContext
-> [TyVar]
-> [LMatch GhcTc (LHsExpr GhcTc)]
-> DsM ()
checkMatches dflags :: DynFlags
dflags ctxt :: DsMatchContext
ctxt vars :: [TyVar]
vars matches :: [LMatch GhcTc (LHsExpr GhcTc)]
matches = do
String -> SDoc -> DsM ()
tracePmD "checkMatches" (SDoc -> Int -> SDoc -> SDoc
hang ([SDoc] -> SDoc
vcat [DsMatchContext -> SDoc
forall a. Outputable a => a -> SDoc
ppr DsMatchContext
ctxt
, [TyVar] -> SDoc
forall a. Outputable a => a -> SDoc
ppr [TyVar]
vars
, String -> SDoc
text "Matches:"])
2
([SDoc] -> SDoc
vcat ((LMatch GhcTc (LHsExpr GhcTc) -> SDoc)
-> [LMatch GhcTc (LHsExpr GhcTc)] -> [SDoc]
forall a b. (a -> b) -> [a] -> [b]
map LMatch GhcTc (LHsExpr GhcTc) -> SDoc
forall a. Outputable a => a -> SDoc
ppr [LMatch GhcTc (LHsExpr GhcTc)]
matches)))
Either IOEnvFailure PmResult
mb_pm_res <- DsM PmResult
-> IOEnv (Env DsGblEnv DsLclEnv) (Either IOEnvFailure PmResult)
forall env r. IOEnv env r -> IOEnv env (Either IOEnvFailure r)
tryM (DsM PmResult
-> IOEnv (Env DsGblEnv DsLclEnv) (Either IOEnvFailure PmResult))
-> DsM PmResult
-> IOEnv (Env DsGblEnv DsLclEnv) (Either IOEnvFailure PmResult)
forall a b. (a -> b) -> a -> b
$ PmM PmResult -> DsM PmResult
getResult (PmM PmResult -> DsM PmResult) -> PmM PmResult -> DsM PmResult
forall a b. (a -> b) -> a -> b
$ case [LMatch GhcTc (LHsExpr GhcTc)]
matches of
[] | [var :: TyVar
var] <- [TyVar]
vars -> TyVar -> PmM PmResult
checkEmptyCase' TyVar
var
_normal_match :: [LMatch GhcTc (LHsExpr GhcTc)]
_normal_match -> [TyVar] -> [LMatch GhcTc (LHsExpr GhcTc)] -> PmM PmResult
checkMatches' [TyVar]
vars [LMatch GhcTc (LHsExpr GhcTc)]
matches
case Either IOEnvFailure PmResult
mb_pm_res of
Left _ -> DynFlags -> DsMatchContext -> DsM ()
warnPmIters DynFlags
dflags DsMatchContext
ctxt
Right res :: PmResult
res -> DynFlags -> DsMatchContext -> PmResult -> DsM ()
dsPmWarn DynFlags
dflags DsMatchContext
ctxt PmResult
res
checkMatches' :: [Id] -> [LMatch GhcTc (LHsExpr GhcTc)] -> PmM PmResult
checkMatches' :: [TyVar] -> [LMatch GhcTc (LHsExpr GhcTc)] -> PmM PmResult
checkMatches' vars :: [TyVar]
vars matches :: [LMatch GhcTc (LHsExpr GhcTc)]
matches
| [LMatch GhcTc (LHsExpr GhcTc)] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [LMatch GhcTc (LHsExpr GhcTc)]
matches = String -> PmM PmResult
forall a. String -> a
panic "checkMatches': EmptyCase"
| Bool
otherwise = do
DsM () -> PmM ()
forall a. DsM a -> PmM a
liftD DsM ()
resetPmIterDs
Uncovered
missing <- [TyVar] -> PmM Uncovered
mkInitialUncovered [TyVar]
vars
String -> SDoc -> PmM ()
tracePm "checkMatches': missing" ([SDoc] -> SDoc
vcat ((ValVec -> SDoc) -> Uncovered -> [SDoc]
forall a b. (a -> b) -> [a] -> [b]
map ValVec -> SDoc
pprValVecDebug Uncovered
missing))
(prov :: Provenance
prov, rs :: [LMatch GhcTc (LHsExpr GhcTc)]
rs,us :: Uncovered
us,ds :: [LMatch GhcTc (LHsExpr GhcTc)]
ds) <- [LMatch GhcTc (LHsExpr GhcTc)]
-> Uncovered
-> PmM
(Provenance, [LMatch GhcTc (LHsExpr GhcTc)], Uncovered,
[LMatch GhcTc (LHsExpr GhcTc)])
go [LMatch GhcTc (LHsExpr GhcTc)]
matches Uncovered
missing
PmResult -> PmM PmResult
forall (m :: * -> *) a. Monad m => a -> m a
return (PmResult -> PmM PmResult) -> PmResult -> PmM PmResult
forall a b. (a -> b) -> a -> b
$ PmResult :: Provenance
-> [Located [LPat GhcTc]]
-> UncoveredCandidates
-> [Located [LPat GhcTc]]
-> PmResult
PmResult {
pmresultProvenance :: Provenance
pmresultProvenance = Provenance
prov
, pmresultRedundant :: [Located [LPat GhcTc]]
pmresultRedundant = (LMatch GhcTc (LHsExpr GhcTc) -> Located [LPat GhcTc])
-> [LMatch GhcTc (LHsExpr GhcTc)] -> [Located [LPat GhcTc]]
forall a b. (a -> b) -> [a] -> [b]
map LMatch GhcTc (LHsExpr GhcTc) -> Located [LPat GhcTc]
forall id body. LMatch id body -> Located [LPat id]
hsLMatchToLPats [LMatch GhcTc (LHsExpr GhcTc)]
rs
, pmresultUncovered :: UncoveredCandidates
pmresultUncovered = Uncovered -> UncoveredCandidates
UncoveredPatterns Uncovered
us
, pmresultInaccessible :: [Located [LPat GhcTc]]
pmresultInaccessible = (LMatch GhcTc (LHsExpr GhcTc) -> Located [LPat GhcTc])
-> [LMatch GhcTc (LHsExpr GhcTc)] -> [Located [LPat GhcTc]]
forall a b. (a -> b) -> [a] -> [b]
map LMatch GhcTc (LHsExpr GhcTc) -> Located [LPat GhcTc]
forall id body. LMatch id body -> Located [LPat id]
hsLMatchToLPats [LMatch GhcTc (LHsExpr GhcTc)]
ds }
where
go :: [LMatch GhcTc (LHsExpr GhcTc)] -> Uncovered
-> PmM (Provenance
, [LMatch GhcTc (LHsExpr GhcTc)]
, Uncovered
, [LMatch GhcTc (LHsExpr GhcTc)])
go :: [LMatch GhcTc (LHsExpr GhcTc)]
-> Uncovered
-> PmM
(Provenance, [LMatch GhcTc (LHsExpr GhcTc)], Uncovered,
[LMatch GhcTc (LHsExpr GhcTc)])
go [] missing :: Uncovered
missing = (Provenance, [LMatch GhcTc (LHsExpr GhcTc)], Uncovered,
[LMatch GhcTc (LHsExpr GhcTc)])
-> PmM
(Provenance, [LMatch GhcTc (LHsExpr GhcTc)], Uncovered,
[LMatch GhcTc (LHsExpr GhcTc)])
forall (m :: * -> *) a. Monad m => a -> m a
return (Provenance
forall a. Monoid a => a
mempty, [], Uncovered
missing, [])
go (m :: LMatch GhcTc (LHsExpr GhcTc)
m:ms :: [LMatch GhcTc (LHsExpr GhcTc)]
ms) missing :: Uncovered
missing = do
String -> SDoc -> PmM ()
tracePm "checMatches': go" (LMatch GhcTc (LHsExpr GhcTc) -> SDoc
forall a. Outputable a => a -> SDoc
ppr LMatch GhcTc (LHsExpr GhcTc)
m SDoc -> SDoc -> SDoc
$$ Uncovered -> SDoc
forall a. Outputable a => a -> SDoc
ppr Uncovered
missing)
FamInstEnvs
fam_insts <- DsM FamInstEnvs -> PmM FamInstEnvs
forall a. DsM a -> PmM a
liftD DsM FamInstEnvs
dsGetFamInstEnvs
(clause :: PatVec
clause, guards :: [PatVec]
guards) <- DsM (PatVec, [PatVec]) -> PmM (PatVec, [PatVec])
forall a. DsM a -> PmM a
liftD (DsM (PatVec, [PatVec]) -> PmM (PatVec, [PatVec]))
-> DsM (PatVec, [PatVec]) -> PmM (PatVec, [PatVec])
forall a b. (a -> b) -> a -> b
$ FamInstEnvs
-> LMatch GhcTc (LHsExpr GhcTc) -> DsM (PatVec, [PatVec])
translateMatch FamInstEnvs
fam_insts LMatch GhcTc (LHsExpr GhcTc)
m
r :: PartialResult
r@(PartialResult prov :: Provenance
prov cs :: Covered
cs missing' :: Uncovered
missing' ds :: Diverged
ds)
<- (ValVec -> PmM PartialResult) -> Uncovered -> PmM PartialResult
runMany (PatVec -> [PatVec] -> ValVec -> PmM PartialResult
pmcheckI PatVec
clause [PatVec]
guards) Uncovered
missing
String -> SDoc -> PmM ()
tracePm "checMatches': go: res" (PartialResult -> SDoc
forall a. Outputable a => a -> SDoc
ppr PartialResult
r)
(ms_prov :: Provenance
ms_prov, rs :: [LMatch GhcTc (LHsExpr GhcTc)]
rs, final_u :: Uncovered
final_u, is :: [LMatch GhcTc (LHsExpr GhcTc)]
is) <- [LMatch GhcTc (LHsExpr GhcTc)]
-> Uncovered
-> PmM
(Provenance, [LMatch GhcTc (LHsExpr GhcTc)], Uncovered,
[LMatch GhcTc (LHsExpr GhcTc)])
go [LMatch GhcTc (LHsExpr GhcTc)]
ms Uncovered
missing'
let final_prov :: Provenance
final_prov = Provenance
prov Provenance -> Provenance -> Provenance
forall a. Monoid a => a -> a -> a
`mappend` Provenance
ms_prov
(Provenance, [LMatch GhcTc (LHsExpr GhcTc)], Uncovered,
[LMatch GhcTc (LHsExpr GhcTc)])
-> PmM
(Provenance, [LMatch GhcTc (LHsExpr GhcTc)], Uncovered,
[LMatch GhcTc (LHsExpr GhcTc)])
forall (m :: * -> *) a. Monad m => a -> m a
return ((Provenance, [LMatch GhcTc (LHsExpr GhcTc)], Uncovered,
[LMatch GhcTc (LHsExpr GhcTc)])
-> PmM
(Provenance, [LMatch GhcTc (LHsExpr GhcTc)], Uncovered,
[LMatch GhcTc (LHsExpr GhcTc)]))
-> (Provenance, [LMatch GhcTc (LHsExpr GhcTc)], Uncovered,
[LMatch GhcTc (LHsExpr GhcTc)])
-> PmM
(Provenance, [LMatch GhcTc (LHsExpr GhcTc)], Uncovered,
[LMatch GhcTc (LHsExpr GhcTc)])
forall a b. (a -> b) -> a -> b
$ case (Covered
cs, Diverged
ds) of
(Covered, _ ) -> (Provenance
final_prov, [LMatch GhcTc (LHsExpr GhcTc)]
rs, Uncovered
final_u, [LMatch GhcTc (LHsExpr GhcTc)]
is)
(NotCovered, NotDiverged) -> (Provenance
final_prov, LMatch GhcTc (LHsExpr GhcTc)
mLMatch GhcTc (LHsExpr GhcTc)
-> [LMatch GhcTc (LHsExpr GhcTc)] -> [LMatch GhcTc (LHsExpr GhcTc)]
forall a. a -> [a] -> [a]
:[LMatch GhcTc (LHsExpr GhcTc)]
rs, Uncovered
final_u,[LMatch GhcTc (LHsExpr GhcTc)]
is)
(NotCovered, Diverged ) -> (Provenance
final_prov, [LMatch GhcTc (LHsExpr GhcTc)]
rs, Uncovered
final_u, LMatch GhcTc (LHsExpr GhcTc)
mLMatch GhcTc (LHsExpr GhcTc)
-> [LMatch GhcTc (LHsExpr GhcTc)] -> [LMatch GhcTc (LHsExpr GhcTc)]
forall a. a -> [a] -> [a]
:[LMatch GhcTc (LHsExpr GhcTc)]
is)
hsLMatchToLPats :: LMatch id body -> Located [LPat id]
hsLMatchToLPats :: LMatch id body -> Located [LPat id]
hsLMatchToLPats (LMatch id body -> Located (SrcSpanLess (LMatch id body))
forall a. HasSrcSpan a => a -> Located (SrcSpanLess a)
dL->L l :: SrcSpan
l (Match { m_pats = pats })) = SrcSpan -> SrcSpanLess (Located [LPat id]) -> Located [LPat id]
forall a. HasSrcSpan a => SrcSpan -> SrcSpanLess a -> a
cL SrcSpan
l [LPat id]
SrcSpanLess (Located [LPat id])
pats
hsLMatchToLPats _ = String -> Located [LPat id]
forall a. String -> a
panic "checMatches'"
checkEmptyCase' :: Id -> PmM PmResult
checkEmptyCase' :: TyVar -> PmM PmResult
checkEmptyCase' var :: TyVar
var = do
Delta
tm_ty_css <- PmM Delta
pmInitialTmTyCs
Either Type (TyCon, [InhabitationCandidate])
mb_candidates <- Bag TyVar
-> Type -> PmM (Either Type (TyCon, [InhabitationCandidate]))
inhabitationCandidates (Delta -> Bag TyVar
delta_ty_cs Delta
tm_ty_css) (TyVar -> Type
idType TyVar
var)
case Either Type (TyCon, [InhabitationCandidate])
mb_candidates of
Left ty :: Type
ty -> PmResult -> PmM PmResult
forall (m :: * -> *) a. Monad m => a -> m a
return (Type -> PmResult
uncoveredWithTy Type
ty)
Right (_, candidates :: [InhabitationCandidate]
candidates) -> do
Uncovered
missing_m <- ((InhabitationCandidate -> ListT DsM (Maybe ValVec))
-> [InhabitationCandidate] -> PmM Uncovered)
-> [InhabitationCandidate]
-> (InhabitationCandidate -> ListT DsM (Maybe ValVec))
-> PmM Uncovered
forall a b c. (a -> b -> c) -> b -> a -> c
flip (InhabitationCandidate -> ListT DsM (Maybe ValVec))
-> [InhabitationCandidate] -> PmM Uncovered
forall (m :: * -> *) a b.
Applicative m =>
(a -> m (Maybe b)) -> [a] -> m [b]
mapMaybeM [InhabitationCandidate]
candidates ((InhabitationCandidate -> ListT DsM (Maybe ValVec))
-> PmM Uncovered)
-> (InhabitationCandidate -> ListT DsM (Maybe ValVec))
-> PmM Uncovered
forall a b. (a -> b) -> a -> b
$
\InhabitationCandidate{ ic_val_abs :: InhabitationCandidate -> PmPat 'VA
ic_val_abs = PmPat 'VA
va, ic_tm_ct :: InhabitationCandidate -> ComplexEq
ic_tm_ct = ComplexEq
tm_ct
, ic_ty_cs :: InhabitationCandidate -> Bag TyVar
ic_ty_cs = Bag TyVar
ty_cs
, ic_strict_arg_tys :: InhabitationCandidate -> [Type]
ic_strict_arg_tys = [Type]
strict_arg_tys } -> do
Maybe Delta
mb_sat <- Delta -> ComplexEq -> Bag TyVar -> [Type] -> PmM (Maybe Delta)
pmIsSatisfiable Delta
tm_ty_css ComplexEq
tm_ct Bag TyVar
ty_cs [Type]
strict_arg_tys
Maybe ValVec -> ListT DsM (Maybe ValVec)
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Maybe ValVec -> ListT DsM (Maybe ValVec))
-> Maybe ValVec -> ListT DsM (Maybe ValVec)
forall a b. (a -> b) -> a -> b
$ (Delta -> ValVec) -> Maybe Delta -> Maybe ValVec
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ([PmPat 'VA] -> Delta -> ValVec
ValVec [PmPat 'VA
va]) Maybe Delta
mb_sat
PmResult -> PmM PmResult
forall (m :: * -> *) a. Monad m => a -> m a
return (PmResult -> PmM PmResult) -> PmResult -> PmM PmResult
forall a b. (a -> b) -> a -> b
$ if Uncovered -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null Uncovered
missing_m
then PmResult
emptyPmResult
else Provenance
-> [Located [LPat GhcTc]]
-> UncoveredCandidates
-> [Located [LPat GhcTc]]
-> PmResult
PmResult Provenance
FromBuiltin [] (Uncovered -> UncoveredCandidates
UncoveredPatterns Uncovered
missing_m) []
pmIsClosedType :: Type -> Bool
pmIsClosedType :: Type -> Bool
pmIsClosedType ty :: Type
ty
= case HasDebugCallStack => Type -> Maybe (TyCon, [Type])
Type -> Maybe (TyCon, [Type])
splitTyConApp_maybe Type
ty of
Just (tc :: TyCon
tc, ty_args :: [Type]
ty_args)
| TyCon -> Bool
is_algebraic_like TyCon
tc Bool -> Bool -> Bool
&& Bool -> Bool
not (TyCon -> Bool
isFamilyTyCon TyCon
tc)
-> ASSERT2( ty_args `lengthIs` tyConArity tc, ppr ty ) True
_other :: Maybe (TyCon, [Type])
_other -> Bool
False
where
is_algebraic_like :: TyCon -> Bool
is_algebraic_like :: TyCon -> Bool
is_algebraic_like tc :: TyCon
tc = TyCon -> Bool
isAlgTyCon TyCon
tc Bool -> Bool -> Bool
|| TyCon
tc TyCon -> TyCon -> Bool
forall a. Eq a => a -> a -> Bool
== TyCon
tYPETyCon
pmTopNormaliseType_maybe :: FamInstEnvs -> Bag EvVar -> Type
-> PmM (Maybe (Type, [DataCon], Type))
pmTopNormaliseType_maybe :: FamInstEnvs
-> Bag TyVar -> Type -> PmM (Maybe (Type, [DataCon], Type))
pmTopNormaliseType_maybe env :: FamInstEnvs
env ty_cs :: Bag TyVar
ty_cs typ :: Type
typ
= do (_, mb_typ' :: Maybe Type
mb_typ') <- DsM (Messages, Maybe Type) -> PmM (Messages, Maybe Type)
forall a. DsM a -> PmM a
liftD (DsM (Messages, Maybe Type) -> PmM (Messages, Maybe Type))
-> DsM (Messages, Maybe Type) -> PmM (Messages, Maybe Type)
forall a b. (a -> b) -> a -> b
$ TcM Type -> DsM (Messages, Maybe Type)
forall a. TcM a -> DsM (Messages, Maybe a)
initTcDsForSolver (TcM Type -> DsM (Messages, Maybe Type))
-> TcM Type -> DsM (Messages, Maybe Type)
forall a b. (a -> b) -> a -> b
$ Bag TyVar -> Type -> TcM Type
tcNormalise Bag TyVar
ty_cs Type
typ
Maybe (Type, [DataCon], Type)
-> PmM (Maybe (Type, [DataCon], Type))
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Maybe (Type, [DataCon], Type)
-> PmM (Maybe (Type, [DataCon], Type)))
-> Maybe (Type, [DataCon], Type)
-> PmM (Maybe (Type, [DataCon], Type))
forall a b. (a -> b) -> a -> b
$ do Type
typ' <- Maybe Type
mb_typ'
((ty_f :: [Type] -> [Type]
ty_f,tm_f :: [DataCon] -> [DataCon]
tm_f), ty :: Type
ty) <- NormaliseStepper ([Type] -> [Type], [DataCon] -> [DataCon])
-> (([Type] -> [Type], [DataCon] -> [DataCon])
-> ([Type] -> [Type], [DataCon] -> [DataCon])
-> ([Type] -> [Type], [DataCon] -> [DataCon]))
-> Type
-> Maybe (([Type] -> [Type], [DataCon] -> [DataCon]), Type)
forall ev.
NormaliseStepper ev -> (ev -> ev -> ev) -> Type -> Maybe (ev, Type)
topNormaliseTypeX NormaliseStepper ([Type] -> [Type], [DataCon] -> [DataCon])
stepper ([Type] -> [Type], [DataCon] -> [DataCon])
-> ([Type] -> [Type], [DataCon] -> [DataCon])
-> ([Type] -> [Type], [DataCon] -> [DataCon])
forall b c b c a a.
(b -> c, b -> c) -> (a -> b, a -> b) -> (a -> c, a -> c)
comb Type
typ'
(Type, [DataCon], Type) -> Maybe (Type, [DataCon], Type)
forall a. a -> Maybe a
Just (Type -> [Type] -> Type
eq_src_ty Type
ty (Type
typ' Type -> [Type] -> [Type]
forall a. a -> [a] -> [a]
: [Type] -> [Type]
ty_f [Type
ty]), [DataCon] -> [DataCon]
tm_f [], Type
ty)
where
eq_src_ty :: Type -> [Type] -> Type
eq_src_ty :: Type -> [Type] -> Type
eq_src_ty ty :: Type
ty tys :: [Type]
tys = Type -> (Type -> Type) -> Maybe Type -> Type
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Type
ty Type -> Type
forall a. a -> a
id ((Type -> Bool) -> [Type] -> Maybe Type
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Maybe a
find Type -> Bool
is_closed_or_data_family [Type]
tys)
is_closed_or_data_family :: Type -> Bool
is_closed_or_data_family :: Type -> Bool
is_closed_or_data_family ty :: Type
ty = Type -> Bool
pmIsClosedType Type
ty Bool -> Bool -> Bool
|| Type -> Bool
isDataFamilyAppType Type
ty
comb :: (b -> c, b -> c) -> (a -> b, a -> b) -> (a -> c, a -> c)
comb (tyf1 :: b -> c
tyf1, tmf1 :: b -> c
tmf1) (tyf2 :: a -> b
tyf2, tmf2 :: a -> b
tmf2) = (b -> c
tyf1 (b -> c) -> (a -> b) -> a -> c
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> b
tyf2, b -> c
tmf1 (b -> c) -> (a -> b) -> a -> c
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> b
tmf2)
stepper :: NormaliseStepper ([Type] -> [Type], [DataCon] -> [DataCon])
stepper = NormaliseStepper ([Type] -> [Type], [DataCon] -> [DataCon])
newTypeStepper NormaliseStepper ([Type] -> [Type], [DataCon] -> [DataCon])
-> NormaliseStepper ([Type] -> [Type], [DataCon] -> [DataCon])
-> NormaliseStepper ([Type] -> [Type], [DataCon] -> [DataCon])
forall ev.
NormaliseStepper ev -> NormaliseStepper ev -> NormaliseStepper ev
`composeSteppers` NormaliseStepper ([Type] -> [Type], [DataCon] -> [DataCon])
tyFamStepper
newTypeStepper :: NormaliseStepper ([Type] -> [Type],[DataCon] -> [DataCon])
newTypeStepper :: NormaliseStepper ([Type] -> [Type], [DataCon] -> [DataCon])
newTypeStepper rec_nts :: RecTcChecker
rec_nts tc :: TyCon
tc tys :: [Type]
tys
| Just (ty' :: Type
ty', _co :: Coercion
_co) <- TyCon -> [Type] -> Maybe (Type, Coercion)
instNewTyCon_maybe TyCon
tc [Type]
tys
= case RecTcChecker -> TyCon -> Maybe RecTcChecker
checkRecTc RecTcChecker
rec_nts TyCon
tc of
Just rec_nts' :: RecTcChecker
rec_nts' -> let tyf :: [Type] -> [Type]
tyf = ((TyCon -> [Type] -> Type
TyConApp TyCon
tc [Type]
tys)Type -> [Type] -> [Type]
forall a. a -> [a] -> [a]
:)
tmf :: [DataCon] -> [DataCon]
tmf = ((TyCon -> DataCon
tyConSingleDataCon TyCon
tc)DataCon -> [DataCon] -> [DataCon]
forall a. a -> [a] -> [a]
:)
in RecTcChecker
-> Type
-> ([Type] -> [Type], [DataCon] -> [DataCon])
-> NormaliseStepResult ([Type] -> [Type], [DataCon] -> [DataCon])
forall ev. RecTcChecker -> Type -> ev -> NormaliseStepResult ev
NS_Step RecTcChecker
rec_nts' Type
ty' ([Type] -> [Type]
tyf, [DataCon] -> [DataCon]
tmf)
Nothing -> NormaliseStepResult ([Type] -> [Type], [DataCon] -> [DataCon])
forall ev. NormaliseStepResult ev
NS_Abort
| Bool
otherwise
= NormaliseStepResult ([Type] -> [Type], [DataCon] -> [DataCon])
forall ev. NormaliseStepResult ev
NS_Done
tyFamStepper :: NormaliseStepper ([Type] -> [Type], [DataCon] -> [DataCon])
tyFamStepper :: NormaliseStepper ([Type] -> [Type], [DataCon] -> [DataCon])
tyFamStepper rec_nts :: RecTcChecker
rec_nts tc :: TyCon
tc tys :: [Type]
tys
= let (_args_co :: Coercion
_args_co, ntys :: [Type]
ntys, _res_co :: Coercion
_res_co) = FamInstEnvs
-> Role -> TyCon -> [Type] -> (Coercion, [Type], Coercion)
normaliseTcArgs FamInstEnvs
env Role
Representational TyCon
tc [Type]
tys in
case FamInstEnvs -> Role -> TyCon -> [Type] -> Maybe (Coercion, Type)
reduceTyFamApp_maybe FamInstEnvs
env Role
Representational TyCon
tc [Type]
ntys of
Just (_co :: Coercion
_co, rhs :: Type
rhs) -> RecTcChecker
-> Type
-> ([Type] -> [Type], [DataCon] -> [DataCon])
-> NormaliseStepResult ([Type] -> [Type], [DataCon] -> [DataCon])
forall ev. RecTcChecker -> Type -> ev -> NormaliseStepResult ev
NS_Step RecTcChecker
rec_nts Type
rhs ((Type
rhsType -> [Type] -> [Type]
forall a. a -> [a] -> [a]
:), [DataCon] -> [DataCon]
forall a. a -> a
id)
_ -> NormaliseStepResult ([Type] -> [Type], [DataCon] -> [DataCon])
forall ev. NormaliseStepResult ev
NS_Done
pmInitialTmTyCs :: PmM Delta
pmInitialTmTyCs :: PmM Delta
pmInitialTmTyCs = do
Bag TyVar
ty_cs <- DsM (Bag TyVar) -> PmM (Bag TyVar)
forall a. DsM a -> PmM a
liftD DsM (Bag TyVar)
getDictsDs
[ComplexEq]
tm_cs <- (SimpleEq -> ComplexEq) -> [SimpleEq] -> [ComplexEq]
forall a b. (a -> b) -> [a] -> [b]
map SimpleEq -> ComplexEq
toComplex ([SimpleEq] -> [ComplexEq])
-> (Bag SimpleEq -> [SimpleEq]) -> Bag SimpleEq -> [ComplexEq]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Bag SimpleEq -> [SimpleEq]
forall a. Bag a -> [a]
bagToList (Bag SimpleEq -> [ComplexEq])
-> ListT DsM (Bag SimpleEq) -> ListT DsM [ComplexEq]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> DsM (Bag SimpleEq) -> ListT DsM (Bag SimpleEq)
forall a. DsM a -> PmM a
liftD DsM (Bag SimpleEq)
getTmCsDs
Bool
sat_ty <- Bag TyVar -> PmM Bool
tyOracle Bag TyVar
ty_cs
let initTyCs :: Bag TyVar
initTyCs = if Bool
sat_ty then Bag TyVar
ty_cs else Bag TyVar
forall a. Bag a
emptyBag
initTmState :: TmState
initTmState = TmState -> Maybe TmState -> TmState
forall a. a -> Maybe a -> a
fromMaybe TmState
initialTmState (TmState -> [ComplexEq] -> Maybe TmState
tmOracle TmState
initialTmState [ComplexEq]
tm_cs)
Delta -> PmM Delta
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Delta -> PmM Delta) -> Delta -> PmM Delta
forall a b. (a -> b) -> a -> b
$ MkDelta :: Bag TyVar -> TmState -> Delta
MkDelta{ delta_tm_cs :: TmState
delta_tm_cs = TmState
initTmState, delta_ty_cs :: Bag TyVar
delta_ty_cs = Bag TyVar
initTyCs }
pmIsSatisfiable
:: Delta
-> ComplexEq
-> Bag EvVar
-> [Type]
-> PmM (Maybe Delta)
pmIsSatisfiable :: Delta -> ComplexEq -> Bag TyVar -> [Type] -> PmM (Maybe Delta)
pmIsSatisfiable amb_cs :: Delta
amb_cs new_tm_c :: ComplexEq
new_tm_c new_ty_cs :: Bag TyVar
new_ty_cs strict_arg_tys :: [Type]
strict_arg_tys = do
Maybe Delta
mb_sat <- Delta -> ComplexEq -> Bag TyVar -> PmM (Maybe Delta)
tmTyCsAreSatisfiable Delta
amb_cs ComplexEq
new_tm_c Bag TyVar
new_ty_cs
case Maybe Delta
mb_sat of
Nothing -> Maybe Delta -> PmM (Maybe Delta)
forall (f :: * -> *) a. Applicative f => a -> f a
pure Maybe Delta
forall a. Maybe a
Nothing
Just delta :: Delta
delta -> do
Bool
all_non_void <- RecTcChecker -> Delta -> [Type] -> PmM Bool
checkAllNonVoid RecTcChecker
initRecTc Delta
delta [Type]
strict_arg_tys
Maybe Delta -> PmM (Maybe Delta)
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Maybe Delta -> PmM (Maybe Delta))
-> Maybe Delta -> PmM (Maybe Delta)
forall a b. (a -> b) -> a -> b
$ if Bool
all_non_void
then Delta -> Maybe Delta
forall a. a -> Maybe a
Just Delta
delta
else Maybe Delta
forall a. Maybe a
Nothing
tmTyCsAreSatisfiable
:: Delta
-> ComplexEq
-> Bag EvVar
-> PmM (Maybe Delta)
tmTyCsAreSatisfiable :: Delta -> ComplexEq -> Bag TyVar -> PmM (Maybe Delta)
tmTyCsAreSatisfiable
(MkDelta{ delta_tm_cs :: Delta -> TmState
delta_tm_cs = TmState
amb_tm_cs, delta_ty_cs :: Delta -> Bag TyVar
delta_ty_cs = Bag TyVar
amb_ty_cs })
new_tm_c :: ComplexEq
new_tm_c new_ty_cs :: Bag TyVar
new_ty_cs = do
let ty_cs :: Bag TyVar
ty_cs = Bag TyVar
new_ty_cs Bag TyVar -> Bag TyVar -> Bag TyVar
forall a. Bag a -> Bag a -> Bag a
`unionBags` Bag TyVar
amb_ty_cs
Bool
sat_ty <- if Bag TyVar -> Bool
forall a. Bag a -> Bool
isEmptyBag Bag TyVar
new_ty_cs
then Bool -> PmM Bool
forall (f :: * -> *) a. Applicative f => a -> f a
pure Bool
True
else Bag TyVar -> PmM Bool
tyOracle Bag TyVar
ty_cs
Maybe Delta -> PmM (Maybe Delta)
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Maybe Delta -> PmM (Maybe Delta))
-> Maybe Delta -> PmM (Maybe Delta)
forall a b. (a -> b) -> a -> b
$ case (Bool
sat_ty, TmState -> ComplexEq -> Maybe TmState
solveOneEq TmState
amb_tm_cs ComplexEq
new_tm_c) of
(True, Just term_cs :: TmState
term_cs) -> Delta -> Maybe Delta
forall a. a -> Maybe a
Just (Delta -> Maybe Delta) -> Delta -> Maybe Delta
forall a b. (a -> b) -> a -> b
$ MkDelta :: Bag TyVar -> TmState -> Delta
MkDelta{ delta_ty_cs :: Bag TyVar
delta_ty_cs = Bag TyVar
ty_cs
, delta_tm_cs :: TmState
delta_tm_cs = TmState
term_cs }
_unsat :: (Bool, Maybe TmState)
_unsat -> Maybe Delta
forall a. Maybe a
Nothing
checkAllNonVoid :: RecTcChecker -> Delta -> [Type] -> PmM Bool
checkAllNonVoid :: RecTcChecker -> Delta -> [Type] -> PmM Bool
checkAllNonVoid rec_ts :: RecTcChecker
rec_ts amb_cs :: Delta
amb_cs strict_arg_tys :: [Type]
strict_arg_tys = do
FamInstEnvs
fam_insts <- DsM FamInstEnvs -> PmM FamInstEnvs
forall a. DsM a -> PmM a
liftD DsM FamInstEnvs
dsGetFamInstEnvs
let definitely_inhabited :: Type -> PmM Bool
definitely_inhabited =
FamInstEnvs -> Bag TyVar -> Type -> PmM Bool
definitelyInhabitedType FamInstEnvs
fam_insts (Delta -> Bag TyVar
delta_ty_cs Delta
amb_cs)
[Type]
tys_to_check <- (Type -> PmM Bool) -> [Type] -> ListT DsM [Type]
forall (m :: * -> *) a.
Applicative m =>
(a -> m Bool) -> [a] -> m [a]
filterOutM Type -> PmM Bool
definitely_inhabited [Type]
strict_arg_tys
let rec_max_bound :: Int
rec_max_bound | [Type]
tys_to_check [Type] -> Int -> Bool
forall a. [a] -> Int -> Bool
`lengthExceeds` 1
= 1
| Bool
otherwise
= Int
defaultRecTcMaxBound
rec_ts' :: RecTcChecker
rec_ts' = Int -> RecTcChecker -> RecTcChecker
setRecTcMaxBound Int
rec_max_bound RecTcChecker
rec_ts
(Type -> PmM Bool) -> [Type] -> PmM Bool
forall (m :: * -> *) a. Monad m => (a -> m Bool) -> [a] -> m Bool
allM (RecTcChecker -> Delta -> Type -> PmM Bool
nonVoid RecTcChecker
rec_ts' Delta
amb_cs) [Type]
tys_to_check
nonVoid
:: RecTcChecker
-> Delta
-> Type
-> PmM Bool
nonVoid :: RecTcChecker -> Delta -> Type -> PmM Bool
nonVoid rec_ts :: RecTcChecker
rec_ts amb_cs :: Delta
amb_cs strict_arg_ty :: Type
strict_arg_ty = do
Either Type (TyCon, [InhabitationCandidate])
mb_cands <- Bag TyVar
-> Type -> PmM (Either Type (TyCon, [InhabitationCandidate]))
inhabitationCandidates (Delta -> Bag TyVar
delta_ty_cs Delta
amb_cs) Type
strict_arg_ty
case Either Type (TyCon, [InhabitationCandidate])
mb_cands of
Right (tc :: TyCon
tc, cands :: [InhabitationCandidate]
cands)
| Just rec_ts' :: RecTcChecker
rec_ts' <- RecTcChecker -> TyCon -> Maybe RecTcChecker
checkRecTc RecTcChecker
rec_ts TyCon
tc
-> (InhabitationCandidate -> PmM Bool)
-> [InhabitationCandidate] -> PmM Bool
forall (m :: * -> *) a. Monad m => (a -> m Bool) -> [a] -> m Bool
anyM (RecTcChecker -> Delta -> InhabitationCandidate -> PmM Bool
cand_is_inhabitable RecTcChecker
rec_ts' Delta
amb_cs) [InhabitationCandidate]
cands
_ -> Bool -> PmM Bool
forall (f :: * -> *) a. Applicative f => a -> f a
pure Bool
True
where
cand_is_inhabitable :: RecTcChecker -> Delta
-> InhabitationCandidate -> PmM Bool
cand_is_inhabitable :: RecTcChecker -> Delta -> InhabitationCandidate -> PmM Bool
cand_is_inhabitable rec_ts :: RecTcChecker
rec_ts amb_cs :: Delta
amb_cs
(InhabitationCandidate{ ic_tm_ct :: InhabitationCandidate -> ComplexEq
ic_tm_ct = ComplexEq
new_term_c
, ic_ty_cs :: InhabitationCandidate -> Bag TyVar
ic_ty_cs = Bag TyVar
new_ty_cs
, ic_strict_arg_tys :: InhabitationCandidate -> [Type]
ic_strict_arg_tys = [Type]
new_strict_arg_tys }) = do
Maybe Delta
mb_sat <- Delta -> ComplexEq -> Bag TyVar -> PmM (Maybe Delta)
tmTyCsAreSatisfiable Delta
amb_cs ComplexEq
new_term_c Bag TyVar
new_ty_cs
case Maybe Delta
mb_sat of
Nothing -> Bool -> PmM Bool
forall (f :: * -> *) a. Applicative f => a -> f a
pure Bool
False
Just new_delta :: Delta
new_delta -> do
RecTcChecker -> Delta -> [Type] -> PmM Bool
checkAllNonVoid RecTcChecker
rec_ts Delta
new_delta [Type]
new_strict_arg_tys
definitelyInhabitedType :: FamInstEnvs -> Bag EvVar -> Type -> PmM Bool
definitelyInhabitedType :: FamInstEnvs -> Bag TyVar -> Type -> PmM Bool
definitelyInhabitedType env :: FamInstEnvs
env ty_cs :: Bag TyVar
ty_cs ty :: Type
ty = do
Maybe (Type, [DataCon], Type)
mb_res <- FamInstEnvs
-> Bag TyVar -> Type -> PmM (Maybe (Type, [DataCon], Type))
pmTopNormaliseType_maybe FamInstEnvs
env Bag TyVar
ty_cs Type
ty
Bool -> PmM Bool
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Bool -> PmM Bool) -> Bool -> PmM Bool
forall a b. (a -> b) -> a -> b
$ case Maybe (Type, [DataCon], Type)
mb_res of
Just (_, cons :: [DataCon]
cons, _) -> (DataCon -> Bool) -> [DataCon] -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
any DataCon -> Bool
meets_criteria [DataCon]
cons
Nothing -> Bool
False
where
meets_criteria :: DataCon -> Bool
meets_criteria :: DataCon -> Bool
meets_criteria con :: DataCon
con =
[EqSpec] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null (DataCon -> [EqSpec]
dataConEqSpec DataCon
con) Bool -> Bool -> Bool
&&
[HsImplBang] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null (DataCon -> [HsImplBang]
dataConImplBangs DataCon
con)
inhabitationCandidates :: Bag EvVar -> Type
-> PmM (Either Type (TyCon, [InhabitationCandidate]))
inhabitationCandidates :: Bag TyVar
-> Type -> PmM (Either Type (TyCon, [InhabitationCandidate]))
inhabitationCandidates ty_cs :: Bag TyVar
ty_cs ty :: Type
ty = do
FamInstEnvs
fam_insts <- DsM FamInstEnvs -> PmM FamInstEnvs
forall a. DsM a -> PmM a
liftD DsM FamInstEnvs
dsGetFamInstEnvs
Maybe (Type, [DataCon], Type)
mb_norm_res <- FamInstEnvs
-> Bag TyVar -> Type -> PmM (Maybe (Type, [DataCon], Type))
pmTopNormaliseType_maybe FamInstEnvs
fam_insts Bag TyVar
ty_cs Type
ty
case Maybe (Type, [DataCon], Type)
mb_norm_res of
Just (src_ty :: Type
src_ty, dcs :: [DataCon]
dcs, core_ty :: Type
core_ty) -> Type
-> Type
-> [DataCon]
-> PmM (Either Type (TyCon, [InhabitationCandidate]))
alts_to_check Type
src_ty Type
core_ty [DataCon]
dcs
Nothing -> Type
-> Type
-> [DataCon]
-> PmM (Either Type (TyCon, [InhabitationCandidate]))
alts_to_check Type
ty Type
ty []
where
trivially_inhabited :: [TyCon]
trivially_inhabited = [ TyCon
charTyCon, TyCon
doubleTyCon, TyCon
floatTyCon
, TyCon
intTyCon, TyCon
wordTyCon, TyCon
word8TyCon ]
build_tm :: ValAbs -> [DataCon] -> ValAbs
build_tm :: PmPat 'VA -> [DataCon] -> PmPat 'VA
build_tm = (DataCon -> PmPat 'VA -> PmPat 'VA)
-> PmPat 'VA -> [DataCon] -> PmPat 'VA
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr (\dc :: DataCon
dc e :: PmPat 'VA
e -> ConLike -> [Type] -> [TyVar] -> [TyVar] -> [PmPat 'VA] -> PmPat 'VA
forall (t :: PatTy).
ConLike -> [Type] -> [TyVar] -> [TyVar] -> [PmPat t] -> PmPat t
PmCon (DataCon -> ConLike
RealDataCon DataCon
dc) [] [] [] [PmPat 'VA
e])
alts_to_check :: Type -> Type -> [DataCon]
-> PmM (Either Type (TyCon, [InhabitationCandidate]))
alts_to_check :: Type
-> Type
-> [DataCon]
-> PmM (Either Type (TyCon, [InhabitationCandidate]))
alts_to_check src_ty :: Type
src_ty core_ty :: Type
core_ty dcs :: [DataCon]
dcs = case HasDebugCallStack => Type -> Maybe (TyCon, [Type])
Type -> Maybe (TyCon, [Type])
splitTyConApp_maybe Type
core_ty of
Just (tc :: TyCon
tc, _)
| TyCon
tc TyCon -> [TyCon] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` [TyCon]
trivially_inhabited
-> case [DataCon]
dcs of
[] -> Either Type (TyCon, [InhabitationCandidate])
-> PmM (Either Type (TyCon, [InhabitationCandidate]))
forall (m :: * -> *) a. Monad m => a -> m a
return (Type -> Either Type (TyCon, [InhabitationCandidate])
forall a b. a -> Either a b
Left Type
src_ty)
(_:_) -> do TyVar
var <- DsM TyVar -> PmM TyVar
forall a. DsM a -> PmM a
liftD (DsM TyVar -> PmM TyVar) -> DsM TyVar -> PmM TyVar
forall a b. (a -> b) -> a -> b
$ Type -> DsM TyVar
mkPmId Type
core_ty
let va :: PmPat 'VA
va = PmPat 'VA -> [DataCon] -> PmPat 'VA
build_tm (TyVar -> PmPat 'VA
forall (t :: PatTy). TyVar -> PmPat t
PmVar TyVar
var) [DataCon]
dcs
Either Type (TyCon, [InhabitationCandidate])
-> PmM (Either Type (TyCon, [InhabitationCandidate]))
forall (m :: * -> *) a. Monad m => a -> m a
return (Either Type (TyCon, [InhabitationCandidate])
-> PmM (Either Type (TyCon, [InhabitationCandidate])))
-> Either Type (TyCon, [InhabitationCandidate])
-> PmM (Either Type (TyCon, [InhabitationCandidate]))
forall a b. (a -> b) -> a -> b
$ (TyCon, [InhabitationCandidate])
-> Either Type (TyCon, [InhabitationCandidate])
forall a b. b -> Either a b
Right (TyCon
tc, [InhabitationCandidate :: PmPat 'VA
-> ComplexEq -> Bag TyVar -> [Type] -> InhabitationCandidate
InhabitationCandidate
{ ic_val_abs :: PmPat 'VA
ic_val_abs = PmPat 'VA
va, ic_tm_ct :: ComplexEq
ic_tm_ct = TyVar -> ComplexEq
mkIdEq TyVar
var
, ic_ty_cs :: Bag TyVar
ic_ty_cs = Bag TyVar
forall a. Bag a
emptyBag, ic_strict_arg_tys :: [Type]
ic_strict_arg_tys = [] }])
| Type -> Bool
pmIsClosedType Type
core_ty Bool -> Bool -> Bool
&& Bool -> Bool
not (TyCon -> Bool
isAbstractTyCon TyCon
tc)
-> DsM (Either Type (TyCon, [InhabitationCandidate]))
-> PmM (Either Type (TyCon, [InhabitationCandidate]))
forall a. DsM a -> PmM a
liftD (DsM (Either Type (TyCon, [InhabitationCandidate]))
-> PmM (Either Type (TyCon, [InhabitationCandidate])))
-> DsM (Either Type (TyCon, [InhabitationCandidate]))
-> PmM (Either Type (TyCon, [InhabitationCandidate]))
forall a b. (a -> b) -> a -> b
$ do
TyVar
var <- Type -> DsM TyVar
mkPmId Type
core_ty
[InhabitationCandidate]
alts <- (DataCon -> IOEnv (Env DsGblEnv DsLclEnv) InhabitationCandidate)
-> [DataCon]
-> IOEnv (Env DsGblEnv DsLclEnv) [InhabitationCandidate]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM (TyVar
-> ConLike -> IOEnv (Env DsGblEnv DsLclEnv) InhabitationCandidate
mkOneConFull TyVar
var (ConLike -> IOEnv (Env DsGblEnv DsLclEnv) InhabitationCandidate)
-> (DataCon -> ConLike)
-> DataCon
-> IOEnv (Env DsGblEnv DsLclEnv) InhabitationCandidate
forall b c a. (b -> c) -> (a -> b) -> a -> c
. DataCon -> ConLike
RealDataCon) (TyCon -> [DataCon]
tyConDataCons TyCon
tc)
Either Type (TyCon, [InhabitationCandidate])
-> DsM (Either Type (TyCon, [InhabitationCandidate]))
forall (m :: * -> *) a. Monad m => a -> m a
return (Either Type (TyCon, [InhabitationCandidate])
-> DsM (Either Type (TyCon, [InhabitationCandidate])))
-> Either Type (TyCon, [InhabitationCandidate])
-> DsM (Either Type (TyCon, [InhabitationCandidate]))
forall a b. (a -> b) -> a -> b
$ (TyCon, [InhabitationCandidate])
-> Either Type (TyCon, [InhabitationCandidate])
forall a b. b -> Either a b
Right
(TyCon
tc, [ InhabitationCandidate
alt{ic_val_abs :: PmPat 'VA
ic_val_abs = PmPat 'VA -> [DataCon] -> PmPat 'VA
build_tm (InhabitationCandidate -> PmPat 'VA
ic_val_abs InhabitationCandidate
alt) [DataCon]
dcs}
| InhabitationCandidate
alt <- [InhabitationCandidate]
alts ])
_other :: Maybe (TyCon, [Type])
_other -> Either Type (TyCon, [InhabitationCandidate])
-> PmM (Either Type (TyCon, [InhabitationCandidate]))
forall (m :: * -> *) a. Monad m => a -> m a
return (Type -> Either Type (TyCon, [InhabitationCandidate])
forall a b. a -> Either a b
Left Type
src_ty)
nullaryConPattern :: ConLike -> Pattern
nullaryConPattern :: ConLike -> PmPat 'PAT
nullaryConPattern con :: ConLike
con =
PmCon :: forall (t :: PatTy).
ConLike -> [Type] -> [TyVar] -> [TyVar] -> [PmPat t] -> PmPat t
PmCon { pm_con_con :: ConLike
pm_con_con = ConLike
con, pm_con_arg_tys :: [Type]
pm_con_arg_tys = []
, pm_con_tvs :: [TyVar]
pm_con_tvs = [], pm_con_dicts :: [TyVar]
pm_con_dicts = [], pm_con_args :: PatVec
pm_con_args = [] }
{-# INLINE nullaryConPattern #-}
truePattern :: Pattern
truePattern :: PmPat 'PAT
truePattern = ConLike -> PmPat 'PAT
nullaryConPattern (DataCon -> ConLike
RealDataCon DataCon
trueDataCon)
{-# INLINE truePattern #-}
fake_pat :: Pattern
fake_pat :: PmPat 'PAT
fake_pat = $WPmGrd :: PatVec -> PmExpr -> PmPat 'PAT
PmGrd { pm_grd_pv :: PatVec
pm_grd_pv = [PmPat 'PAT
truePattern]
, pm_grd_expr :: PmExpr
pm_grd_expr = HsExpr GhcTc -> PmExpr
PmExprOther (XEWildPat GhcTc -> HsExpr GhcTc
forall p. XEWildPat p -> HsExpr p
EWildPat XEWildPat GhcTc
NoExt
noExt) }
{-# INLINE fake_pat #-}
isFakeGuard :: [Pattern] -> PmExpr -> Bool
isFakeGuard :: PatVec -> PmExpr -> Bool
isFakeGuard [PmCon { pm_con_con :: forall (t :: PatTy). PmPat t -> ConLike
pm_con_con = RealDataCon c :: DataCon
c }] (PmExprOther (EWildPat _))
| DataCon
c DataCon -> DataCon -> Bool
forall a. Eq a => a -> a -> Bool
== DataCon
trueDataCon = Bool
True
| Bool
otherwise = Bool
False
isFakeGuard _pats :: PatVec
_pats _e :: PmExpr
_e = Bool
False
mkCanFailPmPat :: Type -> DsM PatVec
mkCanFailPmPat :: Type -> DsM PatVec
mkCanFailPmPat ty :: Type
ty = do
PmPat 'PAT
var <- Type -> DsM (PmPat 'PAT)
forall (p :: PatTy). Type -> DsM (PmPat p)
mkPmVar Type
ty
PatVec -> DsM PatVec
forall (m :: * -> *) a. Monad m => a -> m a
return [PmPat 'PAT
var, PmPat 'PAT
fake_pat]
vanillaConPattern :: ConLike -> [Type] -> PatVec -> Pattern
vanillaConPattern :: ConLike -> [Type] -> PatVec -> PmPat 'PAT
vanillaConPattern con :: ConLike
con arg_tys :: [Type]
arg_tys args :: PatVec
args =
PmCon :: forall (t :: PatTy).
ConLike -> [Type] -> [TyVar] -> [TyVar] -> [PmPat t] -> PmPat t
PmCon { pm_con_con :: ConLike
pm_con_con = ConLike
con, pm_con_arg_tys :: [Type]
pm_con_arg_tys = [Type]
arg_tys
, pm_con_tvs :: [TyVar]
pm_con_tvs = [], pm_con_dicts :: [TyVar]
pm_con_dicts = [], pm_con_args :: PatVec
pm_con_args = PatVec
args }
{-# INLINE vanillaConPattern #-}
nilPattern :: Type -> Pattern
nilPattern :: Type -> PmPat 'PAT
nilPattern ty :: Type
ty =
PmCon :: forall (t :: PatTy).
ConLike -> [Type] -> [TyVar] -> [TyVar] -> [PmPat t] -> PmPat t
PmCon { pm_con_con :: ConLike
pm_con_con = DataCon -> ConLike
RealDataCon DataCon
nilDataCon, pm_con_arg_tys :: [Type]
pm_con_arg_tys = [Type
ty]
, pm_con_tvs :: [TyVar]
pm_con_tvs = [], pm_con_dicts :: [TyVar]
pm_con_dicts = []
, pm_con_args :: PatVec
pm_con_args = [] }
{-# INLINE nilPattern #-}
mkListPatVec :: Type -> PatVec -> PatVec -> PatVec
mkListPatVec :: Type -> PatVec -> PatVec -> PatVec
mkListPatVec ty :: Type
ty xs :: PatVec
xs ys :: PatVec
ys = [PmCon :: forall (t :: PatTy).
ConLike -> [Type] -> [TyVar] -> [TyVar] -> [PmPat t] -> PmPat t
PmCon { pm_con_con :: ConLike
pm_con_con = DataCon -> ConLike
RealDataCon DataCon
consDataCon
, pm_con_arg_tys :: [Type]
pm_con_arg_tys = [Type
ty]
, pm_con_tvs :: [TyVar]
pm_con_tvs = [], pm_con_dicts :: [TyVar]
pm_con_dicts = []
, pm_con_args :: PatVec
pm_con_args = PatVec
xsPatVec -> PatVec -> PatVec
forall a. [a] -> [a] -> [a]
++PatVec
ys }]
{-# INLINE mkListPatVec #-}
mkLitPattern :: HsLit GhcTc -> Pattern
mkLitPattern :: HsLit GhcTc -> PmPat 'PAT
mkLitPattern lit :: HsLit GhcTc
lit = PmLit :: forall (t :: PatTy). PmLit -> PmPat t
PmLit { pm_lit_lit :: PmLit
pm_lit_lit = HsLit GhcTc -> PmLit
PmSLit HsLit GhcTc
lit }
{-# INLINE mkLitPattern #-}
translatePat :: FamInstEnvs -> Pat GhcTc -> DsM PatVec
translatePat :: FamInstEnvs -> LPat GhcTc -> DsM PatVec
translatePat fam_insts :: FamInstEnvs
fam_insts pat :: LPat GhcTc
pat = case LPat GhcTc
pat of
WildPat ty :: XWildPat GhcTc
ty -> [Type] -> DsM PatVec
mkPmVars [Type
XWildPat GhcTc
ty]
VarPat _ id :: Located (IdP GhcTc)
id -> PatVec -> DsM PatVec
forall (m :: * -> *) a. Monad m => a -> m a
return [TyVar -> PmPat 'PAT
forall (t :: PatTy). TyVar -> PmPat t
PmVar (Located TyVar -> SrcSpanLess (Located TyVar)
forall a. HasSrcSpan a => a -> SrcSpanLess a
unLoc Located TyVar
Located (IdP GhcTc)
id)]
ParPat _ p :: LPat GhcTc
p -> FamInstEnvs -> LPat GhcTc -> DsM PatVec
translatePat FamInstEnvs
fam_insts (LPat GhcTc -> SrcSpanLess (LPat GhcTc)
forall a. HasSrcSpan a => a -> SrcSpanLess a
unLoc LPat GhcTc
p)
LazyPat _ _ -> [Type] -> DsM PatVec
mkPmVars [LPat GhcTc -> Type
hsPatType LPat GhcTc
pat]
BangPat _ p :: LPat GhcTc
p -> FamInstEnvs -> LPat GhcTc -> DsM PatVec
translatePat FamInstEnvs
fam_insts (LPat GhcTc -> SrcSpanLess (LPat GhcTc)
forall a. HasSrcSpan a => a -> SrcSpanLess a
unLoc LPat GhcTc
p)
AsPat _ lid :: Located (IdP GhcTc)
lid p :: LPat GhcTc
p -> do
PatVec
ps <- FamInstEnvs -> LPat GhcTc -> DsM PatVec
translatePat FamInstEnvs
fam_insts (LPat GhcTc -> SrcSpanLess (LPat GhcTc)
forall a. HasSrcSpan a => a -> SrcSpanLess a
unLoc LPat GhcTc
p)
let [e :: PmExpr
e] = (PmPat 'VA -> PmExpr) -> [PmPat 'VA] -> [PmExpr]
forall a b. (a -> b) -> [a] -> [b]
map PmPat 'VA -> PmExpr
vaToPmExpr (PatVec -> [PmPat 'VA]
coercePatVec PatVec
ps)
g :: PmPat 'PAT
g = PatVec -> PmExpr -> PmPat 'PAT
PmGrd [TyVar -> PmPat 'PAT
forall (t :: PatTy). TyVar -> PmPat t
PmVar (Located TyVar -> SrcSpanLess (Located TyVar)
forall a. HasSrcSpan a => a -> SrcSpanLess a
unLoc Located TyVar
Located (IdP GhcTc)
lid)] PmExpr
e
PatVec -> DsM PatVec
forall (m :: * -> *) a. Monad m => a -> m a
return (PatVec
ps PatVec -> PatVec -> PatVec
forall a. [a] -> [a] -> [a]
++ [PmPat 'PAT
g])
SigPat _ p :: LPat GhcTc
p _ty :: LHsSigWcType (NoGhcTc GhcTc)
_ty -> FamInstEnvs -> LPat GhcTc -> DsM PatVec
translatePat FamInstEnvs
fam_insts (LPat GhcTc -> SrcSpanLess (LPat GhcTc)
forall a. HasSrcSpan a => a -> SrcSpanLess a
unLoc LPat GhcTc
p)
CoPat _ wrapper :: HsWrapper
wrapper p :: LPat GhcTc
p ty :: Type
ty
| HsWrapper -> Bool
isIdHsWrapper HsWrapper
wrapper -> FamInstEnvs -> LPat GhcTc -> DsM PatVec
translatePat FamInstEnvs
fam_insts LPat GhcTc
p
| WpCast co :: Coercion
co <- HsWrapper
wrapper, Coercion -> Bool
isReflexiveCo Coercion
co -> FamInstEnvs -> LPat GhcTc -> DsM PatVec
translatePat FamInstEnvs
fam_insts LPat GhcTc
p
| Bool
otherwise -> do
PatVec
ps <- FamInstEnvs -> LPat GhcTc -> DsM PatVec
translatePat FamInstEnvs
fam_insts LPat GhcTc
p
(xp :: PmPat 'PAT
xp,xe :: LHsExpr GhcTc
xe) <- Type -> DsM (PmPat 'PAT, LHsExpr GhcTc)
mkPmId2Forms Type
ty
let g :: PmPat 'PAT
g = PatVec -> HsExpr GhcTc -> PmPat 'PAT
mkGuard PatVec
ps (HsWrapper -> HsExpr GhcTc -> HsExpr GhcTc
forall (id :: Pass).
HsWrapper -> HsExpr (GhcPass id) -> HsExpr (GhcPass id)
mkHsWrap HsWrapper
wrapper (LHsExpr GhcTc -> SrcSpanLess (LHsExpr GhcTc)
forall a. HasSrcSpan a => a -> SrcSpanLess a
unLoc LHsExpr GhcTc
xe))
PatVec -> DsM PatVec
forall (m :: * -> *) a. Monad m => a -> m a
return [PmPat 'PAT
xp,PmPat 'PAT
g]
NPlusKPat ty :: XNPlusKPat GhcTc
ty (Located (IdP GhcTc) -> Located (SrcSpanLess (Located TyVar))
forall a. HasSrcSpan a => a -> Located (SrcSpanLess a)
dL->L _ _n :: SrcSpanLess (Located TyVar)
_n) _k1 :: Located (HsOverLit GhcTc)
_k1 _k2 :: HsOverLit GhcTc
_k2 _ge :: SyntaxExpr GhcTc
_ge _minus :: SyntaxExpr GhcTc
_minus -> Type -> DsM PatVec
mkCanFailPmPat Type
XNPlusKPat GhcTc
ty
ViewPat arg_ty :: XViewPat GhcTc
arg_ty lexpr :: LHsExpr GhcTc
lexpr lpat :: LPat GhcTc
lpat -> do
PatVec
ps <- FamInstEnvs -> LPat GhcTc -> DsM PatVec
translatePat FamInstEnvs
fam_insts (LPat GhcTc -> SrcSpanLess (LPat GhcTc)
forall a. HasSrcSpan a => a -> SrcSpanLess a
unLoc LPat GhcTc
lpat)
case (PmPat 'PAT -> Bool) -> PatVec -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
all PmPat 'PAT -> Bool
cantFailPattern PatVec
ps of
True -> do
(xp :: PmPat 'PAT
xp,xe :: LHsExpr GhcTc
xe) <- Type -> DsM (PmPat 'PAT, LHsExpr GhcTc)
mkPmId2Forms Type
XViewPat GhcTc
arg_ty
let g :: PmPat 'PAT
g = PatVec -> HsExpr GhcTc -> PmPat 'PAT
mkGuard PatVec
ps (XApp GhcTc -> LHsExpr GhcTc -> LHsExpr GhcTc -> HsExpr GhcTc
forall p. XApp p -> LHsExpr p -> LHsExpr p -> HsExpr p
HsApp XApp GhcTc
NoExt
noExt LHsExpr GhcTc
lexpr LHsExpr GhcTc
xe)
PatVec -> DsM PatVec
forall (m :: * -> *) a. Monad m => a -> m a
return [PmPat 'PAT
xp,PmPat 'PAT
g]
False -> Type -> DsM PatVec
mkCanFailPmPat Type
XViewPat GhcTc
arg_ty
ListPat (ListPatTc ty Nothing) ps :: [LPat GhcTc]
ps -> do
(PatVec -> PatVec -> PatVec) -> PatVec -> [PatVec] -> PatVec
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr (Type -> PatVec -> PatVec -> PatVec
mkListPatVec Type
ty) [Type -> PmPat 'PAT
nilPattern Type
ty]
([PatVec] -> PatVec)
-> IOEnv (Env DsGblEnv DsLclEnv) [PatVec] -> DsM PatVec
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> FamInstEnvs
-> [LPat GhcTc] -> IOEnv (Env DsGblEnv DsLclEnv) [PatVec]
translatePatVec FamInstEnvs
fam_insts ((LPat GhcTc -> LPat GhcTc) -> [LPat GhcTc] -> [LPat GhcTc]
forall a b. (a -> b) -> [a] -> [b]
map LPat GhcTc -> LPat GhcTc
forall a. HasSrcSpan a => a -> SrcSpanLess a
unLoc [LPat GhcTc]
ps)
ListPat (ListPatTc _elem_ty (Just (pat_ty, _to_list))) lpats :: [LPat GhcTc]
lpats -> do
DynFlags
dflags <- IOEnv (Env DsGblEnv DsLclEnv) DynFlags
forall (m :: * -> *). HasDynFlags m => m DynFlags
getDynFlags
if Extension -> DynFlags -> Bool
xopt Extension
LangExt.RebindableSyntax DynFlags
dflags
then Type -> DsM PatVec
mkCanFailPmPat Type
pat_ty
else case Type -> Maybe Type
splitListTyConApp_maybe Type
pat_ty of
Just e_ty :: Type
e_ty -> FamInstEnvs -> LPat GhcTc -> DsM PatVec
translatePat FamInstEnvs
fam_insts
(XListPat GhcTc -> [LPat GhcTc] -> LPat GhcTc
forall p. XListPat p -> [LPat p] -> LPat p
ListPat (Type -> Maybe (Type, SyntaxExpr GhcTc) -> ListPatTc
ListPatTc Type
e_ty Maybe (Type, SyntaxExpr GhcTc)
forall a. Maybe a
Nothing) [LPat GhcTc]
lpats)
Nothing -> Type -> DsM PatVec
mkCanFailPmPat Type
pat_ty
ConPatOut { pat_con :: forall p. LPat p -> Located ConLike
pat_con = (Located ConLike -> Located (SrcSpanLess (Located ConLike))
forall a. HasSrcSpan a => a -> Located (SrcSpanLess a)
dL->L _ con :: SrcSpanLess (Located ConLike)
con)
, pat_arg_tys :: forall p. LPat p -> [Type]
pat_arg_tys = [Type]
arg_tys
, pat_tvs :: forall p. LPat p -> [TyVar]
pat_tvs = [TyVar]
ex_tvs
, pat_dicts :: forall p. LPat p -> [TyVar]
pat_dicts = [TyVar]
dicts
, pat_args :: forall p. LPat p -> HsConPatDetails p
pat_args = HsConPatDetails GhcTc
ps } -> do
[(Provenance, [ConLike])]
groups <- ConLike -> [Type] -> DsM [(Provenance, [ConLike])]
allCompleteMatches SrcSpanLess (Located ConLike)
ConLike
con [Type]
arg_tys
case [(Provenance, [ConLike])]
groups of
[] -> Type -> DsM PatVec
mkCanFailPmPat (ConLike -> [Type] -> Type
conLikeResTy SrcSpanLess (Located ConLike)
ConLike
con [Type]
arg_tys)
_ -> do
PatVec
args <- FamInstEnvs
-> [Type]
-> [TyVar]
-> ConLike
-> HsConPatDetails GhcTc
-> DsM PatVec
translateConPatVec FamInstEnvs
fam_insts [Type]
arg_tys [TyVar]
ex_tvs SrcSpanLess (Located ConLike)
ConLike
con HsConPatDetails GhcTc
ps
PatVec -> DsM PatVec
forall (m :: * -> *) a. Monad m => a -> m a
return [PmCon :: forall (t :: PatTy).
ConLike -> [Type] -> [TyVar] -> [TyVar] -> [PmPat t] -> PmPat t
PmCon { pm_con_con :: ConLike
pm_con_con = SrcSpanLess (Located ConLike)
ConLike
con
, pm_con_arg_tys :: [Type]
pm_con_arg_tys = [Type]
arg_tys
, pm_con_tvs :: [TyVar]
pm_con_tvs = [TyVar]
ex_tvs
, pm_con_dicts :: [TyVar]
pm_con_dicts = [TyVar]
dicts
, pm_con_args :: PatVec
pm_con_args = PatVec
args }]
NPat _ (Located (HsOverLit GhcTc)
-> Located (SrcSpanLess (Located (HsOverLit GhcTc)))
forall a. HasSrcSpan a => a -> Located (SrcSpanLess a)
dL->L _ olit :: SrcSpanLess (Located (HsOverLit GhcTc))
olit) mb_neg :: Maybe (SyntaxExpr GhcTc)
mb_neg _
| OverLit (OverLitTc False ty) (HsIsString src s) _ <- SrcSpanLess (Located (HsOverLit GhcTc))
olit
, Type -> Bool
isStringTy Type
ty ->
(PatVec -> PatVec -> PatVec) -> PatVec -> [PatVec] -> PatVec
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr (Type -> PatVec -> PatVec -> PatVec
mkListPatVec Type
charTy) [Type -> PmPat 'PAT
nilPattern Type
charTy] ([PatVec] -> PatVec)
-> IOEnv (Env DsGblEnv DsLclEnv) [PatVec] -> DsM PatVec
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>
FamInstEnvs
-> [LPat GhcTc] -> IOEnv (Env DsGblEnv DsLclEnv) [PatVec]
translatePatVec FamInstEnvs
fam_insts
((Char -> LPat GhcTc) -> String -> [LPat GhcTc]
forall a b. (a -> b) -> [a] -> [b]
map (XLitPat GhcTc -> HsLit GhcTc -> LPat GhcTc
forall p. XLitPat p -> HsLit p -> LPat p
LitPat XLitPat GhcTc
NoExt
noExt (HsLit GhcTc -> LPat GhcTc)
-> (Char -> HsLit GhcTc) -> Char -> LPat GhcTc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. XHsChar GhcTc -> Char -> HsLit GhcTc
forall x. XHsChar x -> Char -> HsLit x
HsChar SourceText
XHsChar GhcTc
src) (FastString -> String
unpackFS FastString
s))
| Bool
otherwise -> PatVec -> DsM PatVec
forall (m :: * -> *) a. Monad m => a -> m a
return [PmLit :: forall (t :: PatTy). PmLit -> PmPat t
PmLit { pm_lit_lit :: PmLit
pm_lit_lit = Bool -> HsOverLit GhcTc -> PmLit
PmOLit (Maybe (SyntaxExpr GhcTc) -> Bool
forall a. Maybe a -> Bool
isJust Maybe (SyntaxExpr GhcTc)
mb_neg) SrcSpanLess (Located (HsOverLit GhcTc))
HsOverLit GhcTc
olit }]
LitPat _ lit :: HsLit GhcTc
lit
| HsString src :: XHsString GhcTc
src s :: FastString
s <- HsLit GhcTc
lit ->
(PatVec -> PatVec -> PatVec) -> PatVec -> [PatVec] -> PatVec
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr (Type -> PatVec -> PatVec -> PatVec
mkListPatVec Type
charTy) [Type -> PmPat 'PAT
nilPattern Type
charTy] ([PatVec] -> PatVec)
-> IOEnv (Env DsGblEnv DsLclEnv) [PatVec] -> DsM PatVec
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>
FamInstEnvs
-> [LPat GhcTc] -> IOEnv (Env DsGblEnv DsLclEnv) [PatVec]
translatePatVec FamInstEnvs
fam_insts
((Char -> LPat GhcTc) -> String -> [LPat GhcTc]
forall a b. (a -> b) -> [a] -> [b]
map (XLitPat GhcTc -> HsLit GhcTc -> LPat GhcTc
forall p. XLitPat p -> HsLit p -> LPat p
LitPat XLitPat GhcTc
NoExt
noExt (HsLit GhcTc -> LPat GhcTc)
-> (Char -> HsLit GhcTc) -> Char -> LPat GhcTc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. XHsChar GhcTc -> Char -> HsLit GhcTc
forall x. XHsChar x -> Char -> HsLit x
HsChar XHsString GhcTc
XHsChar GhcTc
src) (FastString -> String
unpackFS FastString
s))
| Bool
otherwise -> PatVec -> DsM PatVec
forall (m :: * -> *) a. Monad m => a -> m a
return [HsLit GhcTc -> PmPat 'PAT
mkLitPattern HsLit GhcTc
lit]
TuplePat tys :: XTuplePat GhcTc
tys ps :: [LPat GhcTc]
ps boxity :: Boxity
boxity -> do
[PatVec]
tidy_ps <- FamInstEnvs
-> [LPat GhcTc] -> IOEnv (Env DsGblEnv DsLclEnv) [PatVec]
translatePatVec FamInstEnvs
fam_insts ((LPat GhcTc -> LPat GhcTc) -> [LPat GhcTc] -> [LPat GhcTc]
forall a b. (a -> b) -> [a] -> [b]
map LPat GhcTc -> LPat GhcTc
forall a. HasSrcSpan a => a -> SrcSpanLess a
unLoc [LPat GhcTc]
ps)
let tuple_con :: ConLike
tuple_con = DataCon -> ConLike
RealDataCon (Boxity -> Int -> DataCon
tupleDataCon Boxity
boxity ([LPat GhcTc] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [LPat GhcTc]
ps))
tys' :: [Type]
tys' = case Boxity
boxity of
Boxed -> [Type]
XTuplePat GhcTc
tys
Unboxed -> (Type -> Type) -> [Type] -> [Type]
forall a b. (a -> b) -> [a] -> [b]
map HasDebugCallStack => Type -> Type
Type -> Type
getRuntimeRep [Type]
XTuplePat GhcTc
tys [Type] -> [Type] -> [Type]
forall a. [a] -> [a] -> [a]
++ [Type]
XTuplePat GhcTc
tys
PatVec -> DsM PatVec
forall (m :: * -> *) a. Monad m => a -> m a
return [ConLike -> [Type] -> PatVec -> PmPat 'PAT
vanillaConPattern ConLike
tuple_con [Type]
tys' ([PatVec] -> PatVec
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat [PatVec]
tidy_ps)]
SumPat ty :: XSumPat GhcTc
ty p :: LPat GhcTc
p alt :: Int
alt arity :: Int
arity -> do
PatVec
tidy_p <- FamInstEnvs -> LPat GhcTc -> DsM PatVec
translatePat FamInstEnvs
fam_insts (LPat GhcTc -> SrcSpanLess (LPat GhcTc)
forall a. HasSrcSpan a => a -> SrcSpanLess a
unLoc LPat GhcTc
p)
let sum_con :: ConLike
sum_con = DataCon -> ConLike
RealDataCon (Int -> Int -> DataCon
sumDataCon Int
alt Int
arity)
PatVec -> DsM PatVec
forall (m :: * -> *) a. Monad m => a -> m a
return [ConLike -> [Type] -> PatVec -> PmPat 'PAT
vanillaConPattern ConLike
sum_con ((Type -> Type) -> [Type] -> [Type]
forall a b. (a -> b) -> [a] -> [b]
map HasDebugCallStack => Type -> Type
Type -> Type
getRuntimeRep [Type]
XSumPat GhcTc
ty [Type] -> [Type] -> [Type]
forall a. [a] -> [a] -> [a]
++ [Type]
XSumPat GhcTc
ty) PatVec
tidy_p]
ConPatIn {} -> String -> DsM PatVec
forall a. String -> a
panic "Check.translatePat: ConPatIn"
SplicePat {} -> String -> DsM PatVec
forall a. String -> a
panic "Check.translatePat: SplicePat"
XPat {} -> String -> DsM PatVec
forall a. String -> a
panic "Check.translatePat: XPat"
translatePatVec :: FamInstEnvs -> [Pat GhcTc] -> DsM [PatVec]
translatePatVec :: FamInstEnvs
-> [LPat GhcTc] -> IOEnv (Env DsGblEnv DsLclEnv) [PatVec]
translatePatVec fam_insts :: FamInstEnvs
fam_insts pats :: [LPat GhcTc]
pats = (LPat GhcTc -> DsM PatVec)
-> [LPat GhcTc] -> IOEnv (Env DsGblEnv DsLclEnv) [PatVec]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM (FamInstEnvs -> LPat GhcTc -> DsM PatVec
translatePat FamInstEnvs
fam_insts) [LPat GhcTc]
pats
translateConPatVec :: FamInstEnvs -> [Type] -> [TyVar]
-> ConLike -> HsConPatDetails GhcTc -> DsM PatVec
translateConPatVec :: FamInstEnvs
-> [Type]
-> [TyVar]
-> ConLike
-> HsConPatDetails GhcTc
-> DsM PatVec
translateConPatVec fam_insts :: FamInstEnvs
fam_insts _univ_tys :: [Type]
_univ_tys _ex_tvs :: [TyVar]
_ex_tvs _ (PrefixCon ps :: [LPat GhcTc]
ps)
= [PatVec] -> PatVec
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat ([PatVec] -> PatVec)
-> IOEnv (Env DsGblEnv DsLclEnv) [PatVec] -> DsM PatVec
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> FamInstEnvs
-> [LPat GhcTc] -> IOEnv (Env DsGblEnv DsLclEnv) [PatVec]
translatePatVec FamInstEnvs
fam_insts ((LPat GhcTc -> LPat GhcTc) -> [LPat GhcTc] -> [LPat GhcTc]
forall a b. (a -> b) -> [a] -> [b]
map LPat GhcTc -> LPat GhcTc
forall a. HasSrcSpan a => a -> SrcSpanLess a
unLoc [LPat GhcTc]
ps)
translateConPatVec fam_insts :: FamInstEnvs
fam_insts _univ_tys :: [Type]
_univ_tys _ex_tvs :: [TyVar]
_ex_tvs _ (InfixCon p1 :: LPat GhcTc
p1 p2 :: LPat GhcTc
p2)
= [PatVec] -> PatVec
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat ([PatVec] -> PatVec)
-> IOEnv (Env DsGblEnv DsLclEnv) [PatVec] -> DsM PatVec
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> FamInstEnvs
-> [LPat GhcTc] -> IOEnv (Env DsGblEnv DsLclEnv) [PatVec]
translatePatVec FamInstEnvs
fam_insts ((LPat GhcTc -> LPat GhcTc) -> [LPat GhcTc] -> [LPat GhcTc]
forall a b. (a -> b) -> [a] -> [b]
map LPat GhcTc -> LPat GhcTc
forall a. HasSrcSpan a => a -> SrcSpanLess a
unLoc [LPat GhcTc
p1,LPat GhcTc
p2])
translateConPatVec fam_insts :: FamInstEnvs
fam_insts univ_tys :: [Type]
univ_tys ex_tvs :: [TyVar]
ex_tvs c :: ConLike
c (RecCon (HsRecFields fs :: [LHsRecField GhcTc (LPat GhcTc)]
fs _))
| [LHsRecField GhcTc (LPat GhcTc)] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [LHsRecField GhcTc (LPat GhcTc)]
fs = [Type] -> DsM PatVec
mkPmVars [Type]
arg_tys
| [Name] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [Name]
orig_lbls = ASSERT(null matched_lbls) mkPmVars arg_tys
| [Name]
matched_lbls [Name] -> [Name] -> Bool
forall a. Eq a => [a] -> [a] -> Bool
`subsetOf` [Name]
orig_lbls
= ASSERT(orig_lbls `equalLength` arg_tys)
let translateOne :: (Name, Type) -> DsM PatVec
translateOne (lbl :: Name
lbl, ty :: Type
ty) = case Name -> [(Name, LPat GhcTc)] -> Maybe (LPat GhcTc)
forall a b. Eq a => a -> [(a, b)] -> Maybe b
lookup Name
lbl [(Name, LPat GhcTc)]
matched_pats of
Just p :: LPat GhcTc
p -> FamInstEnvs -> LPat GhcTc -> DsM PatVec
translatePat FamInstEnvs
fam_insts LPat GhcTc
p
Nothing -> [Type] -> DsM PatVec
mkPmVars [Type
ty]
in ((Name, Type) -> DsM PatVec) -> [(Name, Type)] -> DsM PatVec
forall (m :: * -> *) a b. Monad m => (a -> m [b]) -> [a] -> m [b]
concatMapM (Name, Type) -> DsM PatVec
translateOne ([Name] -> [Type] -> [(Name, Type)]
forall a b. [a] -> [b] -> [(a, b)]
zip [Name]
orig_lbls [Type]
arg_tys)
| Bool
otherwise = do
PatVec
arg_var_pats <- [Type] -> DsM PatVec
mkPmVars [Type]
arg_tys
[(Name, PatVec)]
translated_pats <- [(Name, LPat GhcTc)]
-> ((Name, LPat GhcTc)
-> IOEnv (Env DsGblEnv DsLclEnv) (Name, PatVec))
-> IOEnv (Env DsGblEnv DsLclEnv) [(Name, PatVec)]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
t a -> (a -> m b) -> m (t b)
forM [(Name, LPat GhcTc)]
matched_pats (((Name, LPat GhcTc)
-> IOEnv (Env DsGblEnv DsLclEnv) (Name, PatVec))
-> IOEnv (Env DsGblEnv DsLclEnv) [(Name, PatVec)])
-> ((Name, LPat GhcTc)
-> IOEnv (Env DsGblEnv DsLclEnv) (Name, PatVec))
-> IOEnv (Env DsGblEnv DsLclEnv) [(Name, PatVec)]
forall a b. (a -> b) -> a -> b
$ \(x :: Name
x,pat :: LPat GhcTc
pat) -> do
PatVec
pvec <- FamInstEnvs -> LPat GhcTc -> DsM PatVec
translatePat FamInstEnvs
fam_insts LPat GhcTc
pat
(Name, PatVec) -> IOEnv (Env DsGblEnv DsLclEnv) (Name, PatVec)
forall (m :: * -> *) a. Monad m => a -> m a
return (Name
x, PatVec
pvec)
let zipped :: [(Name, TyVar)]
zipped = [Name] -> [TyVar] -> [(Name, TyVar)]
forall a b. [a] -> [b] -> [(a, b)]
zip [Name]
orig_lbls [ TyVar
x | PmVar x :: TyVar
x <- PatVec
arg_var_pats ]
guards :: PatVec
guards = ((Name, PatVec) -> PmPat 'PAT) -> [(Name, PatVec)] -> PatVec
forall a b. (a -> b) -> [a] -> [b]
map (\(name :: Name
name,pvec :: PatVec
pvec) -> case Name -> [(Name, TyVar)] -> Maybe TyVar
forall a b. Eq a => a -> [(a, b)] -> Maybe b
lookup Name
name [(Name, TyVar)]
zipped of
Just x :: TyVar
x -> PatVec -> PmExpr -> PmPat 'PAT
PmGrd PatVec
pvec (Name -> PmExpr
PmExprVar (TyVar -> Name
idName TyVar
x))
Nothing -> String -> PmPat 'PAT
forall a. String -> a
panic "translateConPatVec: lookup")
[(Name, PatVec)]
translated_pats
PatVec -> DsM PatVec
forall (m :: * -> *) a. Monad m => a -> m a
return (PatVec
arg_var_pats PatVec -> PatVec -> PatVec
forall a. [a] -> [a] -> [a]
++ PatVec
guards)
where
arg_tys :: [Type]
arg_tys = ConLike -> [Type] -> [Type]
conLikeInstOrigArgTys ConLike
c ([Type]
univ_tys [Type] -> [Type] -> [Type]
forall a. [a] -> [a] -> [a]
++ [TyVar] -> [Type]
mkTyVarTys [TyVar]
ex_tvs)
orig_lbls :: [Name]
orig_lbls = (FieldLbl Name -> Name) -> [FieldLbl Name] -> [Name]
forall a b. (a -> b) -> [a] -> [b]
map FieldLbl Name -> Name
forall a. FieldLbl a -> a
flSelector ([FieldLbl Name] -> [Name]) -> [FieldLbl Name] -> [Name]
forall a b. (a -> b) -> a -> b
$ ConLike -> [FieldLbl Name]
conLikeFieldLabels ConLike
c
matched_pats :: [(Name, LPat GhcTc)]
matched_pats = [ (TyVar -> Name
forall a. NamedThing a => a -> Name
getName (Located TyVar -> SrcSpanLess (Located TyVar)
forall a. HasSrcSpan a => a -> SrcSpanLess a
unLoc (HsRecField GhcTc (LPat GhcTc) -> Located TyVar
forall arg. HsRecField GhcTc arg -> Located TyVar
hsRecFieldId SrcSpanLess (LHsRecField GhcTc (LPat GhcTc))
HsRecField GhcTc (LPat GhcTc)
x)), LPat GhcTc -> SrcSpanLess (LPat GhcTc)
forall a. HasSrcSpan a => a -> SrcSpanLess a
unLoc (HsRecField GhcTc (LPat GhcTc) -> LPat GhcTc
forall id arg. HsRecField' id arg -> arg
hsRecFieldArg SrcSpanLess (LHsRecField GhcTc (LPat GhcTc))
HsRecField GhcTc (LPat GhcTc)
x))
| (LHsRecField GhcTc (LPat GhcTc)
-> Located (SrcSpanLess (LHsRecField GhcTc (LPat GhcTc)))
forall a. HasSrcSpan a => a -> Located (SrcSpanLess a)
dL->L _ x :: SrcSpanLess (LHsRecField GhcTc (LPat GhcTc))
x) <- [LHsRecField GhcTc (LPat GhcTc)]
fs]
matched_lbls :: [Name]
matched_lbls = [ Name
name | (name :: Name
name, _pat :: LPat GhcTc
_pat) <- [(Name, LPat GhcTc)]
matched_pats ]
subsetOf :: Eq a => [a] -> [a] -> Bool
subsetOf :: [a] -> [a] -> Bool
subsetOf [] _ = Bool
True
subsetOf (_:_) [] = Bool
False
subsetOf (x :: a
x:xs :: [a]
xs) (y :: a
y:ys :: [a]
ys)
| a
x a -> a -> Bool
forall a. Eq a => a -> a -> Bool
== a
y = [a] -> [a] -> Bool
forall a. Eq a => [a] -> [a] -> Bool
subsetOf [a]
xs [a]
ys
| Bool
otherwise = [a] -> [a] -> Bool
forall a. Eq a => [a] -> [a] -> Bool
subsetOf (a
xa -> [a] -> [a]
forall a. a -> [a] -> [a]
:[a]
xs) [a]
ys
translateMatch :: FamInstEnvs -> LMatch GhcTc (LHsExpr GhcTc)
-> DsM (PatVec,[PatVec])
translateMatch :: FamInstEnvs
-> LMatch GhcTc (LHsExpr GhcTc) -> DsM (PatVec, [PatVec])
translateMatch fam_insts :: FamInstEnvs
fam_insts (LMatch GhcTc (LHsExpr GhcTc)
-> Located (SrcSpanLess (LMatch GhcTc (LHsExpr GhcTc)))
forall a. HasSrcSpan a => a -> Located (SrcSpanLess a)
dL->L _ (Match { m_pats = lpats, m_grhss = grhss })) =
do
PatVec
pats' <- [PatVec] -> PatVec
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat ([PatVec] -> PatVec)
-> IOEnv (Env DsGblEnv DsLclEnv) [PatVec] -> DsM PatVec
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> FamInstEnvs
-> [LPat GhcTc] -> IOEnv (Env DsGblEnv DsLclEnv) [PatVec]
translatePatVec FamInstEnvs
fam_insts [LPat GhcTc]
pats
[PatVec]
guards' <- ([GuardStmt GhcTc] -> DsM PatVec)
-> [[GuardStmt GhcTc]] -> IOEnv (Env DsGblEnv DsLclEnv) [PatVec]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM (FamInstEnvs -> [GuardStmt GhcTc] -> DsM PatVec
translateGuards FamInstEnvs
fam_insts) [[GuardStmt GhcTc]]
guards
(PatVec, [PatVec]) -> DsM (PatVec, [PatVec])
forall (m :: * -> *) a. Monad m => a -> m a
return (PatVec
pats', [PatVec]
guards')
where
extractGuards :: LGRHS GhcTc (LHsExpr GhcTc) -> [GuardStmt GhcTc]
extractGuards :: LGRHS GhcTc (LHsExpr GhcTc) -> [GuardStmt GhcTc]
extractGuards (LGRHS GhcTc (LHsExpr GhcTc)
-> Located (SrcSpanLess (LGRHS GhcTc (LHsExpr GhcTc)))
forall a. HasSrcSpan a => a -> Located (SrcSpanLess a)
dL->L _ (GRHS _ gs _)) = (GuardLStmt GhcTc -> GuardStmt GhcTc)
-> [GuardLStmt GhcTc] -> [GuardStmt GhcTc]
forall a b. (a -> b) -> [a] -> [b]
map GuardLStmt GhcTc -> GuardStmt GhcTc
forall a. HasSrcSpan a => a -> SrcSpanLess a
unLoc [GuardLStmt GhcTc]
gs
extractGuards _ = String -> [GuardStmt GhcTc]
forall a. String -> a
panic "translateMatch"
pats :: [LPat GhcTc]
pats = (LPat GhcTc -> LPat GhcTc) -> [LPat GhcTc] -> [LPat GhcTc]
forall a b. (a -> b) -> [a] -> [b]
map LPat GhcTc -> LPat GhcTc
forall a. HasSrcSpan a => a -> SrcSpanLess a
unLoc [LPat GhcTc]
lpats
guards :: [[GuardStmt GhcTc]]
guards = (LGRHS GhcTc (LHsExpr GhcTc) -> [GuardStmt GhcTc])
-> [LGRHS GhcTc (LHsExpr GhcTc)] -> [[GuardStmt GhcTc]]
forall a b. (a -> b) -> [a] -> [b]
map LGRHS GhcTc (LHsExpr GhcTc) -> [GuardStmt GhcTc]
extractGuards (GRHSs GhcTc (LHsExpr GhcTc) -> [LGRHS GhcTc (LHsExpr GhcTc)]
forall p body. GRHSs p body -> [LGRHS p body]
grhssGRHSs GRHSs GhcTc (LHsExpr GhcTc)
grhss)
translateMatch _ _ = String -> DsM (PatVec, [PatVec])
forall a. String -> a
panic "translateMatch"
translateGuards :: FamInstEnvs -> [GuardStmt GhcTc] -> DsM PatVec
translateGuards :: FamInstEnvs -> [GuardStmt GhcTc] -> DsM PatVec
translateGuards fam_insts :: FamInstEnvs
fam_insts guards :: [GuardStmt GhcTc]
guards = do
PatVec
all_guards <- [PatVec] -> PatVec
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat ([PatVec] -> PatVec)
-> IOEnv (Env DsGblEnv DsLclEnv) [PatVec] -> DsM PatVec
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (GuardStmt GhcTc -> DsM PatVec)
-> [GuardStmt GhcTc] -> IOEnv (Env DsGblEnv DsLclEnv) [PatVec]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM (FamInstEnvs -> GuardStmt GhcTc -> DsM PatVec
translateGuard FamInstEnvs
fam_insts) [GuardStmt GhcTc]
guards
PatVec -> DsM PatVec
forall (m :: * -> *) a. Monad m => a -> m a
return (PatVec -> PatVec
replace_unhandled PatVec
all_guards)
where
replace_unhandled :: PatVec -> PatVec
replace_unhandled :: PatVec -> PatVec
replace_unhandled gv :: PatVec
gv
| PatVec -> Bool
any_unhandled PatVec
gv = PmPat 'PAT
fake_pat PmPat 'PAT -> PatVec -> PatVec
forall a. a -> [a] -> [a]
: [ PmPat 'PAT
p | PmPat 'PAT
p <- PatVec
gv, PmPat 'PAT -> Bool
shouldKeep PmPat 'PAT
p ]
| Bool
otherwise = PatVec
gv
any_unhandled :: PatVec -> Bool
any_unhandled :: PatVec -> Bool
any_unhandled gv :: PatVec
gv = (PmPat 'PAT -> Bool) -> PatVec -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
any (Bool -> Bool
not (Bool -> Bool) -> (PmPat 'PAT -> Bool) -> PmPat 'PAT -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PmPat 'PAT -> Bool
shouldKeep) PatVec
gv
shouldKeep :: Pattern -> Bool
shouldKeep :: PmPat 'PAT -> Bool
shouldKeep p :: PmPat 'PAT
p
| PmVar {} <- PmPat 'PAT
p = Bool
True
| PmCon {} <- PmPat 'PAT
p = ConLike -> Bool
singleConstructor (PmPat 'PAT -> ConLike
forall (t :: PatTy). PmPat t -> ConLike
pm_con_con PmPat 'PAT
p)
Bool -> Bool -> Bool
&& (PmPat 'PAT -> Bool) -> PatVec -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
all PmPat 'PAT -> Bool
shouldKeep (PmPat 'PAT -> PatVec
forall (t :: PatTy). PmPat t -> [PmPat t]
pm_con_args PmPat 'PAT
p)
shouldKeep (PmGrd pv :: PatVec
pv e :: PmExpr
e)
| (PmPat 'PAT -> Bool) -> PatVec -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
all PmPat 'PAT -> Bool
shouldKeep PatVec
pv = Bool
True
| PmExpr -> Bool
isNotPmExprOther PmExpr
e = Bool
True
shouldKeep _other_pat :: PmPat 'PAT
_other_pat = Bool
False
cantFailPattern :: Pattern -> Bool
cantFailPattern :: PmPat 'PAT -> Bool
cantFailPattern p :: PmPat 'PAT
p
| PmVar {} <- PmPat 'PAT
p = Bool
True
| PmCon {} <- PmPat 'PAT
p = ConLike -> Bool
singleConstructor (PmPat 'PAT -> ConLike
forall (t :: PatTy). PmPat t -> ConLike
pm_con_con PmPat 'PAT
p)
Bool -> Bool -> Bool
&& (PmPat 'PAT -> Bool) -> PatVec -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
all PmPat 'PAT -> Bool
cantFailPattern (PmPat 'PAT -> PatVec
forall (t :: PatTy). PmPat t -> [PmPat t]
pm_con_args PmPat 'PAT
p)
cantFailPattern (PmGrd pv :: PatVec
pv _e :: PmExpr
_e)
= (PmPat 'PAT -> Bool) -> PatVec -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
all PmPat 'PAT -> Bool
cantFailPattern PatVec
pv
cantFailPattern _ = Bool
False
translateGuard :: FamInstEnvs -> GuardStmt GhcTc -> DsM PatVec
translateGuard :: FamInstEnvs -> GuardStmt GhcTc -> DsM PatVec
translateGuard fam_insts :: FamInstEnvs
fam_insts guard :: GuardStmt GhcTc
guard = case GuardStmt GhcTc
guard of
BodyStmt _ e :: LHsExpr GhcTc
e _ _ -> LHsExpr GhcTc -> DsM PatVec
translateBoolGuard LHsExpr GhcTc
e
LetStmt _ binds :: LHsLocalBindsLR GhcTc GhcTc
binds -> HsLocalBinds GhcTc -> DsM PatVec
translateLet (LHsLocalBindsLR GhcTc GhcTc
-> SrcSpanLess (LHsLocalBindsLR GhcTc GhcTc)
forall a. HasSrcSpan a => a -> SrcSpanLess a
unLoc LHsLocalBindsLR GhcTc GhcTc
binds)
BindStmt _ p :: LPat GhcTc
p e :: LHsExpr GhcTc
e _ _ -> FamInstEnvs -> LPat GhcTc -> LHsExpr GhcTc -> DsM PatVec
translateBind FamInstEnvs
fam_insts LPat GhcTc
p LHsExpr GhcTc
e
LastStmt {} -> String -> DsM PatVec
forall a. String -> a
panic "translateGuard LastStmt"
ParStmt {} -> String -> DsM PatVec
forall a. String -> a
panic "translateGuard ParStmt"
TransStmt {} -> String -> DsM PatVec
forall a. String -> a
panic "translateGuard TransStmt"
RecStmt {} -> String -> DsM PatVec
forall a. String -> a
panic "translateGuard RecStmt"
ApplicativeStmt {} -> String -> DsM PatVec
forall a. String -> a
panic "translateGuard ApplicativeLastStmt"
XStmtLR {} -> String -> DsM PatVec
forall a. String -> a
panic "translateGuard RecStmt"
translateLet :: HsLocalBinds GhcTc -> DsM PatVec
translateLet :: HsLocalBinds GhcTc -> DsM PatVec
translateLet _binds :: HsLocalBinds GhcTc
_binds = PatVec -> DsM PatVec
forall (m :: * -> *) a. Monad m => a -> m a
return []
translateBind :: FamInstEnvs -> LPat GhcTc -> LHsExpr GhcTc -> DsM PatVec
translateBind :: FamInstEnvs -> LPat GhcTc -> LHsExpr GhcTc -> DsM PatVec
translateBind fam_insts :: FamInstEnvs
fam_insts (LPat GhcTc -> Located (SrcSpanLess (LPat GhcTc))
forall a. HasSrcSpan a => a -> Located (SrcSpanLess a)
dL->L _ p :: SrcSpanLess (LPat GhcTc)
p) e :: LHsExpr GhcTc
e = do
PatVec
ps <- FamInstEnvs -> LPat GhcTc -> DsM PatVec
translatePat FamInstEnvs
fam_insts SrcSpanLess (LPat GhcTc)
LPat GhcTc
p
PatVec -> DsM PatVec
forall (m :: * -> *) a. Monad m => a -> m a
return [PatVec -> HsExpr GhcTc -> PmPat 'PAT
mkGuard PatVec
ps (LHsExpr GhcTc -> SrcSpanLess (LHsExpr GhcTc)
forall a. HasSrcSpan a => a -> SrcSpanLess a
unLoc LHsExpr GhcTc
e)]
translateBoolGuard :: LHsExpr GhcTc -> DsM PatVec
translateBoolGuard :: LHsExpr GhcTc -> DsM PatVec
translateBoolGuard e :: LHsExpr GhcTc
e
| Maybe (CoreExpr -> DsM CoreExpr) -> Bool
forall a. Maybe a -> Bool
isJust (LHsExpr GhcTc -> Maybe (CoreExpr -> DsM CoreExpr)
isTrueLHsExpr LHsExpr GhcTc
e) = PatVec -> DsM PatVec
forall (m :: * -> *) a. Monad m => a -> m a
return []
| Bool
otherwise = PatVec -> DsM PatVec
forall (m :: * -> *) a. Monad m => a -> m a
return [PatVec -> HsExpr GhcTc -> PmPat 'PAT
mkGuard [PmPat 'PAT
truePattern] (LHsExpr GhcTc -> SrcSpanLess (LHsExpr GhcTc)
forall a. HasSrcSpan a => a -> SrcSpanLess a
unLoc LHsExpr GhcTc
e)]
pmPatType :: PmPat p -> Type
pmPatType :: PmPat p -> Type
pmPatType (PmCon { pm_con_con :: forall (t :: PatTy). PmPat t -> ConLike
pm_con_con = ConLike
con, pm_con_arg_tys :: forall (t :: PatTy). PmPat t -> [Type]
pm_con_arg_tys = [Type]
tys })
= ConLike -> [Type] -> Type
conLikeResTy ConLike
con [Type]
tys
pmPatType (PmVar { pm_var_id :: forall (t :: PatTy). PmPat t -> TyVar
pm_var_id = TyVar
x }) = TyVar -> Type
idType TyVar
x
pmPatType (PmLit { pm_lit_lit :: forall (t :: PatTy). PmPat t -> PmLit
pm_lit_lit = PmLit
l }) = PmLit -> Type
pmLitType PmLit
l
pmPatType (PmNLit { pm_lit_id :: PmPat 'VA -> TyVar
pm_lit_id = TyVar
x }) = TyVar -> Type
idType TyVar
x
pmPatType (PmGrd { pm_grd_pv :: PmPat 'PAT -> PatVec
pm_grd_pv = PatVec
pv })
= ASSERT(patVecArity pv == 1) (pmPatType p)
where Just p :: PmPat 'PAT
p = (PmPat 'PAT -> Bool) -> PatVec -> Maybe (PmPat 'PAT)
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Maybe a
find ((Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
==1) (Int -> Bool) -> (PmPat 'PAT -> Int) -> PmPat 'PAT -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PmPat 'PAT -> Int
patternArity) PatVec
pv
data InhabitationCandidate =
InhabitationCandidate
{ InhabitationCandidate -> PmPat 'VA
ic_val_abs :: ValAbs
, InhabitationCandidate -> ComplexEq
ic_tm_ct :: ComplexEq
, InhabitationCandidate -> Bag TyVar
ic_ty_cs :: Bag EvVar
, InhabitationCandidate -> [Type]
ic_strict_arg_tys :: [Type]
}
instance Outputable InhabitationCandidate where
ppr :: InhabitationCandidate -> SDoc
ppr (InhabitationCandidate { ic_val_abs :: InhabitationCandidate -> PmPat 'VA
ic_val_abs = PmPat 'VA
va, ic_tm_ct :: InhabitationCandidate -> ComplexEq
ic_tm_ct = ComplexEq
tm_ct
, ic_ty_cs :: InhabitationCandidate -> Bag TyVar
ic_ty_cs = Bag TyVar
ty_cs
, ic_strict_arg_tys :: InhabitationCandidate -> [Type]
ic_strict_arg_tys = [Type]
strict_arg_tys }) =
String -> SDoc
text "InhabitationCandidate" SDoc -> SDoc -> SDoc
<+>
[SDoc] -> SDoc
vcat [ String -> SDoc
text "ic_val_abs =" SDoc -> SDoc -> SDoc
<+> PmPat 'VA -> SDoc
forall a. Outputable a => a -> SDoc
ppr PmPat 'VA
va
, String -> SDoc
text "ic_tm_ct =" SDoc -> SDoc -> SDoc
<+> ComplexEq -> SDoc
forall a. Outputable a => a -> SDoc
ppr ComplexEq
tm_ct
, String -> SDoc
text "ic_ty_cs =" SDoc -> SDoc -> SDoc
<+> Bag TyVar -> SDoc
forall a. Outputable a => a -> SDoc
ppr Bag TyVar
ty_cs
, String -> SDoc
text "ic_strict_arg_tys =" SDoc -> SDoc -> SDoc
<+> [Type] -> SDoc
forall a. Outputable a => a -> SDoc
ppr [Type]
strict_arg_tys ]
mkOneConFull :: Id -> ConLike -> DsM InhabitationCandidate
mkOneConFull :: TyVar
-> ConLike -> IOEnv (Env DsGblEnv DsLclEnv) InhabitationCandidate
mkOneConFull x :: TyVar
x con :: ConLike
con = do
let res_ty :: Type
res_ty = TyVar -> Type
idType TyVar
x
(univ_tvs :: [TyVar]
univ_tvs, ex_tvs :: [TyVar]
ex_tvs, eq_spec :: [EqSpec]
eq_spec, thetas :: [Type]
thetas, _req_theta :: [Type]
_req_theta , arg_tys :: [Type]
arg_tys, con_res_ty :: Type
con_res_ty)
= ConLike
-> ([TyVar], [TyVar], [EqSpec], [Type], [Type], [Type], Type)
conLikeFullSig ConLike
con
arg_is_banged :: [Bool]
arg_is_banged = (HsImplBang -> Bool) -> [HsImplBang] -> [Bool]
forall a b. (a -> b) -> [a] -> [b]
map HsImplBang -> Bool
isBanged ([HsImplBang] -> [Bool]) -> [HsImplBang] -> [Bool]
forall a b. (a -> b) -> a -> b
$ ConLike -> [HsImplBang]
conLikeImplBangs ConLike
con
tc_args :: [Type]
tc_args = Type -> [Type]
tyConAppArgs Type
res_ty
subst1 :: TCvSubst
subst1 = case ConLike
con of
RealDataCon {} -> [TyVar] -> [Type] -> TCvSubst
HasDebugCallStack => [TyVar] -> [Type] -> TCvSubst
zipTvSubst [TyVar]
univ_tvs [Type]
tc_args
PatSynCon {} -> String -> Maybe TCvSubst -> TCvSubst
forall a. HasCallStack => String -> Maybe a -> a
expectJust "mkOneConFull" (Type -> Type -> Maybe TCvSubst
tcMatchTy Type
con_res_ty Type
res_ty)
(subst :: TCvSubst
subst, ex_tvs' :: [TyVar]
ex_tvs') <- TCvSubst -> [TyVar] -> UniqSupply -> (TCvSubst, [TyVar])
cloneTyVarBndrs TCvSubst
subst1 [TyVar]
ex_tvs (UniqSupply -> (TCvSubst, [TyVar]))
-> IOEnv (Env DsGblEnv DsLclEnv) UniqSupply
-> IOEnv (Env DsGblEnv DsLclEnv) (TCvSubst, [TyVar])
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> IOEnv (Env DsGblEnv DsLclEnv) UniqSupply
forall (m :: * -> *). MonadUnique m => m UniqSupply
getUniqueSupplyM
let arg_tys' :: [Type]
arg_tys' = HasCallStack => TCvSubst -> [Type] -> [Type]
TCvSubst -> [Type] -> [Type]
substTys TCvSubst
subst [Type]
arg_tys
[PmPat 'VA]
arguments <- (Type -> IOEnv (Env DsGblEnv DsLclEnv) (PmPat 'VA))
-> [Type] -> IOEnv (Env DsGblEnv DsLclEnv) [PmPat 'VA]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM Type -> IOEnv (Env DsGblEnv DsLclEnv) (PmPat 'VA)
forall (p :: PatTy). Type -> DsM (PmPat p)
mkPmVar [Type]
arg_tys'
let theta_cs :: [Type]
theta_cs = HasCallStack => TCvSubst -> [Type] -> [Type]
TCvSubst -> [Type] -> [Type]
substTheta TCvSubst
subst ([EqSpec] -> [Type]
eqSpecPreds [EqSpec]
eq_spec [Type] -> [Type] -> [Type]
forall a. [a] -> [a] -> [a]
++ [Type]
thetas)
[TyVar]
evvars <- (Type -> DsM TyVar)
-> [Type] -> IOEnv (Env DsGblEnv DsLclEnv) [TyVar]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM (String -> Type -> DsM TyVar
nameType "pm") [Type]
theta_cs
let con_abs :: PmPat 'VA
con_abs = PmCon :: forall (t :: PatTy).
ConLike -> [Type] -> [TyVar] -> [TyVar] -> [PmPat t] -> PmPat t
PmCon { pm_con_con :: ConLike
pm_con_con = ConLike
con
, pm_con_arg_tys :: [Type]
pm_con_arg_tys = [Type]
tc_args
, pm_con_tvs :: [TyVar]
pm_con_tvs = [TyVar]
ex_tvs'
, pm_con_dicts :: [TyVar]
pm_con_dicts = [TyVar]
evvars
, pm_con_args :: [PmPat 'VA]
pm_con_args = [PmPat 'VA]
arguments }
strict_arg_tys :: [Type]
strict_arg_tys = [Bool] -> [Type] -> [Type]
forall a. [Bool] -> [a] -> [a]
filterByList [Bool]
arg_is_banged [Type]
arg_tys'
InhabitationCandidate
-> IOEnv (Env DsGblEnv DsLclEnv) InhabitationCandidate
forall (m :: * -> *) a. Monad m => a -> m a
return (InhabitationCandidate
-> IOEnv (Env DsGblEnv DsLclEnv) InhabitationCandidate)
-> InhabitationCandidate
-> IOEnv (Env DsGblEnv DsLclEnv) InhabitationCandidate
forall a b. (a -> b) -> a -> b
$ InhabitationCandidate :: PmPat 'VA
-> ComplexEq -> Bag TyVar -> [Type] -> InhabitationCandidate
InhabitationCandidate
{ ic_val_abs :: PmPat 'VA
ic_val_abs = PmPat 'VA
con_abs
, ic_tm_ct :: ComplexEq
ic_tm_ct = (Name -> PmExpr
PmExprVar (TyVar -> Name
idName TyVar
x), PmPat 'VA -> PmExpr
vaToPmExpr PmPat 'VA
con_abs)
, ic_ty_cs :: Bag TyVar
ic_ty_cs = [TyVar] -> Bag TyVar
forall a. [a] -> Bag a
listToBag [TyVar]
evvars
, ic_strict_arg_tys :: [Type]
ic_strict_arg_tys = [Type]
strict_arg_tys
}
mkGuard :: PatVec -> HsExpr GhcTc -> Pattern
mkGuard :: PatVec -> HsExpr GhcTc -> PmPat 'PAT
mkGuard pv :: PatVec
pv e :: HsExpr GhcTc
e
| (PmPat 'PAT -> Bool) -> PatVec -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
all PmPat 'PAT -> Bool
cantFailPattern PatVec
pv = PatVec -> PmExpr -> PmPat 'PAT
PmGrd PatVec
pv PmExpr
expr
| PmExprOther {} <- PmExpr
expr = PmPat 'PAT
fake_pat
| Bool
otherwise = PatVec -> PmExpr -> PmPat 'PAT
PmGrd PatVec
pv PmExpr
expr
where
expr :: PmExpr
expr = HsExpr GhcTc -> PmExpr
hsExprToPmExpr HsExpr GhcTc
e
mkNegEq :: Id -> PmLit -> ComplexEq
mkNegEq :: TyVar -> PmLit -> ComplexEq
mkNegEq x :: TyVar
x l :: PmLit
l = (PmExpr
falsePmExpr, Name -> PmExpr
PmExprVar (TyVar -> Name
idName TyVar
x) PmExpr -> PmExpr -> PmExpr
`PmExprEq` PmLit -> PmExpr
PmExprLit PmLit
l)
{-# INLINE mkNegEq #-}
mkPosEq :: Id -> PmLit -> ComplexEq
mkPosEq :: TyVar -> PmLit -> ComplexEq
mkPosEq x :: TyVar
x l :: PmLit
l = (Name -> PmExpr
PmExprVar (TyVar -> Name
idName TyVar
x), PmLit -> PmExpr
PmExprLit PmLit
l)
{-# INLINE mkPosEq #-}
mkIdEq :: Id -> ComplexEq
mkIdEq :: TyVar -> ComplexEq
mkIdEq x :: TyVar
x = (Name -> PmExpr
PmExprVar Name
name, Name -> PmExpr
PmExprVar Name
name)
where name :: Name
name = TyVar -> Name
idName TyVar
x
{-# INLINE mkIdEq #-}
mkPmVar :: Type -> DsM (PmPat p)
mkPmVar :: Type -> DsM (PmPat p)
mkPmVar ty :: Type
ty = TyVar -> PmPat p
forall (t :: PatTy). TyVar -> PmPat t
PmVar (TyVar -> PmPat p) -> DsM TyVar -> DsM (PmPat p)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Type -> DsM TyVar
mkPmId Type
ty
{-# INLINE mkPmVar #-}
mkPmVars :: [Type] -> DsM PatVec
mkPmVars :: [Type] -> DsM PatVec
mkPmVars tys :: [Type]
tys = (Type -> DsM (PmPat 'PAT)) -> [Type] -> DsM PatVec
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM Type -> DsM (PmPat 'PAT)
forall (p :: PatTy). Type -> DsM (PmPat p)
mkPmVar [Type]
tys
{-# INLINE mkPmVars #-}
mkPmId :: Type -> DsM Id
mkPmId :: Type -> DsM TyVar
mkPmId ty :: Type
ty = IOEnv (Env DsGblEnv DsLclEnv) Unique
forall (m :: * -> *). MonadUnique m => m Unique
getUniqueM IOEnv (Env DsGblEnv DsLclEnv) Unique
-> (Unique -> DsM TyVar) -> DsM TyVar
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \unique :: Unique
unique ->
let occname :: OccName
occname = FastString -> OccName
mkVarOccFS (FastString -> OccName) -> FastString -> OccName
forall a b. (a -> b) -> a -> b
$ String -> FastString
fsLit "$pm"
name :: Name
name = Unique -> OccName -> SrcSpan -> Name
mkInternalName Unique
unique OccName
occname SrcSpan
noSrcSpan
in TyVar -> DsM TyVar
forall (m :: * -> *) a. Monad m => a -> m a
return (Name -> Type -> TyVar
mkLocalId Name
name Type
ty)
mkPmId2Forms :: Type -> DsM (Pattern, LHsExpr GhcTc)
mkPmId2Forms :: Type -> DsM (PmPat 'PAT, LHsExpr GhcTc)
mkPmId2Forms ty :: Type
ty = do
TyVar
x <- Type -> DsM TyVar
mkPmId Type
ty
(PmPat 'PAT, LHsExpr GhcTc) -> DsM (PmPat 'PAT, LHsExpr GhcTc)
forall (m :: * -> *) a. Monad m => a -> m a
return (TyVar -> PmPat 'PAT
forall (t :: PatTy). TyVar -> PmPat t
PmVar TyVar
x, SrcSpanLess (LHsExpr GhcTc) -> LHsExpr GhcTc
forall a. HasSrcSpan a => SrcSpanLess a -> a
noLoc (XVar GhcTc -> Located (IdP GhcTc) -> HsExpr GhcTc
forall p. XVar p -> Located (IdP p) -> HsExpr p
HsVar XVar GhcTc
NoExt
noExt (SrcSpanLess (Located TyVar) -> Located TyVar
forall a. HasSrcSpan a => SrcSpanLess a -> a
noLoc SrcSpanLess (Located TyVar)
TyVar
x)))
vaToPmExpr :: ValAbs -> PmExpr
vaToPmExpr :: PmPat 'VA -> PmExpr
vaToPmExpr (PmCon { pm_con_con :: forall (t :: PatTy). PmPat t -> ConLike
pm_con_con = ConLike
c, pm_con_args :: forall (t :: PatTy). PmPat t -> [PmPat t]
pm_con_args = [PmPat 'VA]
ps })
= ConLike -> [PmExpr] -> PmExpr
PmExprCon ConLike
c ((PmPat 'VA -> PmExpr) -> [PmPat 'VA] -> [PmExpr]
forall a b. (a -> b) -> [a] -> [b]
map PmPat 'VA -> PmExpr
vaToPmExpr [PmPat 'VA]
ps)
vaToPmExpr (PmVar { pm_var_id :: forall (t :: PatTy). PmPat t -> TyVar
pm_var_id = TyVar
x }) = Name -> PmExpr
PmExprVar (TyVar -> Name
idName TyVar
x)
vaToPmExpr (PmLit { pm_lit_lit :: forall (t :: PatTy). PmPat t -> PmLit
pm_lit_lit = PmLit
l }) = PmLit -> PmExpr
PmExprLit PmLit
l
vaToPmExpr (PmNLit { pm_lit_id :: PmPat 'VA -> TyVar
pm_lit_id = TyVar
x }) = Name -> PmExpr
PmExprVar (TyVar -> Name
idName TyVar
x)
coercePatVec :: PatVec -> [ValAbs]
coercePatVec :: PatVec -> [PmPat 'VA]
coercePatVec pv :: PatVec
pv = (PmPat 'PAT -> [PmPat 'VA]) -> PatVec -> [PmPat 'VA]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap PmPat 'PAT -> [PmPat 'VA]
coercePmPat PatVec
pv
coercePmPat :: Pattern -> [ValAbs]
coercePmPat :: PmPat 'PAT -> [PmPat 'VA]
coercePmPat (PmVar { pm_var_id :: forall (t :: PatTy). PmPat t -> TyVar
pm_var_id = TyVar
x }) = [PmVar :: forall (t :: PatTy). TyVar -> PmPat t
PmVar { pm_var_id :: TyVar
pm_var_id = TyVar
x }]
coercePmPat (PmLit { pm_lit_lit :: forall (t :: PatTy). PmPat t -> PmLit
pm_lit_lit = PmLit
l }) = [PmLit :: forall (t :: PatTy). PmLit -> PmPat t
PmLit { pm_lit_lit :: PmLit
pm_lit_lit = PmLit
l }]
coercePmPat (PmCon { pm_con_con :: forall (t :: PatTy). PmPat t -> ConLike
pm_con_con = ConLike
con, pm_con_arg_tys :: forall (t :: PatTy). PmPat t -> [Type]
pm_con_arg_tys = [Type]
arg_tys
, pm_con_tvs :: forall (t :: PatTy). PmPat t -> [TyVar]
pm_con_tvs = [TyVar]
tvs, pm_con_dicts :: forall (t :: PatTy). PmPat t -> [TyVar]
pm_con_dicts = [TyVar]
dicts
, pm_con_args :: forall (t :: PatTy). PmPat t -> [PmPat t]
pm_con_args = PatVec
args })
= [PmCon :: forall (t :: PatTy).
ConLike -> [Type] -> [TyVar] -> [TyVar] -> [PmPat t] -> PmPat t
PmCon { pm_con_con :: ConLike
pm_con_con = ConLike
con, pm_con_arg_tys :: [Type]
pm_con_arg_tys = [Type]
arg_tys
, pm_con_tvs :: [TyVar]
pm_con_tvs = [TyVar]
tvs, pm_con_dicts :: [TyVar]
pm_con_dicts = [TyVar]
dicts
, pm_con_args :: [PmPat 'VA]
pm_con_args = PatVec -> [PmPat 'VA]
coercePatVec PatVec
args }]
coercePmPat (PmGrd {}) = []
singleConstructor :: ConLike -> Bool
singleConstructor :: ConLike -> Bool
singleConstructor (RealDataCon dc :: DataCon
dc) =
case TyCon -> [DataCon]
tyConDataCons (DataCon -> TyCon
dataConTyCon DataCon
dc) of
[_] -> Bool
True
_ -> Bool
False
singleConstructor _ = Bool
False
allCompleteMatches :: ConLike -> [Type] -> DsM [(Provenance, [ConLike])]
allCompleteMatches :: ConLike -> [Type] -> DsM [(Provenance, [ConLike])]
allCompleteMatches cl :: ConLike
cl tys :: [Type]
tys = do
let fam :: [(Provenance, [ConLike])]
fam = case ConLike
cl of
RealDataCon dc :: DataCon
dc ->
[(Provenance
FromBuiltin, (DataCon -> ConLike) -> [DataCon] -> [ConLike]
forall a b. (a -> b) -> [a] -> [b]
map DataCon -> ConLike
RealDataCon (TyCon -> [DataCon]
tyConDataCons (DataCon -> TyCon
dataConTyCon DataCon
dc)))]
PatSynCon _ -> []
ty :: Type
ty = ConLike -> [Type] -> Type
conLikeResTy ConLike
cl [Type]
tys
[CompleteMatch]
pragmas <- case HasDebugCallStack => Type -> Maybe (TyCon, [Type])
Type -> Maybe (TyCon, [Type])
splitTyConApp_maybe Type
ty of
Just (tc :: TyCon
tc, _) -> TyCon -> DsM [CompleteMatch]
dsGetCompleteMatches TyCon
tc
Nothing -> [CompleteMatch] -> DsM [CompleteMatch]
forall (m :: * -> *) a. Monad m => a -> m a
return []
let fams :: CompleteMatch
-> IOEnv (Env DsGblEnv DsLclEnv) (Provenance, [ConLike])
fams cm :: CompleteMatch
cm = (Provenance
FromComplete,) ([ConLike] -> (Provenance, [ConLike]))
-> IOEnv (Env DsGblEnv DsLclEnv) [ConLike]
-> IOEnv (Env DsGblEnv DsLclEnv) (Provenance, [ConLike])
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>
(Name -> IOEnv (Env DsGblEnv DsLclEnv) ConLike)
-> [Name] -> IOEnv (Env DsGblEnv DsLclEnv) [ConLike]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM Name -> IOEnv (Env DsGblEnv DsLclEnv) ConLike
dsLookupConLike (CompleteMatch -> [Name]
completeMatchConLikes CompleteMatch
cm)
[(Provenance, [ConLike])]
from_pragma <- ((Provenance, [ConLike]) -> Bool)
-> [(Provenance, [ConLike])] -> [(Provenance, [ConLike])]
forall a. (a -> Bool) -> [a] -> [a]
filter (\(_,m :: [ConLike]
m) -> Type -> [ConLike] -> Bool
isValidCompleteMatch Type
ty [ConLike]
m) ([(Provenance, [ConLike])] -> [(Provenance, [ConLike])])
-> DsM [(Provenance, [ConLike])] -> DsM [(Provenance, [ConLike])]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>
(CompleteMatch
-> IOEnv (Env DsGblEnv DsLclEnv) (Provenance, [ConLike]))
-> [CompleteMatch] -> DsM [(Provenance, [ConLike])]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM CompleteMatch
-> IOEnv (Env DsGblEnv DsLclEnv) (Provenance, [ConLike])
fams [CompleteMatch]
pragmas
let final_groups :: [(Provenance, [ConLike])]
final_groups = [(Provenance, [ConLike])]
fam [(Provenance, [ConLike])]
-> [(Provenance, [ConLike])] -> [(Provenance, [ConLike])]
forall a. [a] -> [a] -> [a]
++ [(Provenance, [ConLike])]
from_pragma
[(Provenance, [ConLike])] -> DsM [(Provenance, [ConLike])]
forall (m :: * -> *) a. Monad m => a -> m a
return [(Provenance, [ConLike])]
final_groups
where
isValidCompleteMatch :: Type -> [ConLike] -> Bool
isValidCompleteMatch :: Type -> [ConLike] -> Bool
isValidCompleteMatch ty :: Type
ty = (ConLike -> Bool) -> [ConLike] -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
all ConLike -> Bool
go
where
go :: ConLike -> Bool
go (RealDataCon {}) = Bool
True
go (PatSynCon psc :: PatSyn
psc) = Maybe TCvSubst -> Bool
forall a. Maybe a -> Bool
isJust (Maybe TCvSubst -> Bool) -> Maybe TCvSubst -> Bool
forall a b. (a -> b) -> a -> b
$ (Type -> Type -> Maybe TCvSubst) -> Type -> Type -> Maybe TCvSubst
forall a b c. (a -> b -> c) -> b -> a -> c
flip Type -> Type -> Maybe TCvSubst
tcMatchTy Type
ty (Type -> Maybe TCvSubst) -> Type -> Maybe TCvSubst
forall a b. (a -> b) -> a -> b
$ ([TyVar], [Type], [TyVar], [Type], [Type], Type) -> Type
forall a b c d e f. (a, b, c, d, e, f) -> f
patSynResTy
(([TyVar], [Type], [TyVar], [Type], [Type], Type) -> Type)
-> ([TyVar], [Type], [TyVar], [Type], [Type], Type) -> Type
forall a b. (a -> b) -> a -> b
$ PatSyn -> ([TyVar], [Type], [TyVar], [Type], [Type], Type)
patSynSig PatSyn
psc
patSynResTy :: (a, b, c, d, e, f) -> f
patSynResTy (_, _, _, _, _, res_ty :: f
res_ty) = f
res_ty
newEvVar :: Name -> Type -> EvVar
newEvVar :: Name -> Type -> TyVar
newEvVar name :: Name
name ty :: Type
ty = Name -> Type -> TyVar
mkLocalId Name
name Type
ty
nameType :: String -> Type -> DsM EvVar
nameType :: String -> Type -> DsM TyVar
nameType name :: String
name ty :: Type
ty = do
Unique
unique <- IOEnv (Env DsGblEnv DsLclEnv) Unique
forall (m :: * -> *). MonadUnique m => m Unique
getUniqueM
let occname :: OccName
occname = FastString -> OccName
mkVarOccFS (String -> FastString
fsLit (String
nameString -> ShowS
forall a. [a] -> [a] -> [a]
++"_"String -> ShowS
forall a. [a] -> [a] -> [a]
++Unique -> String
forall a. Show a => a -> String
show Unique
unique))
idname :: Name
idname = Unique -> OccName -> SrcSpan -> Name
mkInternalName Unique
unique OccName
occname SrcSpan
noSrcSpan
TyVar -> DsM TyVar
forall (m :: * -> *) a. Monad m => a -> m a
return (Name -> Type -> TyVar
newEvVar Name
idname Type
ty)
tyOracle :: Bag EvVar -> PmM Bool
tyOracle :: Bag TyVar -> PmM Bool
tyOracle evs :: Bag TyVar
evs
= DsM Bool -> PmM Bool
forall a. DsM a -> PmM a
liftD (DsM Bool -> PmM Bool) -> DsM Bool -> PmM Bool
forall a b. (a -> b) -> a -> b
$
do { ((_warns :: WarningMessages
_warns, errs :: WarningMessages
errs), res :: Maybe Bool
res) <- TcM Bool -> DsM (Messages, Maybe Bool)
forall a. TcM a -> DsM (Messages, Maybe a)
initTcDsForSolver (TcM Bool -> DsM (Messages, Maybe Bool))
-> TcM Bool -> DsM (Messages, Maybe Bool)
forall a b. (a -> b) -> a -> b
$ Bag TyVar -> TcM Bool
tcCheckSatisfiability Bag TyVar
evs
; case Maybe Bool
res of
Just sat :: Bool
sat -> Bool -> DsM Bool
forall (m :: * -> *) a. Monad m => a -> m a
return Bool
sat
Nothing -> String -> SDoc -> DsM Bool
forall a. HasCallStack => String -> SDoc -> a
pprPanic "tyOracle" ([SDoc] -> SDoc
vcat ([SDoc] -> SDoc) -> [SDoc] -> SDoc
forall a b. (a -> b) -> a -> b
$ WarningMessages -> [SDoc]
pprErrMsgBagWithLoc WarningMessages
errs) }
type PmArity = Int
patVecArity :: PatVec -> PmArity
patVecArity :: PatVec -> Int
patVecArity = [Int] -> Int
forall (t :: * -> *) a. (Foldable t, Num a) => t a -> a
sum ([Int] -> Int) -> (PatVec -> [Int]) -> PatVec -> Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (PmPat 'PAT -> Int) -> PatVec -> [Int]
forall a b. (a -> b) -> [a] -> [b]
map PmPat 'PAT -> Int
patternArity
patternArity :: Pattern -> PmArity
patternArity :: PmPat 'PAT -> Int
patternArity (PmGrd {}) = 0
patternArity _other_pat :: PmPat 'PAT
_other_pat = 1
runMany :: (ValVec -> PmM PartialResult) -> (Uncovered -> PmM PartialResult)
runMany :: (ValVec -> PmM PartialResult) -> Uncovered -> PmM PartialResult
runMany _ [] = PartialResult -> PmM PartialResult
forall (m :: * -> *) a. Monad m => a -> m a
return PartialResult
forall a. Monoid a => a
mempty
runMany pm :: ValVec -> PmM PartialResult
pm (m :: ValVec
m:ms :: Uncovered
ms) = PartialResult -> PartialResult -> PartialResult
forall a. Monoid a => a -> a -> a
mappend (PartialResult -> PartialResult -> PartialResult)
-> PmM PartialResult -> ListT DsM (PartialResult -> PartialResult)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ValVec -> PmM PartialResult
pm ValVec
m ListT DsM (PartialResult -> PartialResult)
-> PmM PartialResult -> PmM PartialResult
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (ValVec -> PmM PartialResult) -> Uncovered -> PmM PartialResult
runMany ValVec -> PmM PartialResult
pm Uncovered
ms
mkInitialUncovered :: [Id] -> PmM Uncovered
mkInitialUncovered :: [TyVar] -> PmM Uncovered
mkInitialUncovered vars :: [TyVar]
vars = do
Delta
delta <- PmM Delta
pmInitialTmTyCs
let patterns :: [PmPat 'VA]
patterns = (TyVar -> PmPat 'VA) -> [TyVar] -> [PmPat 'VA]
forall a b. (a -> b) -> [a] -> [b]
map TyVar -> PmPat 'VA
forall (t :: PatTy). TyVar -> PmPat t
PmVar [TyVar]
vars
Uncovered -> PmM Uncovered
forall (m :: * -> *) a. Monad m => a -> m a
return [[PmPat 'VA] -> Delta -> ValVec
ValVec [PmPat 'VA]
patterns Delta
delta]
pmcheckI :: PatVec -> [PatVec] -> ValVec -> PmM PartialResult
pmcheckI :: PatVec -> [PatVec] -> ValVec -> PmM PartialResult
pmcheckI ps :: PatVec
ps guards :: [PatVec]
guards vva :: ValVec
vva = do
Int
n <- DsM Int -> PmM Int
forall a. DsM a -> PmM a
liftD DsM Int
incrCheckPmIterDs
String -> SDoc -> PmM ()
tracePm "pmCheck" (Int -> SDoc
forall a. Outputable a => a -> SDoc
ppr Int
n SDoc -> SDoc -> SDoc
<> SDoc
colon SDoc -> SDoc -> SDoc
<+> PatVec -> SDoc
pprPatVec PatVec
ps
SDoc -> SDoc -> SDoc
$$ SDoc -> Int -> SDoc -> SDoc
hang (String -> SDoc
text "guards:") 2 ([SDoc] -> SDoc
vcat ((PatVec -> SDoc) -> [PatVec] -> [SDoc]
forall a b. (a -> b) -> [a] -> [b]
map PatVec -> SDoc
pprPatVec [PatVec]
guards))
SDoc -> SDoc -> SDoc
$$ ValVec -> SDoc
pprValVecDebug ValVec
vva)
PartialResult
res <- PatVec -> [PatVec] -> ValVec -> PmM PartialResult
pmcheck PatVec
ps [PatVec]
guards ValVec
vva
String -> SDoc -> PmM ()
tracePm "pmCheckResult:" (PartialResult -> SDoc
forall a. Outputable a => a -> SDoc
ppr PartialResult
res)
PartialResult -> PmM PartialResult
forall (m :: * -> *) a. Monad m => a -> m a
return PartialResult
res
{-# INLINE pmcheckI #-}
pmcheckGuardsI :: [PatVec] -> ValVec -> PmM PartialResult
pmcheckGuardsI :: [PatVec] -> ValVec -> PmM PartialResult
pmcheckGuardsI gvs :: [PatVec]
gvs vva :: ValVec
vva = DsM Int -> PmM Int
forall a. DsM a -> PmM a
liftD DsM Int
incrCheckPmIterDs PmM Int -> PmM PartialResult -> PmM PartialResult
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> [PatVec] -> ValVec -> PmM PartialResult
pmcheckGuards [PatVec]
gvs ValVec
vva
{-# INLINE pmcheckGuardsI #-}
pmcheckHdI :: Pattern -> PatVec -> [PatVec] -> ValAbs -> ValVec
-> PmM PartialResult
pmcheckHdI :: PmPat 'PAT
-> PatVec -> [PatVec] -> PmPat 'VA -> ValVec -> PmM PartialResult
pmcheckHdI p :: PmPat 'PAT
p ps :: PatVec
ps guards :: [PatVec]
guards va :: PmPat 'VA
va vva :: ValVec
vva = do
Int
n <- DsM Int -> PmM Int
forall a. DsM a -> PmM a
liftD DsM Int
incrCheckPmIterDs
String -> SDoc -> PmM ()
tracePm "pmCheckHdI" (Int -> SDoc
forall a. Outputable a => a -> SDoc
ppr Int
n SDoc -> SDoc -> SDoc
<> SDoc
colon SDoc -> SDoc -> SDoc
<+> PmPat 'PAT -> SDoc
forall (a :: PatTy). PmPat a -> SDoc
pprPmPatDebug PmPat 'PAT
p
SDoc -> SDoc -> SDoc
$$ PatVec -> SDoc
pprPatVec PatVec
ps
SDoc -> SDoc -> SDoc
$$ SDoc -> Int -> SDoc -> SDoc
hang (String -> SDoc
text "guards:") 2 ([SDoc] -> SDoc
vcat ((PatVec -> SDoc) -> [PatVec] -> [SDoc]
forall a b. (a -> b) -> [a] -> [b]
map PatVec -> SDoc
pprPatVec [PatVec]
guards))
SDoc -> SDoc -> SDoc
$$ PmPat 'VA -> SDoc
forall (a :: PatTy). PmPat a -> SDoc
pprPmPatDebug PmPat 'VA
va
SDoc -> SDoc -> SDoc
$$ ValVec -> SDoc
pprValVecDebug ValVec
vva)
PartialResult
res <- PmPat 'PAT
-> PatVec -> [PatVec] -> PmPat 'VA -> ValVec -> PmM PartialResult
pmcheckHd PmPat 'PAT
p PatVec
ps [PatVec]
guards PmPat 'VA
va ValVec
vva
String -> SDoc -> PmM ()
tracePm "pmCheckHdI: res" (PartialResult -> SDoc
forall a. Outputable a => a -> SDoc
ppr PartialResult
res)
PartialResult -> PmM PartialResult
forall (m :: * -> *) a. Monad m => a -> m a
return PartialResult
res
{-# INLINE pmcheckHdI #-}
pmcheck :: PatVec -> [PatVec] -> ValVec -> PmM PartialResult
pmcheck :: PatVec -> [PatVec] -> ValVec -> PmM PartialResult
pmcheck [] guards :: [PatVec]
guards vva :: ValVec
vva@(ValVec [] _)
| [PatVec] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [PatVec]
guards = PartialResult -> PmM PartialResult
forall (m :: * -> *) a. Monad m => a -> m a
return (PartialResult -> PmM PartialResult)
-> PartialResult -> PmM PartialResult
forall a b. (a -> b) -> a -> b
$ PartialResult
forall a. Monoid a => a
mempty { presultCovered :: Covered
presultCovered = Covered
Covered }
| Bool
otherwise = [PatVec] -> ValVec -> PmM PartialResult
pmcheckGuardsI [PatVec]
guards ValVec
vva
pmcheck (p :: PmPat 'PAT
p@(PmGrd pv :: PatVec
pv e :: PmExpr
e) : ps :: PatVec
ps) guards :: [PatVec]
guards vva :: ValVec
vva@(ValVec vas :: [PmPat 'VA]
vas delta :: Delta
delta)
| PatVec -> PmExpr -> Bool
isFakeGuard PatVec
pv PmExpr
e = PartialResult -> PartialResult
forces (PartialResult -> PartialResult)
-> (PartialResult -> PartialResult)
-> PartialResult
-> PartialResult
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ValVec -> PartialResult -> PartialResult
mkCons ValVec
vva (PartialResult -> PartialResult)
-> PmM PartialResult -> PmM PartialResult
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> PatVec -> [PatVec] -> ValVec -> PmM PartialResult
pmcheckI PatVec
ps [PatVec]
guards ValVec
vva
| Bool
otherwise = do
TyVar
y <- DsM TyVar -> PmM TyVar
forall a. DsM a -> PmM a
liftD (DsM TyVar -> PmM TyVar) -> DsM TyVar -> PmM TyVar
forall a b. (a -> b) -> a -> b
$ Type -> DsM TyVar
mkPmId (PmPat 'PAT -> Type
forall (p :: PatTy). PmPat p -> Type
pmPatType PmPat 'PAT
p)
let tm_state :: TmState
tm_state = TyVar -> PmExpr -> TmState -> TmState
extendSubst TyVar
y PmExpr
e (Delta -> TmState
delta_tm_cs Delta
delta)
delta' :: Delta
delta' = Delta
delta { delta_tm_cs :: TmState
delta_tm_cs = TmState
tm_state }
PartialResult -> PartialResult
utail (PartialResult -> PartialResult)
-> PmM PartialResult -> PmM PartialResult
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> PatVec -> [PatVec] -> ValVec -> PmM PartialResult
pmcheckI (PatVec
pv PatVec -> PatVec -> PatVec
forall a. [a] -> [a] -> [a]
++ PatVec
ps) [PatVec]
guards ([PmPat 'VA] -> Delta -> ValVec
ValVec (TyVar -> PmPat 'VA
forall (t :: PatTy). TyVar -> PmPat t
PmVar TyVar
y PmPat 'VA -> [PmPat 'VA] -> [PmPat 'VA]
forall a. a -> [a] -> [a]
: [PmPat 'VA]
vas) Delta
delta')
pmcheck [] _ (ValVec (_:_) _) = String -> PmM PartialResult
forall a. String -> a
panic "pmcheck: nil-cons"
pmcheck (_:_) _ (ValVec [] _) = String -> PmM PartialResult
forall a. String -> a
panic "pmcheck: cons-nil"
pmcheck (p :: PmPat 'PAT
p:ps :: PatVec
ps) guards :: [PatVec]
guards (ValVec (va :: PmPat 'VA
va:vva :: [PmPat 'VA]
vva) delta :: Delta
delta)
= PmPat 'PAT
-> PatVec -> [PatVec] -> PmPat 'VA -> ValVec -> PmM PartialResult
pmcheckHdI PmPat 'PAT
p PatVec
ps [PatVec]
guards PmPat 'VA
va ([PmPat 'VA] -> Delta -> ValVec
ValVec [PmPat 'VA]
vva Delta
delta)
pmcheckGuards :: [PatVec] -> ValVec -> PmM PartialResult
pmcheckGuards :: [PatVec] -> ValVec -> PmM PartialResult
pmcheckGuards [] vva :: ValVec
vva = PartialResult -> PmM PartialResult
forall (m :: * -> *) a. Monad m => a -> m a
return (Uncovered -> PartialResult
usimple [ValVec
vva])
pmcheckGuards (gv :: PatVec
gv:gvs :: [PatVec]
gvs) vva :: ValVec
vva = do
(PartialResult prov1 :: Provenance
prov1 cs :: Covered
cs vsa :: Uncovered
vsa ds :: Diverged
ds) <- PatVec -> [PatVec] -> ValVec -> PmM PartialResult
pmcheckI PatVec
gv [] ValVec
vva
(PartialResult prov2 :: Provenance
prov2 css :: Covered
css vsas :: Uncovered
vsas dss :: Diverged
dss) <- (ValVec -> PmM PartialResult) -> Uncovered -> PmM PartialResult
runMany ([PatVec] -> ValVec -> PmM PartialResult
pmcheckGuardsI [PatVec]
gvs) Uncovered
vsa
PartialResult -> PmM PartialResult
forall (m :: * -> *) a. Monad m => a -> m a
return (PartialResult -> PmM PartialResult)
-> PartialResult -> PmM PartialResult
forall a b. (a -> b) -> a -> b
$ Provenance -> Covered -> Uncovered -> Diverged -> PartialResult
PartialResult (Provenance
prov1 Provenance -> Provenance -> Provenance
forall a. Monoid a => a -> a -> a
`mappend` Provenance
prov2)
(Covered
cs Covered -> Covered -> Covered
forall a. Monoid a => a -> a -> a
`mappend` Covered
css)
Uncovered
vsas
(Diverged
ds Diverged -> Diverged -> Diverged
forall a. Monoid a => a -> a -> a
`mappend` Diverged
dss)
pmcheckHd :: Pattern -> PatVec -> [PatVec] -> ValAbs -> ValVec
-> PmM PartialResult
pmcheckHd :: PmPat 'PAT
-> PatVec -> [PatVec] -> PmPat 'VA -> ValVec -> PmM PartialResult
pmcheckHd (PmVar x :: TyVar
x) ps :: PatVec
ps guards :: [PatVec]
guards va :: PmPat 'VA
va (ValVec vva :: [PmPat 'VA]
vva delta :: Delta
delta)
| Just tm_state :: TmState
tm_state <- TmState -> ComplexEq -> Maybe TmState
solveOneEq (Delta -> TmState
delta_tm_cs Delta
delta)
(Name -> PmExpr
PmExprVar (TyVar -> Name
idName TyVar
x), PmPat 'VA -> PmExpr
vaToPmExpr PmPat 'VA
va)
= PmPat 'VA -> PartialResult -> PartialResult
ucon PmPat 'VA
va (PartialResult -> PartialResult)
-> PmM PartialResult -> PmM PartialResult
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> PatVec -> [PatVec] -> ValVec -> PmM PartialResult
pmcheckI PatVec
ps [PatVec]
guards ([PmPat 'VA] -> Delta -> ValVec
ValVec [PmPat 'VA]
vva (Delta
delta {delta_tm_cs :: TmState
delta_tm_cs = TmState
tm_state}))
| Bool
otherwise = PartialResult -> PmM PartialResult
forall (m :: * -> *) a. Monad m => a -> m a
return PartialResult
forall a. Monoid a => a
mempty
pmcheckHd ( p :: PmPat 'PAT
p@(PmCon { pm_con_con :: forall (t :: PatTy). PmPat t -> ConLike
pm_con_con = ConLike
c1, pm_con_tvs :: forall (t :: PatTy). PmPat t -> [TyVar]
pm_con_tvs = [TyVar]
ex_tvs1
, pm_con_args :: forall (t :: PatTy). PmPat t -> [PmPat t]
pm_con_args = PatVec
args1})) ps :: PatVec
ps guards :: [PatVec]
guards
(va :: PmPat 'VA
va@(PmCon { pm_con_con :: forall (t :: PatTy). PmPat t -> ConLike
pm_con_con = ConLike
c2, pm_con_tvs :: forall (t :: PatTy). PmPat t -> [TyVar]
pm_con_tvs = [TyVar]
ex_tvs2
, pm_con_args :: forall (t :: PatTy). PmPat t -> [PmPat t]
pm_con_args = [PmPat 'VA]
args2})) (ValVec vva :: [PmPat 'VA]
vva delta :: Delta
delta)
| ConLike
c1 ConLike -> ConLike -> Bool
forall a. Eq a => a -> a -> Bool
/= ConLike
c2 =
PartialResult -> PmM PartialResult
forall (m :: * -> *) a. Monad m => a -> m a
return (Uncovered -> PartialResult
usimple [[PmPat 'VA] -> Delta -> ValVec
ValVec (PmPat 'VA
vaPmPat 'VA -> [PmPat 'VA] -> [PmPat 'VA]
forall a. a -> [a] -> [a]
:[PmPat 'VA]
vva) Delta
delta])
| Bool
otherwise = do
let to_evvar :: TyVar -> TyVar -> DsM TyVar
to_evvar tv1 :: TyVar
tv1 tv2 :: TyVar
tv2 = String -> Type -> DsM TyVar
nameType "pmConCon" (Type -> DsM TyVar) -> Type -> DsM TyVar
forall a b. (a -> b) -> a -> b
$
Type -> Type -> Type
mkPrimEqPred (TyVar -> Type
mkTyVarTy TyVar
tv1) (TyVar -> Type
mkTyVarTy TyVar
tv2)
mb_to_evvar :: TyVar -> TyVar -> IOEnv (Env DsGblEnv DsLclEnv) (Maybe TyVar)
mb_to_evvar tv1 :: TyVar
tv1 tv2 :: TyVar
tv2
| TyVar
tv1 TyVar -> TyVar -> Bool
forall a. Eq a => a -> a -> Bool
== TyVar
tv2 = Maybe TyVar -> IOEnv (Env DsGblEnv DsLclEnv) (Maybe TyVar)
forall (f :: * -> *) a. Applicative f => a -> f a
pure Maybe TyVar
forall a. Maybe a
Nothing
| Bool
otherwise = TyVar -> Maybe TyVar
forall a. a -> Maybe a
Just (TyVar -> Maybe TyVar)
-> DsM TyVar -> IOEnv (Env DsGblEnv DsLclEnv) (Maybe TyVar)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> TyVar -> TyVar -> DsM TyVar
to_evvar TyVar
tv1 TyVar
tv2
Bag TyVar
evvars <- ([TyVar] -> Bag TyVar
forall a. [a] -> Bag a
listToBag ([TyVar] -> Bag TyVar)
-> ([Maybe TyVar] -> [TyVar]) -> [Maybe TyVar] -> Bag TyVar
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Maybe TyVar] -> [TyVar]
forall a. [Maybe a] -> [a]
catMaybes) ([Maybe TyVar] -> Bag TyVar)
-> ListT DsM [Maybe TyVar] -> PmM (Bag TyVar)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>
ASSERT(ex_tvs1 `equalLength` ex_tvs2)
DsM [Maybe TyVar] -> ListT DsM [Maybe TyVar]
forall a. DsM a -> PmM a
liftD ((TyVar -> TyVar -> IOEnv (Env DsGblEnv DsLclEnv) (Maybe TyVar))
-> [TyVar] -> [TyVar] -> DsM [Maybe TyVar]
forall (m :: * -> *) a b c.
Applicative m =>
(a -> b -> m c) -> [a] -> [b] -> m [c]
zipWithM TyVar -> TyVar -> IOEnv (Env DsGblEnv DsLclEnv) (Maybe TyVar)
mb_to_evvar [TyVar]
ex_tvs1 [TyVar]
ex_tvs2)
let delta' :: Delta
delta' = Delta
delta { delta_ty_cs :: Bag TyVar
delta_ty_cs = Bag TyVar
evvars Bag TyVar -> Bag TyVar -> Bag TyVar
forall a. Bag a -> Bag a -> Bag a
`unionBags` Delta -> Bag TyVar
delta_ty_cs Delta
delta }
ConLike
-> [Type] -> [TyVar] -> [TyVar] -> PartialResult -> PartialResult
kcon ConLike
c1 (PmPat 'PAT -> [Type]
forall (t :: PatTy). PmPat t -> [Type]
pm_con_arg_tys PmPat 'PAT
p) (PmPat 'PAT -> [TyVar]
forall (t :: PatTy). PmPat t -> [TyVar]
pm_con_tvs PmPat 'PAT
p) (PmPat 'PAT -> [TyVar]
forall (t :: PatTy). PmPat t -> [TyVar]
pm_con_dicts PmPat 'PAT
p)
(PartialResult -> PartialResult)
-> PmM PartialResult -> PmM PartialResult
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> PatVec -> [PatVec] -> ValVec -> PmM PartialResult
pmcheckI (PatVec
args1 PatVec -> PatVec -> PatVec
forall a. [a] -> [a] -> [a]
++ PatVec
ps) [PatVec]
guards ([PmPat 'VA] -> Delta -> ValVec
ValVec ([PmPat 'VA]
args2 [PmPat 'VA] -> [PmPat 'VA] -> [PmPat 'VA]
forall a. [a] -> [a] -> [a]
++ [PmPat 'VA]
vva) Delta
delta')
pmcheckHd (PmLit l1 :: PmLit
l1) ps :: PatVec
ps guards :: [PatVec]
guards (va :: PmPat 'VA
va@(PmLit l2 :: PmLit
l2)) vva :: ValVec
vva =
case PmLit -> PmLit -> Bool
eqPmLit PmLit
l1 PmLit
l2 of
True -> PmPat 'VA -> PartialResult -> PartialResult
ucon PmPat 'VA
va (PartialResult -> PartialResult)
-> PmM PartialResult -> PmM PartialResult
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> PatVec -> [PatVec] -> ValVec -> PmM PartialResult
pmcheckI PatVec
ps [PatVec]
guards ValVec
vva
False -> PartialResult -> PmM PartialResult
forall (m :: * -> *) a. Monad m => a -> m a
return (PartialResult -> PmM PartialResult)
-> PartialResult -> PmM PartialResult
forall a b. (a -> b) -> a -> b
$ PmPat 'VA -> PartialResult -> PartialResult
ucon PmPat 'VA
va (Uncovered -> PartialResult
usimple [ValVec
vva])
pmcheckHd (p :: PmPat 'PAT
p@(PmCon { pm_con_con :: forall (t :: PatTy). PmPat t -> ConLike
pm_con_con = ConLike
con, pm_con_arg_tys :: forall (t :: PatTy). PmPat t -> [Type]
pm_con_arg_tys = [Type]
tys }))
ps :: PatVec
ps guards :: [PatVec]
guards
(PmVar x :: TyVar
x) (ValVec vva :: [PmPat 'VA]
vva delta :: Delta
delta) = do
(prov :: Provenance
prov, complete_match :: [ConLike]
complete_match) <- [(Provenance, [ConLike])] -> ListT DsM (Provenance, [ConLike])
forall (m :: * -> *) a. Monad m => [a] -> ListT m a
select ([(Provenance, [ConLike])] -> ListT DsM (Provenance, [ConLike]))
-> ListT DsM [(Provenance, [ConLike])]
-> ListT DsM (Provenance, [ConLike])
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< DsM [(Provenance, [ConLike])]
-> ListT DsM [(Provenance, [ConLike])]
forall a. DsM a -> PmM a
liftD (ConLike -> [Type] -> DsM [(Provenance, [ConLike])]
allCompleteMatches ConLike
con [Type]
tys)
[InhabitationCandidate]
cons_cs <- (ConLike -> ListT DsM InhabitationCandidate)
-> [ConLike] -> ListT DsM [InhabitationCandidate]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM (IOEnv (Env DsGblEnv DsLclEnv) InhabitationCandidate
-> ListT DsM InhabitationCandidate
forall a. DsM a -> PmM a
liftD (IOEnv (Env DsGblEnv DsLclEnv) InhabitationCandidate
-> ListT DsM InhabitationCandidate)
-> (ConLike -> IOEnv (Env DsGblEnv DsLclEnv) InhabitationCandidate)
-> ConLike
-> ListT DsM InhabitationCandidate
forall b c a. (b -> c) -> (a -> b) -> a -> c
. TyVar
-> ConLike -> IOEnv (Env DsGblEnv DsLclEnv) InhabitationCandidate
mkOneConFull TyVar
x) [ConLike]
complete_match
Uncovered
inst_vsa <- ((InhabitationCandidate -> ListT DsM (Maybe ValVec))
-> [InhabitationCandidate] -> PmM Uncovered)
-> [InhabitationCandidate]
-> (InhabitationCandidate -> ListT DsM (Maybe ValVec))
-> PmM Uncovered
forall a b c. (a -> b -> c) -> b -> a -> c
flip (InhabitationCandidate -> ListT DsM (Maybe ValVec))
-> [InhabitationCandidate] -> PmM Uncovered
forall (m :: * -> *) a b.
Applicative m =>
(a -> m (Maybe b)) -> [a] -> m [b]
mapMaybeM [InhabitationCandidate]
cons_cs ((InhabitationCandidate -> ListT DsM (Maybe ValVec))
-> PmM Uncovered)
-> (InhabitationCandidate -> ListT DsM (Maybe ValVec))
-> PmM Uncovered
forall a b. (a -> b) -> a -> b
$
\InhabitationCandidate{ ic_val_abs :: InhabitationCandidate -> PmPat 'VA
ic_val_abs = PmPat 'VA
va, ic_tm_ct :: InhabitationCandidate -> ComplexEq
ic_tm_ct = ComplexEq
tm_ct
, ic_ty_cs :: InhabitationCandidate -> Bag TyVar
ic_ty_cs = Bag TyVar
ty_cs
, ic_strict_arg_tys :: InhabitationCandidate -> [Type]
ic_strict_arg_tys = [Type]
strict_arg_tys } -> do
Maybe Delta
mb_sat <- Delta -> ComplexEq -> Bag TyVar -> [Type] -> PmM (Maybe Delta)
pmIsSatisfiable Delta
delta ComplexEq
tm_ct Bag TyVar
ty_cs [Type]
strict_arg_tys
Maybe ValVec -> ListT DsM (Maybe ValVec)
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Maybe ValVec -> ListT DsM (Maybe ValVec))
-> Maybe ValVec -> ListT DsM (Maybe ValVec)
forall a b. (a -> b) -> a -> b
$ (Delta -> ValVec) -> Maybe Delta -> Maybe ValVec
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ([PmPat 'VA] -> Delta -> ValVec
ValVec (PmPat 'VA
vaPmPat 'VA -> [PmPat 'VA] -> [PmPat 'VA]
forall a. a -> [a] -> [a]
:[PmPat 'VA]
vva)) Maybe Delta
mb_sat
Provenance -> PartialResult -> PartialResult
set_provenance Provenance
prov (PartialResult -> PartialResult)
-> (PartialResult -> PartialResult)
-> PartialResult
-> PartialResult
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
Bool -> PartialResult -> PartialResult
force_if (Name -> TmState -> Bool
canDiverge (TyVar -> Name
idName TyVar
x) (Delta -> TmState
delta_tm_cs Delta
delta)) (PartialResult -> PartialResult)
-> PmM PartialResult -> PmM PartialResult
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>
(ValVec -> PmM PartialResult) -> Uncovered -> PmM PartialResult
runMany (PatVec -> [PatVec] -> ValVec -> PmM PartialResult
pmcheckI (PmPat 'PAT
pPmPat 'PAT -> PatVec -> PatVec
forall a. a -> [a] -> [a]
:PatVec
ps) [PatVec]
guards) Uncovered
inst_vsa
pmcheckHd (p :: PmPat 'PAT
p@(PmLit l :: PmLit
l)) ps :: PatVec
ps guards :: [PatVec]
guards (PmVar x :: TyVar
x) (ValVec vva :: [PmPat 'VA]
vva delta :: Delta
delta)
= Bool -> PartialResult -> PartialResult
force_if (Name -> TmState -> Bool
canDiverge (TyVar -> Name
idName TyVar
x) (Delta -> TmState
delta_tm_cs Delta
delta)) (PartialResult -> PartialResult)
-> (PartialResult -> PartialResult)
-> PartialResult
-> PartialResult
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>
PartialResult -> PartialResult -> PartialResult
mkUnion PartialResult
non_matched (PartialResult -> PartialResult)
-> PmM PartialResult -> PmM PartialResult
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>
case TmState -> ComplexEq -> Maybe TmState
solveOneEq (Delta -> TmState
delta_tm_cs Delta
delta) (TyVar -> PmLit -> ComplexEq
mkPosEq TyVar
x PmLit
l) of
Just tm_state :: TmState
tm_state -> PmPat 'PAT
-> PatVec -> [PatVec] -> PmPat 'VA -> ValVec -> PmM PartialResult
pmcheckHdI PmPat 'PAT
p PatVec
ps [PatVec]
guards (PmLit -> PmPat 'VA
forall (t :: PatTy). PmLit -> PmPat t
PmLit PmLit
l) (ValVec -> PmM PartialResult) -> ValVec -> PmM PartialResult
forall a b. (a -> b) -> a -> b
$
[PmPat 'VA] -> Delta -> ValVec
ValVec [PmPat 'VA]
vva (Delta
delta {delta_tm_cs :: TmState
delta_tm_cs = TmState
tm_state})
Nothing -> PartialResult -> PmM PartialResult
forall (m :: * -> *) a. Monad m => a -> m a
return PartialResult
forall a. Monoid a => a
mempty
where
us :: Uncovered
us | Just tm_state :: TmState
tm_state <- TmState -> ComplexEq -> Maybe TmState
solveOneEq (Delta -> TmState
delta_tm_cs Delta
delta) (TyVar -> PmLit -> ComplexEq
mkNegEq TyVar
x PmLit
l)
= [[PmPat 'VA] -> Delta -> ValVec
ValVec (TyVar -> [PmLit] -> PmPat 'VA
PmNLit TyVar
x [PmLit
l] PmPat 'VA -> [PmPat 'VA] -> [PmPat 'VA]
forall a. a -> [a] -> [a]
: [PmPat 'VA]
vva) (Delta
delta { delta_tm_cs :: TmState
delta_tm_cs = TmState
tm_state })]
| Bool
otherwise = []
non_matched :: PartialResult
non_matched = Uncovered -> PartialResult
usimple Uncovered
us
pmcheckHd (p :: PmPat 'PAT
p@(PmLit l :: PmLit
l)) ps :: PatVec
ps guards :: [PatVec]
guards
(PmNLit { pm_lit_id :: PmPat 'VA -> TyVar
pm_lit_id = TyVar
x, pm_lit_not :: PmPat 'VA -> [PmLit]
pm_lit_not = [PmLit]
lits }) (ValVec vva :: [PmPat 'VA]
vva delta :: Delta
delta)
| (PmLit -> Bool) -> [PmLit] -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
all (Bool -> Bool
not (Bool -> Bool) -> (PmLit -> Bool) -> PmLit -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PmLit -> PmLit -> Bool
eqPmLit PmLit
l) [PmLit]
lits
, Just tm_state :: TmState
tm_state <- TmState -> ComplexEq -> Maybe TmState
solveOneEq (Delta -> TmState
delta_tm_cs Delta
delta) (TyVar -> PmLit -> ComplexEq
mkPosEq TyVar
x PmLit
l)
= PartialResult -> PartialResult -> PartialResult
mkUnion PartialResult
non_matched (PartialResult -> PartialResult)
-> PmM PartialResult -> PmM PartialResult
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>
PmPat 'PAT
-> PatVec -> [PatVec] -> PmPat 'VA -> ValVec -> PmM PartialResult
pmcheckHdI PmPat 'PAT
p PatVec
ps [PatVec]
guards (PmLit -> PmPat 'VA
forall (t :: PatTy). PmLit -> PmPat t
PmLit PmLit
l)
([PmPat 'VA] -> Delta -> ValVec
ValVec [PmPat 'VA]
vva (Delta
delta { delta_tm_cs :: TmState
delta_tm_cs = TmState
tm_state }))
| Bool
otherwise = PartialResult -> PmM PartialResult
forall (m :: * -> *) a. Monad m => a -> m a
return PartialResult
non_matched
where
us :: Uncovered
us | Just tm_state :: TmState
tm_state <- TmState -> ComplexEq -> Maybe TmState
solveOneEq (Delta -> TmState
delta_tm_cs Delta
delta) (TyVar -> PmLit -> ComplexEq
mkNegEq TyVar
x PmLit
l)
= [[PmPat 'VA] -> Delta -> ValVec
ValVec (TyVar -> [PmLit] -> PmPat 'VA
PmNLit TyVar
x (PmLit
lPmLit -> [PmLit] -> [PmLit]
forall a. a -> [a] -> [a]
:[PmLit]
lits) PmPat 'VA -> [PmPat 'VA] -> [PmPat 'VA]
forall a. a -> [a] -> [a]
: [PmPat 'VA]
vva) (Delta
delta { delta_tm_cs :: TmState
delta_tm_cs = TmState
tm_state })]
| Bool
otherwise = []
non_matched :: PartialResult
non_matched = Uncovered -> PartialResult
usimple Uncovered
us
pmcheckHd (PmLit l :: PmLit
l) ps :: PatVec
ps guards :: [PatVec]
guards (va :: PmPat 'VA
va@(PmCon {})) (ValVec vva :: [PmPat 'VA]
vva delta :: Delta
delta)
= do TyVar
y <- DsM TyVar -> PmM TyVar
forall a. DsM a -> PmM a
liftD (DsM TyVar -> PmM TyVar) -> DsM TyVar -> PmM TyVar
forall a b. (a -> b) -> a -> b
$ Type -> DsM TyVar
mkPmId (PmPat 'VA -> Type
forall (p :: PatTy). PmPat p -> Type
pmPatType PmPat 'VA
va)
let tm_state :: TmState
tm_state = TyVar -> PmExpr -> TmState -> TmState
extendSubst TyVar
y (PmLit -> PmExpr
PmExprLit PmLit
l) (Delta -> TmState
delta_tm_cs Delta
delta)
delta' :: Delta
delta' = Delta
delta { delta_tm_cs :: TmState
delta_tm_cs = TmState
tm_state }
PmPat 'PAT
-> PatVec -> [PatVec] -> PmPat 'VA -> ValVec -> PmM PartialResult
pmcheckHdI (TyVar -> PmPat 'PAT
forall (t :: PatTy). TyVar -> PmPat t
PmVar TyVar
y) PatVec
ps [PatVec]
guards PmPat 'VA
va ([PmPat 'VA] -> Delta -> ValVec
ValVec [PmPat 'VA]
vva Delta
delta')
pmcheckHd (p :: PmPat 'PAT
p@(PmCon {})) ps :: PatVec
ps guards :: [PatVec]
guards (PmLit l :: PmLit
l) (ValVec vva :: [PmPat 'VA]
vva delta :: Delta
delta)
= do TyVar
y <- DsM TyVar -> PmM TyVar
forall a. DsM a -> PmM a
liftD (DsM TyVar -> PmM TyVar) -> DsM TyVar -> PmM TyVar
forall a b. (a -> b) -> a -> b
$ Type -> DsM TyVar
mkPmId (PmPat 'PAT -> Type
forall (p :: PatTy). PmPat p -> Type
pmPatType PmPat 'PAT
p)
let tm_state :: TmState
tm_state = TyVar -> PmExpr -> TmState -> TmState
extendSubst TyVar
y (PmLit -> PmExpr
PmExprLit PmLit
l) (Delta -> TmState
delta_tm_cs Delta
delta)
delta' :: Delta
delta' = Delta
delta { delta_tm_cs :: TmState
delta_tm_cs = TmState
tm_state }
PmPat 'PAT
-> PatVec -> [PatVec] -> PmPat 'VA -> ValVec -> PmM PartialResult
pmcheckHdI PmPat 'PAT
p PatVec
ps [PatVec]
guards (TyVar -> PmPat 'VA
forall (t :: PatTy). TyVar -> PmPat t
PmVar TyVar
y) ([PmPat 'VA] -> Delta -> ValVec
ValVec [PmPat 'VA]
vva Delta
delta')
pmcheckHd (p :: PmPat 'PAT
p@(PmCon {})) ps :: PatVec
ps guards :: [PatVec]
guards (PmNLit { pm_lit_id :: PmPat 'VA -> TyVar
pm_lit_id = TyVar
x }) vva :: ValVec
vva
= PmPat 'PAT
-> PatVec -> [PatVec] -> PmPat 'VA -> ValVec -> PmM PartialResult
pmcheckHdI PmPat 'PAT
p PatVec
ps [PatVec]
guards (TyVar -> PmPat 'VA
forall (t :: PatTy). TyVar -> PmPat t
PmVar TyVar
x) ValVec
vva
pmcheckHd (PmGrd {}) _ _ _ _ = String -> PmM PartialResult
forall a. String -> a
panic "pmcheckHd: Guard"
updateVsa :: (ValSetAbs -> ValSetAbs) -> (PartialResult -> PartialResult)
updateVsa :: (Uncovered -> Uncovered) -> PartialResult -> PartialResult
updateVsa f :: Uncovered -> Uncovered
f p :: PartialResult
p@(PartialResult { presultUncovered :: PartialResult -> Uncovered
presultUncovered = Uncovered
old })
= PartialResult
p { presultUncovered :: Uncovered
presultUncovered = Uncovered -> Uncovered
f Uncovered
old }
usimple :: ValSetAbs -> PartialResult
usimple :: Uncovered -> PartialResult
usimple vsa :: Uncovered
vsa = PartialResult
forall a. Monoid a => a
mempty { presultUncovered :: Uncovered
presultUncovered = Uncovered
vsa }
utail :: PartialResult -> PartialResult
utail :: PartialResult -> PartialResult
utail = (Uncovered -> Uncovered) -> PartialResult -> PartialResult
updateVsa Uncovered -> Uncovered
upd
where upd :: Uncovered -> Uncovered
upd vsa :: Uncovered
vsa = [ [PmPat 'VA] -> Delta -> ValVec
ValVec [PmPat 'VA]
vva Delta
delta | ValVec (_:vva :: [PmPat 'VA]
vva) delta :: Delta
delta <- Uncovered
vsa ]
ucon :: ValAbs -> PartialResult -> PartialResult
ucon :: PmPat 'VA -> PartialResult -> PartialResult
ucon va :: PmPat 'VA
va = (Uncovered -> Uncovered) -> PartialResult -> PartialResult
updateVsa Uncovered -> Uncovered
upd
where
upd :: Uncovered -> Uncovered
upd vsa :: Uncovered
vsa = [ [PmPat 'VA] -> Delta -> ValVec
ValVec (PmPat 'VA
vaPmPat 'VA -> [PmPat 'VA] -> [PmPat 'VA]
forall a. a -> [a] -> [a]
:[PmPat 'VA]
vva) Delta
delta | ValVec vva :: [PmPat 'VA]
vva delta :: Delta
delta <- Uncovered
vsa ]
kcon :: ConLike -> [Type] -> [TyVar] -> [EvVar]
-> PartialResult -> PartialResult
kcon :: ConLike
-> [Type] -> [TyVar] -> [TyVar] -> PartialResult -> PartialResult
kcon con :: ConLike
con arg_tys :: [Type]
arg_tys ex_tvs :: [TyVar]
ex_tvs dicts :: [TyVar]
dicts
= let n :: Int
n = ConLike -> Int
conLikeArity ConLike
con
upd :: Uncovered -> Uncovered
upd vsa :: Uncovered
vsa =
[ [PmPat 'VA] -> Delta -> ValVec
ValVec (PmPat 'VA
vaPmPat 'VA -> [PmPat 'VA] -> [PmPat 'VA]
forall a. a -> [a] -> [a]
:[PmPat 'VA]
vva) Delta
delta
| ValVec vva' :: [PmPat 'VA]
vva' delta :: Delta
delta <- Uncovered
vsa
, let (args :: [PmPat 'VA]
args, vva :: [PmPat 'VA]
vva) = Int -> [PmPat 'VA] -> ([PmPat 'VA], [PmPat 'VA])
forall a. Int -> [a] -> ([a], [a])
splitAt Int
n [PmPat 'VA]
vva'
, let va :: PmPat 'VA
va = PmCon :: forall (t :: PatTy).
ConLike -> [Type] -> [TyVar] -> [TyVar] -> [PmPat t] -> PmPat t
PmCon { pm_con_con :: ConLike
pm_con_con = ConLike
con
, pm_con_arg_tys :: [Type]
pm_con_arg_tys = [Type]
arg_tys
, pm_con_tvs :: [TyVar]
pm_con_tvs = [TyVar]
ex_tvs
, pm_con_dicts :: [TyVar]
pm_con_dicts = [TyVar]
dicts
, pm_con_args :: [PmPat 'VA]
pm_con_args = [PmPat 'VA]
args } ]
in (Uncovered -> Uncovered) -> PartialResult -> PartialResult
updateVsa Uncovered -> Uncovered
upd
mkUnion :: PartialResult -> PartialResult -> PartialResult
mkUnion :: PartialResult -> PartialResult -> PartialResult
mkUnion = PartialResult -> PartialResult -> PartialResult
forall a. Monoid a => a -> a -> a
mappend
mkCons :: ValVec -> PartialResult -> PartialResult
mkCons :: ValVec -> PartialResult -> PartialResult
mkCons vva :: ValVec
vva = (Uncovered -> Uncovered) -> PartialResult -> PartialResult
updateVsa (ValVec
vvaValVec -> Uncovered -> Uncovered
forall a. a -> [a] -> [a]
:)
forces :: PartialResult -> PartialResult
forces :: PartialResult -> PartialResult
forces pres :: PartialResult
pres = PartialResult
pres { presultDivergent :: Diverged
presultDivergent = Diverged
Diverged }
force_if :: Bool -> PartialResult -> PartialResult
force_if :: Bool -> PartialResult -> PartialResult
force_if True pres :: PartialResult
pres = PartialResult -> PartialResult
forces PartialResult
pres
force_if False pres :: PartialResult
pres = PartialResult
pres
set_provenance :: Provenance -> PartialResult -> PartialResult
set_provenance :: Provenance -> PartialResult -> PartialResult
set_provenance prov :: Provenance
prov pr :: PartialResult
pr = PartialResult
pr { presultProvenance :: Provenance
presultProvenance = Provenance
prov }
genCaseTmCs2 :: Maybe (LHsExpr GhcTc)
-> [Pat GhcTc]
-> [Id]
-> DsM (Bag SimpleEq)
genCaseTmCs2 :: Maybe (LHsExpr GhcTc)
-> [LPat GhcTc] -> [TyVar] -> DsM (Bag SimpleEq)
genCaseTmCs2 Nothing _ _ = Bag SimpleEq -> DsM (Bag SimpleEq)
forall (m :: * -> *) a. Monad m => a -> m a
return Bag SimpleEq
forall a. Bag a
emptyBag
genCaseTmCs2 (Just scr :: LHsExpr GhcTc
scr) [p :: LPat GhcTc
p] [var :: TyVar
var] = do
FamInstEnvs
fam_insts <- DsM FamInstEnvs
dsGetFamInstEnvs
[e :: PmExpr
e] <- (PmPat 'VA -> PmExpr) -> [PmPat 'VA] -> [PmExpr]
forall a b. (a -> b) -> [a] -> [b]
map PmPat 'VA -> PmExpr
vaToPmExpr ([PmPat 'VA] -> [PmExpr])
-> (PatVec -> [PmPat 'VA]) -> PatVec -> [PmExpr]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PatVec -> [PmPat 'VA]
coercePatVec (PatVec -> [PmExpr])
-> DsM PatVec -> IOEnv (Env DsGblEnv DsLclEnv) [PmExpr]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> FamInstEnvs -> LPat GhcTc -> DsM PatVec
translatePat FamInstEnvs
fam_insts LPat GhcTc
p
let scr_e :: PmExpr
scr_e = LHsExpr GhcTc -> PmExpr
lhsExprToPmExpr LHsExpr GhcTc
scr
Bag SimpleEq -> DsM (Bag SimpleEq)
forall (m :: * -> *) a. Monad m => a -> m a
return (Bag SimpleEq -> DsM (Bag SimpleEq))
-> Bag SimpleEq -> DsM (Bag SimpleEq)
forall a b. (a -> b) -> a -> b
$ [SimpleEq] -> Bag SimpleEq
forall a. [a] -> Bag a
listToBag [(TyVar
var, PmExpr
e), (TyVar
var, PmExpr
scr_e)]
genCaseTmCs2 _ _ _ = String -> DsM (Bag SimpleEq)
forall a. String -> a
panic "genCaseTmCs2: HsCase"
genCaseTmCs1 :: Maybe (LHsExpr GhcTc) -> [Id] -> Bag SimpleEq
genCaseTmCs1 :: Maybe (LHsExpr GhcTc) -> [TyVar] -> Bag SimpleEq
genCaseTmCs1 Nothing _ = Bag SimpleEq
forall a. Bag a
emptyBag
genCaseTmCs1 (Just scr :: LHsExpr GhcTc
scr) [var :: TyVar
var] = SimpleEq -> Bag SimpleEq
forall a. a -> Bag a
unitBag (TyVar
var, LHsExpr GhcTc -> PmExpr
lhsExprToPmExpr LHsExpr GhcTc
scr)
genCaseTmCs1 _ _ = String -> Bag SimpleEq
forall a. String -> a
panic "genCaseTmCs1: HsCase"
isAnyPmCheckEnabled :: DynFlags -> DsMatchContext -> Bool
isAnyPmCheckEnabled :: DynFlags -> DsMatchContext -> Bool
isAnyPmCheckEnabled dflags :: DynFlags
dflags (DsMatchContext kind :: HsMatchContext Name
kind _loc :: SrcSpan
_loc)
= WarningFlag -> DynFlags -> Bool
wopt WarningFlag
Opt_WarnOverlappingPatterns DynFlags
dflags Bool -> Bool -> Bool
|| DynFlags -> HsMatchContext Name -> Bool
forall id. DynFlags -> HsMatchContext id -> Bool
exhaustive DynFlags
dflags HsMatchContext Name
kind
instance Outputable ValVec where
ppr :: ValVec -> SDoc
ppr (ValVec vva :: [PmPat 'VA]
vva delta :: Delta
delta)
= let (residual_eqs :: [ComplexEq]
residual_eqs, subst :: PmVarEnv
subst) = TmState -> ([ComplexEq], PmVarEnv)
wrapUpTmState (Delta -> TmState
delta_tm_cs Delta
delta)
vector :: [PmExpr]
vector = PmVarEnv -> [PmPat 'VA] -> [PmExpr]
substInValAbs PmVarEnv
subst [PmPat 'VA]
vva
in ([PmExpr], [ComplexEq]) -> SDoc
ppr_uncovered ([PmExpr]
vector, [ComplexEq]
residual_eqs)
substInValAbs :: PmVarEnv -> [ValAbs] -> [PmExpr]
substInValAbs :: PmVarEnv -> [PmPat 'VA] -> [PmExpr]
substInValAbs subst :: PmVarEnv
subst = (PmPat 'VA -> PmExpr) -> [PmPat 'VA] -> [PmExpr]
forall a b. (a -> b) -> [a] -> [b]
map (PmVarEnv -> PmExpr -> PmExpr
exprDeepLookup PmVarEnv
subst (PmExpr -> PmExpr) -> (PmPat 'VA -> PmExpr) -> PmPat 'VA -> PmExpr
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PmPat 'VA -> PmExpr
vaToPmExpr)
wrapUpTmState :: TmState -> ([ComplexEq], PmVarEnv)
wrapUpTmState :: TmState -> ([ComplexEq], PmVarEnv)
wrapUpTmState (residual :: [ComplexEq]
residual, (_, subst :: PmVarEnv
subst)) = ([ComplexEq]
residual, PmVarEnv -> PmVarEnv
flattenPmVarEnv PmVarEnv
subst)
dsPmWarn :: DynFlags -> DsMatchContext -> PmResult -> DsM ()
dsPmWarn :: DynFlags -> DsMatchContext -> PmResult -> DsM ()
dsPmWarn dflags :: DynFlags
dflags ctx :: DsMatchContext
ctx@(DsMatchContext kind :: HsMatchContext Name
kind loc :: SrcSpan
loc) pm_result :: PmResult
pm_result
= Bool -> DsM () -> DsM ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (Bool
flag_i Bool -> Bool -> Bool
|| Bool
flag_u) (DsM () -> DsM ()) -> DsM () -> DsM ()
forall a b. (a -> b) -> a -> b
$ do
let exists_r :: Bool
exists_r = Bool
flag_i Bool -> Bool -> Bool
&& [Located [LPat GhcTc]] -> Bool
forall a. [a] -> Bool
notNull [Located [LPat GhcTc]]
redundant Bool -> Bool -> Bool
&& Bool
onlyBuiltin
exists_i :: Bool
exists_i = Bool
flag_i Bool -> Bool -> Bool
&& [Located [LPat GhcTc]] -> Bool
forall a. [a] -> Bool
notNull [Located [LPat GhcTc]]
inaccessible Bool -> Bool -> Bool
&& Bool
onlyBuiltin Bool -> Bool -> Bool
&& Bool -> Bool
not Bool
is_rec_upd
exists_u :: Bool
exists_u = Bool
flag_u Bool -> Bool -> Bool
&& (case UncoveredCandidates
uncovered of
TypeOfUncovered _ -> Bool
True
UncoveredPatterns u :: Uncovered
u -> Uncovered -> Bool
forall a. [a] -> Bool
notNull Uncovered
u)
Bool -> DsM () -> DsM ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when Bool
exists_r (DsM () -> DsM ()) -> DsM () -> DsM ()
forall a b. (a -> b) -> a -> b
$ [Located [LPat GhcTc]]
-> (Located [LPat GhcTc] -> DsM ()) -> DsM ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
t a -> (a -> m b) -> m ()
forM_ [Located [LPat GhcTc]]
redundant ((Located [LPat GhcTc] -> DsM ()) -> DsM ())
-> (Located [LPat GhcTc] -> DsM ()) -> DsM ()
forall a b. (a -> b) -> a -> b
$ \(Located [LPat GhcTc]
-> Located (SrcSpanLess (Located [LPat GhcTc]))
forall a. HasSrcSpan a => a -> Located (SrcSpanLess a)
dL->L l :: SrcSpan
l q :: SrcSpanLess (Located [LPat GhcTc])
q) -> do
SrcSpan -> DsM () -> DsM ()
forall a. SrcSpan -> DsM a -> DsM a
putSrcSpanDs SrcSpan
l (WarnReason -> SDoc -> DsM ()
warnDs (WarningFlag -> WarnReason
Reason WarningFlag
Opt_WarnOverlappingPatterns)
([LPat GhcTc] -> String -> SDoc
pprEqn [LPat GhcTc]
SrcSpanLess (Located [LPat GhcTc])
q "is redundant"))
Bool -> DsM () -> DsM ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when Bool
exists_i (DsM () -> DsM ()) -> DsM () -> DsM ()
forall a b. (a -> b) -> a -> b
$ [Located [LPat GhcTc]]
-> (Located [LPat GhcTc] -> DsM ()) -> DsM ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
t a -> (a -> m b) -> m ()
forM_ [Located [LPat GhcTc]]
inaccessible ((Located [LPat GhcTc] -> DsM ()) -> DsM ())
-> (Located [LPat GhcTc] -> DsM ()) -> DsM ()
forall a b. (a -> b) -> a -> b
$ \(Located [LPat GhcTc]
-> Located (SrcSpanLess (Located [LPat GhcTc]))
forall a. HasSrcSpan a => a -> Located (SrcSpanLess a)
dL->L l :: SrcSpan
l q :: SrcSpanLess (Located [LPat GhcTc])
q) -> do
SrcSpan -> DsM () -> DsM ()
forall a. SrcSpan -> DsM a -> DsM a
putSrcSpanDs SrcSpan
l (WarnReason -> SDoc -> DsM ()
warnDs (WarningFlag -> WarnReason
Reason WarningFlag
Opt_WarnOverlappingPatterns)
([LPat GhcTc] -> String -> SDoc
pprEqn [LPat GhcTc]
SrcSpanLess (Located [LPat GhcTc])
q "has inaccessible right hand side"))
Bool -> DsM () -> DsM ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when Bool
exists_u (DsM () -> DsM ()) -> DsM () -> DsM ()
forall a b. (a -> b) -> a -> b
$ SrcSpan -> DsM () -> DsM ()
forall a. SrcSpan -> DsM a -> DsM a
putSrcSpanDs SrcSpan
loc (DsM () -> DsM ()) -> DsM () -> DsM ()
forall a b. (a -> b) -> a -> b
$ WarnReason -> SDoc -> DsM ()
warnDs WarnReason
flag_u_reason (SDoc -> DsM ()) -> SDoc -> DsM ()
forall a b. (a -> b) -> a -> b
$
case UncoveredCandidates
uncovered of
TypeOfUncovered ty :: Type
ty -> Type -> SDoc
warnEmptyCase Type
ty
UncoveredPatterns candidates :: Uncovered
candidates -> Uncovered -> SDoc
pprEqns Uncovered
candidates
where
PmResult
{ pmresultProvenance :: PmResult -> Provenance
pmresultProvenance = Provenance
prov
, pmresultRedundant :: PmResult -> [Located [LPat GhcTc]]
pmresultRedundant = [Located [LPat GhcTc]]
redundant
, pmresultUncovered :: PmResult -> UncoveredCandidates
pmresultUncovered = UncoveredCandidates
uncovered
, pmresultInaccessible :: PmResult -> [Located [LPat GhcTc]]
pmresultInaccessible = [Located [LPat GhcTc]]
inaccessible } = PmResult
pm_result
flag_i :: Bool
flag_i = WarningFlag -> DynFlags -> Bool
wopt WarningFlag
Opt_WarnOverlappingPatterns DynFlags
dflags
flag_u :: Bool
flag_u = DynFlags -> HsMatchContext Name -> Bool
forall id. DynFlags -> HsMatchContext id -> Bool
exhaustive DynFlags
dflags HsMatchContext Name
kind
flag_u_reason :: WarnReason
flag_u_reason = WarnReason
-> (WarningFlag -> WarnReason) -> Maybe WarningFlag -> WarnReason
forall b a. b -> (a -> b) -> Maybe a -> b
maybe WarnReason
NoReason WarningFlag -> WarnReason
Reason (HsMatchContext Name -> Maybe WarningFlag
forall id. HsMatchContext id -> Maybe WarningFlag
exhaustiveWarningFlag HsMatchContext Name
kind)
is_rec_upd :: Bool
is_rec_upd = case HsMatchContext Name
kind of { RecUpd -> Bool
True; _ -> Bool
False }
onlyBuiltin :: Bool
onlyBuiltin = Provenance
prov Provenance -> Provenance -> Bool
forall a. Eq a => a -> a -> Bool
== Provenance
FromBuiltin
maxPatterns :: Int
maxPatterns = DynFlags -> Int
maxUncoveredPatterns DynFlags
dflags
pprEqn :: [LPat GhcTc] -> String -> SDoc
pprEqn q :: [LPat GhcTc]
q txt :: String
txt = Bool -> DsMatchContext -> SDoc -> ((SDoc -> SDoc) -> SDoc) -> SDoc
pp_context Bool
True DsMatchContext
ctx (String -> SDoc
text String
txt) (((SDoc -> SDoc) -> SDoc) -> SDoc)
-> ((SDoc -> SDoc) -> SDoc) -> SDoc
forall a b. (a -> b) -> a -> b
$ \f :: SDoc -> SDoc
f -> (SDoc -> SDoc) -> HsMatchContext Name -> [LPat GhcTc] -> SDoc
ppr_eqn SDoc -> SDoc
f HsMatchContext Name
kind [LPat GhcTc]
q
pprEqns :: Uncovered -> SDoc
pprEqns qs :: Uncovered
qs = Bool -> DsMatchContext -> SDoc -> ((SDoc -> SDoc) -> SDoc) -> SDoc
pp_context Bool
False DsMatchContext
ctx (String -> SDoc
text "are non-exhaustive") (((SDoc -> SDoc) -> SDoc) -> SDoc)
-> ((SDoc -> SDoc) -> SDoc) -> SDoc
forall a b. (a -> b) -> a -> b
$ \_ ->
case Uncovered
qs of
[ValVec [] _]
-> String -> SDoc
text "Guards do not cover entire pattern space"
_missing :: Uncovered
_missing -> let us :: [SDoc]
us = (ValVec -> SDoc) -> Uncovered -> [SDoc]
forall a b. (a -> b) -> [a] -> [b]
map ValVec -> SDoc
forall a. Outputable a => a -> SDoc
ppr Uncovered
qs
in SDoc -> Int -> SDoc -> SDoc
hang (String -> SDoc
text "Patterns not matched:") 4
([SDoc] -> SDoc
vcat (Int -> [SDoc] -> [SDoc]
forall a. Int -> [a] -> [a]
take Int
maxPatterns [SDoc]
us)
SDoc -> SDoc -> SDoc
$$ Int -> [SDoc] -> SDoc
forall a. Int -> [a] -> SDoc
dots Int
maxPatterns [SDoc]
us)
warnEmptyCase :: Type -> SDoc
warnEmptyCase ty :: Type
ty = Bool -> DsMatchContext -> SDoc -> ((SDoc -> SDoc) -> SDoc) -> SDoc
pp_context Bool
False DsMatchContext
ctx (String -> SDoc
text "are non-exhaustive") (((SDoc -> SDoc) -> SDoc) -> SDoc)
-> ((SDoc -> SDoc) -> SDoc) -> SDoc
forall a b. (a -> b) -> a -> b
$ \_ ->
SDoc -> Int -> SDoc -> SDoc
hang (String -> SDoc
text "Patterns not matched:") 4 (SDoc
underscore SDoc -> SDoc -> SDoc
<+> SDoc
dcolon SDoc -> SDoc -> SDoc
<+> Type -> SDoc
forall a. Outputable a => a -> SDoc
ppr Type
ty)
warnPmIters :: DynFlags -> DsMatchContext -> DsM ()
warnPmIters :: DynFlags -> DsMatchContext -> DsM ()
warnPmIters dflags :: DynFlags
dflags (DsMatchContext kind :: HsMatchContext Name
kind loc :: SrcSpan
loc)
= Bool -> DsM () -> DsM ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (Bool
flag_i Bool -> Bool -> Bool
|| Bool
flag_u) (DsM () -> DsM ()) -> DsM () -> DsM ()
forall a b. (a -> b) -> a -> b
$ do
Int
iters <- DynFlags -> Int
maxPmCheckIterations (DynFlags -> Int)
-> IOEnv (Env DsGblEnv DsLclEnv) DynFlags -> DsM Int
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> IOEnv (Env DsGblEnv DsLclEnv) DynFlags
forall (m :: * -> *). HasDynFlags m => m DynFlags
getDynFlags
SrcSpan -> DsM () -> DsM ()
forall a. SrcSpan -> DsM a -> DsM a
putSrcSpanDs SrcSpan
loc (WarnReason -> SDoc -> DsM ()
warnDs WarnReason
NoReason (Int -> SDoc
msg Int
iters))
where
ctxt :: SDoc
ctxt = HsMatchContext Name -> SDoc
forall id.
(Outputable (NameOrRdrName id), Outputable id) =>
HsMatchContext id -> SDoc
pprMatchContext HsMatchContext Name
kind
msg :: Int -> SDoc
msg is :: Int
is = [SDoc] -> SDoc
fsep [ String -> SDoc
text "Pattern match checker exceeded"
, SDoc -> SDoc
parens (Int -> SDoc
forall a. Outputable a => a -> SDoc
ppr Int
is), String -> SDoc
text "iterations in", SDoc
ctxt SDoc -> SDoc -> SDoc
<> SDoc
dot
, String -> SDoc
text "(Use -fmax-pmcheck-iterations=n"
, String -> SDoc
text "to set the maximum number of iterations to n)" ]
flag_i :: Bool
flag_i = WarningFlag -> DynFlags -> Bool
wopt WarningFlag
Opt_WarnOverlappingPatterns DynFlags
dflags
flag_u :: Bool
flag_u = DynFlags -> HsMatchContext Name -> Bool
forall id. DynFlags -> HsMatchContext id -> Bool
exhaustive DynFlags
dflags HsMatchContext Name
kind
dots :: Int -> [a] -> SDoc
dots :: Int -> [a] -> SDoc
dots maxPatterns :: Int
maxPatterns qs :: [a]
qs
| [a]
qs [a] -> Int -> Bool
forall a. [a] -> Int -> Bool
`lengthExceeds` Int
maxPatterns = String -> SDoc
text "..."
| Bool
otherwise = SDoc
empty
exhaustive :: DynFlags -> HsMatchContext id -> Bool
exhaustive :: DynFlags -> HsMatchContext id -> Bool
exhaustive dflags :: DynFlags
dflags = Bool -> (WarningFlag -> Bool) -> Maybe WarningFlag -> Bool
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Bool
False (WarningFlag -> DynFlags -> Bool
`wopt` DynFlags
dflags) (Maybe WarningFlag -> Bool)
-> (HsMatchContext id -> Maybe WarningFlag)
-> HsMatchContext id
-> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. HsMatchContext id -> Maybe WarningFlag
forall id. HsMatchContext id -> Maybe WarningFlag
exhaustiveWarningFlag
exhaustiveWarningFlag :: HsMatchContext id -> Maybe WarningFlag
exhaustiveWarningFlag :: HsMatchContext id -> Maybe WarningFlag
exhaustiveWarningFlag (FunRhs {}) = WarningFlag -> Maybe WarningFlag
forall a. a -> Maybe a
Just WarningFlag
Opt_WarnIncompletePatterns
exhaustiveWarningFlag CaseAlt = WarningFlag -> Maybe WarningFlag
forall a. a -> Maybe a
Just WarningFlag
Opt_WarnIncompletePatterns
exhaustiveWarningFlag IfAlt = WarningFlag -> Maybe WarningFlag
forall a. a -> Maybe a
Just WarningFlag
Opt_WarnIncompletePatterns
exhaustiveWarningFlag LambdaExpr = WarningFlag -> Maybe WarningFlag
forall a. a -> Maybe a
Just WarningFlag
Opt_WarnIncompleteUniPatterns
exhaustiveWarningFlag PatBindRhs = WarningFlag -> Maybe WarningFlag
forall a. a -> Maybe a
Just WarningFlag
Opt_WarnIncompleteUniPatterns
exhaustiveWarningFlag PatBindGuards = WarningFlag -> Maybe WarningFlag
forall a. a -> Maybe a
Just WarningFlag
Opt_WarnIncompletePatterns
exhaustiveWarningFlag ProcExpr = WarningFlag -> Maybe WarningFlag
forall a. a -> Maybe a
Just WarningFlag
Opt_WarnIncompleteUniPatterns
exhaustiveWarningFlag RecUpd = WarningFlag -> Maybe WarningFlag
forall a. a -> Maybe a
Just WarningFlag
Opt_WarnIncompletePatternsRecUpd
exhaustiveWarningFlag ThPatSplice = Maybe WarningFlag
forall a. Maybe a
Nothing
exhaustiveWarningFlag PatSyn = Maybe WarningFlag
forall a. Maybe a
Nothing
exhaustiveWarningFlag ThPatQuote = Maybe WarningFlag
forall a. Maybe a
Nothing
exhaustiveWarningFlag (StmtCtxt {}) = Maybe WarningFlag
forall a. Maybe a
Nothing
pp_context :: Bool -> DsMatchContext -> SDoc -> ((SDoc -> SDoc) -> SDoc) -> SDoc
pp_context :: Bool -> DsMatchContext -> SDoc -> ((SDoc -> SDoc) -> SDoc) -> SDoc
pp_context singular :: Bool
singular (DsMatchContext kind :: HsMatchContext Name
kind _loc :: SrcSpan
_loc) msg :: SDoc
msg rest_of_msg_fun :: (SDoc -> SDoc) -> SDoc
rest_of_msg_fun
= [SDoc] -> SDoc
vcat [String -> SDoc
text String
txt SDoc -> SDoc -> SDoc
<+> SDoc
msg,
[SDoc] -> SDoc
sep [ String -> SDoc
text "In" SDoc -> SDoc -> SDoc
<+> SDoc
ppr_match SDoc -> SDoc -> SDoc
<> Char -> SDoc
char ':'
, Int -> SDoc -> SDoc
nest 4 ((SDoc -> SDoc) -> SDoc
rest_of_msg_fun SDoc -> SDoc
pref)]]
where
txt :: String
txt | Bool
singular = "Pattern match"
| Bool
otherwise = "Pattern match(es)"
(ppr_match :: SDoc
ppr_match, pref :: SDoc -> SDoc
pref)
= case HsMatchContext Name
kind of
FunRhs { mc_fun :: forall id. HsMatchContext id -> Located id
mc_fun = (Located Name -> Located (SrcSpanLess (Located Name))
forall a. HasSrcSpan a => a -> Located (SrcSpanLess a)
dL->L _ fun :: SrcSpanLess (Located Name)
fun) }
-> (HsMatchContext Name -> SDoc
forall id.
(Outputable (NameOrRdrName id), Outputable id) =>
HsMatchContext id -> SDoc
pprMatchContext HsMatchContext Name
kind, \ pp :: SDoc
pp -> Name -> SDoc
forall a. Outputable a => a -> SDoc
ppr Name
SrcSpanLess (Located Name)
fun SDoc -> SDoc -> SDoc
<+> SDoc
pp)
_ -> (HsMatchContext Name -> SDoc
forall id.
(Outputable (NameOrRdrName id), Outputable id) =>
HsMatchContext id -> SDoc
pprMatchContext HsMatchContext Name
kind, \ pp :: SDoc
pp -> SDoc
pp)
ppr_pats :: HsMatchContext Name -> [Pat GhcTc] -> SDoc
ppr_pats :: HsMatchContext Name -> [LPat GhcTc] -> SDoc
ppr_pats kind :: HsMatchContext Name
kind pats :: [LPat GhcTc]
pats
= [SDoc] -> SDoc
sep [[SDoc] -> SDoc
sep ((LPat GhcTc -> SDoc) -> [LPat GhcTc] -> [SDoc]
forall a b. (a -> b) -> [a] -> [b]
map LPat GhcTc -> SDoc
forall a. Outputable a => a -> SDoc
ppr [LPat GhcTc]
pats), HsMatchContext Name -> SDoc
forall id. HsMatchContext id -> SDoc
matchSeparator HsMatchContext Name
kind, String -> SDoc
text "..."]
ppr_eqn :: (SDoc -> SDoc) -> HsMatchContext Name -> [LPat GhcTc] -> SDoc
ppr_eqn :: (SDoc -> SDoc) -> HsMatchContext Name -> [LPat GhcTc] -> SDoc
ppr_eqn prefixF :: SDoc -> SDoc
prefixF kind :: HsMatchContext Name
kind eqn :: [LPat GhcTc]
eqn = SDoc -> SDoc
prefixF (HsMatchContext Name -> [LPat GhcTc] -> SDoc
ppr_pats HsMatchContext Name
kind ((LPat GhcTc -> LPat GhcTc) -> [LPat GhcTc] -> [LPat GhcTc]
forall a b. (a -> b) -> [a] -> [b]
map LPat GhcTc -> LPat GhcTc
forall a. HasSrcSpan a => a -> SrcSpanLess a
unLoc [LPat GhcTc]
eqn))
ppr_constraint :: (SDoc,[PmLit]) -> SDoc
ppr_constraint :: (SDoc, [PmLit]) -> SDoc
ppr_constraint (var :: SDoc
var, lits :: [PmLit]
lits) = SDoc
var SDoc -> SDoc -> SDoc
<+> String -> SDoc
text "is not one of"
SDoc -> SDoc -> SDoc
<+> SDoc -> SDoc
braces ((PmLit -> SDoc) -> [PmLit] -> SDoc
forall a. (a -> SDoc) -> [a] -> SDoc
pprWithCommas PmLit -> SDoc
forall a. Outputable a => a -> SDoc
ppr [PmLit]
lits)
ppr_uncovered :: ([PmExpr], [ComplexEq]) -> SDoc
ppr_uncovered :: ([PmExpr], [ComplexEq]) -> SDoc
ppr_uncovered (expr_vec :: [PmExpr]
expr_vec, complex :: [ComplexEq]
complex)
| [(SDoc, [PmLit])] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [(SDoc, [PmLit])]
cs = [SDoc] -> SDoc
fsep [SDoc]
vec
| Bool
otherwise = SDoc -> Int -> SDoc -> SDoc
hang ([SDoc] -> SDoc
fsep [SDoc]
vec) 4 (SDoc -> SDoc) -> SDoc -> SDoc
forall a b. (a -> b) -> a -> b
$
String -> SDoc
text "where" SDoc -> SDoc -> SDoc
<+> [SDoc] -> SDoc
vcat (((SDoc, [PmLit]) -> SDoc) -> [(SDoc, [PmLit])] -> [SDoc]
forall a b. (a -> b) -> [a] -> [b]
map (SDoc, [PmLit]) -> SDoc
ppr_constraint [(SDoc, [PmLit])]
cs)
where
sdoc_vec :: StateT ([PmNegLitCt], NameSet) Identity [SDoc]
sdoc_vec = (PmExpr -> StateT ([PmNegLitCt], NameSet) Identity SDoc)
-> [PmExpr] -> StateT ([PmNegLitCt], NameSet) Identity [SDoc]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM PmExpr -> StateT ([PmNegLitCt], NameSet) Identity SDoc
pprPmExprWithParens [PmExpr]
expr_vec
(vec :: [SDoc]
vec,cs :: [(SDoc, [PmLit])]
cs) = StateT ([PmNegLitCt], NameSet) Identity [SDoc]
-> [PmNegLitCt] -> ([SDoc], [(SDoc, [PmLit])])
forall a. PmPprM a -> [PmNegLitCt] -> (a, [(SDoc, [PmLit])])
runPmPprM StateT ([PmNegLitCt], NameSet) Identity [SDoc]
sdoc_vec ([ComplexEq] -> [PmNegLitCt]
filterComplex [ComplexEq]
complex)
tracePm :: String -> SDoc -> PmM ()
tracePm :: String -> SDoc -> PmM ()
tracePm herald :: String
herald doc :: SDoc
doc = DsM () -> PmM ()
forall a. DsM a -> PmM a
liftD (DsM () -> PmM ()) -> DsM () -> PmM ()
forall a b. (a -> b) -> a -> b
$ String -> SDoc -> DsM ()
tracePmD String
herald SDoc
doc
tracePmD :: String -> SDoc -> DsM ()
tracePmD :: String -> SDoc -> DsM ()
tracePmD herald :: String
herald doc :: SDoc
doc = do
DynFlags
dflags <- IOEnv (Env DsGblEnv DsLclEnv) DynFlags
forall (m :: * -> *). HasDynFlags m => m DynFlags
getDynFlags
PrintUnqualified
printer <- DsM PrintUnqualified
mkPrintUnqualifiedDs
IO () -> DsM ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> DsM ()) -> IO () -> DsM ()
forall a b. (a -> b) -> a -> b
$ PrintUnqualified -> DynFlags -> DumpFlag -> SDoc -> IO ()
dumpIfSet_dyn_printer PrintUnqualified
printer DynFlags
dflags
DumpFlag
Opt_D_dump_ec_trace (String -> SDoc
text String
herald SDoc -> SDoc -> SDoc
$$ (Int -> SDoc -> SDoc
nest 2 SDoc
doc))
pprPmPatDebug :: PmPat a -> SDoc
pprPmPatDebug :: PmPat a -> SDoc
pprPmPatDebug (PmCon cc :: ConLike
cc _arg_tys :: [Type]
_arg_tys _con_tvs :: [TyVar]
_con_tvs _con_dicts :: [TyVar]
_con_dicts con_args :: [PmPat a]
con_args)
= [SDoc] -> SDoc
hsep [String -> SDoc
text "PmCon", ConLike -> SDoc
forall a. Outputable a => a -> SDoc
ppr ConLike
cc, [SDoc] -> SDoc
hsep ((PmPat a -> SDoc) -> [PmPat a] -> [SDoc]
forall a b. (a -> b) -> [a] -> [b]
map PmPat a -> SDoc
forall (a :: PatTy). PmPat a -> SDoc
pprPmPatDebug [PmPat a]
con_args)]
pprPmPatDebug (PmVar vid :: TyVar
vid) = String -> SDoc
text "PmVar" SDoc -> SDoc -> SDoc
<+> TyVar -> SDoc
forall a. Outputable a => a -> SDoc
ppr TyVar
vid
pprPmPatDebug (PmLit li :: PmLit
li) = String -> SDoc
text "PmLit" SDoc -> SDoc -> SDoc
<+> PmLit -> SDoc
forall a. Outputable a => a -> SDoc
ppr PmLit
li
pprPmPatDebug (PmNLit i :: TyVar
i nl :: [PmLit]
nl) = String -> SDoc
text "PmNLit" SDoc -> SDoc -> SDoc
<+> TyVar -> SDoc
forall a. Outputable a => a -> SDoc
ppr TyVar
i SDoc -> SDoc -> SDoc
<+> [PmLit] -> SDoc
forall a. Outputable a => a -> SDoc
ppr [PmLit]
nl
pprPmPatDebug (PmGrd pv :: PatVec
pv ge :: PmExpr
ge) = String -> SDoc
text "PmGrd" SDoc -> SDoc -> SDoc
<+> [SDoc] -> SDoc
hsep ((PmPat 'PAT -> SDoc) -> PatVec -> [SDoc]
forall a b. (a -> b) -> [a] -> [b]
map PmPat 'PAT -> SDoc
forall (a :: PatTy). PmPat a -> SDoc
pprPmPatDebug PatVec
pv)
SDoc -> SDoc -> SDoc
<+> PmExpr -> SDoc
forall a. Outputable a => a -> SDoc
ppr PmExpr
ge
pprPatVec :: PatVec -> SDoc
pprPatVec :: PatVec -> SDoc
pprPatVec ps :: PatVec
ps = SDoc -> Int -> SDoc -> SDoc
hang (String -> SDoc
text "Pattern:") 2
(SDoc -> SDoc
brackets (SDoc -> SDoc) -> SDoc -> SDoc
forall a b. (a -> b) -> a -> b
$ [SDoc] -> SDoc
sep
([SDoc] -> SDoc) -> [SDoc] -> SDoc
forall a b. (a -> b) -> a -> b
$ SDoc -> [SDoc] -> [SDoc]
punctuate (SDoc
comma SDoc -> SDoc -> SDoc
<> Char -> SDoc
char '\n') ((PmPat 'PAT -> SDoc) -> PatVec -> [SDoc]
forall a b. (a -> b) -> [a] -> [b]
map PmPat 'PAT -> SDoc
forall (a :: PatTy). PmPat a -> SDoc
pprPmPatDebug PatVec
ps))
pprValAbs :: [ValAbs] -> SDoc
pprValAbs :: [PmPat 'VA] -> SDoc
pprValAbs ps :: [PmPat 'VA]
ps = SDoc -> Int -> SDoc -> SDoc
hang (String -> SDoc
text "ValAbs:") 2
(SDoc -> SDoc
brackets (SDoc -> SDoc) -> SDoc -> SDoc
forall a b. (a -> b) -> a -> b
$ [SDoc] -> SDoc
sep
([SDoc] -> SDoc) -> [SDoc] -> SDoc
forall a b. (a -> b) -> a -> b
$ SDoc -> [SDoc] -> [SDoc]
punctuate (SDoc
comma) ((PmPat 'VA -> SDoc) -> [PmPat 'VA] -> [SDoc]
forall a b. (a -> b) -> [a] -> [b]
map PmPat 'VA -> SDoc
forall (a :: PatTy). PmPat a -> SDoc
pprPmPatDebug [PmPat 'VA]
ps))
pprValVecDebug :: ValVec -> SDoc
pprValVecDebug :: ValVec -> SDoc
pprValVecDebug (ValVec vas :: [PmPat 'VA]
vas _d :: Delta
_d) = String -> SDoc
text "ValVec" SDoc -> SDoc -> SDoc
<+>
SDoc -> SDoc
parens ([PmPat 'VA] -> SDoc
pprValAbs [PmPat 'VA]
vas)