{-# LANGUAGE CPP #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE ViewPatterns #-}
module MatchCon ( matchConFamily, matchPatSyn ) where
#include "HsVersions.h"
import GhcPrelude
import {-# SOURCE #-} Match ( match )
import HsSyn
import DsBinds
import ConLike
import BasicTypes ( Origin(..) )
import TcType
import DsMonad
import DsUtils
import MkCore ( mkCoreLets )
import Util
import Id
import NameEnv
import FieldLabel ( flSelector )
import SrcLoc
import Outputable
import Control.Monad(liftM)
import Data.List (groupBy)
matchConFamily :: [Id]
-> Type
-> [[EquationInfo]]
-> DsM MatchResult
matchConFamily :: [Id] -> Type -> [[EquationInfo]] -> DsM MatchResult
matchConFamily (var :: Id
var:vars :: [Id]
vars) ty :: Type
ty groups :: [[EquationInfo]]
groups
= do [CaseAlt DataCon]
alts <- ([EquationInfo] -> IOEnv (Env DsGblEnv DsLclEnv) (CaseAlt DataCon))
-> [[EquationInfo]]
-> IOEnv (Env DsGblEnv DsLclEnv) [CaseAlt DataCon]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM ((CaseAlt ConLike -> CaseAlt DataCon)
-> IOEnv (Env DsGblEnv DsLclEnv) (CaseAlt ConLike)
-> IOEnv (Env DsGblEnv DsLclEnv) (CaseAlt DataCon)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap CaseAlt ConLike -> CaseAlt DataCon
toRealAlt (IOEnv (Env DsGblEnv DsLclEnv) (CaseAlt ConLike)
-> IOEnv (Env DsGblEnv DsLclEnv) (CaseAlt DataCon))
-> ([EquationInfo]
-> IOEnv (Env DsGblEnv DsLclEnv) (CaseAlt ConLike))
-> [EquationInfo]
-> IOEnv (Env DsGblEnv DsLclEnv) (CaseAlt DataCon)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Id]
-> Type
-> [EquationInfo]
-> IOEnv (Env DsGblEnv DsLclEnv) (CaseAlt ConLike)
matchOneConLike [Id]
vars Type
ty) [[EquationInfo]]
groups
MatchResult -> DsM MatchResult
forall (m :: * -> *) a. Monad m => a -> m a
return (Id -> Type -> [CaseAlt DataCon] -> MatchResult
mkCoAlgCaseMatchResult Id
var Type
ty [CaseAlt DataCon]
alts)
where
toRealAlt :: CaseAlt ConLike -> CaseAlt DataCon
toRealAlt alt :: CaseAlt ConLike
alt = case CaseAlt ConLike -> ConLike
forall a. CaseAlt a -> a
alt_pat CaseAlt ConLike
alt of
RealDataCon dcon :: DataCon
dcon -> CaseAlt ConLike
alt{ alt_pat :: DataCon
alt_pat = DataCon
dcon }
_ -> String -> CaseAlt DataCon
forall a. String -> a
panic "matchConFamily: not RealDataCon"
matchConFamily [] _ _ = String -> DsM MatchResult
forall a. String -> a
panic "matchConFamily []"
matchPatSyn :: [Id]
-> Type
-> [EquationInfo]
-> DsM MatchResult
matchPatSyn :: [Id] -> Type -> [EquationInfo] -> DsM MatchResult
matchPatSyn (var :: Id
var:vars :: [Id]
vars) ty :: Type
ty eqns :: [EquationInfo]
eqns
= do CaseAlt PatSyn
alt <- (CaseAlt ConLike -> CaseAlt PatSyn)
-> IOEnv (Env DsGblEnv DsLclEnv) (CaseAlt ConLike)
-> IOEnv (Env DsGblEnv DsLclEnv) (CaseAlt PatSyn)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap CaseAlt ConLike -> CaseAlt PatSyn
toSynAlt (IOEnv (Env DsGblEnv DsLclEnv) (CaseAlt ConLike)
-> IOEnv (Env DsGblEnv DsLclEnv) (CaseAlt PatSyn))
-> IOEnv (Env DsGblEnv DsLclEnv) (CaseAlt ConLike)
-> IOEnv (Env DsGblEnv DsLclEnv) (CaseAlt PatSyn)
forall a b. (a -> b) -> a -> b
$ [Id]
-> Type
-> [EquationInfo]
-> IOEnv (Env DsGblEnv DsLclEnv) (CaseAlt ConLike)
matchOneConLike [Id]
vars Type
ty [EquationInfo]
eqns
MatchResult -> DsM MatchResult
forall (m :: * -> *) a. Monad m => a -> m a
return (Id -> Type -> CaseAlt PatSyn -> MatchResult
mkCoSynCaseMatchResult Id
var Type
ty CaseAlt PatSyn
alt)
where
toSynAlt :: CaseAlt ConLike -> CaseAlt PatSyn
toSynAlt alt :: CaseAlt ConLike
alt = case CaseAlt ConLike -> ConLike
forall a. CaseAlt a -> a
alt_pat CaseAlt ConLike
alt of
PatSynCon psyn :: PatSyn
psyn -> CaseAlt ConLike
alt{ alt_pat :: PatSyn
alt_pat = PatSyn
psyn }
_ -> String -> CaseAlt PatSyn
forall a. String -> a
panic "matchPatSyn: not PatSynCon"
matchPatSyn _ _ _ = String -> DsM MatchResult
forall a. String -> a
panic "matchPatSyn []"
type ConArgPats = HsConDetails (LPat GhcTc) (HsRecFields GhcTc (LPat GhcTc))
matchOneConLike :: [Id]
-> Type
-> [EquationInfo]
-> DsM (CaseAlt ConLike)
matchOneConLike :: [Id]
-> Type
-> [EquationInfo]
-> IOEnv (Env DsGblEnv DsLclEnv) (CaseAlt ConLike)
matchOneConLike vars :: [Id]
vars ty :: Type
ty (eqn1 :: EquationInfo
eqn1 : eqns :: [EquationInfo]
eqns)
= do { let inst_tys :: [Type]
inst_tys = ASSERT( all tcIsTcTyVar ex_tvs )
ASSERT( tvs1 `equalLength` ex_tvs )
[Type]
arg_tys [Type] -> [Type] -> [Type]
forall a. [a] -> [a] -> [a]
++ [Id] -> [Type]
mkTyVarTys [Id]
tvs1
val_arg_tys :: [Type]
val_arg_tys = ConLike -> [Type] -> [Type]
conLikeInstOrigArgTys SrcSpanLess (Located ConLike)
ConLike
con1 [Type]
inst_tys
match_group :: [Id]
-> [(ConArgPats, EquationInfo)] -> DsM MatchResult
match_group :: [Id] -> [(ConArgPats, EquationInfo)] -> DsM MatchResult
match_group arg_vars :: [Id]
arg_vars arg_eqn_prs :: [(ConArgPats, EquationInfo)]
arg_eqn_prs
= ASSERT( notNull arg_eqn_prs )
do { (wraps :: [CoreExpr -> CoreExpr]
wraps, eqns' :: [EquationInfo]
eqns') <- ([(CoreExpr -> CoreExpr, EquationInfo)]
-> ([CoreExpr -> CoreExpr], [EquationInfo]))
-> IOEnv
(Env DsGblEnv DsLclEnv) [(CoreExpr -> CoreExpr, EquationInfo)]
-> IOEnv
(Env DsGblEnv DsLclEnv) ([CoreExpr -> CoreExpr], [EquationInfo])
forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
liftM [(CoreExpr -> CoreExpr, EquationInfo)]
-> ([CoreExpr -> CoreExpr], [EquationInfo])
forall a b. [(a, b)] -> ([a], [b])
unzip (((ConArgPats, EquationInfo)
-> IOEnv
(Env DsGblEnv DsLclEnv) (CoreExpr -> CoreExpr, EquationInfo))
-> [(ConArgPats, EquationInfo)]
-> IOEnv
(Env DsGblEnv DsLclEnv) [(CoreExpr -> CoreExpr, EquationInfo)]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM (ConArgPats, EquationInfo)
-> IOEnv
(Env DsGblEnv DsLclEnv) (CoreExpr -> CoreExpr, EquationInfo)
shift [(ConArgPats, EquationInfo)]
arg_eqn_prs)
; let group_arg_vars :: [Id]
group_arg_vars = [Id] -> [(ConArgPats, EquationInfo)] -> [Id]
select_arg_vars [Id]
arg_vars [(ConArgPats, EquationInfo)]
arg_eqn_prs
; MatchResult
match_result <- [Id] -> Type -> [EquationInfo] -> DsM MatchResult
match ([Id]
group_arg_vars [Id] -> [Id] -> [Id]
forall a. [a] -> [a] -> [a]
++ [Id]
vars) Type
ty [EquationInfo]
eqns'
; MatchResult -> DsM MatchResult
forall (m :: * -> *) a. Monad m => a -> m a
return ((CoreExpr -> CoreExpr) -> MatchResult -> MatchResult
adjustMatchResult (((CoreExpr -> CoreExpr)
-> (CoreExpr -> CoreExpr) -> CoreExpr -> CoreExpr)
-> [CoreExpr -> CoreExpr] -> CoreExpr -> CoreExpr
forall (t :: * -> *) a. Foldable t => (a -> a -> a) -> t a -> a
foldr1 (CoreExpr -> CoreExpr)
-> (CoreExpr -> CoreExpr) -> CoreExpr -> CoreExpr
forall b c a. (b -> c) -> (a -> b) -> a -> c
(.) [CoreExpr -> CoreExpr]
wraps) MatchResult
match_result) }
shift :: (ConArgPats, EquationInfo)
-> IOEnv
(Env DsGblEnv DsLclEnv) (CoreExpr -> CoreExpr, EquationInfo)
shift (_, eqn :: EquationInfo
eqn@(EqnInfo { eqn_pats :: EquationInfo -> [Pat GhcTc]
eqn_pats = ConPatOut{ pat_tvs :: forall p. Pat p -> [Id]
pat_tvs = [Id]
tvs, pat_dicts :: forall p. Pat p -> [Id]
pat_dicts = [Id]
ds,
pat_binds :: forall p. Pat p -> TcEvBinds
pat_binds = TcEvBinds
bind, pat_args :: forall p. Pat p -> HsConPatDetails p
pat_args = ConArgPats
args
} : pats :: [Pat GhcTc]
pats }))
= do [CoreBind]
ds_bind <- TcEvBinds -> DsM [CoreBind]
dsTcEvBinds TcEvBinds
bind
(CoreExpr -> CoreExpr, EquationInfo)
-> IOEnv
(Env DsGblEnv DsLclEnv) (CoreExpr -> CoreExpr, EquationInfo)
forall (m :: * -> *) a. Monad m => a -> m a
return ( [(Id, Id)] -> CoreExpr -> CoreExpr
wrapBinds ([Id]
tvs [Id] -> [Id] -> [(Id, Id)]
forall a b. [a] -> [b] -> [(a, b)]
`zip` [Id]
tvs1)
(CoreExpr -> CoreExpr)
-> (CoreExpr -> CoreExpr) -> CoreExpr -> CoreExpr
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [(Id, Id)] -> CoreExpr -> CoreExpr
wrapBinds ([Id]
ds [Id] -> [Id] -> [(Id, Id)]
forall a b. [a] -> [b] -> [(a, b)]
`zip` [Id]
dicts1)
(CoreExpr -> CoreExpr)
-> (CoreExpr -> CoreExpr) -> CoreExpr -> CoreExpr
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [CoreBind] -> CoreExpr -> CoreExpr
mkCoreLets [CoreBind]
ds_bind
, EquationInfo
eqn { eqn_orig :: Origin
eqn_orig = Origin
Generated
, eqn_pats :: [Pat GhcTc]
eqn_pats = [Type] -> ConArgPats -> [Pat GhcTc]
conArgPats [Type]
val_arg_tys ConArgPats
args [Pat GhcTc] -> [Pat GhcTc] -> [Pat GhcTc]
forall a. [a] -> [a] -> [a]
++ [Pat GhcTc]
pats }
)
shift (_, (EqnInfo { eqn_pats :: EquationInfo -> [Pat GhcTc]
eqn_pats = [Pat GhcTc]
ps })) = String
-> SDoc
-> IOEnv
(Env DsGblEnv DsLclEnv) (CoreExpr -> CoreExpr, EquationInfo)
forall a. HasCallStack => String -> SDoc -> a
pprPanic "matchOneCon/shift" ([Pat GhcTc] -> SDoc
forall a. Outputable a => a -> SDoc
ppr [Pat GhcTc]
ps)
; [Id]
arg_vars <- [Type] -> ConArgPats -> DsM [Id]
selectConMatchVars [Type]
val_arg_tys ConArgPats
args1
; let groups :: [[(ConArgPats, EquationInfo)]]
groups :: [[(ConArgPats, EquationInfo)]]
groups = ((ConArgPats, EquationInfo) -> (ConArgPats, EquationInfo) -> Bool)
-> [(ConArgPats, EquationInfo)] -> [[(ConArgPats, EquationInfo)]]
forall a. (a -> a -> Bool) -> [a] -> [[a]]
groupBy (ConArgPats, EquationInfo) -> (ConArgPats, EquationInfo) -> Bool
forall a. (ConArgPats, a) -> (ConArgPats, a) -> Bool
compatible_pats [ (Pat GhcTc -> ConArgPats
forall p. Pat p -> HsConPatDetails p
pat_args (EquationInfo -> Pat GhcTc
firstPat EquationInfo
eqn), EquationInfo
eqn)
| EquationInfo
eqn <- EquationInfo
eqn1EquationInfo -> [EquationInfo] -> [EquationInfo]
forall a. a -> [a] -> [a]
:[EquationInfo]
eqns ]
; [MatchResult]
match_results <- ([(ConArgPats, EquationInfo)] -> DsM MatchResult)
-> [[(ConArgPats, EquationInfo)]]
-> IOEnv (Env DsGblEnv DsLclEnv) [MatchResult]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM ([Id] -> [(ConArgPats, EquationInfo)] -> DsM MatchResult
match_group [Id]
arg_vars) [[(ConArgPats, EquationInfo)]]
groups
; CaseAlt ConLike -> IOEnv (Env DsGblEnv DsLclEnv) (CaseAlt ConLike)
forall (m :: * -> *) a. Monad m => a -> m a
return (CaseAlt ConLike
-> IOEnv (Env DsGblEnv DsLclEnv) (CaseAlt ConLike))
-> CaseAlt ConLike
-> IOEnv (Env DsGblEnv DsLclEnv) (CaseAlt ConLike)
forall a b. (a -> b) -> a -> b
$ MkCaseAlt :: forall a. a -> [Id] -> HsWrapper -> MatchResult -> CaseAlt a
MkCaseAlt{ alt_pat :: ConLike
alt_pat = SrcSpanLess (Located ConLike)
ConLike
con1,
alt_bndrs :: [Id]
alt_bndrs = [Id]
tvs1 [Id] -> [Id] -> [Id]
forall a. [a] -> [a] -> [a]
++ [Id]
dicts1 [Id] -> [Id] -> [Id]
forall a. [a] -> [a] -> [a]
++ [Id]
arg_vars,
alt_wrapper :: HsWrapper
alt_wrapper = HsWrapper
wrapper1,
alt_result :: MatchResult
alt_result = (MatchResult -> MatchResult -> MatchResult)
-> [MatchResult] -> MatchResult
forall (t :: * -> *) a. Foldable t => (a -> a -> a) -> t a -> a
foldr1 MatchResult -> MatchResult -> MatchResult
combineMatchResults [MatchResult]
match_results } }
where
ConPatOut { pat_con :: forall p. Pat p -> Located ConLike
pat_con = (Located ConLike -> Located (SrcSpanLess (Located ConLike))
forall a. HasSrcSpan a => a -> Located (SrcSpanLess a)
dL->L _ con1 :: SrcSpanLess (Located ConLike)
con1)
, pat_arg_tys :: forall p. Pat p -> [Type]
pat_arg_tys = [Type]
arg_tys, pat_wrap :: forall p. Pat p -> HsWrapper
pat_wrap = HsWrapper
wrapper1,
pat_tvs :: forall p. Pat p -> [Id]
pat_tvs = [Id]
tvs1, pat_dicts :: forall p. Pat p -> [Id]
pat_dicts = [Id]
dicts1, pat_args :: forall p. Pat p -> HsConPatDetails p
pat_args = ConArgPats
args1 }
= EquationInfo -> Pat GhcTc
firstPat EquationInfo
eqn1
fields1 :: [Name]
fields1 = (FieldLbl Name -> Name) -> [FieldLbl Name] -> [Name]
forall a b. (a -> b) -> [a] -> [b]
map FieldLbl Name -> Name
forall a. FieldLbl a -> a
flSelector (ConLike -> [FieldLbl Name]
conLikeFieldLabels SrcSpanLess (Located ConLike)
ConLike
con1)
ex_tvs :: [Id]
ex_tvs = ConLike -> [Id]
conLikeExTyCoVars SrcSpanLess (Located ConLike)
ConLike
con1
select_arg_vars :: [Id] -> [(ConArgPats, EquationInfo)] -> [Id]
select_arg_vars :: [Id] -> [(ConArgPats, EquationInfo)] -> [Id]
select_arg_vars arg_vars :: [Id]
arg_vars ((arg_pats :: ConArgPats
arg_pats, _) : _)
| RecCon flds :: HsRecFields GhcTc (Pat GhcTc)
flds <- ConArgPats
arg_pats
, let rpats :: [LHsRecField GhcTc (Pat GhcTc)]
rpats = HsRecFields GhcTc (Pat GhcTc) -> [LHsRecField GhcTc (Pat GhcTc)]
forall p arg. HsRecFields p arg -> [LHsRecField p arg]
rec_flds HsRecFields GhcTc (Pat GhcTc)
flds
, Bool -> Bool
not ([LHsRecField GhcTc (Pat GhcTc)] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [LHsRecField GhcTc (Pat GhcTc)]
rpats)
= ASSERT2( fields1 `equalLength` arg_vars,
ppr con1 $$ ppr fields1 $$ ppr arg_vars )
(LHsRecField GhcTc (Pat GhcTc) -> Id)
-> [LHsRecField GhcTc (Pat GhcTc)] -> [Id]
forall a b. (a -> b) -> [a] -> [b]
map LHsRecField GhcTc (Pat GhcTc) -> Id
lookup_fld [LHsRecField GhcTc (Pat GhcTc)]
rpats
| Bool
otherwise
= [Id]
arg_vars
where
fld_var_env :: NameEnv Id
fld_var_env = [(Name, Id)] -> NameEnv Id
forall a. [(Name, a)] -> NameEnv a
mkNameEnv ([(Name, Id)] -> NameEnv Id) -> [(Name, Id)] -> NameEnv Id
forall a b. (a -> b) -> a -> b
$ String -> [Name] -> [Id] -> [(Name, Id)]
forall a b. String -> [a] -> [b] -> [(a, b)]
zipEqual "get_arg_vars" [Name]
fields1 [Id]
arg_vars
lookup_fld :: LHsRecField GhcTc (Pat GhcTc) -> Id
lookup_fld (LHsRecField GhcTc (Pat GhcTc)
-> Located (SrcSpanLess (LHsRecField GhcTc (Pat GhcTc)))
forall a. HasSrcSpan a => a -> Located (SrcSpanLess a)
dL->L _ rpat :: SrcSpanLess (LHsRecField GhcTc (Pat GhcTc))
rpat) = NameEnv Id -> Name -> Id
forall a. NameEnv a -> Name -> a
lookupNameEnv_NF NameEnv Id
fld_var_env
(Id -> Name
idName (Located Id -> SrcSpanLess (Located Id)
forall a. HasSrcSpan a => a -> SrcSpanLess a
unLoc (HsRecField GhcTc (Pat GhcTc) -> Located Id
forall arg. HsRecField GhcTc arg -> Located Id
hsRecFieldId SrcSpanLess (LHsRecField GhcTc (Pat GhcTc))
HsRecField GhcTc (Pat GhcTc)
rpat)))
select_arg_vars _ [] = String -> [Id]
forall a. String -> a
panic "matchOneCon/select_arg_vars []"
matchOneConLike _ _ [] = String -> IOEnv (Env DsGblEnv DsLclEnv) (CaseAlt ConLike)
forall a. String -> a
panic "matchOneCon []"
compatible_pats :: (ConArgPats,a) -> (ConArgPats,a) -> Bool
compatible_pats :: (ConArgPats, a) -> (ConArgPats, a) -> Bool
compatible_pats (RecCon flds1 :: HsRecFields GhcTc (Pat GhcTc)
flds1, _) (RecCon flds2 :: HsRecFields GhcTc (Pat GhcTc)
flds2, _) = HsRecFields GhcTc (Pat GhcTc)
-> HsRecFields GhcTc (Pat GhcTc) -> Bool
same_fields HsRecFields GhcTc (Pat GhcTc)
flds1 HsRecFields GhcTc (Pat GhcTc)
flds2
compatible_pats (RecCon flds1 :: HsRecFields GhcTc (Pat GhcTc)
flds1, _) _ = [LHsRecField GhcTc (Pat GhcTc)] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null (HsRecFields GhcTc (Pat GhcTc) -> [LHsRecField GhcTc (Pat GhcTc)]
forall p arg. HsRecFields p arg -> [LHsRecField p arg]
rec_flds HsRecFields GhcTc (Pat GhcTc)
flds1)
compatible_pats _ (RecCon flds2 :: HsRecFields GhcTc (Pat GhcTc)
flds2, _) = [LHsRecField GhcTc (Pat GhcTc)] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null (HsRecFields GhcTc (Pat GhcTc) -> [LHsRecField GhcTc (Pat GhcTc)]
forall p arg. HsRecFields p arg -> [LHsRecField p arg]
rec_flds HsRecFields GhcTc (Pat GhcTc)
flds2)
compatible_pats _ _ = Bool
True
same_fields :: HsRecFields GhcTc (LPat GhcTc) -> HsRecFields GhcTc (LPat GhcTc)
-> Bool
same_fields :: HsRecFields GhcTc (Pat GhcTc)
-> HsRecFields GhcTc (Pat GhcTc) -> Bool
same_fields flds1 :: HsRecFields GhcTc (Pat GhcTc)
flds1 flds2 :: HsRecFields GhcTc (Pat GhcTc)
flds2
= (LHsRecField GhcTc (Pat GhcTc)
-> LHsRecField GhcTc (Pat GhcTc) -> Bool)
-> [LHsRecField GhcTc (Pat GhcTc)]
-> [LHsRecField GhcTc (Pat GhcTc)]
-> Bool
forall a b. (a -> b -> Bool) -> [a] -> [b] -> Bool
all2 (\(LHsRecField GhcTc (Pat GhcTc)
-> Located (SrcSpanLess (LHsRecField GhcTc (Pat GhcTc)))
forall a. HasSrcSpan a => a -> Located (SrcSpanLess a)
dL->L _ f1 :: SrcSpanLess (LHsRecField GhcTc (Pat GhcTc))
f1) (LHsRecField GhcTc (Pat GhcTc)
-> Located (SrcSpanLess (LHsRecField GhcTc (Pat GhcTc)))
forall a. HasSrcSpan a => a -> Located (SrcSpanLess a)
dL->L _ f2 :: SrcSpanLess (LHsRecField GhcTc (Pat GhcTc))
f2)
-> Located Id -> SrcSpanLess (Located Id)
forall a. HasSrcSpan a => a -> SrcSpanLess a
unLoc (HsRecField GhcTc (Pat GhcTc) -> Located Id
forall arg. HsRecField GhcTc arg -> Located Id
hsRecFieldId SrcSpanLess (LHsRecField GhcTc (Pat GhcTc))
HsRecField GhcTc (Pat GhcTc)
f1) Id -> Id -> Bool
forall a. Eq a => a -> a -> Bool
== Located Id -> SrcSpanLess (Located Id)
forall a. HasSrcSpan a => a -> SrcSpanLess a
unLoc (HsRecField GhcTc (Pat GhcTc) -> Located Id
forall arg. HsRecField GhcTc arg -> Located Id
hsRecFieldId SrcSpanLess (LHsRecField GhcTc (Pat GhcTc))
HsRecField GhcTc (Pat GhcTc)
f2))
(HsRecFields GhcTc (Pat GhcTc) -> [LHsRecField GhcTc (Pat GhcTc)]
forall p arg. HsRecFields p arg -> [LHsRecField p arg]
rec_flds HsRecFields GhcTc (Pat GhcTc)
flds1) (HsRecFields GhcTc (Pat GhcTc) -> [LHsRecField GhcTc (Pat GhcTc)]
forall p arg. HsRecFields p arg -> [LHsRecField p arg]
rec_flds HsRecFields GhcTc (Pat GhcTc)
flds2)
selectConMatchVars :: [Type] -> ConArgPats -> DsM [Id]
selectConMatchVars :: [Type] -> ConArgPats -> DsM [Id]
selectConMatchVars arg_tys :: [Type]
arg_tys (RecCon {}) = [Type] -> DsM [Id]
newSysLocalsDsNoLP [Type]
arg_tys
selectConMatchVars _ (PrefixCon ps :: [Pat GhcTc]
ps) = [Pat GhcTc] -> DsM [Id]
selectMatchVars ((Pat GhcTc -> Pat GhcTc) -> [Pat GhcTc] -> [Pat GhcTc]
forall a b. (a -> b) -> [a] -> [b]
map Pat GhcTc -> Pat GhcTc
forall a. HasSrcSpan a => a -> SrcSpanLess a
unLoc [Pat GhcTc]
ps)
selectConMatchVars _ (InfixCon p1 :: Pat GhcTc
p1 p2 :: Pat GhcTc
p2) = [Pat GhcTc] -> DsM [Id]
selectMatchVars [Pat GhcTc -> SrcSpanLess (Pat GhcTc)
forall a. HasSrcSpan a => a -> SrcSpanLess a
unLoc Pat GhcTc
p1, Pat GhcTc -> SrcSpanLess (Pat GhcTc)
forall a. HasSrcSpan a => a -> SrcSpanLess a
unLoc Pat GhcTc
p2]
conArgPats :: [Type]
-> ConArgPats
-> [Pat GhcTc]
conArgPats :: [Type] -> ConArgPats -> [Pat GhcTc]
conArgPats _arg_tys :: [Type]
_arg_tys (PrefixCon ps :: [Pat GhcTc]
ps) = (Pat GhcTc -> Pat GhcTc) -> [Pat GhcTc] -> [Pat GhcTc]
forall a b. (a -> b) -> [a] -> [b]
map Pat GhcTc -> Pat GhcTc
forall a. HasSrcSpan a => a -> SrcSpanLess a
unLoc [Pat GhcTc]
ps
conArgPats _arg_tys :: [Type]
_arg_tys (InfixCon p1 :: Pat GhcTc
p1 p2 :: Pat GhcTc
p2) = [Pat GhcTc -> SrcSpanLess (Pat GhcTc)
forall a. HasSrcSpan a => a -> SrcSpanLess a
unLoc Pat GhcTc
p1, Pat GhcTc -> SrcSpanLess (Pat GhcTc)
forall a. HasSrcSpan a => a -> SrcSpanLess a
unLoc Pat GhcTc
p2]
conArgPats arg_tys :: [Type]
arg_tys (RecCon (HsRecFields { rec_flds :: forall p arg. HsRecFields p arg -> [LHsRecField p arg]
rec_flds = [LHsRecField GhcTc (Pat GhcTc)]
rpats }))
| [LHsRecField GhcTc (Pat GhcTc)] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [LHsRecField GhcTc (Pat GhcTc)]
rpats = (Type -> Pat GhcTc) -> [Type] -> [Pat GhcTc]
forall a b. (a -> b) -> [a] -> [b]
map Type -> Pat GhcTc
forall p. XWildPat p -> Pat p
WildPat [Type]
arg_tys
| Bool
otherwise = (LHsRecField GhcTc (Pat GhcTc) -> Pat GhcTc)
-> [LHsRecField GhcTc (Pat GhcTc)] -> [Pat GhcTc]
forall a b. (a -> b) -> [a] -> [b]
map (Pat GhcTc -> Pat GhcTc
forall a. HasSrcSpan a => a -> SrcSpanLess a
unLoc (Pat GhcTc -> Pat GhcTc)
-> (LHsRecField GhcTc (Pat GhcTc) -> Pat GhcTc)
-> LHsRecField GhcTc (Pat GhcTc)
-> Pat GhcTc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. HsRecField GhcTc (Pat GhcTc) -> Pat GhcTc
forall id arg. HsRecField' id arg -> arg
hsRecFieldArg (HsRecField GhcTc (Pat GhcTc) -> Pat GhcTc)
-> (LHsRecField GhcTc (Pat GhcTc) -> HsRecField GhcTc (Pat GhcTc))
-> LHsRecField GhcTc (Pat GhcTc)
-> Pat GhcTc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. LHsRecField GhcTc (Pat GhcTc) -> HsRecField GhcTc (Pat GhcTc)
forall a. HasSrcSpan a => a -> SrcSpanLess a
unLoc) [LHsRecField GhcTc (Pat GhcTc)]
rpats