{-# LANGUAGE CPP #-}
{-# LANGUAGE NondecreasingIndentation #-}
{-# OPTIONS_GHC -Wno-incomplete-record-updates #-}
module GHC.IfaceToCore (
tcLookupImported_maybe,
importDecl, checkWiredInTyCon, tcHiBootIface, typecheckIface,
typecheckIfacesForMerging,
typecheckIfaceForInstantiate,
tcIfaceDecl, tcIfaceInst, tcIfaceFamInst, tcIfaceRules,
tcIfaceAnnotations, tcIfaceCompleteSigs,
tcIfaceExpr,
tcIfaceGlobal,
tcIfaceOneShot
) where
#include "HsVersions.h"
import GHC.Prelude
import GHC.Builtin.Types.Literals(typeNatCoAxiomRules)
import GHC.Iface.Syntax
import GHC.Iface.Load
import GHC.Iface.Env
import GHC.StgToCmm.Types
import GHC.Tc.TyCl.Build
import GHC.Tc.Utils.Monad
import GHC.Tc.Utils.TcType
import GHC.Core.Type
import GHC.Core.Coercion
import GHC.Core.Coercion.Axiom
import GHC.Core.FVs
import GHC.Core.TyCo.Rep
import GHC.Core.TyCo.Subst ( substTyCoVars )
import GHC.Driver.Types
import GHC.Types.Annotations
import GHC.Core.InstEnv
import GHC.Core.FamInstEnv
import GHC.Core
import GHC.Core.Utils
import GHC.Core.Unfold
import GHC.Core.Lint
import GHC.Core.Make
import GHC.Types.Id
import GHC.Types.Id.Make
import GHC.Types.Id.Info
import GHC.Core.Class
import GHC.Core.TyCon
import GHC.Core.ConLike
import GHC.Core.DataCon
import GHC.Builtin.Types
import GHC.Types.Literal
import GHC.Types.Var as Var
import GHC.Types.Var.Set
import GHC.Types.Name
import GHC.Types.Name.Env
import GHC.Types.Name.Set
import GHC.Core.Opt.OccurAnal ( occurAnalyseExpr )
import GHC.Unit.Module
import GHC.Types.Unique.FM
import GHC.Types.Unique.Supply
import GHC.Utils.Outputable
import GHC.Data.Maybe
import GHC.Types.SrcLoc
import GHC.Driver.Session
import GHC.Utils.Misc
import GHC.Data.FastString
import GHC.Types.Basic hiding ( SuccessFlag(..) )
import GHC.Data.List.SetOps
import GHC.Fingerprint
import qualified GHC.Data.BooleanFormula as BF
import Control.Monad
import qualified Data.Map as Map
typecheckIface :: ModIface
-> IfG ModDetails
typecheckIface :: ModIface -> IfG ModDetails
typecheckIface ModIface
iface
= Module
-> SDoc -> IsBootInterface -> IfL ModDetails -> IfG ModDetails
forall a lcl.
Module -> SDoc -> IsBootInterface -> IfL a -> IfM lcl a
initIfaceLcl (ModIface -> Module
forall (a :: ModIfacePhase). ModIface_ a -> Module
mi_semantic_module ModIface
iface) (String -> SDoc
text String
"typecheckIface") (ModIface -> IsBootInterface
mi_boot ModIface
iface) (IfL ModDetails -> IfG ModDetails)
-> IfL ModDetails -> IfG ModDetails
forall a b. (a -> b) -> a -> b
$ do
{
Bool
ignore_prags <- GeneralFlag -> TcRnIf IfGblEnv IfLclEnv Bool
forall gbl lcl. GeneralFlag -> TcRnIf gbl lcl Bool
goptM GeneralFlag
Opt_IgnoreInterfacePragmas
; [(Name, TyThing)]
names_w_things <- Bool -> [(Fingerprint, IfaceDecl)] -> IfL [(Name, TyThing)]
loadDecls Bool
ignore_prags (ModIface -> [IfaceDeclExts 'ModIfaceFinal]
forall (phase :: ModIfacePhase).
ModIface_ phase -> [IfaceDeclExts phase]
mi_decls ModIface
iface)
; let type_env :: TypeEnv
type_env = [(Name, TyThing)] -> TypeEnv
forall a. [(Name, a)] -> NameEnv a
mkNameEnv [(Name, TyThing)]
names_w_things
; [ClsInst]
insts <- (IfaceClsInst -> IOEnv (Env IfGblEnv IfLclEnv) ClsInst)
-> [IfaceClsInst] -> IOEnv (Env IfGblEnv IfLclEnv) [ClsInst]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM IfaceClsInst -> IOEnv (Env IfGblEnv IfLclEnv) ClsInst
tcIfaceInst (ModIface -> [IfaceClsInst]
forall (phase :: ModIfacePhase). ModIface_ phase -> [IfaceClsInst]
mi_insts ModIface
iface)
; [FamInst]
fam_insts <- (IfaceFamInst -> IOEnv (Env IfGblEnv IfLclEnv) FamInst)
-> [IfaceFamInst] -> IOEnv (Env IfGblEnv IfLclEnv) [FamInst]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM IfaceFamInst -> IOEnv (Env IfGblEnv IfLclEnv) FamInst
tcIfaceFamInst (ModIface -> [IfaceFamInst]
forall (phase :: ModIfacePhase). ModIface_ phase -> [IfaceFamInst]
mi_fam_insts ModIface
iface)
; [CoreRule]
rules <- Bool -> [IfaceRule] -> IfL [CoreRule]
tcIfaceRules Bool
ignore_prags (ModIface -> [IfaceRule]
forall (phase :: ModIfacePhase). ModIface_ phase -> [IfaceRule]
mi_rules ModIface
iface)
; [Annotation]
anns <- [IfaceAnnotation] -> IfL [Annotation]
tcIfaceAnnotations (ModIface -> [IfaceAnnotation]
forall (phase :: ModIfacePhase).
ModIface_ phase -> [IfaceAnnotation]
mi_anns ModIface
iface)
; [AvailInfo]
exports <- [AvailInfo] -> TcRnIf IfGblEnv IfLclEnv [AvailInfo]
forall gbl lcl. [AvailInfo] -> TcRnIf gbl lcl [AvailInfo]
ifaceExportNames (ModIface -> [AvailInfo]
forall (phase :: ModIfacePhase). ModIface_ phase -> [AvailInfo]
mi_exports ModIface
iface)
; [CompleteMatch]
complete_sigs <- [IfaceCompleteMatch] -> IfL [CompleteMatch]
tcIfaceCompleteSigs (ModIface -> [IfaceCompleteMatch]
forall (phase :: ModIfacePhase).
ModIface_ phase -> [IfaceCompleteMatch]
mi_complete_sigs ModIface
iface)
; SDoc -> TcRnIf IfGblEnv IfLclEnv ()
forall m n. SDoc -> TcRnIf m n ()
traceIf ([SDoc] -> SDoc
vcat [String -> SDoc
text String
"Finished typechecking interface for" SDoc -> SDoc -> SDoc
<+> Module -> SDoc
forall a. Outputable a => a -> SDoc
ppr (ModIface -> Module
forall (a :: ModIfacePhase). ModIface_ a -> Module
mi_module ModIface
iface),
String -> SDoc
text String
"Type envt:" SDoc -> SDoc -> SDoc
<+> [Name] -> SDoc
forall a. Outputable a => a -> SDoc
ppr (((Name, TyThing) -> Name) -> [(Name, TyThing)] -> [Name]
forall a b. (a -> b) -> [a] -> [b]
map (Name, TyThing) -> Name
forall a b. (a, b) -> a
fst [(Name, TyThing)]
names_w_things)])
; ModDetails -> IfL ModDetails
forall (m :: * -> *) a. Monad m => a -> m a
return (ModDetails -> IfL ModDetails) -> ModDetails -> IfL ModDetails
forall a b. (a -> b) -> a -> b
$ ModDetails :: [AvailInfo]
-> TypeEnv
-> [ClsInst]
-> [FamInst]
-> [CoreRule]
-> [Annotation]
-> [CompleteMatch]
-> ModDetails
ModDetails { md_types :: TypeEnv
md_types = TypeEnv
type_env
, md_insts :: [ClsInst]
md_insts = [ClsInst]
insts
, md_fam_insts :: [FamInst]
md_fam_insts = [FamInst]
fam_insts
, md_rules :: [CoreRule]
md_rules = [CoreRule]
rules
, md_anns :: [Annotation]
md_anns = [Annotation]
anns
, md_exports :: [AvailInfo]
md_exports = [AvailInfo]
exports
, md_complete_sigs :: [CompleteMatch]
md_complete_sigs = [CompleteMatch]
complete_sigs
}
}
isAbstractIfaceDecl :: IfaceDecl -> Bool
isAbstractIfaceDecl :: IfaceDecl -> Bool
isAbstractIfaceDecl IfaceData{ ifCons :: IfaceDecl -> IfaceConDecls
ifCons = IfaceConDecls
IfAbstractTyCon } = Bool
True
isAbstractIfaceDecl IfaceClass{ ifBody :: IfaceDecl -> IfaceClassBody
ifBody = IfaceClassBody
IfAbstractClass } = Bool
True
isAbstractIfaceDecl IfaceFamily{ ifFamFlav :: IfaceDecl -> IfaceFamTyConFlav
ifFamFlav = IfaceFamTyConFlav
IfaceAbstractClosedSynFamilyTyCon } = Bool
True
isAbstractIfaceDecl IfaceDecl
_ = Bool
False
ifMaybeRoles :: IfaceDecl -> Maybe [Role]
ifMaybeRoles :: IfaceDecl -> Maybe [Role]
ifMaybeRoles IfaceData { ifRoles :: IfaceDecl -> [Role]
ifRoles = [Role]
rs } = [Role] -> Maybe [Role]
forall a. a -> Maybe a
Just [Role]
rs
ifMaybeRoles IfaceSynonym { ifRoles :: IfaceDecl -> [Role]
ifRoles = [Role]
rs } = [Role] -> Maybe [Role]
forall a. a -> Maybe a
Just [Role]
rs
ifMaybeRoles IfaceClass { ifRoles :: IfaceDecl -> [Role]
ifRoles = [Role]
rs } = [Role] -> Maybe [Role]
forall a. a -> Maybe a
Just [Role]
rs
ifMaybeRoles IfaceDecl
_ = Maybe [Role]
forall a. Maybe a
Nothing
mergeIfaceDecl :: IfaceDecl -> IfaceDecl -> IfaceDecl
mergeIfaceDecl :: IfaceDecl -> IfaceDecl -> IfaceDecl
mergeIfaceDecl IfaceDecl
d1 IfaceDecl
d2
| IfaceDecl -> Bool
isAbstractIfaceDecl IfaceDecl
d1 = IfaceDecl
d2 IfaceDecl -> IfaceDecl -> IfaceDecl
`withRolesFrom` IfaceDecl
d1
| IfaceDecl -> Bool
isAbstractIfaceDecl IfaceDecl
d2 = IfaceDecl
d1 IfaceDecl -> IfaceDecl -> IfaceDecl
`withRolesFrom` IfaceDecl
d2
| IfaceClass{ ifBody :: IfaceDecl -> IfaceClassBody
ifBody = IfConcreteClass { ifSigs :: IfaceClassBody -> [IfaceClassOp]
ifSigs = [IfaceClassOp]
ops1, ifMinDef :: IfaceClassBody -> BooleanFormula IfLclName
ifMinDef = BooleanFormula IfLclName
bf1 } } <- IfaceDecl
d1
, IfaceClass{ ifBody :: IfaceDecl -> IfaceClassBody
ifBody = IfConcreteClass { ifSigs :: IfaceClassBody -> [IfaceClassOp]
ifSigs = [IfaceClassOp]
ops2, ifMinDef :: IfaceClassBody -> BooleanFormula IfLclName
ifMinDef = BooleanFormula IfLclName
bf2 } } <- IfaceDecl
d2
= let ops :: [IfaceClassOp]
ops = NameEnv IfaceClassOp -> [IfaceClassOp]
forall a. NameEnv a -> [a]
nameEnvElts (NameEnv IfaceClassOp -> [IfaceClassOp])
-> NameEnv IfaceClassOp -> [IfaceClassOp]
forall a b. (a -> b) -> a -> b
$
(IfaceClassOp -> IfaceClassOp -> IfaceClassOp)
-> NameEnv IfaceClassOp
-> NameEnv IfaceClassOp
-> NameEnv IfaceClassOp
forall a. (a -> a -> a) -> NameEnv a -> NameEnv a -> NameEnv a
plusNameEnv_C IfaceClassOp -> IfaceClassOp -> IfaceClassOp
mergeIfaceClassOp
([(Name, IfaceClassOp)] -> NameEnv IfaceClassOp
forall a. [(Name, a)] -> NameEnv a
mkNameEnv [ (Name
n, IfaceClassOp
op) | op :: IfaceClassOp
op@(IfaceClassOp Name
n IfaceType
_ Maybe (DefMethSpec IfaceType)
_) <- [IfaceClassOp]
ops1 ])
([(Name, IfaceClassOp)] -> NameEnv IfaceClassOp
forall a. [(Name, a)] -> NameEnv a
mkNameEnv [ (Name
n, IfaceClassOp
op) | op :: IfaceClassOp
op@(IfaceClassOp Name
n IfaceType
_ Maybe (DefMethSpec IfaceType)
_) <- [IfaceClassOp]
ops2 ])
in IfaceDecl
d1 { ifBody :: IfaceClassBody
ifBody = (IfaceDecl -> IfaceClassBody
ifBody IfaceDecl
d1) {
ifSigs :: [IfaceClassOp]
ifSigs = [IfaceClassOp]
ops,
ifMinDef :: BooleanFormula IfLclName
ifMinDef = [LBooleanFormula IfLclName] -> BooleanFormula IfLclName
forall a. Eq a => [LBooleanFormula a] -> BooleanFormula a
BF.mkOr [BooleanFormula IfLclName -> LBooleanFormula IfLclName
forall e. e -> Located e
noLoc BooleanFormula IfLclName
bf1, BooleanFormula IfLclName -> LBooleanFormula IfLclName
forall e. e -> Located e
noLoc BooleanFormula IfLclName
bf2]
}
} IfaceDecl -> IfaceDecl -> IfaceDecl
`withRolesFrom` IfaceDecl
d2
| Bool
otherwise = IfaceDecl
d1 IfaceDecl -> IfaceDecl -> IfaceDecl
`withRolesFrom` IfaceDecl
d2
withRolesFrom :: IfaceDecl -> IfaceDecl -> IfaceDecl
IfaceDecl
d1 withRolesFrom :: IfaceDecl -> IfaceDecl -> IfaceDecl
`withRolesFrom` IfaceDecl
d2
| Just [Role]
roles1 <- IfaceDecl -> Maybe [Role]
ifMaybeRoles IfaceDecl
d1
, Just [Role]
roles2 <- IfaceDecl -> Maybe [Role]
ifMaybeRoles IfaceDecl
d2
, Bool -> Bool
not (IfaceDecl -> Bool
isRepInjectiveIfaceDecl IfaceDecl
d1 Bool -> Bool -> Bool
|| IfaceDecl -> Bool
isRepInjectiveIfaceDecl IfaceDecl
d2)
= IfaceDecl
d1 { ifRoles :: [Role]
ifRoles = [Role] -> [Role] -> [Role]
forall {c}. Ord c => [c] -> [c] -> [c]
mergeRoles [Role]
roles1 [Role]
roles2 }
| Bool
otherwise = IfaceDecl
d1
where
mergeRoles :: [c] -> [c] -> [c]
mergeRoles [c]
roles1 [c]
roles2 = String -> (c -> c -> c) -> [c] -> [c] -> [c]
forall a b c. String -> (a -> b -> c) -> [a] -> [b] -> [c]
zipWithEqual String
"mergeRoles" c -> c -> c
forall a. Ord a => a -> a -> a
max [c]
roles1 [c]
roles2
isRepInjectiveIfaceDecl :: IfaceDecl -> Bool
isRepInjectiveIfaceDecl :: IfaceDecl -> Bool
isRepInjectiveIfaceDecl IfaceData{ ifCons :: IfaceDecl -> IfaceConDecls
ifCons = IfDataTyCon [IfaceConDecl]
_ } = Bool
True
isRepInjectiveIfaceDecl IfaceFamily{ ifFamFlav :: IfaceDecl -> IfaceFamTyConFlav
ifFamFlav = IfaceFamTyConFlav
IfaceDataFamilyTyCon } = Bool
True
isRepInjectiveIfaceDecl IfaceDecl
_ = Bool
False
mergeIfaceClassOp :: IfaceClassOp -> IfaceClassOp -> IfaceClassOp
mergeIfaceClassOp :: IfaceClassOp -> IfaceClassOp -> IfaceClassOp
mergeIfaceClassOp op1 :: IfaceClassOp
op1@(IfaceClassOp Name
_ IfaceType
_ (Just DefMethSpec IfaceType
_)) IfaceClassOp
_ = IfaceClassOp
op1
mergeIfaceClassOp IfaceClassOp
_ IfaceClassOp
op2 = IfaceClassOp
op2
mergeIfaceDecls :: OccEnv IfaceDecl -> OccEnv IfaceDecl -> OccEnv IfaceDecl
mergeIfaceDecls :: OccEnv IfaceDecl -> OccEnv IfaceDecl -> OccEnv IfaceDecl
mergeIfaceDecls = (IfaceDecl -> IfaceDecl -> IfaceDecl)
-> OccEnv IfaceDecl -> OccEnv IfaceDecl -> OccEnv IfaceDecl
forall a. (a -> a -> a) -> OccEnv a -> OccEnv a -> OccEnv a
plusOccEnv_C IfaceDecl -> IfaceDecl -> IfaceDecl
mergeIfaceDecl
typecheckIfacesForMerging :: Module -> [ModIface] -> IORef TypeEnv -> IfM lcl (TypeEnv, [ModDetails])
typecheckIfacesForMerging :: forall lcl.
Module
-> [ModIface] -> IORef TypeEnv -> IfM lcl (TypeEnv, [ModDetails])
typecheckIfacesForMerging Module
mod [ModIface]
ifaces IORef TypeEnv
tc_env_var =
Module
-> SDoc
-> IsBootInterface
-> IfL (TypeEnv, [ModDetails])
-> IfM lcl (TypeEnv, [ModDetails])
forall a lcl.
Module -> SDoc -> IsBootInterface -> IfL a -> IfM lcl a
initIfaceLcl Module
mod (String -> SDoc
text String
"typecheckIfacesForMerging") IsBootInterface
NotBoot (IfL (TypeEnv, [ModDetails]) -> IfM lcl (TypeEnv, [ModDetails]))
-> IfL (TypeEnv, [ModDetails]) -> IfM lcl (TypeEnv, [ModDetails])
forall a b. (a -> b) -> a -> b
$ do
Bool
ignore_prags <- GeneralFlag -> TcRnIf IfGblEnv IfLclEnv Bool
forall gbl lcl. GeneralFlag -> TcRnIf gbl lcl Bool
goptM GeneralFlag
Opt_IgnoreInterfacePragmas
let mk_decl_env :: [IfaceDecl] -> OccEnv IfaceDecl
mk_decl_env [IfaceDecl]
decls
= [(OccName, IfaceDecl)] -> OccEnv IfaceDecl
forall a. [(OccName, a)] -> OccEnv a
mkOccEnv [ (IfaceDecl -> OccName
forall a. NamedThing a => a -> OccName
getOccName IfaceDecl
decl, IfaceDecl
decl)
| IfaceDecl
decl <- [IfaceDecl]
decls
, case IfaceDecl
decl of
IfaceId { ifIdDetails :: IfaceDecl -> IfaceIdDetails
ifIdDetails = IfaceIdDetails
IfDFunId } -> Bool
False
IfaceDecl
_ -> Bool
True ]
decl_envs :: [OccEnv IfaceDecl]
decl_envs = (ModIface -> OccEnv IfaceDecl) -> [ModIface] -> [OccEnv IfaceDecl]
forall a b. (a -> b) -> [a] -> [b]
map ([IfaceDecl] -> OccEnv IfaceDecl
mk_decl_env ([IfaceDecl] -> OccEnv IfaceDecl)
-> (ModIface -> [IfaceDecl]) -> ModIface -> OccEnv IfaceDecl
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ((Fingerprint, IfaceDecl) -> IfaceDecl)
-> [(Fingerprint, IfaceDecl)] -> [IfaceDecl]
forall a b. (a -> b) -> [a] -> [b]
map (Fingerprint, IfaceDecl) -> IfaceDecl
forall a b. (a, b) -> b
snd ([(Fingerprint, IfaceDecl)] -> [IfaceDecl])
-> (ModIface -> [(Fingerprint, IfaceDecl)])
-> ModIface
-> [IfaceDecl]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ModIface -> [(Fingerprint, IfaceDecl)]
forall (phase :: ModIfacePhase).
ModIface_ phase -> [IfaceDeclExts phase]
mi_decls) [ModIface]
ifaces
:: [OccEnv IfaceDecl]
decl_env :: OccEnv IfaceDecl
decl_env = (OccEnv IfaceDecl -> OccEnv IfaceDecl -> OccEnv IfaceDecl)
-> OccEnv IfaceDecl -> [OccEnv IfaceDecl] -> OccEnv IfaceDecl
forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
foldl' OccEnv IfaceDecl -> OccEnv IfaceDecl -> OccEnv IfaceDecl
mergeIfaceDecls OccEnv IfaceDecl
forall a. OccEnv a
emptyOccEnv [OccEnv IfaceDecl]
decl_envs
:: OccEnv IfaceDecl
[(Name, TyThing)]
names_w_things <- Bool -> [(Fingerprint, IfaceDecl)] -> IfL [(Name, TyThing)]
loadDecls Bool
ignore_prags ((IfaceDecl -> (Fingerprint, IfaceDecl))
-> [IfaceDecl] -> [(Fingerprint, IfaceDecl)]
forall a b. (a -> b) -> [a] -> [b]
map (\IfaceDecl
x -> (Fingerprint
fingerprint0, IfaceDecl
x))
(OccEnv IfaceDecl -> [IfaceDecl]
forall a. OccEnv a -> [a]
occEnvElts OccEnv IfaceDecl
decl_env))
let global_type_env :: TypeEnv
global_type_env = [(Name, TyThing)] -> TypeEnv
forall a. [(Name, a)] -> NameEnv a
mkNameEnv [(Name, TyThing)]
names_w_things
IORef TypeEnv -> TypeEnv -> TcRnIf IfGblEnv IfLclEnv ()
forall a env. IORef a -> a -> IOEnv env ()
writeMutVar IORef TypeEnv
tc_env_var TypeEnv
global_type_env
[ModDetails]
details <- [ModIface]
-> (ModIface -> IfL ModDetails)
-> IOEnv (Env IfGblEnv IfLclEnv) [ModDetails]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
t a -> (a -> m b) -> m (t b)
forM [ModIface]
ifaces ((ModIface -> IfL ModDetails)
-> IOEnv (Env IfGblEnv IfLclEnv) [ModDetails])
-> (ModIface -> IfL ModDetails)
-> IOEnv (Env IfGblEnv IfLclEnv) [ModDetails]
forall a b. (a -> b) -> a -> b
$ \ModIface
iface -> do
TypeEnv
type_env <- (TypeEnv -> IOEnv (Env IfGblEnv IfLclEnv) TypeEnv)
-> IOEnv (Env IfGblEnv IfLclEnv) TypeEnv
forall a env. (a -> IOEnv env a) -> IOEnv env a
fixM ((TypeEnv -> IOEnv (Env IfGblEnv IfLclEnv) TypeEnv)
-> IOEnv (Env IfGblEnv IfLclEnv) TypeEnv)
-> (TypeEnv -> IOEnv (Env IfGblEnv IfLclEnv) TypeEnv)
-> IOEnv (Env IfGblEnv IfLclEnv) TypeEnv
forall a b. (a -> b) -> a -> b
$ \TypeEnv
type_env -> do
TypeEnv
-> IOEnv (Env IfGblEnv IfLclEnv) TypeEnv
-> IOEnv (Env IfGblEnv IfLclEnv) TypeEnv
forall a. TypeEnv -> IfL a -> IfL a
setImplicitEnvM TypeEnv
type_env (IOEnv (Env IfGblEnv IfLclEnv) TypeEnv
-> IOEnv (Env IfGblEnv IfLclEnv) TypeEnv)
-> IOEnv (Env IfGblEnv IfLclEnv) TypeEnv
-> IOEnv (Env IfGblEnv IfLclEnv) TypeEnv
forall a b. (a -> b) -> a -> b
$ do
[(Name, TyThing)]
decls <- Bool -> [(Fingerprint, IfaceDecl)] -> IfL [(Name, TyThing)]
loadDecls Bool
ignore_prags (ModIface -> [IfaceDeclExts 'ModIfaceFinal]
forall (phase :: ModIfacePhase).
ModIface_ phase -> [IfaceDeclExts phase]
mi_decls ModIface
iface)
TypeEnv -> IOEnv (Env IfGblEnv IfLclEnv) TypeEnv
forall (m :: * -> *) a. Monad m => a -> m a
return ([(Name, TyThing)] -> TypeEnv
forall a. [(Name, a)] -> NameEnv a
mkNameEnv [(Name, TyThing)]
decls)
TypeEnv -> IfL ModDetails -> IfL ModDetails
forall a. TypeEnv -> IfL a -> IfL a
setImplicitEnvM TypeEnv
type_env (IfL ModDetails -> IfL ModDetails)
-> IfL ModDetails -> IfL ModDetails
forall a b. (a -> b) -> a -> b
$ do
[ClsInst]
insts <- (IfaceClsInst -> IOEnv (Env IfGblEnv IfLclEnv) ClsInst)
-> [IfaceClsInst] -> IOEnv (Env IfGblEnv IfLclEnv) [ClsInst]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM IfaceClsInst -> IOEnv (Env IfGblEnv IfLclEnv) ClsInst
tcIfaceInst (ModIface -> [IfaceClsInst]
forall (phase :: ModIfacePhase). ModIface_ phase -> [IfaceClsInst]
mi_insts ModIface
iface)
[FamInst]
fam_insts <- (IfaceFamInst -> IOEnv (Env IfGblEnv IfLclEnv) FamInst)
-> [IfaceFamInst] -> IOEnv (Env IfGblEnv IfLclEnv) [FamInst]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM IfaceFamInst -> IOEnv (Env IfGblEnv IfLclEnv) FamInst
tcIfaceFamInst (ModIface -> [IfaceFamInst]
forall (phase :: ModIfacePhase). ModIface_ phase -> [IfaceFamInst]
mi_fam_insts ModIface
iface)
[CoreRule]
rules <- Bool -> [IfaceRule] -> IfL [CoreRule]
tcIfaceRules Bool
ignore_prags (ModIface -> [IfaceRule]
forall (phase :: ModIfacePhase). ModIface_ phase -> [IfaceRule]
mi_rules ModIface
iface)
[Annotation]
anns <- [IfaceAnnotation] -> IfL [Annotation]
tcIfaceAnnotations (ModIface -> [IfaceAnnotation]
forall (phase :: ModIfacePhase).
ModIface_ phase -> [IfaceAnnotation]
mi_anns ModIface
iface)
[AvailInfo]
exports <- [AvailInfo] -> TcRnIf IfGblEnv IfLclEnv [AvailInfo]
forall gbl lcl. [AvailInfo] -> TcRnIf gbl lcl [AvailInfo]
ifaceExportNames (ModIface -> [AvailInfo]
forall (phase :: ModIfacePhase). ModIface_ phase -> [AvailInfo]
mi_exports ModIface
iface)
[CompleteMatch]
complete_sigs <- [IfaceCompleteMatch] -> IfL [CompleteMatch]
tcIfaceCompleteSigs (ModIface -> [IfaceCompleteMatch]
forall (phase :: ModIfacePhase).
ModIface_ phase -> [IfaceCompleteMatch]
mi_complete_sigs ModIface
iface)
ModDetails -> IfL ModDetails
forall (m :: * -> *) a. Monad m => a -> m a
return (ModDetails -> IfL ModDetails) -> ModDetails -> IfL ModDetails
forall a b. (a -> b) -> a -> b
$ ModDetails :: [AvailInfo]
-> TypeEnv
-> [ClsInst]
-> [FamInst]
-> [CoreRule]
-> [Annotation]
-> [CompleteMatch]
-> ModDetails
ModDetails { md_types :: TypeEnv
md_types = TypeEnv
type_env
, md_insts :: [ClsInst]
md_insts = [ClsInst]
insts
, md_fam_insts :: [FamInst]
md_fam_insts = [FamInst]
fam_insts
, md_rules :: [CoreRule]
md_rules = [CoreRule]
rules
, md_anns :: [Annotation]
md_anns = [Annotation]
anns
, md_exports :: [AvailInfo]
md_exports = [AvailInfo]
exports
, md_complete_sigs :: [CompleteMatch]
md_complete_sigs = [CompleteMatch]
complete_sigs
}
(TypeEnv, [ModDetails]) -> IfL (TypeEnv, [ModDetails])
forall (m :: * -> *) a. Monad m => a -> m a
return (TypeEnv
global_type_env, [ModDetails]
details)
typecheckIfaceForInstantiate :: NameShape -> ModIface -> IfM lcl ModDetails
typecheckIfaceForInstantiate :: forall lcl. NameShape -> ModIface -> IfM lcl ModDetails
typecheckIfaceForInstantiate NameShape
nsubst ModIface
iface =
Module
-> SDoc
-> IsBootInterface
-> NameShape
-> IfL ModDetails
-> IfM lcl ModDetails
forall a lcl.
Module
-> SDoc -> IsBootInterface -> NameShape -> IfL a -> IfM lcl a
initIfaceLclWithSubst (ModIface -> Module
forall (a :: ModIfacePhase). ModIface_ a -> Module
mi_semantic_module ModIface
iface)
(String -> SDoc
text String
"typecheckIfaceForInstantiate")
(ModIface -> IsBootInterface
mi_boot ModIface
iface) NameShape
nsubst (IfL ModDetails -> IfM lcl ModDetails)
-> IfL ModDetails -> IfM lcl ModDetails
forall a b. (a -> b) -> a -> b
$ do
Bool
ignore_prags <- GeneralFlag -> TcRnIf IfGblEnv IfLclEnv Bool
forall gbl lcl. GeneralFlag -> TcRnIf gbl lcl Bool
goptM GeneralFlag
Opt_IgnoreInterfacePragmas
TypeEnv
type_env <- (TypeEnv -> IOEnv (Env IfGblEnv IfLclEnv) TypeEnv)
-> IOEnv (Env IfGblEnv IfLclEnv) TypeEnv
forall a env. (a -> IOEnv env a) -> IOEnv env a
fixM ((TypeEnv -> IOEnv (Env IfGblEnv IfLclEnv) TypeEnv)
-> IOEnv (Env IfGblEnv IfLclEnv) TypeEnv)
-> (TypeEnv -> IOEnv (Env IfGblEnv IfLclEnv) TypeEnv)
-> IOEnv (Env IfGblEnv IfLclEnv) TypeEnv
forall a b. (a -> b) -> a -> b
$ \TypeEnv
type_env -> do
TypeEnv
-> IOEnv (Env IfGblEnv IfLclEnv) TypeEnv
-> IOEnv (Env IfGblEnv IfLclEnv) TypeEnv
forall a. TypeEnv -> IfL a -> IfL a
setImplicitEnvM TypeEnv
type_env (IOEnv (Env IfGblEnv IfLclEnv) TypeEnv
-> IOEnv (Env IfGblEnv IfLclEnv) TypeEnv)
-> IOEnv (Env IfGblEnv IfLclEnv) TypeEnv
-> IOEnv (Env IfGblEnv IfLclEnv) TypeEnv
forall a b. (a -> b) -> a -> b
$ do
[(Name, TyThing)]
decls <- Bool -> [(Fingerprint, IfaceDecl)] -> IfL [(Name, TyThing)]
loadDecls Bool
ignore_prags (ModIface -> [IfaceDeclExts 'ModIfaceFinal]
forall (phase :: ModIfacePhase).
ModIface_ phase -> [IfaceDeclExts phase]
mi_decls ModIface
iface)
TypeEnv -> IOEnv (Env IfGblEnv IfLclEnv) TypeEnv
forall (m :: * -> *) a. Monad m => a -> m a
return ([(Name, TyThing)] -> TypeEnv
forall a. [(Name, a)] -> NameEnv a
mkNameEnv [(Name, TyThing)]
decls)
TypeEnv -> IfL ModDetails -> IfL ModDetails
forall a. TypeEnv -> IfL a -> IfL a
setImplicitEnvM TypeEnv
type_env (IfL ModDetails -> IfL ModDetails)
-> IfL ModDetails -> IfL ModDetails
forall a b. (a -> b) -> a -> b
$ do
[ClsInst]
insts <- (IfaceClsInst -> IOEnv (Env IfGblEnv IfLclEnv) ClsInst)
-> [IfaceClsInst] -> IOEnv (Env IfGblEnv IfLclEnv) [ClsInst]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM IfaceClsInst -> IOEnv (Env IfGblEnv IfLclEnv) ClsInst
tcIfaceInst (ModIface -> [IfaceClsInst]
forall (phase :: ModIfacePhase). ModIface_ phase -> [IfaceClsInst]
mi_insts ModIface
iface)
[FamInst]
fam_insts <- (IfaceFamInst -> IOEnv (Env IfGblEnv IfLclEnv) FamInst)
-> [IfaceFamInst] -> IOEnv (Env IfGblEnv IfLclEnv) [FamInst]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM IfaceFamInst -> IOEnv (Env IfGblEnv IfLclEnv) FamInst
tcIfaceFamInst (ModIface -> [IfaceFamInst]
forall (phase :: ModIfacePhase). ModIface_ phase -> [IfaceFamInst]
mi_fam_insts ModIface
iface)
[CoreRule]
rules <- Bool -> [IfaceRule] -> IfL [CoreRule]
tcIfaceRules Bool
ignore_prags (ModIface -> [IfaceRule]
forall (phase :: ModIfacePhase). ModIface_ phase -> [IfaceRule]
mi_rules ModIface
iface)
[Annotation]
anns <- [IfaceAnnotation] -> IfL [Annotation]
tcIfaceAnnotations (ModIface -> [IfaceAnnotation]
forall (phase :: ModIfacePhase).
ModIface_ phase -> [IfaceAnnotation]
mi_anns ModIface
iface)
[AvailInfo]
exports <- [AvailInfo] -> TcRnIf IfGblEnv IfLclEnv [AvailInfo]
forall gbl lcl. [AvailInfo] -> TcRnIf gbl lcl [AvailInfo]
ifaceExportNames (ModIface -> [AvailInfo]
forall (phase :: ModIfacePhase). ModIface_ phase -> [AvailInfo]
mi_exports ModIface
iface)
[CompleteMatch]
complete_sigs <- [IfaceCompleteMatch] -> IfL [CompleteMatch]
tcIfaceCompleteSigs (ModIface -> [IfaceCompleteMatch]
forall (phase :: ModIfacePhase).
ModIface_ phase -> [IfaceCompleteMatch]
mi_complete_sigs ModIface
iface)
ModDetails -> IfL ModDetails
forall (m :: * -> *) a. Monad m => a -> m a
return (ModDetails -> IfL ModDetails) -> ModDetails -> IfL ModDetails
forall a b. (a -> b) -> a -> b
$ ModDetails :: [AvailInfo]
-> TypeEnv
-> [ClsInst]
-> [FamInst]
-> [CoreRule]
-> [Annotation]
-> [CompleteMatch]
-> ModDetails
ModDetails { md_types :: TypeEnv
md_types = TypeEnv
type_env
, md_insts :: [ClsInst]
md_insts = [ClsInst]
insts
, md_fam_insts :: [FamInst]
md_fam_insts = [FamInst]
fam_insts
, md_rules :: [CoreRule]
md_rules = [CoreRule]
rules
, md_anns :: [Annotation]
md_anns = [Annotation]
anns
, md_exports :: [AvailInfo]
md_exports = [AvailInfo]
exports
, md_complete_sigs :: [CompleteMatch]
md_complete_sigs = [CompleteMatch]
complete_sigs
}
tcHiBootIface :: HscSource -> Module -> TcRn SelfBootInfo
tcHiBootIface :: HscSource -> Module -> TcRn SelfBootInfo
tcHiBootIface HscSource
hsc_src Module
mod
| HscSource
HsBootFile <- HscSource
hsc_src
= SelfBootInfo -> TcRn SelfBootInfo
forall (m :: * -> *) a. Monad m => a -> m a
return SelfBootInfo
NoSelfBoot
| Bool
otherwise
= do { SDoc -> TcRnIf TcGblEnv TcLclEnv ()
forall m n. SDoc -> TcRnIf m n ()
traceIf (String -> SDoc
text String
"loadHiBootInterface" SDoc -> SDoc -> SDoc
<+> Module -> SDoc
forall a. Outputable a => a -> SDoc
ppr Module
mod)
; GhcMode
mode <- TcRnIf TcGblEnv TcLclEnv GhcMode
forall gbl lcl. TcRnIf gbl lcl GhcMode
getGhcMode
; if Bool -> Bool
not (GhcMode -> Bool
isOneShot GhcMode
mode)
then do { HomePackageTable
hpt <- TcRnIf TcGblEnv TcLclEnv HomePackageTable
forall gbl lcl. TcRnIf gbl lcl HomePackageTable
getHpt
; case HomePackageTable -> ModuleName -> Maybe HomeModInfo
lookupHpt HomePackageTable
hpt (Module -> ModuleName
forall unit. GenModule unit -> ModuleName
moduleName Module
mod) of
Just HomeModInfo
info | ModIface -> IsBootInterface
mi_boot (HomeModInfo -> ModIface
hm_iface HomeModInfo
info) IsBootInterface -> IsBootInterface -> Bool
forall a. Eq a => a -> a -> Bool
== IsBootInterface
IsBoot
-> ModIface -> ModDetails -> TcRn SelfBootInfo
mkSelfBootInfo (HomeModInfo -> ModIface
hm_iface HomeModInfo
info) (HomeModInfo -> ModDetails
hm_details HomeModInfo
info)
Maybe HomeModInfo
_ -> SelfBootInfo -> TcRn SelfBootInfo
forall (m :: * -> *) a. Monad m => a -> m a
return SelfBootInfo
NoSelfBoot }
else do
{ MaybeErr SDoc (ModIface, String)
read_result <- SDoc
-> InstalledModule
-> Module
-> IsBootInterface
-> TcRnIf TcGblEnv TcLclEnv (MaybeErr SDoc (ModIface, String))
forall gbl lcl.
SDoc
-> InstalledModule
-> Module
-> IsBootInterface
-> TcRnIf gbl lcl (MaybeErr SDoc (ModIface, String))
findAndReadIface
SDoc
need ((InstalledModule, Maybe InstantiatedModule) -> InstalledModule
forall a b. (a, b) -> a
fst (Module -> (InstalledModule, Maybe InstantiatedModule)
getModuleInstantiation Module
mod)) Module
mod
IsBootInterface
IsBoot
; case MaybeErr SDoc (ModIface, String)
read_result of {
Succeeded (ModIface
iface, String
_path) -> do { ModDetails
tc_iface <- IfG ModDetails -> TcRn ModDetails
forall a. IfG a -> TcRn a
initIfaceTcRn (IfG ModDetails -> TcRn ModDetails)
-> IfG ModDetails -> TcRn ModDetails
forall a b. (a -> b) -> a -> b
$ ModIface -> IfG ModDetails
typecheckIface ModIface
iface
; ModIface -> ModDetails -> TcRn SelfBootInfo
mkSelfBootInfo ModIface
iface ModDetails
tc_iface } ;
Failed SDoc
err ->
do { ExternalPackageState
eps <- TcRnIf TcGblEnv TcLclEnv ExternalPackageState
forall gbl lcl. TcRnIf gbl lcl ExternalPackageState
getEps
; case UniqFM ModuleName ModuleNameWithIsBoot
-> ModuleName -> Maybe ModuleNameWithIsBoot
forall key elt. Uniquable key => UniqFM key elt -> key -> Maybe elt
lookupUFM (ExternalPackageState -> UniqFM ModuleName ModuleNameWithIsBoot
eps_is_boot ExternalPackageState
eps) (Module -> ModuleName
forall unit. GenModule unit -> ModuleName
moduleName Module
mod) of
Maybe ModuleNameWithIsBoot
Nothing -> SelfBootInfo -> TcRn SelfBootInfo
forall (m :: * -> *) a. Monad m => a -> m a
return SelfBootInfo
NoSelfBoot
Just (GWIB { gwib_isBoot :: forall mod. GenWithIsBoot mod -> IsBootInterface
gwib_isBoot = IsBootInterface
is_boot }) -> case IsBootInterface
is_boot of
IsBootInterface
IsBoot -> SDoc -> TcRn SelfBootInfo
forall a. SDoc -> TcM a
failWithTc (SDoc -> SDoc
elaborate SDoc
err)
IsBootInterface
NotBoot -> SDoc -> TcRn SelfBootInfo
forall a. SDoc -> TcM a
failWithTc SDoc
moduleLoop
}}}}
where
need :: SDoc
need = String -> SDoc
text String
"Need the hi-boot interface for" SDoc -> SDoc -> SDoc
<+> Module -> SDoc
forall a. Outputable a => a -> SDoc
ppr Module
mod
SDoc -> SDoc -> SDoc
<+> String -> SDoc
text String
"to compare against the Real Thing"
moduleLoop :: SDoc
moduleLoop = String -> SDoc
text String
"Circular imports: module" SDoc -> SDoc -> SDoc
<+> SDoc -> SDoc
quotes (Module -> SDoc
forall a. Outputable a => a -> SDoc
ppr Module
mod)
SDoc -> SDoc -> SDoc
<+> String -> SDoc
text String
"depends on itself"
elaborate :: SDoc -> SDoc
elaborate SDoc
err = SDoc -> Int -> SDoc -> SDoc
hang (String -> SDoc
text String
"Could not find hi-boot interface for" SDoc -> SDoc -> SDoc
<+>
SDoc -> SDoc
quotes (Module -> SDoc
forall a. Outputable a => a -> SDoc
ppr Module
mod) SDoc -> SDoc -> SDoc
<> SDoc
colon) Int
4 SDoc
err
mkSelfBootInfo :: ModIface -> ModDetails -> TcRn SelfBootInfo
mkSelfBootInfo :: ModIface -> ModDetails -> TcRn SelfBootInfo
mkSelfBootInfo ModIface
iface ModDetails
mds
= do
let tcs :: [Name]
tcs = (IfaceDecl -> Name) -> [IfaceDecl] -> [Name]
forall a b. (a -> b) -> [a] -> [b]
map IfaceDecl -> Name
ifName
([IfaceDecl] -> [Name])
-> ([(Fingerprint, IfaceDecl)] -> [IfaceDecl])
-> [(Fingerprint, IfaceDecl)]
-> [Name]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (IfaceDecl -> Bool) -> [IfaceDecl] -> [IfaceDecl]
forall a. (a -> Bool) -> [a] -> [a]
filter IfaceDecl -> Bool
isIfaceTyCon
([IfaceDecl] -> [IfaceDecl])
-> ([(Fingerprint, IfaceDecl)] -> [IfaceDecl])
-> [(Fingerprint, IfaceDecl)]
-> [IfaceDecl]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ((Fingerprint, IfaceDecl) -> IfaceDecl)
-> [(Fingerprint, IfaceDecl)] -> [IfaceDecl]
forall a b. (a -> b) -> [a] -> [b]
map (Fingerprint, IfaceDecl) -> IfaceDecl
forall a b. (a, b) -> b
snd
([(Fingerprint, IfaceDecl)] -> [Name])
-> [(Fingerprint, IfaceDecl)] -> [Name]
forall a b. (a -> b) -> a -> b
$ ModIface -> [IfaceDeclExts 'ModIfaceFinal]
forall (phase :: ModIfacePhase).
ModIface_ phase -> [IfaceDeclExts phase]
mi_decls ModIface
iface
SelfBootInfo -> TcRn SelfBootInfo
forall (m :: * -> *) a. Monad m => a -> m a
return (SelfBootInfo -> TcRn SelfBootInfo)
-> SelfBootInfo -> TcRn SelfBootInfo
forall a b. (a -> b) -> a -> b
$ SelfBoot :: ModDetails -> NameSet -> SelfBootInfo
SelfBoot { sb_mds :: ModDetails
sb_mds = ModDetails
mds
, sb_tcs :: NameSet
sb_tcs = [Name] -> NameSet
mkNameSet [Name]
tcs }
where
isIfaceTyCon :: IfaceDecl -> Bool
isIfaceTyCon IfaceId{} = Bool
False
isIfaceTyCon IfaceData{} = Bool
True
isIfaceTyCon IfaceSynonym{} = Bool
True
isIfaceTyCon IfaceFamily{} = Bool
True
isIfaceTyCon IfaceClass{} = Bool
True
isIfaceTyCon IfaceAxiom{} = Bool
False
isIfaceTyCon IfacePatSyn{} = Bool
False
tcIfaceDecl :: Bool
-> IfaceDecl
-> IfL TyThing
tcIfaceDecl :: Bool -> IfaceDecl -> IfL TyThing
tcIfaceDecl = Maybe Class -> Bool -> IfaceDecl -> IfL TyThing
tc_iface_decl Maybe Class
forall a. Maybe a
Nothing
tc_iface_decl :: Maybe Class
-> Bool
-> IfaceDecl
-> IfL TyThing
tc_iface_decl :: Maybe Class -> Bool -> IfaceDecl -> IfL TyThing
tc_iface_decl Maybe Class
_ Bool
ignore_prags (IfaceId {ifName :: IfaceDecl -> Name
ifName = Name
name, ifType :: IfaceDecl -> IfaceType
ifType = IfaceType
iface_type,
ifIdDetails :: IfaceDecl -> IfaceIdDetails
ifIdDetails = IfaceIdDetails
details, ifIdInfo :: IfaceDecl -> IfaceIdInfo
ifIdInfo = IfaceIdInfo
info})
= do { Type
ty <- IfaceType -> IfL Type
tcIfaceType IfaceType
iface_type
; IdDetails
details <- Type -> IfaceIdDetails -> IfL IdDetails
tcIdDetails Type
ty IfaceIdDetails
details
; IdInfo
info <- Bool -> TopLevelFlag -> Name -> Type -> IfaceIdInfo -> IfL IdInfo
tcIdInfo Bool
ignore_prags TopLevelFlag
TopLevel Name
name Type
ty IfaceIdInfo
info
; TyThing -> IfL TyThing
forall (m :: * -> *) a. Monad m => a -> m a
return (Var -> TyThing
AnId (IdDetails -> Name -> Type -> IdInfo -> Var
mkGlobalId IdDetails
details Name
name Type
ty IdInfo
info)) }
tc_iface_decl Maybe Class
_ Bool
_ (IfaceData {ifName :: IfaceDecl -> Name
ifName = Name
tc_name,
ifCType :: IfaceDecl -> Maybe CType
ifCType = Maybe CType
cType,
ifBinders :: IfaceDecl -> [IfaceTyConBinder]
ifBinders = [IfaceTyConBinder]
binders,
ifResKind :: IfaceDecl -> IfaceType
ifResKind = IfaceType
res_kind,
ifRoles :: IfaceDecl -> [Role]
ifRoles = [Role]
roles,
ifCtxt :: IfaceDecl -> IfaceContext
ifCtxt = IfaceContext
ctxt, ifGadtSyntax :: IfaceDecl -> Bool
ifGadtSyntax = Bool
gadt_syn,
ifCons :: IfaceDecl -> IfaceConDecls
ifCons = IfaceConDecls
rdr_cons,
ifParent :: IfaceDecl -> IfaceTyConParent
ifParent = IfaceTyConParent
mb_parent })
= [IfaceTyConBinder] -> ([TyConBinder] -> IfL TyThing) -> IfL TyThing
forall a. [IfaceTyConBinder] -> ([TyConBinder] -> IfL a) -> IfL a
bindIfaceTyConBinders_AT [IfaceTyConBinder]
binders (([TyConBinder] -> IfL TyThing) -> IfL TyThing)
-> ([TyConBinder] -> IfL TyThing) -> IfL TyThing
forall a b. (a -> b) -> a -> b
$ \ [TyConBinder]
binders' -> do
{ Type
res_kind' <- IfaceType -> IfL Type
tcIfaceType IfaceType
res_kind
; TyCon
tycon <- (TyCon -> IOEnv (Env IfGblEnv IfLclEnv) TyCon)
-> IOEnv (Env IfGblEnv IfLclEnv) TyCon
forall a env. (a -> IOEnv env a) -> IOEnv env a
fixM ((TyCon -> IOEnv (Env IfGblEnv IfLclEnv) TyCon)
-> IOEnv (Env IfGblEnv IfLclEnv) TyCon)
-> (TyCon -> IOEnv (Env IfGblEnv IfLclEnv) TyCon)
-> IOEnv (Env IfGblEnv IfLclEnv) TyCon
forall a b. (a -> b) -> a -> b
$ \ TyCon
tycon -> do
{ ThetaType
stupid_theta <- IfaceContext -> IfL ThetaType
tcIfaceCtxt IfaceContext
ctxt
; AlgTyConFlav
parent' <- Name -> IfaceTyConParent -> IfL AlgTyConFlav
tc_parent Name
tc_name IfaceTyConParent
mb_parent
; AlgTyConRhs
cons <- Name -> TyCon -> [TyConBinder] -> IfaceConDecls -> IfL AlgTyConRhs
tcIfaceDataCons Name
tc_name TyCon
tycon [TyConBinder]
binders' IfaceConDecls
rdr_cons
; TyCon -> IOEnv (Env IfGblEnv IfLclEnv) TyCon
forall (m :: * -> *) a. Monad m => a -> m a
return (Name
-> [TyConBinder]
-> Type
-> [Role]
-> Maybe CType
-> ThetaType
-> AlgTyConRhs
-> AlgTyConFlav
-> Bool
-> TyCon
mkAlgTyCon Name
tc_name [TyConBinder]
binders' Type
res_kind'
[Role]
roles Maybe CType
cType ThetaType
stupid_theta
AlgTyConRhs
cons AlgTyConFlav
parent' Bool
gadt_syn) }
; SDoc -> TcRnIf IfGblEnv IfLclEnv ()
forall m n. SDoc -> TcRnIf m n ()
traceIf (String -> SDoc
text String
"tcIfaceDecl4" SDoc -> SDoc -> SDoc
<+> TyCon -> SDoc
forall a. Outputable a => a -> SDoc
ppr TyCon
tycon)
; TyThing -> IfL TyThing
forall (m :: * -> *) a. Monad m => a -> m a
return (TyCon -> TyThing
ATyCon TyCon
tycon) }
where
tc_parent :: Name -> IfaceTyConParent -> IfL AlgTyConFlav
tc_parent :: Name -> IfaceTyConParent -> IfL AlgTyConFlav
tc_parent Name
tc_name IfaceTyConParent
IfNoParent
= do { Name
tc_rep_name <- Name -> TcRnIf IfGblEnv IfLclEnv Name
forall gbl lcl. Name -> TcRnIf gbl lcl Name
newTyConRepName Name
tc_name
; AlgTyConFlav -> IfL AlgTyConFlav
forall (m :: * -> *) a. Monad m => a -> m a
return (Name -> AlgTyConFlav
VanillaAlgTyCon Name
tc_rep_name) }
tc_parent Name
_ (IfDataInstance Name
ax_name IfaceTyCon
_ IfaceAppArgs
arg_tys)
= do { CoAxiom Branched
ax <- Name -> IfL (CoAxiom Branched)
tcIfaceCoAxiom Name
ax_name
; let fam_tc :: TyCon
fam_tc = CoAxiom Branched -> TyCon
forall (br :: BranchFlag). CoAxiom br -> TyCon
coAxiomTyCon CoAxiom Branched
ax
ax_unbr :: CoAxiom Unbranched
ax_unbr = CoAxiom Branched -> CoAxiom Unbranched
forall (br :: BranchFlag). CoAxiom br -> CoAxiom Unbranched
toUnbranchedAxiom CoAxiom Branched
ax
; ThetaType
lhs_tys <- IfaceAppArgs -> IfL ThetaType
tcIfaceAppArgs IfaceAppArgs
arg_tys
; AlgTyConFlav -> IfL AlgTyConFlav
forall (m :: * -> *) a. Monad m => a -> m a
return (CoAxiom Unbranched -> TyCon -> ThetaType -> AlgTyConFlav
DataFamInstTyCon CoAxiom Unbranched
ax_unbr TyCon
fam_tc ThetaType
lhs_tys) }
tc_iface_decl Maybe Class
_ Bool
_ (IfaceSynonym {ifName :: IfaceDecl -> Name
ifName = Name
tc_name,
ifRoles :: IfaceDecl -> [Role]
ifRoles = [Role]
roles,
ifSynRhs :: IfaceDecl -> IfaceType
ifSynRhs = IfaceType
rhs_ty,
ifBinders :: IfaceDecl -> [IfaceTyConBinder]
ifBinders = [IfaceTyConBinder]
binders,
ifResKind :: IfaceDecl -> IfaceType
ifResKind = IfaceType
res_kind })
= [IfaceTyConBinder] -> ([TyConBinder] -> IfL TyThing) -> IfL TyThing
forall a. [IfaceTyConBinder] -> ([TyConBinder] -> IfL a) -> IfL a
bindIfaceTyConBinders_AT [IfaceTyConBinder]
binders (([TyConBinder] -> IfL TyThing) -> IfL TyThing)
-> ([TyConBinder] -> IfL TyThing) -> IfL TyThing
forall a b. (a -> b) -> a -> b
$ \ [TyConBinder]
binders' -> do
{ Type
res_kind' <- IfaceType -> IfL Type
tcIfaceType IfaceType
res_kind
; Type
rhs <- SDoc -> IfL Type -> IfL Type
forall a. SDoc -> IfL a -> IfL a
forkM (Name -> SDoc
forall a. Outputable a => a -> SDoc
mk_doc Name
tc_name) (IfL Type -> IfL Type) -> IfL Type -> IfL Type
forall a b. (a -> b) -> a -> b
$
IfaceType -> IfL Type
tcIfaceType IfaceType
rhs_ty
; let tycon :: TyCon
tycon = Name -> [TyConBinder] -> Type -> [Role] -> Type -> TyCon
buildSynTyCon Name
tc_name [TyConBinder]
binders' Type
res_kind' [Role]
roles Type
rhs
; TyThing -> IfL TyThing
forall (m :: * -> *) a. Monad m => a -> m a
return (TyCon -> TyThing
ATyCon TyCon
tycon) }
where
mk_doc :: a -> SDoc
mk_doc a
n = String -> SDoc
text String
"Type synonym" SDoc -> SDoc -> SDoc
<+> a -> SDoc
forall a. Outputable a => a -> SDoc
ppr a
n
tc_iface_decl Maybe Class
parent Bool
_ (IfaceFamily {ifName :: IfaceDecl -> Name
ifName = Name
tc_name,
ifFamFlav :: IfaceDecl -> IfaceFamTyConFlav
ifFamFlav = IfaceFamTyConFlav
fam_flav,
ifBinders :: IfaceDecl -> [IfaceTyConBinder]
ifBinders = [IfaceTyConBinder]
binders,
ifResKind :: IfaceDecl -> IfaceType
ifResKind = IfaceType
res_kind,
ifResVar :: IfaceDecl -> Maybe IfLclName
ifResVar = Maybe IfLclName
res, ifFamInj :: IfaceDecl -> Injectivity
ifFamInj = Injectivity
inj })
= [IfaceTyConBinder] -> ([TyConBinder] -> IfL TyThing) -> IfL TyThing
forall a. [IfaceTyConBinder] -> ([TyConBinder] -> IfL a) -> IfL a
bindIfaceTyConBinders_AT [IfaceTyConBinder]
binders (([TyConBinder] -> IfL TyThing) -> IfL TyThing)
-> ([TyConBinder] -> IfL TyThing) -> IfL TyThing
forall a b. (a -> b) -> a -> b
$ \ [TyConBinder]
binders' -> do
{ Type
res_kind' <- IfaceType -> IfL Type
tcIfaceType IfaceType
res_kind
; FamTyConFlav
rhs <- SDoc -> IfL FamTyConFlav -> IfL FamTyConFlav
forall a. SDoc -> IfL a -> IfL a
forkM (Name -> SDoc
forall a. Outputable a => a -> SDoc
mk_doc Name
tc_name) (IfL FamTyConFlav -> IfL FamTyConFlav)
-> IfL FamTyConFlav -> IfL FamTyConFlav
forall a b. (a -> b) -> a -> b
$
Name -> IfaceFamTyConFlav -> IfL FamTyConFlav
tc_fam_flav Name
tc_name IfaceFamTyConFlav
fam_flav
; Maybe Name
res_name <- (IfLclName -> TcRnIf IfGblEnv IfLclEnv Name)
-> Maybe IfLclName -> IOEnv (Env IfGblEnv IfLclEnv) (Maybe Name)
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse (OccName -> TcRnIf IfGblEnv IfLclEnv Name
newIfaceName (OccName -> TcRnIf IfGblEnv IfLclEnv Name)
-> (IfLclName -> OccName)
-> IfLclName
-> TcRnIf IfGblEnv IfLclEnv Name
forall b c a. (b -> c) -> (a -> b) -> a -> c
. IfLclName -> OccName
mkTyVarOccFS) Maybe IfLclName
res
; let tycon :: TyCon
tycon = Name
-> [TyConBinder]
-> Type
-> Maybe Name
-> FamTyConFlav
-> Maybe Class
-> Injectivity
-> TyCon
mkFamilyTyCon Name
tc_name [TyConBinder]
binders' Type
res_kind' Maybe Name
res_name FamTyConFlav
rhs Maybe Class
parent Injectivity
inj
; TyThing -> IfL TyThing
forall (m :: * -> *) a. Monad m => a -> m a
return (TyCon -> TyThing
ATyCon TyCon
tycon) }
where
mk_doc :: a -> SDoc
mk_doc a
n = String -> SDoc
text String
"Type synonym" SDoc -> SDoc -> SDoc
<+> a -> SDoc
forall a. Outputable a => a -> SDoc
ppr a
n
tc_fam_flav :: Name -> IfaceFamTyConFlav -> IfL FamTyConFlav
tc_fam_flav :: Name -> IfaceFamTyConFlav -> IfL FamTyConFlav
tc_fam_flav Name
tc_name IfaceFamTyConFlav
IfaceDataFamilyTyCon
= do { Name
tc_rep_name <- Name -> TcRnIf IfGblEnv IfLclEnv Name
forall gbl lcl. Name -> TcRnIf gbl lcl Name
newTyConRepName Name
tc_name
; FamTyConFlav -> IfL FamTyConFlav
forall (m :: * -> *) a. Monad m => a -> m a
return (Name -> FamTyConFlav
DataFamilyTyCon Name
tc_rep_name) }
tc_fam_flav Name
_ IfaceFamTyConFlav
IfaceOpenSynFamilyTyCon= FamTyConFlav -> IfL FamTyConFlav
forall (m :: * -> *) a. Monad m => a -> m a
return FamTyConFlav
OpenSynFamilyTyCon
tc_fam_flav Name
_ (IfaceClosedSynFamilyTyCon Maybe (Name, [IfaceAxBranch])
mb_ax_name_branches)
= do { Maybe (CoAxiom Branched)
ax <- ((Name, [IfaceAxBranch]) -> IfL (CoAxiom Branched))
-> Maybe (Name, [IfaceAxBranch])
-> IOEnv (Env IfGblEnv IfLclEnv) (Maybe (CoAxiom Branched))
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse (Name -> IfL (CoAxiom Branched)
tcIfaceCoAxiom (Name -> IfL (CoAxiom Branched))
-> ((Name, [IfaceAxBranch]) -> Name)
-> (Name, [IfaceAxBranch])
-> IfL (CoAxiom Branched)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Name, [IfaceAxBranch]) -> Name
forall a b. (a, b) -> a
fst) Maybe (Name, [IfaceAxBranch])
mb_ax_name_branches
; FamTyConFlav -> IfL FamTyConFlav
forall (m :: * -> *) a. Monad m => a -> m a
return (Maybe (CoAxiom Branched) -> FamTyConFlav
ClosedSynFamilyTyCon Maybe (CoAxiom Branched)
ax) }
tc_fam_flav Name
_ IfaceFamTyConFlav
IfaceAbstractClosedSynFamilyTyCon
= FamTyConFlav -> IfL FamTyConFlav
forall (m :: * -> *) a. Monad m => a -> m a
return FamTyConFlav
AbstractClosedSynFamilyTyCon
tc_fam_flav Name
_ IfaceFamTyConFlav
IfaceBuiltInSynFamTyCon
= String -> SDoc -> IfL FamTyConFlav
forall a. HasCallStack => String -> SDoc -> a
pprPanic String
"tc_iface_decl"
(String -> SDoc
text String
"IfaceBuiltInSynFamTyCon in interface file")
tc_iface_decl Maybe Class
_parent Bool
_ignore_prags
(IfaceClass {ifName :: IfaceDecl -> Name
ifName = Name
tc_name,
ifRoles :: IfaceDecl -> [Role]
ifRoles = [Role]
roles,
ifBinders :: IfaceDecl -> [IfaceTyConBinder]
ifBinders = [IfaceTyConBinder]
binders,
ifFDs :: IfaceDecl -> [FunDep IfLclName]
ifFDs = [FunDep IfLclName]
rdr_fds,
ifBody :: IfaceDecl -> IfaceClassBody
ifBody = IfaceClassBody
IfAbstractClass})
= [IfaceTyConBinder] -> ([TyConBinder] -> IfL TyThing) -> IfL TyThing
forall a. [IfaceTyConBinder] -> ([TyConBinder] -> IfL a) -> IfL a
bindIfaceTyConBinders [IfaceTyConBinder]
binders (([TyConBinder] -> IfL TyThing) -> IfL TyThing)
-> ([TyConBinder] -> IfL TyThing) -> IfL TyThing
forall a b. (a -> b) -> a -> b
$ \ [TyConBinder]
binders' -> do
{ [FunDep Var]
fds <- (FunDep IfLclName -> IOEnv (Env IfGblEnv IfLclEnv) (FunDep Var))
-> [FunDep IfLclName] -> IOEnv (Env IfGblEnv IfLclEnv) [FunDep Var]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM FunDep IfLclName -> IOEnv (Env IfGblEnv IfLclEnv) (FunDep Var)
tc_fd [FunDep IfLclName]
rdr_fds
; Class
cls <- Name
-> [TyConBinder]
-> [Role]
-> [FunDep Var]
-> Maybe
(ThetaType, [ClassATItem], [KnotTied MethInfo], ClassMinimalDef)
-> TcRnIf IfGblEnv IfLclEnv Class
forall m n.
Name
-> [TyConBinder]
-> [Role]
-> [FunDep Var]
-> Maybe
(ThetaType, [ClassATItem], [KnotTied MethInfo], ClassMinimalDef)
-> TcRnIf m n Class
buildClass Name
tc_name [TyConBinder]
binders' [Role]
roles [FunDep Var]
fds Maybe
(ThetaType, [ClassATItem], [KnotTied MethInfo], ClassMinimalDef)
forall a. Maybe a
Nothing
; TyThing -> IfL TyThing
forall (m :: * -> *) a. Monad m => a -> m a
return (TyCon -> TyThing
ATyCon (Class -> TyCon
classTyCon Class
cls)) }
tc_iface_decl Maybe Class
_parent Bool
ignore_prags
(IfaceClass {ifName :: IfaceDecl -> Name
ifName = Name
tc_name,
ifRoles :: IfaceDecl -> [Role]
ifRoles = [Role]
roles,
ifBinders :: IfaceDecl -> [IfaceTyConBinder]
ifBinders = [IfaceTyConBinder]
binders,
ifFDs :: IfaceDecl -> [FunDep IfLclName]
ifFDs = [FunDep IfLclName]
rdr_fds,
ifBody :: IfaceDecl -> IfaceClassBody
ifBody = IfConcreteClass {
ifClassCtxt :: IfaceClassBody -> IfaceContext
ifClassCtxt = IfaceContext
rdr_ctxt,
ifATs :: IfaceClassBody -> [IfaceAT]
ifATs = [IfaceAT]
rdr_ats, ifSigs :: IfaceClassBody -> [IfaceClassOp]
ifSigs = [IfaceClassOp]
rdr_sigs,
ifMinDef :: IfaceClassBody -> BooleanFormula IfLclName
ifMinDef = BooleanFormula IfLclName
mindef_occ
}})
= [IfaceTyConBinder] -> ([TyConBinder] -> IfL TyThing) -> IfL TyThing
forall a. [IfaceTyConBinder] -> ([TyConBinder] -> IfL a) -> IfL a
bindIfaceTyConBinders [IfaceTyConBinder]
binders (([TyConBinder] -> IfL TyThing) -> IfL TyThing)
-> ([TyConBinder] -> IfL TyThing) -> IfL TyThing
forall a b. (a -> b) -> a -> b
$ \ [TyConBinder]
binders' -> do
{ SDoc -> TcRnIf IfGblEnv IfLclEnv ()
forall m n. SDoc -> TcRnIf m n ()
traceIf (String -> SDoc
text String
"tc-iface-class1" SDoc -> SDoc -> SDoc
<+> Name -> SDoc
forall a. Outputable a => a -> SDoc
ppr Name
tc_name)
; ThetaType
ctxt <- (IfaceType -> IfL Type) -> IfaceContext -> IfL ThetaType
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM IfaceType -> IfL Type
tc_sc IfaceContext
rdr_ctxt
; SDoc -> TcRnIf IfGblEnv IfLclEnv ()
forall m n. SDoc -> TcRnIf m n ()
traceIf (String -> SDoc
text String
"tc-iface-class2" SDoc -> SDoc -> SDoc
<+> Name -> SDoc
forall a. Outputable a => a -> SDoc
ppr Name
tc_name)
; [KnotTied MethInfo]
sigs <- (IfaceClassOp -> IOEnv (Env IfGblEnv IfLclEnv) (KnotTied MethInfo))
-> [IfaceClassOp]
-> IOEnv (Env IfGblEnv IfLclEnv) [KnotTied MethInfo]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM IfaceClassOp -> IOEnv (Env IfGblEnv IfLclEnv) (KnotTied MethInfo)
tc_sig [IfaceClassOp]
rdr_sigs
; [FunDep Var]
fds <- (FunDep IfLclName -> IOEnv (Env IfGblEnv IfLclEnv) (FunDep Var))
-> [FunDep IfLclName] -> IOEnv (Env IfGblEnv IfLclEnv) [FunDep Var]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM FunDep IfLclName -> IOEnv (Env IfGblEnv IfLclEnv) (FunDep Var)
tc_fd [FunDep IfLclName]
rdr_fds
; SDoc -> TcRnIf IfGblEnv IfLclEnv ()
forall m n. SDoc -> TcRnIf m n ()
traceIf (String -> SDoc
text String
"tc-iface-class3" SDoc -> SDoc -> SDoc
<+> Name -> SDoc
forall a. Outputable a => a -> SDoc
ppr Name
tc_name)
; ClassMinimalDef
mindef <- (IfLclName -> TcRnIf IfGblEnv IfLclEnv Name)
-> BooleanFormula IfLclName
-> IOEnv (Env IfGblEnv IfLclEnv) ClassMinimalDef
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse (OccName -> TcRnIf IfGblEnv IfLclEnv Name
lookupIfaceTop (OccName -> TcRnIf IfGblEnv IfLclEnv Name)
-> (IfLclName -> OccName)
-> IfLclName
-> TcRnIf IfGblEnv IfLclEnv Name
forall b c a. (b -> c) -> (a -> b) -> a -> c
. IfLclName -> OccName
mkVarOccFS) BooleanFormula IfLclName
mindef_occ
; Class
cls <- (Class -> TcRnIf IfGblEnv IfLclEnv Class)
-> TcRnIf IfGblEnv IfLclEnv Class
forall a env. (a -> IOEnv env a) -> IOEnv env a
fixM ((Class -> TcRnIf IfGblEnv IfLclEnv Class)
-> TcRnIf IfGblEnv IfLclEnv Class)
-> (Class -> TcRnIf IfGblEnv IfLclEnv Class)
-> TcRnIf IfGblEnv IfLclEnv Class
forall a b. (a -> b) -> a -> b
$ \ Class
cls -> do
{ [ClassATItem]
ats <- (IfaceAT -> IOEnv (Env IfGblEnv IfLclEnv) ClassATItem)
-> [IfaceAT] -> IOEnv (Env IfGblEnv IfLclEnv) [ClassATItem]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM (Class -> IfaceAT -> IOEnv (Env IfGblEnv IfLclEnv) ClassATItem
tc_at Class
cls) [IfaceAT]
rdr_ats
; SDoc -> TcRnIf IfGblEnv IfLclEnv ()
forall m n. SDoc -> TcRnIf m n ()
traceIf (String -> SDoc
text String
"tc-iface-class4" SDoc -> SDoc -> SDoc
<+> Name -> SDoc
forall a. Outputable a => a -> SDoc
ppr Name
tc_name)
; Name
-> [TyConBinder]
-> [Role]
-> [FunDep Var]
-> Maybe
(ThetaType, [ClassATItem], [KnotTied MethInfo], ClassMinimalDef)
-> TcRnIf IfGblEnv IfLclEnv Class
forall m n.
Name
-> [TyConBinder]
-> [Role]
-> [FunDep Var]
-> Maybe
(ThetaType, [ClassATItem], [KnotTied MethInfo], ClassMinimalDef)
-> TcRnIf m n Class
buildClass Name
tc_name [TyConBinder]
binders' [Role]
roles [FunDep Var]
fds ((ThetaType, [ClassATItem], [KnotTied MethInfo], ClassMinimalDef)
-> Maybe
(ThetaType, [ClassATItem], [KnotTied MethInfo], ClassMinimalDef)
forall a. a -> Maybe a
Just (ThetaType
ctxt, [ClassATItem]
ats, [KnotTied MethInfo]
sigs, ClassMinimalDef
mindef)) }
; TyThing -> IfL TyThing
forall (m :: * -> *) a. Monad m => a -> m a
return (TyCon -> TyThing
ATyCon (Class -> TyCon
classTyCon Class
cls)) }
where
tc_sc :: IfaceType -> IfL Type
tc_sc IfaceType
pred = SDoc -> IfL Type -> IfL Type
forall a. SDoc -> IfL a -> IfL a
forkM (IfaceType -> SDoc
forall a. Outputable a => a -> SDoc
mk_sc_doc IfaceType
pred) (IfaceType -> IfL Type
tcIfaceType IfaceType
pred)
tc_sig :: IfaceClassOp -> IfL TcMethInfo
tc_sig :: IfaceClassOp -> IOEnv (Env IfGblEnv IfLclEnv) (KnotTied MethInfo)
tc_sig (IfaceClassOp Name
op_name IfaceType
rdr_ty Maybe (DefMethSpec IfaceType)
dm)
= do { let doc :: SDoc
doc = Name -> IfaceType -> SDoc
forall {a} {a}. (Outputable a, Outputable a) => a -> a -> SDoc
mk_op_doc Name
op_name IfaceType
rdr_ty
; Type
op_ty <- SDoc -> IfL Type -> IfL Type
forall a. SDoc -> IfL a -> IfL a
forkM (SDoc
doc SDoc -> SDoc -> SDoc
<+> String -> SDoc
text String
"ty") (IfL Type -> IfL Type) -> IfL Type -> IfL Type
forall a b. (a -> b) -> a -> b
$ IfaceType -> IfL Type
tcIfaceType IfaceType
rdr_ty
; Maybe (DefMethSpec (SrcSpan, Type))
dm' <- SDoc
-> Maybe (DefMethSpec IfaceType)
-> IfL (Maybe (DefMethSpec (SrcSpan, Type)))
tc_dm SDoc
doc Maybe (DefMethSpec IfaceType)
dm
; KnotTied MethInfo
-> IOEnv (Env IfGblEnv IfLclEnv) (KnotTied MethInfo)
forall (m :: * -> *) a. Monad m => a -> m a
return (Name
op_name, Type
op_ty, Maybe (DefMethSpec (SrcSpan, Type))
dm') }
tc_dm :: SDoc
-> Maybe (DefMethSpec IfaceType)
-> IfL (Maybe (DefMethSpec (SrcSpan, Type)))
tc_dm :: SDoc
-> Maybe (DefMethSpec IfaceType)
-> IfL (Maybe (DefMethSpec (SrcSpan, Type)))
tc_dm SDoc
_ Maybe (DefMethSpec IfaceType)
Nothing = Maybe (DefMethSpec (SrcSpan, Type))
-> IfL (Maybe (DefMethSpec (SrcSpan, Type)))
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe (DefMethSpec (SrcSpan, Type))
forall a. Maybe a
Nothing
tc_dm SDoc
_ (Just DefMethSpec IfaceType
VanillaDM) = Maybe (DefMethSpec (SrcSpan, Type))
-> IfL (Maybe (DefMethSpec (SrcSpan, Type)))
forall (m :: * -> *) a. Monad m => a -> m a
return (DefMethSpec (SrcSpan, Type) -> Maybe (DefMethSpec (SrcSpan, Type))
forall a. a -> Maybe a
Just DefMethSpec (SrcSpan, Type)
forall ty. DefMethSpec ty
VanillaDM)
tc_dm SDoc
doc (Just (GenericDM IfaceType
ty))
= do {
; Type
ty' <- SDoc -> IfL Type -> IfL Type
forall a. SDoc -> IfL a -> IfL a
forkM (SDoc
doc SDoc -> SDoc -> SDoc
<+> String -> SDoc
text String
"dm") (IfL Type -> IfL Type) -> IfL Type -> IfL Type
forall a b. (a -> b) -> a -> b
$ IfaceType -> IfL Type
tcIfaceType IfaceType
ty
; Maybe (DefMethSpec (SrcSpan, Type))
-> IfL (Maybe (DefMethSpec (SrcSpan, Type)))
forall (m :: * -> *) a. Monad m => a -> m a
return (DefMethSpec (SrcSpan, Type) -> Maybe (DefMethSpec (SrcSpan, Type))
forall a. a -> Maybe a
Just ((SrcSpan, Type) -> DefMethSpec (SrcSpan, Type)
forall ty. ty -> DefMethSpec ty
GenericDM (SrcSpan
noSrcSpan, Type
ty'))) }
tc_at :: Class -> IfaceAT -> IOEnv (Env IfGblEnv IfLclEnv) ClassATItem
tc_at Class
cls (IfaceAT IfaceDecl
tc_decl Maybe IfaceType
if_def)
= do ATyCon TyCon
tc <- Maybe Class -> Bool -> IfaceDecl -> IfL TyThing
tc_iface_decl (Class -> Maybe Class
forall a. a -> Maybe a
Just Class
cls) Bool
ignore_prags IfaceDecl
tc_decl
Maybe (Type, ATValidityInfo)
mb_def <- case Maybe IfaceType
if_def of
Maybe IfaceType
Nothing -> Maybe (Type, ATValidityInfo)
-> IOEnv (Env IfGblEnv IfLclEnv) (Maybe (Type, ATValidityInfo))
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe (Type, ATValidityInfo)
forall a. Maybe a
Nothing
Just IfaceType
def -> SDoc
-> IOEnv (Env IfGblEnv IfLclEnv) (Maybe (Type, ATValidityInfo))
-> IOEnv (Env IfGblEnv IfLclEnv) (Maybe (Type, ATValidityInfo))
forall a. SDoc -> IfL a -> IfL a
forkM (TyCon -> SDoc
forall a. Outputable a => a -> SDoc
mk_at_doc TyCon
tc) (IOEnv (Env IfGblEnv IfLclEnv) (Maybe (Type, ATValidityInfo))
-> IOEnv (Env IfGblEnv IfLclEnv) (Maybe (Type, ATValidityInfo)))
-> IOEnv (Env IfGblEnv IfLclEnv) (Maybe (Type, ATValidityInfo))
-> IOEnv (Env IfGblEnv IfLclEnv) (Maybe (Type, ATValidityInfo))
forall a b. (a -> b) -> a -> b
$
[Var]
-> IOEnv (Env IfGblEnv IfLclEnv) (Maybe (Type, ATValidityInfo))
-> IOEnv (Env IfGblEnv IfLclEnv) (Maybe (Type, ATValidityInfo))
forall a. [Var] -> IfL a -> IfL a
extendIfaceTyVarEnv (TyCon -> [Var]
tyConTyVars TyCon
tc) (IOEnv (Env IfGblEnv IfLclEnv) (Maybe (Type, ATValidityInfo))
-> IOEnv (Env IfGblEnv IfLclEnv) (Maybe (Type, ATValidityInfo)))
-> IOEnv (Env IfGblEnv IfLclEnv) (Maybe (Type, ATValidityInfo))
-> IOEnv (Env IfGblEnv IfLclEnv) (Maybe (Type, ATValidityInfo))
forall a b. (a -> b) -> a -> b
$
do { Type
tc_def <- IfaceType -> IfL Type
tcIfaceType IfaceType
def
; Maybe (Type, ATValidityInfo)
-> IOEnv (Env IfGblEnv IfLclEnv) (Maybe (Type, ATValidityInfo))
forall (m :: * -> *) a. Monad m => a -> m a
return ((Type, ATValidityInfo) -> Maybe (Type, ATValidityInfo)
forall a. a -> Maybe a
Just (Type
tc_def, ATValidityInfo
NoATVI)) }
ClassATItem -> IOEnv (Env IfGblEnv IfLclEnv) ClassATItem
forall (m :: * -> *) a. Monad m => a -> m a
return (TyCon -> Maybe (Type, ATValidityInfo) -> ClassATItem
ATI TyCon
tc Maybe (Type, ATValidityInfo)
mb_def)
mk_sc_doc :: a -> SDoc
mk_sc_doc a
pred = String -> SDoc
text String
"Superclass" SDoc -> SDoc -> SDoc
<+> a -> SDoc
forall a. Outputable a => a -> SDoc
ppr a
pred
mk_at_doc :: a -> SDoc
mk_at_doc a
tc = String -> SDoc
text String
"Associated type" SDoc -> SDoc -> SDoc
<+> a -> SDoc
forall a. Outputable a => a -> SDoc
ppr a
tc
mk_op_doc :: a -> a -> SDoc
mk_op_doc a
op_name a
op_ty = String -> SDoc
text String
"Class op" SDoc -> SDoc -> SDoc
<+> [SDoc] -> SDoc
sep [a -> SDoc
forall a. Outputable a => a -> SDoc
ppr a
op_name, a -> SDoc
forall a. Outputable a => a -> SDoc
ppr a
op_ty]
tc_iface_decl Maybe Class
_ Bool
_ (IfaceAxiom { ifName :: IfaceDecl -> Name
ifName = Name
tc_name, ifTyCon :: IfaceDecl -> IfaceTyCon
ifTyCon = IfaceTyCon
tc
, ifAxBranches :: IfaceDecl -> [IfaceAxBranch]
ifAxBranches = [IfaceAxBranch]
branches, ifRole :: IfaceDecl -> Role
ifRole = Role
role })
= do { TyCon
tc_tycon <- IfaceTyCon -> IOEnv (Env IfGblEnv IfLclEnv) TyCon
tcIfaceTyCon IfaceTyCon
tc
; [CoAxBranch]
tc_branches <- SDoc -> IfL [CoAxBranch] -> IfL [CoAxBranch]
forall a. SDoc -> IfL a -> IfL a
forkM (String -> SDoc
text String
"Axiom branches" SDoc -> SDoc -> SDoc
<+> Name -> SDoc
forall a. Outputable a => a -> SDoc
ppr Name
tc_name)
(IfL [CoAxBranch] -> IfL [CoAxBranch])
-> IfL [CoAxBranch] -> IfL [CoAxBranch]
forall a b. (a -> b) -> a -> b
$ [IfaceAxBranch] -> IfL [CoAxBranch]
tc_ax_branches [IfaceAxBranch]
branches
; let axiom :: CoAxiom Branched
axiom = CoAxiom :: forall (br :: BranchFlag).
Unique
-> Name -> Role -> TyCon -> Branches br -> Bool -> CoAxiom br
CoAxiom { co_ax_unique :: Unique
co_ax_unique = Name -> Unique
nameUnique Name
tc_name
, co_ax_name :: Name
co_ax_name = Name
tc_name
, co_ax_tc :: TyCon
co_ax_tc = TyCon
tc_tycon
, co_ax_role :: Role
co_ax_role = Role
role
, co_ax_branches :: Branches Branched
co_ax_branches = [CoAxBranch] -> Branches Branched
manyBranches [CoAxBranch]
tc_branches
, co_ax_implicit :: Bool
co_ax_implicit = Bool
False }
; TyThing -> IfL TyThing
forall (m :: * -> *) a. Monad m => a -> m a
return (CoAxiom Branched -> TyThing
ACoAxiom CoAxiom Branched
axiom) }
tc_iface_decl Maybe Class
_ Bool
_ (IfacePatSyn{ ifName :: IfaceDecl -> Name
ifName = Name
name
, ifPatMatcher :: IfaceDecl -> (Name, Bool)
ifPatMatcher = (Name, Bool)
if_matcher
, ifPatBuilder :: IfaceDecl -> Maybe (Name, Bool)
ifPatBuilder = Maybe (Name, Bool)
if_builder
, ifPatIsInfix :: IfaceDecl -> Bool
ifPatIsInfix = Bool
is_infix
, ifPatUnivBndrs :: IfaceDecl -> [IfaceForAllSpecBndr]
ifPatUnivBndrs = [IfaceForAllSpecBndr]
univ_bndrs
, ifPatExBndrs :: IfaceDecl -> [IfaceForAllSpecBndr]
ifPatExBndrs = [IfaceForAllSpecBndr]
ex_bndrs
, ifPatProvCtxt :: IfaceDecl -> IfaceContext
ifPatProvCtxt = IfaceContext
prov_ctxt
, ifPatReqCtxt :: IfaceDecl -> IfaceContext
ifPatReqCtxt = IfaceContext
req_ctxt
, ifPatArgs :: IfaceDecl -> IfaceContext
ifPatArgs = IfaceContext
args
, ifPatTy :: IfaceDecl -> IfaceType
ifPatTy = IfaceType
pat_ty
, ifFieldLabels :: IfaceDecl -> [FieldLabel]
ifFieldLabels = [FieldLabel]
field_labels })
= do { SDoc -> TcRnIf IfGblEnv IfLclEnv ()
forall m n. SDoc -> TcRnIf m n ()
traceIf (String -> SDoc
text String
"tc_iface_decl" SDoc -> SDoc -> SDoc
<+> Name -> SDoc
forall a. Outputable a => a -> SDoc
ppr Name
name)
; (Var, Bool)
matcher <- (Name, Bool) -> IfL (Var, Bool)
tc_pr (Name, Bool)
if_matcher
; Maybe (Var, Bool)
builder <- ((Name, Bool) -> IfL (Var, Bool))
-> Maybe (Name, Bool)
-> IOEnv (Env IfGblEnv IfLclEnv) (Maybe (Var, Bool))
forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> Maybe a -> m (Maybe b)
fmapMaybeM (Name, Bool) -> IfL (Var, Bool)
tc_pr Maybe (Name, Bool)
if_builder
; [IfaceForAllSpecBndr]
-> ([VarBndr Var Specificity] -> IfL TyThing) -> IfL TyThing
forall vis a.
[VarBndr IfaceBndr vis] -> ([VarBndr Var vis] -> IfL a) -> IfL a
bindIfaceForAllBndrs [IfaceForAllSpecBndr]
univ_bndrs (([VarBndr Var Specificity] -> IfL TyThing) -> IfL TyThing)
-> ([VarBndr Var Specificity] -> IfL TyThing) -> IfL TyThing
forall a b. (a -> b) -> a -> b
$ \[VarBndr Var Specificity]
univ_tvs -> do
{ [IfaceForAllSpecBndr]
-> ([VarBndr Var Specificity] -> IfL TyThing) -> IfL TyThing
forall vis a.
[VarBndr IfaceBndr vis] -> ([VarBndr Var vis] -> IfL a) -> IfL a
bindIfaceForAllBndrs [IfaceForAllSpecBndr]
ex_bndrs (([VarBndr Var Specificity] -> IfL TyThing) -> IfL TyThing)
-> ([VarBndr Var Specificity] -> IfL TyThing) -> IfL TyThing
forall a b. (a -> b) -> a -> b
$ \[VarBndr Var Specificity]
ex_tvs -> do
{ PatSyn
patsyn <- SDoc -> IfL PatSyn -> IfL PatSyn
forall a. SDoc -> IfL a -> IfL a
forkM (Name -> SDoc
forall a. Outputable a => a -> SDoc
mk_doc Name
name) (IfL PatSyn -> IfL PatSyn) -> IfL PatSyn -> IfL PatSyn
forall a b. (a -> b) -> a -> b
$
do { ThetaType
prov_theta <- IfaceContext -> IfL ThetaType
tcIfaceCtxt IfaceContext
prov_ctxt
; ThetaType
req_theta <- IfaceContext -> IfL ThetaType
tcIfaceCtxt IfaceContext
req_ctxt
; Type
pat_ty <- IfaceType -> IfL Type
tcIfaceType IfaceType
pat_ty
; ThetaType
arg_tys <- (IfaceType -> IfL Type) -> IfaceContext -> IfL ThetaType
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM IfaceType -> IfL Type
tcIfaceType IfaceContext
args
; PatSyn -> IfL PatSyn
forall (m :: * -> *) a. Monad m => a -> m a
return (PatSyn -> IfL PatSyn) -> PatSyn -> IfL PatSyn
forall a b. (a -> b) -> a -> b
$ Name
-> Bool
-> (Var, Bool)
-> Maybe (Var, Bool)
-> ([VarBndr Var Specificity], ThetaType)
-> ([VarBndr Var Specificity], ThetaType)
-> ThetaType
-> Type
-> [FieldLabel]
-> PatSyn
buildPatSyn Name
name Bool
is_infix (Var, Bool)
matcher Maybe (Var, Bool)
builder
([VarBndr Var Specificity]
univ_tvs, ThetaType
req_theta)
([VarBndr Var Specificity]
ex_tvs, ThetaType
prov_theta)
ThetaType
arg_tys Type
pat_ty [FieldLabel]
field_labels }
; TyThing -> IfL TyThing
forall (m :: * -> *) a. Monad m => a -> m a
return (TyThing -> IfL TyThing) -> TyThing -> IfL TyThing
forall a b. (a -> b) -> a -> b
$ ConLike -> TyThing
AConLike (ConLike -> TyThing) -> (PatSyn -> ConLike) -> PatSyn -> TyThing
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PatSyn -> ConLike
PatSynCon (PatSyn -> TyThing) -> PatSyn -> TyThing
forall a b. (a -> b) -> a -> b
$ PatSyn
patsyn }}}
where
mk_doc :: a -> SDoc
mk_doc a
n = String -> SDoc
text String
"Pattern synonym" SDoc -> SDoc -> SDoc
<+> a -> SDoc
forall a. Outputable a => a -> SDoc
ppr a
n
tc_pr :: (IfExtName, Bool) -> IfL (Id, Bool)
tc_pr :: (Name, Bool) -> IfL (Var, Bool)
tc_pr (Name
nm, Bool
b) = do { Var
id <- SDoc -> IfL Var -> IfL Var
forall a. SDoc -> IfL a -> IfL a
forkM (Name -> SDoc
forall a. Outputable a => a -> SDoc
ppr Name
nm) (Name -> IfL Var
tcIfaceExtId Name
nm)
; (Var, Bool) -> IfL (Var, Bool)
forall (m :: * -> *) a. Monad m => a -> m a
return (Var
id, Bool
b) }
tc_fd :: FunDep IfLclName -> IfL (FunDep TyVar)
tc_fd :: FunDep IfLclName -> IOEnv (Env IfGblEnv IfLclEnv) (FunDep Var)
tc_fd ([IfLclName]
tvs1, [IfLclName]
tvs2) = do { [Var]
tvs1' <- (IfLclName -> IfL Var)
-> [IfLclName] -> IOEnv (Env IfGblEnv IfLclEnv) [Var]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM IfLclName -> IfL Var
tcIfaceTyVar [IfLclName]
tvs1
; [Var]
tvs2' <- (IfLclName -> IfL Var)
-> [IfLclName] -> IOEnv (Env IfGblEnv IfLclEnv) [Var]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM IfLclName -> IfL Var
tcIfaceTyVar [IfLclName]
tvs2
; FunDep Var -> IOEnv (Env IfGblEnv IfLclEnv) (FunDep Var)
forall (m :: * -> *) a. Monad m => a -> m a
return ([Var]
tvs1', [Var]
tvs2') }
tc_ax_branches :: [IfaceAxBranch] -> IfL [CoAxBranch]
tc_ax_branches :: [IfaceAxBranch] -> IfL [CoAxBranch]
tc_ax_branches [IfaceAxBranch]
if_branches = ([CoAxBranch] -> IfaceAxBranch -> IfL [CoAxBranch])
-> [CoAxBranch] -> [IfaceAxBranch] -> IfL [CoAxBranch]
forall (t :: * -> *) (m :: * -> *) b a.
(Foldable t, Monad m) =>
(b -> a -> m b) -> b -> t a -> m b
foldlM [CoAxBranch] -> IfaceAxBranch -> IfL [CoAxBranch]
tc_ax_branch [] [IfaceAxBranch]
if_branches
tc_ax_branch :: [CoAxBranch] -> IfaceAxBranch -> IfL [CoAxBranch]
tc_ax_branch :: [CoAxBranch] -> IfaceAxBranch -> IfL [CoAxBranch]
tc_ax_branch [CoAxBranch]
prev_branches
(IfaceAxBranch { ifaxbTyVars :: IfaceAxBranch -> [IfaceTvBndr]
ifaxbTyVars = [IfaceTvBndr]
tv_bndrs
, ifaxbEtaTyVars :: IfaceAxBranch -> [IfaceTvBndr]
ifaxbEtaTyVars = [IfaceTvBndr]
eta_tv_bndrs
, ifaxbCoVars :: IfaceAxBranch -> [IfaceIdBndr]
ifaxbCoVars = [IfaceIdBndr]
cv_bndrs
, ifaxbLHS :: IfaceAxBranch -> IfaceAppArgs
ifaxbLHS = IfaceAppArgs
lhs, ifaxbRHS :: IfaceAxBranch -> IfaceType
ifaxbRHS = IfaceType
rhs
, ifaxbRoles :: IfaceAxBranch -> [Role]
ifaxbRoles = [Role]
roles, ifaxbIncomps :: IfaceAxBranch -> [Int]
ifaxbIncomps = [Int]
incomps })
= [IfaceTyConBinder]
-> ([TyConBinder] -> IfL [CoAxBranch]) -> IfL [CoAxBranch]
forall a. [IfaceTyConBinder] -> ([TyConBinder] -> IfL a) -> IfL a
bindIfaceTyConBinders_AT
((IfaceTvBndr -> IfaceTyConBinder)
-> [IfaceTvBndr] -> [IfaceTyConBinder]
forall a b. (a -> b) -> [a] -> [b]
map (\IfaceTvBndr
b -> IfaceBndr -> TyConBndrVis -> IfaceTyConBinder
forall var argf. var -> argf -> VarBndr var argf
Bndr (IfaceTvBndr -> IfaceBndr
IfaceTvBndr IfaceTvBndr
b) (ArgFlag -> TyConBndrVis
NamedTCB ArgFlag
Inferred)) [IfaceTvBndr]
tv_bndrs) (([TyConBinder] -> IfL [CoAxBranch]) -> IfL [CoAxBranch])
-> ([TyConBinder] -> IfL [CoAxBranch]) -> IfL [CoAxBranch]
forall a b. (a -> b) -> a -> b
$ \ [TyConBinder]
tvs ->
[IfaceIdBndr] -> ([Var] -> IfL [CoAxBranch]) -> IfL [CoAxBranch]
forall a. [IfaceIdBndr] -> ([Var] -> IfL a) -> IfL a
bindIfaceIds [IfaceIdBndr]
cv_bndrs (([Var] -> IfL [CoAxBranch]) -> IfL [CoAxBranch])
-> ([Var] -> IfL [CoAxBranch]) -> IfL [CoAxBranch]
forall a b. (a -> b) -> a -> b
$ \ [Var]
cvs -> do
{ ThetaType
tc_lhs <- IfaceAppArgs -> IfL ThetaType
tcIfaceAppArgs IfaceAppArgs
lhs
; Type
tc_rhs <- IfaceType -> IfL Type
tcIfaceType IfaceType
rhs
; [Var]
eta_tvs <- [IfaceTvBndr]
-> ([Var] -> IOEnv (Env IfGblEnv IfLclEnv) [Var])
-> IOEnv (Env IfGblEnv IfLclEnv) [Var]
forall a. [IfaceTvBndr] -> ([Var] -> IfL a) -> IfL a
bindIfaceTyVars [IfaceTvBndr]
eta_tv_bndrs [Var] -> IOEnv (Env IfGblEnv IfLclEnv) [Var]
forall (m :: * -> *) a. Monad m => a -> m a
return
; Module
this_mod <- IfL Module
getIfModule
; let loc :: SrcSpan
loc = IfLclName -> SrcSpan
mkGeneralSrcSpan (String -> IfLclName
fsLit String
"module " IfLclName -> IfLclName -> IfLclName
`appendFS`
ModuleName -> IfLclName
moduleNameFS (Module -> ModuleName
forall unit. GenModule unit -> ModuleName
moduleName Module
this_mod))
br :: CoAxBranch
br = CoAxBranch :: SrcSpan
-> [Var]
-> [Var]
-> [Var]
-> [Role]
-> ThetaType
-> Type
-> [CoAxBranch]
-> CoAxBranch
CoAxBranch { cab_loc :: SrcSpan
cab_loc = SrcSpan
loc
, cab_tvs :: [Var]
cab_tvs = [TyConBinder] -> [Var]
forall tv argf. [VarBndr tv argf] -> [tv]
binderVars [TyConBinder]
tvs
, cab_eta_tvs :: [Var]
cab_eta_tvs = [Var]
eta_tvs
, cab_cvs :: [Var]
cab_cvs = [Var]
cvs
, cab_lhs :: ThetaType
cab_lhs = ThetaType
tc_lhs
, cab_roles :: [Role]
cab_roles = [Role]
roles
, cab_rhs :: Type
cab_rhs = Type
tc_rhs
, cab_incomps :: [CoAxBranch]
cab_incomps = (Int -> CoAxBranch) -> [Int] -> [CoAxBranch]
forall a b. (a -> b) -> [a] -> [b]
map ([CoAxBranch]
prev_branches [CoAxBranch] -> Int -> CoAxBranch
forall a. Outputable a => [a] -> Int -> a
`getNth`) [Int]
incomps }
; [CoAxBranch] -> IfL [CoAxBranch]
forall (m :: * -> *) a. Monad m => a -> m a
return ([CoAxBranch]
prev_branches [CoAxBranch] -> [CoAxBranch] -> [CoAxBranch]
forall a. [a] -> [a] -> [a]
++ [CoAxBranch
br]) }
tcIfaceDataCons :: Name -> TyCon -> [TyConBinder] -> IfaceConDecls -> IfL AlgTyConRhs
tcIfaceDataCons :: Name -> TyCon -> [TyConBinder] -> IfaceConDecls -> IfL AlgTyConRhs
tcIfaceDataCons Name
tycon_name TyCon
tycon [TyConBinder]
tc_tybinders IfaceConDecls
if_cons
= case IfaceConDecls
if_cons of
IfaceConDecls
IfAbstractTyCon -> AlgTyConRhs -> IfL AlgTyConRhs
forall (m :: * -> *) a. Monad m => a -> m a
return AlgTyConRhs
AbstractTyCon
IfDataTyCon [IfaceConDecl]
cons -> do { [DataCon]
data_cons <- (IfaceConDecl -> IOEnv (Env IfGblEnv IfLclEnv) DataCon)
-> [IfaceConDecl] -> IOEnv (Env IfGblEnv IfLclEnv) [DataCon]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM IfaceConDecl -> IOEnv (Env IfGblEnv IfLclEnv) DataCon
tc_con_decl [IfaceConDecl]
cons
; AlgTyConRhs -> IfL AlgTyConRhs
forall (m :: * -> *) a. Monad m => a -> m a
return ([DataCon] -> AlgTyConRhs
mkDataTyConRhs [DataCon]
data_cons) }
IfNewTyCon IfaceConDecl
con -> do { DataCon
data_con <- IfaceConDecl -> IOEnv (Env IfGblEnv IfLclEnv) DataCon
tc_con_decl IfaceConDecl
con
; Name -> TyCon -> DataCon -> IfL AlgTyConRhs
forall m n. Name -> TyCon -> DataCon -> TcRnIf m n AlgTyConRhs
mkNewTyConRhs Name
tycon_name TyCon
tycon DataCon
data_con }
where
univ_tvs :: [TyVar]
univ_tvs :: [Var]
univ_tvs = [TyConBinder] -> [Var]
forall tv argf. [VarBndr tv argf] -> [tv]
binderVars [TyConBinder]
tc_tybinders
tag_map :: NameEnv ConTag
tag_map :: NameEnv Int
tag_map = TyCon -> NameEnv Int
mkTyConTagMap TyCon
tycon
tc_con_decl :: IfaceConDecl -> IOEnv (Env IfGblEnv IfLclEnv) DataCon
tc_con_decl (IfCon { ifConInfix :: IfaceConDecl -> Bool
ifConInfix = Bool
is_infix,
ifConExTCvs :: IfaceConDecl -> [IfaceBndr]
ifConExTCvs = [IfaceBndr]
ex_bndrs,
ifConUserTvBinders :: IfaceConDecl -> [IfaceForAllSpecBndr]
ifConUserTvBinders = [IfaceForAllSpecBndr]
user_bndrs,
ifConName :: IfaceConDecl -> Name
ifConName = Name
dc_name,
ifConCtxt :: IfaceConDecl -> IfaceContext
ifConCtxt = IfaceContext
ctxt, ifConEqSpec :: IfaceConDecl -> [IfaceTvBndr]
ifConEqSpec = [IfaceTvBndr]
spec,
ifConArgTys :: IfaceConDecl -> [(IfaceType, IfaceType)]
ifConArgTys = [(IfaceType, IfaceType)]
args, ifConFields :: IfaceConDecl -> [FieldLabel]
ifConFields = [FieldLabel]
lbl_names,
ifConStricts :: IfaceConDecl -> [IfaceBang]
ifConStricts = [IfaceBang]
if_stricts,
ifConSrcStricts :: IfaceConDecl -> [IfaceSrcBang]
ifConSrcStricts = [IfaceSrcBang]
if_src_stricts})
=
[IfaceBndr]
-> ([Var] -> IOEnv (Env IfGblEnv IfLclEnv) DataCon)
-> IOEnv (Env IfGblEnv IfLclEnv) DataCon
forall a. [IfaceBndr] -> ([Var] -> IfL a) -> IfL a
bindIfaceBndrs [IfaceBndr]
ex_bndrs (([Var] -> IOEnv (Env IfGblEnv IfLclEnv) DataCon)
-> IOEnv (Env IfGblEnv IfLclEnv) DataCon)
-> ([Var] -> IOEnv (Env IfGblEnv IfLclEnv) DataCon)
-> IOEnv (Env IfGblEnv IfLclEnv) DataCon
forall a b. (a -> b) -> a -> b
$ \ [Var]
ex_tvs -> do
{ SDoc -> TcRnIf IfGblEnv IfLclEnv ()
forall m n. SDoc -> TcRnIf m n ()
traceIf (String -> SDoc
text String
"Start interface-file tc_con_decl" SDoc -> SDoc -> SDoc
<+> Name -> SDoc
forall a. Outputable a => a -> SDoc
ppr Name
dc_name)
; [VarBndr Var Specificity]
user_tv_bndrs <- (IfaceForAllSpecBndr
-> IOEnv (Env IfGblEnv IfLclEnv) (VarBndr Var Specificity))
-> [IfaceForAllSpecBndr]
-> IOEnv (Env IfGblEnv IfLclEnv) [VarBndr Var Specificity]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM (\(Bndr IfaceBndr
bd Specificity
vis) ->
case IfaceBndr
bd of
IfaceIdBndr (IfaceType
_, IfLclName
name, IfaceType
_) ->
Var -> Specificity -> VarBndr Var Specificity
forall var argf. var -> argf -> VarBndr var argf
Bndr (Var -> Specificity -> VarBndr Var Specificity)
-> IfL Var
-> IOEnv
(Env IfGblEnv IfLclEnv) (Specificity -> VarBndr Var Specificity)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> IfLclName -> IfL Var
tcIfaceLclId IfLclName
name IOEnv
(Env IfGblEnv IfLclEnv) (Specificity -> VarBndr Var Specificity)
-> IOEnv (Env IfGblEnv IfLclEnv) Specificity
-> IOEnv (Env IfGblEnv IfLclEnv) (VarBndr Var Specificity)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Specificity -> IOEnv (Env IfGblEnv IfLclEnv) Specificity
forall (f :: * -> *) a. Applicative f => a -> f a
pure Specificity
vis
IfaceTvBndr (IfLclName
name, IfaceType
_) ->
Var -> Specificity -> VarBndr Var Specificity
forall var argf. var -> argf -> VarBndr var argf
Bndr (Var -> Specificity -> VarBndr Var Specificity)
-> IfL Var
-> IOEnv
(Env IfGblEnv IfLclEnv) (Specificity -> VarBndr Var Specificity)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> IfLclName -> IfL Var
tcIfaceTyVar IfLclName
name IOEnv
(Env IfGblEnv IfLclEnv) (Specificity -> VarBndr Var Specificity)
-> IOEnv (Env IfGblEnv IfLclEnv) Specificity
-> IOEnv (Env IfGblEnv IfLclEnv) (VarBndr Var Specificity)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Specificity -> IOEnv (Env IfGblEnv IfLclEnv) Specificity
forall (f :: * -> *) a. Applicative f => a -> f a
pure Specificity
vis)
[IfaceForAllSpecBndr]
user_bndrs
; ~([EqSpec]
eq_spec, ThetaType
theta, [Scaled Type]
arg_tys, [HsImplBang]
stricts) <- SDoc
-> IfL ([EqSpec], ThetaType, [Scaled Type], [HsImplBang])
-> IfL ([EqSpec], ThetaType, [Scaled Type], [HsImplBang])
forall a. SDoc -> IfL a -> IfL a
forkM (Name -> SDoc
forall a. Outputable a => a -> SDoc
mk_doc Name
dc_name) (IfL ([EqSpec], ThetaType, [Scaled Type], [HsImplBang])
-> IfL ([EqSpec], ThetaType, [Scaled Type], [HsImplBang]))
-> IfL ([EqSpec], ThetaType, [Scaled Type], [HsImplBang])
-> IfL ([EqSpec], ThetaType, [Scaled Type], [HsImplBang])
forall a b. (a -> b) -> a -> b
$
do { [EqSpec]
eq_spec <- [IfaceTvBndr] -> IfL [EqSpec]
tcIfaceEqSpec [IfaceTvBndr]
spec
; ThetaType
theta <- IfaceContext -> IfL ThetaType
tcIfaceCtxt IfaceContext
ctxt
; [Scaled Type]
arg_tys <- SDoc -> IfL [Scaled Type] -> IfL [Scaled Type]
forall a. SDoc -> IfL a -> IfL a
forkM (Name -> SDoc
forall a. Outputable a => a -> SDoc
mk_doc Name
dc_name SDoc -> SDoc -> SDoc
<+> String -> SDoc
text String
"arg_tys")
(IfL [Scaled Type] -> IfL [Scaled Type])
-> IfL [Scaled Type] -> IfL [Scaled Type]
forall a b. (a -> b) -> a -> b
$ ((IfaceType, IfaceType)
-> IOEnv (Env IfGblEnv IfLclEnv) (Scaled Type))
-> [(IfaceType, IfaceType)] -> IfL [Scaled Type]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM (\(IfaceType
w, IfaceType
ty) -> Type -> Type -> Scaled Type
forall a. Type -> a -> Scaled a
mkScaled (Type -> Type -> Scaled Type)
-> IfL Type -> IOEnv (Env IfGblEnv IfLclEnv) (Type -> Scaled Type)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> IfaceType -> IfL Type
tcIfaceType IfaceType
w IOEnv (Env IfGblEnv IfLclEnv) (Type -> Scaled Type)
-> IfL Type -> IOEnv (Env IfGblEnv IfLclEnv) (Scaled Type)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> IfaceType -> IfL Type
tcIfaceType IfaceType
ty) [(IfaceType, IfaceType)]
args
; [HsImplBang]
stricts <- (IfaceBang -> IOEnv (Env IfGblEnv IfLclEnv) HsImplBang)
-> [IfaceBang] -> IOEnv (Env IfGblEnv IfLclEnv) [HsImplBang]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM IfaceBang -> IOEnv (Env IfGblEnv IfLclEnv) HsImplBang
tc_strict [IfaceBang]
if_stricts
; ([EqSpec], ThetaType, [Scaled Type], [HsImplBang])
-> IfL ([EqSpec], ThetaType, [Scaled Type], [HsImplBang])
forall (m :: * -> *) a. Monad m => a -> m a
return ([EqSpec]
eq_spec, ThetaType
theta, [Scaled Type]
arg_tys, [HsImplBang]
stricts) }
; let orig_res_ty :: Type
orig_res_ty = TyCon -> ThetaType -> Type
mkFamilyTyConApp TyCon
tycon
(TCvSubst -> [Var] -> ThetaType
substTyCoVars ([(Var, Type)] -> TCvSubst
mkTvSubstPrs ((EqSpec -> (Var, Type)) -> [EqSpec] -> [(Var, Type)]
forall a b. (a -> b) -> [a] -> [b]
map EqSpec -> (Var, Type)
eqSpecPair [EqSpec]
eq_spec))
([TyConBinder] -> [Var]
forall tv argf. [VarBndr tv argf] -> [tv]
binderVars [TyConBinder]
tc_tybinders))
; Name
prom_rep_name <- Name -> TcRnIf IfGblEnv IfLclEnv Name
forall gbl lcl. Name -> TcRnIf gbl lcl Name
newTyConRepName Name
dc_name
; DataCon
con <- FamInstEnvs
-> Name
-> Bool
-> Name
-> [HsSrcBang]
-> Maybe [HsImplBang]
-> [FieldLabel]
-> [Var]
-> [Var]
-> [VarBndr Var Specificity]
-> [EqSpec]
-> ThetaType
-> [Scaled Type]
-> Type
-> TyCon
-> NameEnv Int
-> IOEnv (Env IfGblEnv IfLclEnv) DataCon
forall m n.
FamInstEnvs
-> Name
-> Bool
-> Name
-> [HsSrcBang]
-> Maybe [HsImplBang]
-> [FieldLabel]
-> [Var]
-> [Var]
-> [VarBndr Var Specificity]
-> [EqSpec]
-> ThetaType
-> [Scaled Type]
-> Type
-> TyCon
-> NameEnv Int
-> TcRnIf m n DataCon
buildDataCon (String -> SDoc -> FamInstEnvs
forall a. HasCallStack => String -> SDoc -> a
pprPanic String
"tcIfaceDataCons: FamInstEnvs" (Name -> SDoc
forall a. Outputable a => a -> SDoc
ppr Name
dc_name))
Name
dc_name Bool
is_infix Name
prom_rep_name
((IfaceSrcBang -> HsSrcBang) -> [IfaceSrcBang] -> [HsSrcBang]
forall a b. (a -> b) -> [a] -> [b]
map IfaceSrcBang -> HsSrcBang
src_strict [IfaceSrcBang]
if_src_stricts)
([HsImplBang] -> Maybe [HsImplBang]
forall a. a -> Maybe a
Just [HsImplBang]
stricts)
[FieldLabel]
lbl_names
[Var]
univ_tvs [Var]
ex_tvs [VarBndr Var Specificity]
user_tv_bndrs
[EqSpec]
eq_spec ThetaType
theta
[Scaled Type]
arg_tys Type
orig_res_ty TyCon
tycon NameEnv Int
tag_map
; SDoc -> TcRnIf IfGblEnv IfLclEnv ()
forall m n. SDoc -> TcRnIf m n ()
traceIf (String -> SDoc
text String
"Done interface-file tc_con_decl" SDoc -> SDoc -> SDoc
<+> Name -> SDoc
forall a. Outputable a => a -> SDoc
ppr Name
dc_name)
; DataCon -> IOEnv (Env IfGblEnv IfLclEnv) DataCon
forall (m :: * -> *) a. Monad m => a -> m a
return DataCon
con }
mk_doc :: a -> SDoc
mk_doc a
con_name = String -> SDoc
text String
"Constructor" SDoc -> SDoc -> SDoc
<+> a -> SDoc
forall a. Outputable a => a -> SDoc
ppr a
con_name
tc_strict :: IfaceBang -> IfL HsImplBang
tc_strict :: IfaceBang -> IOEnv (Env IfGblEnv IfLclEnv) HsImplBang
tc_strict IfaceBang
IfNoBang = HsImplBang -> IOEnv (Env IfGblEnv IfLclEnv) HsImplBang
forall (m :: * -> *) a. Monad m => a -> m a
return (HsImplBang
HsLazy)
tc_strict IfaceBang
IfStrict = HsImplBang -> IOEnv (Env IfGblEnv IfLclEnv) HsImplBang
forall (m :: * -> *) a. Monad m => a -> m a
return (HsImplBang
HsStrict)
tc_strict IfaceBang
IfUnpack = HsImplBang -> IOEnv (Env IfGblEnv IfLclEnv) HsImplBang
forall (m :: * -> *) a. Monad m => a -> m a
return (Maybe Coercion -> HsImplBang
HsUnpack Maybe Coercion
forall a. Maybe a
Nothing)
tc_strict (IfUnpackCo IfaceCoercion
if_co) = do { Coercion
co <- IfaceCoercion -> IfL Coercion
tcIfaceCo IfaceCoercion
if_co
; HsImplBang -> IOEnv (Env IfGblEnv IfLclEnv) HsImplBang
forall (m :: * -> *) a. Monad m => a -> m a
return (Maybe Coercion -> HsImplBang
HsUnpack (Coercion -> Maybe Coercion
forall a. a -> Maybe a
Just Coercion
co)) }
src_strict :: IfaceSrcBang -> HsSrcBang
src_strict :: IfaceSrcBang -> HsSrcBang
src_strict (IfSrcBang SrcUnpackedness
unpk SrcStrictness
bang) = SourceText -> SrcUnpackedness -> SrcStrictness -> HsSrcBang
HsSrcBang SourceText
NoSourceText SrcUnpackedness
unpk SrcStrictness
bang
tcIfaceEqSpec :: IfaceEqSpec -> IfL [EqSpec]
tcIfaceEqSpec :: [IfaceTvBndr] -> IfL [EqSpec]
tcIfaceEqSpec [IfaceTvBndr]
spec
= (IfaceTvBndr -> IOEnv (Env IfGblEnv IfLclEnv) EqSpec)
-> [IfaceTvBndr] -> IfL [EqSpec]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM IfaceTvBndr -> IOEnv (Env IfGblEnv IfLclEnv) EqSpec
do_item [IfaceTvBndr]
spec
where
do_item :: IfaceTvBndr -> IOEnv (Env IfGblEnv IfLclEnv) EqSpec
do_item (IfLclName
occ, IfaceType
if_ty) = do { Var
tv <- IfLclName -> IfL Var
tcIfaceTyVar IfLclName
occ
; Type
ty <- IfaceType -> IfL Type
tcIfaceType IfaceType
if_ty
; EqSpec -> IOEnv (Env IfGblEnv IfLclEnv) EqSpec
forall (m :: * -> *) a. Monad m => a -> m a
return (Var -> Type -> EqSpec
mkEqSpec Var
tv Type
ty) }
tcIfaceInst :: IfaceClsInst -> IfL ClsInst
tcIfaceInst :: IfaceClsInst -> IOEnv (Env IfGblEnv IfLclEnv) ClsInst
tcIfaceInst (IfaceClsInst { ifDFun :: IfaceClsInst -> Name
ifDFun = Name
dfun_name, ifOFlag :: IfaceClsInst -> OverlapFlag
ifOFlag = OverlapFlag
oflag
, ifInstCls :: IfaceClsInst -> Name
ifInstCls = Name
cls, ifInstTys :: IfaceClsInst -> [Maybe IfaceTyCon]
ifInstTys = [Maybe IfaceTyCon]
mb_tcs
, ifInstOrph :: IfaceClsInst -> IsOrphan
ifInstOrph = IsOrphan
orph })
= do { Var
dfun <- SDoc -> IfL Var -> IfL Var
forall a. SDoc -> IfL a -> IfL a
forkM (String -> SDoc
text String
"Dict fun" SDoc -> SDoc -> SDoc
<+> Name -> SDoc
forall a. Outputable a => a -> SDoc
ppr Name
dfun_name) (IfL Var -> IfL Var) -> IfL Var -> IfL Var
forall a b. (a -> b) -> a -> b
$
(TyThing -> Var) -> IfL TyThing -> IfL Var
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap HasDebugCallStack => TyThing -> Var
TyThing -> Var
tyThingId (Name -> IfL TyThing
tcIfaceImplicit Name
dfun_name)
; let mb_tcs' :: [Maybe Name]
mb_tcs' = (Maybe IfaceTyCon -> Maybe Name)
-> [Maybe IfaceTyCon] -> [Maybe Name]
forall a b. (a -> b) -> [a] -> [b]
map ((IfaceTyCon -> Name) -> Maybe IfaceTyCon -> Maybe Name
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap IfaceTyCon -> Name
ifaceTyConName) [Maybe IfaceTyCon]
mb_tcs
; ClsInst -> IOEnv (Env IfGblEnv IfLclEnv) ClsInst
forall (m :: * -> *) a. Monad m => a -> m a
return (Name
-> [Maybe Name]
-> Name
-> Var
-> OverlapFlag
-> IsOrphan
-> ClsInst
mkImportedInstance Name
cls [Maybe Name]
mb_tcs' Name
dfun_name Var
dfun OverlapFlag
oflag IsOrphan
orph) }
tcIfaceFamInst :: IfaceFamInst -> IfL FamInst
tcIfaceFamInst :: IfaceFamInst -> IOEnv (Env IfGblEnv IfLclEnv) FamInst
tcIfaceFamInst (IfaceFamInst { ifFamInstFam :: IfaceFamInst -> Name
ifFamInstFam = Name
fam, ifFamInstTys :: IfaceFamInst -> [Maybe IfaceTyCon]
ifFamInstTys = [Maybe IfaceTyCon]
mb_tcs
, ifFamInstAxiom :: IfaceFamInst -> Name
ifFamInstAxiom = Name
axiom_name } )
= do { CoAxiom Branched
axiom' <- SDoc -> IfL (CoAxiom Branched) -> IfL (CoAxiom Branched)
forall a. SDoc -> IfL a -> IfL a
forkM (String -> SDoc
text String
"Axiom" SDoc -> SDoc -> SDoc
<+> Name -> SDoc
forall a. Outputable a => a -> SDoc
ppr Name
axiom_name) (IfL (CoAxiom Branched) -> IfL (CoAxiom Branched))
-> IfL (CoAxiom Branched) -> IfL (CoAxiom Branched)
forall a b. (a -> b) -> a -> b
$
Name -> IfL (CoAxiom Branched)
tcIfaceCoAxiom Name
axiom_name
; let axiom'' :: CoAxiom Unbranched
axiom'' = CoAxiom Branched -> CoAxiom Unbranched
forall (br :: BranchFlag). CoAxiom br -> CoAxiom Unbranched
toUnbranchedAxiom CoAxiom Branched
axiom'
mb_tcs' :: [Maybe Name]
mb_tcs' = (Maybe IfaceTyCon -> Maybe Name)
-> [Maybe IfaceTyCon] -> [Maybe Name]
forall a b. (a -> b) -> [a] -> [b]
map ((IfaceTyCon -> Name) -> Maybe IfaceTyCon -> Maybe Name
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap IfaceTyCon -> Name
ifaceTyConName) [Maybe IfaceTyCon]
mb_tcs
; FamInst -> IOEnv (Env IfGblEnv IfLclEnv) FamInst
forall (m :: * -> *) a. Monad m => a -> m a
return (Name -> [Maybe Name] -> CoAxiom Unbranched -> FamInst
mkImportedFamInst Name
fam [Maybe Name]
mb_tcs' CoAxiom Unbranched
axiom'') }
tcIfaceRules :: Bool
-> [IfaceRule]
-> IfL [CoreRule]
tcIfaceRules :: Bool -> [IfaceRule] -> IfL [CoreRule]
tcIfaceRules Bool
ignore_prags [IfaceRule]
if_rules
| Bool
ignore_prags = [CoreRule] -> IfL [CoreRule]
forall (m :: * -> *) a. Monad m => a -> m a
return []
| Bool
otherwise = (IfaceRule -> IOEnv (Env IfGblEnv IfLclEnv) CoreRule)
-> [IfaceRule] -> IfL [CoreRule]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM IfaceRule -> IOEnv (Env IfGblEnv IfLclEnv) CoreRule
tcIfaceRule [IfaceRule]
if_rules
tcIfaceRule :: IfaceRule -> IfL CoreRule
tcIfaceRule :: IfaceRule -> IOEnv (Env IfGblEnv IfLclEnv) CoreRule
tcIfaceRule (IfaceRule {ifRuleName :: IfaceRule -> IfLclName
ifRuleName = IfLclName
name, ifActivation :: IfaceRule -> Activation
ifActivation = Activation
act, ifRuleBndrs :: IfaceRule -> [IfaceBndr]
ifRuleBndrs = [IfaceBndr]
bndrs,
ifRuleHead :: IfaceRule -> Name
ifRuleHead = Name
fn, ifRuleArgs :: IfaceRule -> [IfaceExpr]
ifRuleArgs = [IfaceExpr]
args, ifRuleRhs :: IfaceRule -> IfaceExpr
ifRuleRhs = IfaceExpr
rhs,
ifRuleAuto :: IfaceRule -> Bool
ifRuleAuto = Bool
auto, ifRuleOrph :: IfaceRule -> IsOrphan
ifRuleOrph = IsOrphan
orph })
= do { ~([Var]
bndrs', [CoreExpr]
args', CoreExpr
rhs') <-
SDoc
-> IfL ([Var], [CoreExpr], CoreExpr)
-> IfL ([Var], [CoreExpr], CoreExpr)
forall a. SDoc -> IfL a -> IfL a
forkM (String -> SDoc
text String
"Rule" SDoc -> SDoc -> SDoc
<+> IfLclName -> SDoc
pprRuleName IfLclName
name) (IfL ([Var], [CoreExpr], CoreExpr)
-> IfL ([Var], [CoreExpr], CoreExpr))
-> IfL ([Var], [CoreExpr], CoreExpr)
-> IfL ([Var], [CoreExpr], CoreExpr)
forall a b. (a -> b) -> a -> b
$
[IfaceBndr]
-> ([Var] -> IfL ([Var], [CoreExpr], CoreExpr))
-> IfL ([Var], [CoreExpr], CoreExpr)
forall a. [IfaceBndr] -> ([Var] -> IfL a) -> IfL a
bindIfaceBndrs [IfaceBndr]
bndrs (([Var] -> IfL ([Var], [CoreExpr], CoreExpr))
-> IfL ([Var], [CoreExpr], CoreExpr))
-> ([Var] -> IfL ([Var], [CoreExpr], CoreExpr))
-> IfL ([Var], [CoreExpr], CoreExpr)
forall a b. (a -> b) -> a -> b
$ \ [Var]
bndrs' ->
do { [CoreExpr]
args' <- (IfaceExpr -> IOEnv (Env IfGblEnv IfLclEnv) CoreExpr)
-> [IfaceExpr] -> IOEnv (Env IfGblEnv IfLclEnv) [CoreExpr]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM IfaceExpr -> IOEnv (Env IfGblEnv IfLclEnv) CoreExpr
tcIfaceExpr [IfaceExpr]
args
; CoreExpr
rhs' <- IfaceExpr -> IOEnv (Env IfGblEnv IfLclEnv) CoreExpr
tcIfaceExpr IfaceExpr
rhs
; GeneralFlag
-> TcRnIf IfGblEnv IfLclEnv () -> TcRnIf IfGblEnv IfLclEnv ()
forall gbl lcl.
GeneralFlag -> TcRnIf gbl lcl () -> TcRnIf gbl lcl ()
whenGOptM GeneralFlag
Opt_DoCoreLinting (TcRnIf IfGblEnv IfLclEnv () -> TcRnIf IfGblEnv IfLclEnv ())
-> TcRnIf IfGblEnv IfLclEnv () -> TcRnIf IfGblEnv IfLclEnv ()
forall a b. (a -> b) -> a -> b
$ do
{ DynFlags
dflags <- IOEnv (Env IfGblEnv IfLclEnv) DynFlags
forall (m :: * -> *). HasDynFlags m => m DynFlags
getDynFlags
; (IfGblEnv
_, IfLclEnv
lcl_env) <- TcRnIf IfGblEnv IfLclEnv (IfGblEnv, IfLclEnv)
forall gbl lcl. TcRnIf gbl lcl (gbl, lcl)
getEnvs
; let in_scope :: [Var]
in_scope :: [Var]
in_scope = ((UniqFM IfLclName Var -> [Var]
forall key elt. UniqFM key elt -> [elt]
nonDetEltsUFM (UniqFM IfLclName Var -> [Var]) -> UniqFM IfLclName Var -> [Var]
forall a b. (a -> b) -> a -> b
$ IfLclEnv -> UniqFM IfLclName Var
if_tv_env IfLclEnv
lcl_env) [Var] -> [Var] -> [Var]
forall a. [a] -> [a] -> [a]
++
(UniqFM IfLclName Var -> [Var]
forall key elt. UniqFM key elt -> [elt]
nonDetEltsUFM (UniqFM IfLclName Var -> [Var]) -> UniqFM IfLclName Var -> [Var]
forall a b. (a -> b) -> a -> b
$ IfLclEnv -> UniqFM IfLclName Var
if_id_env IfLclEnv
lcl_env) [Var] -> [Var] -> [Var]
forall a. [a] -> [a] -> [a]
++
[Var]
bndrs' [Var] -> [Var] -> [Var]
forall a. [a] -> [a] -> [a]
++
[CoreExpr] -> [Var]
exprsFreeIdsList [CoreExpr]
args')
; case DynFlags -> [Var] -> CoreExpr -> Maybe SDoc
lintExpr DynFlags
dflags [Var]
in_scope CoreExpr
rhs' of
Maybe SDoc
Nothing -> () -> TcRnIf IfGblEnv IfLclEnv ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
Just SDoc
fail_msg -> do { Module
mod <- IfL Module
getIfModule
; String -> SDoc -> TcRnIf IfGblEnv IfLclEnv ()
forall a. HasCallStack => String -> SDoc -> a
pprPanic String
"Iface Lint failure"
([SDoc] -> SDoc
vcat [ String -> SDoc
text String
"In interface for" SDoc -> SDoc -> SDoc
<+> Module -> SDoc
forall a. Outputable a => a -> SDoc
ppr Module
mod
, SDoc -> Int -> SDoc -> SDoc
hang SDoc
doc Int
2 SDoc
fail_msg
, IfLclName -> SDoc
forall a. Outputable a => a -> SDoc
ppr IfLclName
name SDoc -> SDoc -> SDoc
<+> SDoc
equals SDoc -> SDoc -> SDoc
<+> CoreExpr -> SDoc
forall a. Outputable a => a -> SDoc
ppr CoreExpr
rhs'
, String -> SDoc
text String
"Iface expr =" SDoc -> SDoc -> SDoc
<+> IfaceExpr -> SDoc
forall a. Outputable a => a -> SDoc
ppr IfaceExpr
rhs ]) } }
; ([Var], [CoreExpr], CoreExpr) -> IfL ([Var], [CoreExpr], CoreExpr)
forall (m :: * -> *) a. Monad m => a -> m a
return ([Var]
bndrs', [CoreExpr]
args', CoreExpr
rhs') }
; let mb_tcs :: [Maybe Name]
mb_tcs = (IfaceExpr -> Maybe Name) -> [IfaceExpr] -> [Maybe Name]
forall a b. (a -> b) -> [a] -> [b]
map IfaceExpr -> Maybe Name
ifTopFreeName [IfaceExpr]
args
; Module
this_mod <- IfL Module
getIfModule
; CoreRule -> IOEnv (Env IfGblEnv IfLclEnv) CoreRule
forall (m :: * -> *) a. Monad m => a -> m a
return (Rule :: IfLclName
-> Activation
-> Name
-> [Maybe Name]
-> [Var]
-> [CoreExpr]
-> CoreExpr
-> Bool
-> Module
-> IsOrphan
-> Bool
-> CoreRule
Rule { ru_name :: IfLclName
ru_name = IfLclName
name, ru_fn :: Name
ru_fn = Name
fn, ru_act :: Activation
ru_act = Activation
act,
ru_bndrs :: [Var]
ru_bndrs = [Var]
bndrs', ru_args :: [CoreExpr]
ru_args = [CoreExpr]
args',
ru_rhs :: CoreExpr
ru_rhs = CoreExpr -> CoreExpr
occurAnalyseExpr CoreExpr
rhs',
ru_rough :: [Maybe Name]
ru_rough = [Maybe Name]
mb_tcs,
ru_origin :: Module
ru_origin = Module
this_mod,
ru_orphan :: IsOrphan
ru_orphan = IsOrphan
orph,
ru_auto :: Bool
ru_auto = Bool
auto,
ru_local :: Bool
ru_local = Bool
False }) }
where
ifTopFreeName :: IfaceExpr -> Maybe Name
ifTopFreeName :: IfaceExpr -> Maybe Name
ifTopFreeName (IfaceType (IfaceTyConApp IfaceTyCon
tc IfaceAppArgs
_ )) = Name -> Maybe Name
forall a. a -> Maybe a
Just (IfaceTyCon -> Name
ifaceTyConName IfaceTyCon
tc)
ifTopFreeName (IfaceType (IfaceTupleTy TupleSort
s PromotionFlag
_ IfaceAppArgs
ts)) = Name -> Maybe Name
forall a. a -> Maybe a
Just (TupleSort -> Int -> Name
tupleTyConName TupleSort
s (IfaceContext -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length (IfaceAppArgs -> IfaceContext
appArgsIfaceTypes IfaceAppArgs
ts)))
ifTopFreeName (IfaceApp IfaceExpr
f IfaceExpr
_) = IfaceExpr -> Maybe Name
ifTopFreeName IfaceExpr
f
ifTopFreeName (IfaceExt Name
n) = Name -> Maybe Name
forall a. a -> Maybe a
Just Name
n
ifTopFreeName IfaceExpr
_ = Maybe Name
forall a. Maybe a
Nothing
doc :: SDoc
doc = String -> SDoc
text String
"Unfolding of" SDoc -> SDoc -> SDoc
<+> IfLclName -> SDoc
forall a. Outputable a => a -> SDoc
ppr IfLclName
name
tcIfaceAnnotations :: [IfaceAnnotation] -> IfL [Annotation]
tcIfaceAnnotations :: [IfaceAnnotation] -> IfL [Annotation]
tcIfaceAnnotations = (IfaceAnnotation -> IOEnv (Env IfGblEnv IfLclEnv) Annotation)
-> [IfaceAnnotation] -> IfL [Annotation]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM IfaceAnnotation -> IOEnv (Env IfGblEnv IfLclEnv) Annotation
tcIfaceAnnotation
tcIfaceAnnotation :: IfaceAnnotation -> IfL Annotation
tcIfaceAnnotation :: IfaceAnnotation -> IOEnv (Env IfGblEnv IfLclEnv) Annotation
tcIfaceAnnotation (IfaceAnnotation IfaceAnnTarget
target AnnPayload
serialized) = do
AnnTarget Name
target' <- IfaceAnnTarget -> IfL (AnnTarget Name)
tcIfaceAnnTarget IfaceAnnTarget
target
Annotation -> IOEnv (Env IfGblEnv IfLclEnv) Annotation
forall (m :: * -> *) a. Monad m => a -> m a
return (Annotation -> IOEnv (Env IfGblEnv IfLclEnv) Annotation)
-> Annotation -> IOEnv (Env IfGblEnv IfLclEnv) Annotation
forall a b. (a -> b) -> a -> b
$ Annotation :: AnnTarget Name -> AnnPayload -> Annotation
Annotation {
ann_target :: AnnTarget Name
ann_target = AnnTarget Name
target',
ann_value :: AnnPayload
ann_value = AnnPayload
serialized
}
tcIfaceAnnTarget :: IfaceAnnTarget -> IfL (AnnTarget Name)
tcIfaceAnnTarget :: IfaceAnnTarget -> IfL (AnnTarget Name)
tcIfaceAnnTarget (NamedTarget OccName
occ) = do
Name
name <- OccName -> TcRnIf IfGblEnv IfLclEnv Name
lookupIfaceTop OccName
occ
AnnTarget Name -> IfL (AnnTarget Name)
forall (m :: * -> *) a. Monad m => a -> m a
return (AnnTarget Name -> IfL (AnnTarget Name))
-> AnnTarget Name -> IfL (AnnTarget Name)
forall a b. (a -> b) -> a -> b
$ Name -> AnnTarget Name
forall name. name -> AnnTarget name
NamedTarget Name
name
tcIfaceAnnTarget (ModuleTarget Module
mod) = do
AnnTarget Name -> IfL (AnnTarget Name)
forall (m :: * -> *) a. Monad m => a -> m a
return (AnnTarget Name -> IfL (AnnTarget Name))
-> AnnTarget Name -> IfL (AnnTarget Name)
forall a b. (a -> b) -> a -> b
$ Module -> AnnTarget Name
forall name. Module -> AnnTarget name
ModuleTarget Module
mod
tcIfaceCompleteSigs :: [IfaceCompleteMatch] -> IfL [CompleteMatch]
tcIfaceCompleteSigs :: [IfaceCompleteMatch] -> IfL [CompleteMatch]
tcIfaceCompleteSigs = (IfaceCompleteMatch -> IOEnv (Env IfGblEnv IfLclEnv) CompleteMatch)
-> [IfaceCompleteMatch] -> IfL [CompleteMatch]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM IfaceCompleteMatch -> IOEnv (Env IfGblEnv IfLclEnv) CompleteMatch
tcIfaceCompleteSig
tcIfaceCompleteSig :: IfaceCompleteMatch -> IfL CompleteMatch
tcIfaceCompleteSig :: IfaceCompleteMatch -> IOEnv (Env IfGblEnv IfLclEnv) CompleteMatch
tcIfaceCompleteSig (IfaceCompleteMatch [Name]
ms Name
t) = CompleteMatch -> IOEnv (Env IfGblEnv IfLclEnv) CompleteMatch
forall (m :: * -> *) a. Monad m => a -> m a
return ([Name] -> Name -> CompleteMatch
CompleteMatch [Name]
ms Name
t)
tcIfaceType :: IfaceType -> IfL Type
tcIfaceType :: IfaceType -> IfL Type
tcIfaceType = IfaceType -> IfL Type
go
where
go :: IfaceType -> IfL Type
go (IfaceTyVar IfLclName
n) = Var -> Type
TyVarTy (Var -> Type) -> IfL Var -> IfL Type
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> IfLclName -> IfL Var
tcIfaceTyVar IfLclName
n
go (IfaceFreeTyVar Var
n) = String -> SDoc -> IfL Type
forall a. HasCallStack => String -> SDoc -> a
pprPanic String
"tcIfaceType:IfaceFreeTyVar" (Var -> SDoc
forall a. Outputable a => a -> SDoc
ppr Var
n)
go (IfaceLitTy IfaceTyLit
l) = TyLit -> Type
LitTy (TyLit -> Type) -> IOEnv (Env IfGblEnv IfLclEnv) TyLit -> IfL Type
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> IfaceTyLit -> IOEnv (Env IfGblEnv IfLclEnv) TyLit
tcIfaceTyLit IfaceTyLit
l
go (IfaceFunTy AnonArgFlag
flag IfaceType
w IfaceType
t1 IfaceType
t2) = AnonArgFlag -> Type -> Type -> Type -> Type
FunTy AnonArgFlag
flag (Type -> Type -> Type -> Type)
-> IfL Type -> IOEnv (Env IfGblEnv IfLclEnv) (Type -> Type -> Type)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> IfaceType -> IfL Type
tcIfaceType IfaceType
w IOEnv (Env IfGblEnv IfLclEnv) (Type -> Type -> Type)
-> IfL Type -> IOEnv (Env IfGblEnv IfLclEnv) (Type -> Type)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> IfaceType -> IfL Type
go IfaceType
t1 IOEnv (Env IfGblEnv IfLclEnv) (Type -> Type)
-> IfL Type -> IfL Type
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> IfaceType -> IfL Type
go IfaceType
t2
go (IfaceTupleTy TupleSort
s PromotionFlag
i IfaceAppArgs
tks) = TupleSort -> PromotionFlag -> IfaceAppArgs -> IfL Type
tcIfaceTupleTy TupleSort
s PromotionFlag
i IfaceAppArgs
tks
go (IfaceAppTy IfaceType
t IfaceAppArgs
ts)
= do { Type
t' <- IfaceType -> IfL Type
go IfaceType
t
; ThetaType
ts' <- (IfaceType -> IfL Type) -> IfaceContext -> IfL ThetaType
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse IfaceType -> IfL Type
go (IfaceAppArgs -> IfaceContext
appArgsIfaceTypes IfaceAppArgs
ts)
; Type -> IfL Type
forall (f :: * -> *) a. Applicative f => a -> f a
pure ((Type -> Type -> Type) -> Type -> ThetaType -> Type
forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
foldl' Type -> Type -> Type
AppTy Type
t' ThetaType
ts') }
go (IfaceTyConApp IfaceTyCon
tc IfaceAppArgs
tks)
= do { TyCon
tc' <- IfaceTyCon -> IOEnv (Env IfGblEnv IfLclEnv) TyCon
tcIfaceTyCon IfaceTyCon
tc
; ThetaType
tks' <- (IfaceType -> IfL Type) -> IfaceContext -> IfL ThetaType
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM IfaceType -> IfL Type
go (IfaceAppArgs -> IfaceContext
appArgsIfaceTypes IfaceAppArgs
tks)
; Type -> IfL Type
forall (m :: * -> *) a. Monad m => a -> m a
return (TyCon -> ThetaType -> Type
mkTyConApp TyCon
tc' ThetaType
tks') }
go (IfaceForAllTy IfaceForAllBndr
bndr IfaceType
t)
= IfaceForAllBndr -> (Var -> ArgFlag -> IfL Type) -> IfL Type
forall vis a.
VarBndr IfaceBndr vis -> (Var -> vis -> IfL a) -> IfL a
bindIfaceForAllBndr IfaceForAllBndr
bndr ((Var -> ArgFlag -> IfL Type) -> IfL Type)
-> (Var -> ArgFlag -> IfL Type) -> IfL Type
forall a b. (a -> b) -> a -> b
$ \ Var
tv' ArgFlag
vis ->
TyCoVarBinder -> Type -> Type
ForAllTy (Var -> ArgFlag -> TyCoVarBinder
forall var argf. var -> argf -> VarBndr var argf
Bndr Var
tv' ArgFlag
vis) (Type -> Type) -> IfL Type -> IfL Type
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> IfaceType -> IfL Type
go IfaceType
t
go (IfaceCastTy IfaceType
ty IfaceCoercion
co) = Type -> Coercion -> Type
CastTy (Type -> Coercion -> Type)
-> IfL Type -> IOEnv (Env IfGblEnv IfLclEnv) (Coercion -> Type)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> IfaceType -> IfL Type
go IfaceType
ty IOEnv (Env IfGblEnv IfLclEnv) (Coercion -> Type)
-> IfL Coercion -> IfL Type
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> IfaceCoercion -> IfL Coercion
tcIfaceCo IfaceCoercion
co
go (IfaceCoercionTy IfaceCoercion
co) = Coercion -> Type
CoercionTy (Coercion -> Type) -> IfL Coercion -> IfL Type
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> IfaceCoercion -> IfL Coercion
tcIfaceCo IfaceCoercion
co
tcIfaceTupleTy :: TupleSort -> PromotionFlag -> IfaceAppArgs -> IfL Type
tcIfaceTupleTy :: TupleSort -> PromotionFlag -> IfaceAppArgs -> IfL Type
tcIfaceTupleTy TupleSort
sort PromotionFlag
is_promoted IfaceAppArgs
args
= do { ThetaType
args' <- IfaceAppArgs -> IfL ThetaType
tcIfaceAppArgs IfaceAppArgs
args
; let arity :: Int
arity = ThetaType -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length ThetaType
args'
; TyCon
base_tc <- Bool -> TupleSort -> Int -> IOEnv (Env IfGblEnv IfLclEnv) TyCon
tcTupleTyCon Bool
True TupleSort
sort Int
arity
; case PromotionFlag
is_promoted of
PromotionFlag
NotPromoted
-> Type -> IfL Type
forall (m :: * -> *) a. Monad m => a -> m a
return (TyCon -> ThetaType -> Type
mkTyConApp TyCon
base_tc ThetaType
args')
PromotionFlag
IsPromoted
-> do { let tc :: TyCon
tc = DataCon -> TyCon
promoteDataCon (TyCon -> DataCon
tyConSingleDataCon TyCon
base_tc)
kind_args :: ThetaType
kind_args = (Type -> Type) -> ThetaType -> ThetaType
forall a b. (a -> b) -> [a] -> [b]
map HasDebugCallStack => Type -> Type
Type -> Type
typeKind ThetaType
args'
; Type -> IfL Type
forall (m :: * -> *) a. Monad m => a -> m a
return (TyCon -> ThetaType -> Type
mkTyConApp TyCon
tc (ThetaType
kind_args ThetaType -> ThetaType -> ThetaType
forall a. [a] -> [a] -> [a]
++ ThetaType
args')) } }
tcTupleTyCon :: Bool
-> TupleSort
-> Arity
-> IfL TyCon
tcTupleTyCon :: Bool -> TupleSort -> Int -> IOEnv (Env IfGblEnv IfLclEnv) TyCon
tcTupleTyCon Bool
in_type TupleSort
sort Int
arity
= case TupleSort
sort of
TupleSort
ConstraintTuple -> do { TyThing
thing <- Name -> IfL TyThing
tcIfaceGlobal (Int -> Name
cTupleTyConName Int
arity)
; TyCon -> IOEnv (Env IfGblEnv IfLclEnv) TyCon
forall (m :: * -> *) a. Monad m => a -> m a
return (HasDebugCallStack => TyThing -> TyCon
TyThing -> TyCon
tyThingTyCon TyThing
thing) }
TupleSort
BoxedTuple -> TyCon -> IOEnv (Env IfGblEnv IfLclEnv) TyCon
forall (m :: * -> *) a. Monad m => a -> m a
return (Boxity -> Int -> TyCon
tupleTyCon Boxity
Boxed Int
arity)
TupleSort
UnboxedTuple -> TyCon -> IOEnv (Env IfGblEnv IfLclEnv) TyCon
forall (m :: * -> *) a. Monad m => a -> m a
return (Boxity -> Int -> TyCon
tupleTyCon Boxity
Unboxed Int
arity')
where arity' :: Int
arity' | Bool
in_type = Int
arity Int -> Int -> Int
forall a. Integral a => a -> a -> a
`div` Int
2
| Bool
otherwise = Int
arity
tcIfaceAppArgs :: IfaceAppArgs -> IfL [Type]
tcIfaceAppArgs :: IfaceAppArgs -> IfL ThetaType
tcIfaceAppArgs = (IfaceType -> IfL Type) -> IfaceContext -> IfL ThetaType
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM IfaceType -> IfL Type
tcIfaceType (IfaceContext -> IfL ThetaType)
-> (IfaceAppArgs -> IfaceContext) -> IfaceAppArgs -> IfL ThetaType
forall b c a. (b -> c) -> (a -> b) -> a -> c
. IfaceAppArgs -> IfaceContext
appArgsIfaceTypes
tcIfaceCtxt :: IfaceContext -> IfL ThetaType
tcIfaceCtxt :: IfaceContext -> IfL ThetaType
tcIfaceCtxt IfaceContext
sts = (IfaceType -> IfL Type) -> IfaceContext -> IfL ThetaType
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM IfaceType -> IfL Type
tcIfaceType IfaceContext
sts
tcIfaceTyLit :: IfaceTyLit -> IfL TyLit
tcIfaceTyLit :: IfaceTyLit -> IOEnv (Env IfGblEnv IfLclEnv) TyLit
tcIfaceTyLit (IfaceNumTyLit Integer
n) = TyLit -> IOEnv (Env IfGblEnv IfLclEnv) TyLit
forall (m :: * -> *) a. Monad m => a -> m a
return (Integer -> TyLit
NumTyLit Integer
n)
tcIfaceTyLit (IfaceStrTyLit IfLclName
n) = TyLit -> IOEnv (Env IfGblEnv IfLclEnv) TyLit
forall (m :: * -> *) a. Monad m => a -> m a
return (IfLclName -> TyLit
StrTyLit IfLclName
n)
tcIfaceCo :: IfaceCoercion -> IfL Coercion
tcIfaceCo :: IfaceCoercion -> IfL Coercion
tcIfaceCo = IfaceCoercion -> IfL Coercion
go
where
go_mco :: IfaceMCoercion -> IOEnv (Env IfGblEnv IfLclEnv) MCoercion
go_mco IfaceMCoercion
IfaceMRefl = MCoercion -> IOEnv (Env IfGblEnv IfLclEnv) MCoercion
forall (f :: * -> *) a. Applicative f => a -> f a
pure MCoercion
MRefl
go_mco (IfaceMCo IfaceCoercion
co) = Coercion -> MCoercion
MCo (Coercion -> MCoercion)
-> IfL Coercion -> IOEnv (Env IfGblEnv IfLclEnv) MCoercion
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (IfaceCoercion -> IfL Coercion
go IfaceCoercion
co)
go :: IfaceCoercion -> IfL Coercion
go (IfaceReflCo IfaceType
t) = Type -> Coercion
Refl (Type -> Coercion) -> IfL Type -> IfL Coercion
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> IfaceType -> IfL Type
tcIfaceType IfaceType
t
go (IfaceGReflCo Role
r IfaceType
t IfaceMCoercion
mco) = Role -> Type -> MCoercion -> Coercion
GRefl Role
r (Type -> MCoercion -> Coercion)
-> IfL Type
-> IOEnv (Env IfGblEnv IfLclEnv) (MCoercion -> Coercion)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> IfaceType -> IfL Type
tcIfaceType IfaceType
t IOEnv (Env IfGblEnv IfLclEnv) (MCoercion -> Coercion)
-> IOEnv (Env IfGblEnv IfLclEnv) MCoercion -> IfL Coercion
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> IfaceMCoercion -> IOEnv (Env IfGblEnv IfLclEnv) MCoercion
go_mco IfaceMCoercion
mco
go (IfaceFunCo Role
r IfaceCoercion
w IfaceCoercion
c1 IfaceCoercion
c2) = Role -> Coercion -> Coercion -> Coercion -> Coercion
mkFunCo Role
r (Coercion -> Coercion -> Coercion -> Coercion)
-> IfL Coercion
-> IOEnv (Env IfGblEnv IfLclEnv) (Coercion -> Coercion -> Coercion)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> IfaceCoercion -> IfL Coercion
go IfaceCoercion
w IOEnv (Env IfGblEnv IfLclEnv) (Coercion -> Coercion -> Coercion)
-> IfL Coercion
-> IOEnv (Env IfGblEnv IfLclEnv) (Coercion -> Coercion)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> IfaceCoercion -> IfL Coercion
go IfaceCoercion
c1 IOEnv (Env IfGblEnv IfLclEnv) (Coercion -> Coercion)
-> IfL Coercion -> IfL Coercion
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> IfaceCoercion -> IfL Coercion
go IfaceCoercion
c2
go (IfaceTyConAppCo Role
r IfaceTyCon
tc [IfaceCoercion]
cs)
= Role -> TyCon -> [Coercion] -> Coercion
TyConAppCo Role
r (TyCon -> [Coercion] -> Coercion)
-> IOEnv (Env IfGblEnv IfLclEnv) TyCon
-> IOEnv (Env IfGblEnv IfLclEnv) ([Coercion] -> Coercion)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> IfaceTyCon -> IOEnv (Env IfGblEnv IfLclEnv) TyCon
tcIfaceTyCon IfaceTyCon
tc IOEnv (Env IfGblEnv IfLclEnv) ([Coercion] -> Coercion)
-> IOEnv (Env IfGblEnv IfLclEnv) [Coercion] -> IfL Coercion
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (IfaceCoercion -> IfL Coercion)
-> [IfaceCoercion] -> IOEnv (Env IfGblEnv IfLclEnv) [Coercion]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM IfaceCoercion -> IfL Coercion
go [IfaceCoercion]
cs
go (IfaceAppCo IfaceCoercion
c1 IfaceCoercion
c2) = Coercion -> Coercion -> Coercion
AppCo (Coercion -> Coercion -> Coercion)
-> IfL Coercion
-> IOEnv (Env IfGblEnv IfLclEnv) (Coercion -> Coercion)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> IfaceCoercion -> IfL Coercion
go IfaceCoercion
c1 IOEnv (Env IfGblEnv IfLclEnv) (Coercion -> Coercion)
-> IfL Coercion -> IfL Coercion
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> IfaceCoercion -> IfL Coercion
go IfaceCoercion
c2
go (IfaceForAllCo IfaceBndr
tv IfaceCoercion
k IfaceCoercion
c) = do { Coercion
k' <- IfaceCoercion -> IfL Coercion
go IfaceCoercion
k
; IfaceBndr -> (Var -> IfL Coercion) -> IfL Coercion
forall a. IfaceBndr -> (Var -> IfL a) -> IfL a
bindIfaceBndr IfaceBndr
tv ((Var -> IfL Coercion) -> IfL Coercion)
-> (Var -> IfL Coercion) -> IfL Coercion
forall a b. (a -> b) -> a -> b
$ \ Var
tv' ->
Var -> Coercion -> Coercion -> Coercion
ForAllCo Var
tv' Coercion
k' (Coercion -> Coercion) -> IfL Coercion -> IfL Coercion
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> IfaceCoercion -> IfL Coercion
go IfaceCoercion
c }
go (IfaceCoVarCo IfLclName
n) = Var -> Coercion
CoVarCo (Var -> Coercion) -> IfL Var -> IfL Coercion
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> IfLclName -> IfL Var
go_var IfLclName
n
go (IfaceAxiomInstCo Name
n Int
i [IfaceCoercion]
cs) = CoAxiom Branched -> Int -> [Coercion] -> Coercion
AxiomInstCo (CoAxiom Branched -> Int -> [Coercion] -> Coercion)
-> IfL (CoAxiom Branched)
-> IOEnv (Env IfGblEnv IfLclEnv) (Int -> [Coercion] -> Coercion)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Name -> IfL (CoAxiom Branched)
tcIfaceCoAxiom Name
n IOEnv (Env IfGblEnv IfLclEnv) (Int -> [Coercion] -> Coercion)
-> IOEnv (Env IfGblEnv IfLclEnv) Int
-> IOEnv (Env IfGblEnv IfLclEnv) ([Coercion] -> Coercion)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Int -> IOEnv (Env IfGblEnv IfLclEnv) Int
forall (f :: * -> *) a. Applicative f => a -> f a
pure Int
i IOEnv (Env IfGblEnv IfLclEnv) ([Coercion] -> Coercion)
-> IOEnv (Env IfGblEnv IfLclEnv) [Coercion] -> IfL Coercion
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (IfaceCoercion -> IfL Coercion)
-> [IfaceCoercion] -> IOEnv (Env IfGblEnv IfLclEnv) [Coercion]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM IfaceCoercion -> IfL Coercion
go [IfaceCoercion]
cs
go (IfaceUnivCo IfaceUnivCoProv
p Role
r IfaceType
t1 IfaceType
t2) = UnivCoProvenance -> Role -> Type -> Type -> Coercion
UnivCo (UnivCoProvenance -> Role -> Type -> Type -> Coercion)
-> IOEnv (Env IfGblEnv IfLclEnv) UnivCoProvenance
-> IOEnv (Env IfGblEnv IfLclEnv) (Role -> Type -> Type -> Coercion)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> IfaceUnivCoProv -> IOEnv (Env IfGblEnv IfLclEnv) UnivCoProvenance
tcIfaceUnivCoProv IfaceUnivCoProv
p IOEnv (Env IfGblEnv IfLclEnv) (Role -> Type -> Type -> Coercion)
-> IOEnv (Env IfGblEnv IfLclEnv) Role
-> IOEnv (Env IfGblEnv IfLclEnv) (Type -> Type -> Coercion)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Role -> IOEnv (Env IfGblEnv IfLclEnv) Role
forall (f :: * -> *) a. Applicative f => a -> f a
pure Role
r
IOEnv (Env IfGblEnv IfLclEnv) (Type -> Type -> Coercion)
-> IfL Type -> IOEnv (Env IfGblEnv IfLclEnv) (Type -> Coercion)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> IfaceType -> IfL Type
tcIfaceType IfaceType
t1 IOEnv (Env IfGblEnv IfLclEnv) (Type -> Coercion)
-> IfL Type -> IfL Coercion
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> IfaceType -> IfL Type
tcIfaceType IfaceType
t2
go (IfaceSymCo IfaceCoercion
c) = Coercion -> Coercion
SymCo (Coercion -> Coercion) -> IfL Coercion -> IfL Coercion
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> IfaceCoercion -> IfL Coercion
go IfaceCoercion
c
go (IfaceTransCo IfaceCoercion
c1 IfaceCoercion
c2) = Coercion -> Coercion -> Coercion
TransCo (Coercion -> Coercion -> Coercion)
-> IfL Coercion
-> IOEnv (Env IfGblEnv IfLclEnv) (Coercion -> Coercion)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> IfaceCoercion -> IfL Coercion
go IfaceCoercion
c1
IOEnv (Env IfGblEnv IfLclEnv) (Coercion -> Coercion)
-> IfL Coercion -> IfL Coercion
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> IfaceCoercion -> IfL Coercion
go IfaceCoercion
c2
go (IfaceInstCo IfaceCoercion
c1 IfaceCoercion
t2) = Coercion -> Coercion -> Coercion
InstCo (Coercion -> Coercion -> Coercion)
-> IfL Coercion
-> IOEnv (Env IfGblEnv IfLclEnv) (Coercion -> Coercion)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> IfaceCoercion -> IfL Coercion
go IfaceCoercion
c1
IOEnv (Env IfGblEnv IfLclEnv) (Coercion -> Coercion)
-> IfL Coercion -> IfL Coercion
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> IfaceCoercion -> IfL Coercion
go IfaceCoercion
t2
go (IfaceNthCo Int
d IfaceCoercion
c) = do { Coercion
c' <- IfaceCoercion -> IfL Coercion
go IfaceCoercion
c
; Coercion -> IfL Coercion
forall (m :: * -> *) a. Monad m => a -> m a
return (Coercion -> IfL Coercion) -> Coercion -> IfL Coercion
forall a b. (a -> b) -> a -> b
$ HasDebugCallStack => Role -> Int -> Coercion -> Coercion
Role -> Int -> Coercion -> Coercion
mkNthCo (Int -> Coercion -> Role
nthCoRole Int
d Coercion
c') Int
d Coercion
c' }
go (IfaceLRCo LeftOrRight
lr IfaceCoercion
c) = LeftOrRight -> Coercion -> Coercion
LRCo LeftOrRight
lr (Coercion -> Coercion) -> IfL Coercion -> IfL Coercion
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> IfaceCoercion -> IfL Coercion
go IfaceCoercion
c
go (IfaceKindCo IfaceCoercion
c) = Coercion -> Coercion
KindCo (Coercion -> Coercion) -> IfL Coercion -> IfL Coercion
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> IfaceCoercion -> IfL Coercion
go IfaceCoercion
c
go (IfaceSubCo IfaceCoercion
c) = Coercion -> Coercion
SubCo (Coercion -> Coercion) -> IfL Coercion -> IfL Coercion
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> IfaceCoercion -> IfL Coercion
go IfaceCoercion
c
go (IfaceAxiomRuleCo IfLclName
ax [IfaceCoercion]
cos) = CoAxiomRule -> [Coercion] -> Coercion
AxiomRuleCo (CoAxiomRule -> [Coercion] -> Coercion)
-> IOEnv (Env IfGblEnv IfLclEnv) CoAxiomRule
-> IOEnv (Env IfGblEnv IfLclEnv) ([Coercion] -> Coercion)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> IfLclName -> IOEnv (Env IfGblEnv IfLclEnv) CoAxiomRule
tcIfaceCoAxiomRule IfLclName
ax
IOEnv (Env IfGblEnv IfLclEnv) ([Coercion] -> Coercion)
-> IOEnv (Env IfGblEnv IfLclEnv) [Coercion] -> IfL Coercion
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (IfaceCoercion -> IfL Coercion)
-> [IfaceCoercion] -> IOEnv (Env IfGblEnv IfLclEnv) [Coercion]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM IfaceCoercion -> IfL Coercion
go [IfaceCoercion]
cos
go (IfaceFreeCoVar Var
c) = String -> SDoc -> IfL Coercion
forall a. HasCallStack => String -> SDoc -> a
pprPanic String
"tcIfaceCo:IfaceFreeCoVar" (Var -> SDoc
forall a. Outputable a => a -> SDoc
ppr Var
c)
go (IfaceHoleCo Var
c) = String -> SDoc -> IfL Coercion
forall a. HasCallStack => String -> SDoc -> a
pprPanic String
"tcIfaceCo:IfaceHoleCo" (Var -> SDoc
forall a. Outputable a => a -> SDoc
ppr Var
c)
go_var :: FastString -> IfL CoVar
go_var :: IfLclName -> IfL Var
go_var = IfLclName -> IfL Var
tcIfaceLclId
tcIfaceUnivCoProv :: IfaceUnivCoProv -> IfL UnivCoProvenance
tcIfaceUnivCoProv :: IfaceUnivCoProv -> IOEnv (Env IfGblEnv IfLclEnv) UnivCoProvenance
tcIfaceUnivCoProv (IfacePhantomProv IfaceCoercion
kco) = Coercion -> UnivCoProvenance
PhantomProv (Coercion -> UnivCoProvenance)
-> IfL Coercion -> IOEnv (Env IfGblEnv IfLclEnv) UnivCoProvenance
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> IfaceCoercion -> IfL Coercion
tcIfaceCo IfaceCoercion
kco
tcIfaceUnivCoProv (IfaceProofIrrelProv IfaceCoercion
kco) = Coercion -> UnivCoProvenance
ProofIrrelProv (Coercion -> UnivCoProvenance)
-> IfL Coercion -> IOEnv (Env IfGblEnv IfLclEnv) UnivCoProvenance
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> IfaceCoercion -> IfL Coercion
tcIfaceCo IfaceCoercion
kco
tcIfaceUnivCoProv (IfacePluginProv String
str) = UnivCoProvenance -> IOEnv (Env IfGblEnv IfLclEnv) UnivCoProvenance
forall (m :: * -> *) a. Monad m => a -> m a
return (UnivCoProvenance
-> IOEnv (Env IfGblEnv IfLclEnv) UnivCoProvenance)
-> UnivCoProvenance
-> IOEnv (Env IfGblEnv IfLclEnv) UnivCoProvenance
forall a b. (a -> b) -> a -> b
$ String -> UnivCoProvenance
PluginProv String
str
tcIfaceExpr :: IfaceExpr -> IfL CoreExpr
tcIfaceExpr :: IfaceExpr -> IOEnv (Env IfGblEnv IfLclEnv) CoreExpr
tcIfaceExpr (IfaceType IfaceType
ty)
= Type -> CoreExpr
forall b. Type -> Expr b
Type (Type -> CoreExpr)
-> IfL Type -> IOEnv (Env IfGblEnv IfLclEnv) CoreExpr
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> IfaceType -> IfL Type
tcIfaceType IfaceType
ty
tcIfaceExpr (IfaceCo IfaceCoercion
co)
= Coercion -> CoreExpr
forall b. Coercion -> Expr b
Coercion (Coercion -> CoreExpr)
-> IfL Coercion -> IOEnv (Env IfGblEnv IfLclEnv) CoreExpr
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> IfaceCoercion -> IfL Coercion
tcIfaceCo IfaceCoercion
co
tcIfaceExpr (IfaceCast IfaceExpr
expr IfaceCoercion
co)
= CoreExpr -> Coercion -> CoreExpr
forall b. Expr b -> Coercion -> Expr b
Cast (CoreExpr -> Coercion -> CoreExpr)
-> IOEnv (Env IfGblEnv IfLclEnv) CoreExpr
-> IOEnv (Env IfGblEnv IfLclEnv) (Coercion -> CoreExpr)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> IfaceExpr -> IOEnv (Env IfGblEnv IfLclEnv) CoreExpr
tcIfaceExpr IfaceExpr
expr IOEnv (Env IfGblEnv IfLclEnv) (Coercion -> CoreExpr)
-> IfL Coercion -> IOEnv (Env IfGblEnv IfLclEnv) CoreExpr
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> IfaceCoercion -> IfL Coercion
tcIfaceCo IfaceCoercion
co
tcIfaceExpr (IfaceLcl IfLclName
name)
= Var -> CoreExpr
forall b. Var -> Expr b
Var (Var -> CoreExpr)
-> IfL Var -> IOEnv (Env IfGblEnv IfLclEnv) CoreExpr
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> IfLclName -> IfL Var
tcIfaceLclId IfLclName
name
tcIfaceExpr (IfaceExt Name
gbl)
= Var -> CoreExpr
forall b. Var -> Expr b
Var (Var -> CoreExpr)
-> IfL Var -> IOEnv (Env IfGblEnv IfLclEnv) CoreExpr
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Name -> IfL Var
tcIfaceExtId Name
gbl
tcIfaceExpr (IfaceLit Literal
lit)
= do Literal
lit' <- Literal -> IfL Literal
tcIfaceLit Literal
lit
CoreExpr -> IOEnv (Env IfGblEnv IfLclEnv) CoreExpr
forall (m :: * -> *) a. Monad m => a -> m a
return (Literal -> CoreExpr
forall b. Literal -> Expr b
Lit Literal
lit')
tcIfaceExpr (IfaceFCall ForeignCall
cc IfaceType
ty) = do
Type
ty' <- IfaceType -> IfL Type
tcIfaceType IfaceType
ty
Unique
u <- TcRnIf IfGblEnv IfLclEnv Unique
forall gbl lcl. TcRnIf gbl lcl Unique
newUnique
DynFlags
dflags <- IOEnv (Env IfGblEnv IfLclEnv) DynFlags
forall (m :: * -> *). HasDynFlags m => m DynFlags
getDynFlags
CoreExpr -> IOEnv (Env IfGblEnv IfLclEnv) CoreExpr
forall (m :: * -> *) a. Monad m => a -> m a
return (Var -> CoreExpr
forall b. Var -> Expr b
Var (DynFlags -> Unique -> ForeignCall -> Type -> Var
mkFCallId DynFlags
dflags Unique
u ForeignCall
cc Type
ty'))
tcIfaceExpr (IfaceTuple TupleSort
sort [IfaceExpr]
args)
= do { [CoreExpr]
args' <- (IfaceExpr -> IOEnv (Env IfGblEnv IfLclEnv) CoreExpr)
-> [IfaceExpr] -> IOEnv (Env IfGblEnv IfLclEnv) [CoreExpr]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM IfaceExpr -> IOEnv (Env IfGblEnv IfLclEnv) CoreExpr
tcIfaceExpr [IfaceExpr]
args
; TyCon
tc <- Bool -> TupleSort -> Int -> IOEnv (Env IfGblEnv IfLclEnv) TyCon
tcTupleTyCon Bool
False TupleSort
sort Int
arity
; let con_tys :: ThetaType
con_tys = (CoreExpr -> Type) -> [CoreExpr] -> ThetaType
forall a b. (a -> b) -> [a] -> [b]
map CoreExpr -> Type
exprType [CoreExpr]
args'
some_con_args :: [CoreExpr]
some_con_args = (Type -> CoreExpr) -> ThetaType -> [CoreExpr]
forall a b. (a -> b) -> [a] -> [b]
map Type -> CoreExpr
forall b. Type -> Expr b
Type ThetaType
con_tys [CoreExpr] -> [CoreExpr] -> [CoreExpr]
forall a. [a] -> [a] -> [a]
++ [CoreExpr]
args'
con_args :: [CoreExpr]
con_args = case TupleSort
sort of
TupleSort
UnboxedTuple -> (Type -> CoreExpr) -> ThetaType -> [CoreExpr]
forall a b. (a -> b) -> [a] -> [b]
map (Type -> CoreExpr
forall b. Type -> Expr b
Type (Type -> CoreExpr) -> (Type -> Type) -> Type -> CoreExpr
forall b c a. (b -> c) -> (a -> b) -> a -> c
. HasDebugCallStack => Type -> Type
Type -> Type
getRuntimeRep) ThetaType
con_tys [CoreExpr] -> [CoreExpr] -> [CoreExpr]
forall a. [a] -> [a] -> [a]
++ [CoreExpr]
some_con_args
TupleSort
_ -> [CoreExpr]
some_con_args
con_id :: Var
con_id = DataCon -> Var
dataConWorkId (TyCon -> DataCon
tyConSingleDataCon TyCon
tc)
; CoreExpr -> IOEnv (Env IfGblEnv IfLclEnv) CoreExpr
forall (m :: * -> *) a. Monad m => a -> m a
return (CoreExpr -> [CoreExpr] -> CoreExpr
forall b. Expr b -> [Expr b] -> Expr b
mkApps (Var -> CoreExpr
forall b. Var -> Expr b
Var Var
con_id) [CoreExpr]
con_args) }
where
arity :: Int
arity = [IfaceExpr] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [IfaceExpr]
args
tcIfaceExpr (IfaceLam (IfaceBndr
bndr, IfaceOneShot
os) IfaceExpr
body)
= IfaceBndr
-> (Var -> IOEnv (Env IfGblEnv IfLclEnv) CoreExpr)
-> IOEnv (Env IfGblEnv IfLclEnv) CoreExpr
forall a. IfaceBndr -> (Var -> IfL a) -> IfL a
bindIfaceBndr IfaceBndr
bndr ((Var -> IOEnv (Env IfGblEnv IfLclEnv) CoreExpr)
-> IOEnv (Env IfGblEnv IfLclEnv) CoreExpr)
-> (Var -> IOEnv (Env IfGblEnv IfLclEnv) CoreExpr)
-> IOEnv (Env IfGblEnv IfLclEnv) CoreExpr
forall a b. (a -> b) -> a -> b
$ \Var
bndr' ->
Var -> CoreExpr -> CoreExpr
forall b. b -> Expr b -> Expr b
Lam (IfaceOneShot -> Var -> Var
tcIfaceOneShot IfaceOneShot
os Var
bndr') (CoreExpr -> CoreExpr)
-> IOEnv (Env IfGblEnv IfLclEnv) CoreExpr
-> IOEnv (Env IfGblEnv IfLclEnv) CoreExpr
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> IfaceExpr -> IOEnv (Env IfGblEnv IfLclEnv) CoreExpr
tcIfaceExpr IfaceExpr
body
where
tcIfaceOneShot :: IfaceOneShot -> Var -> Var
tcIfaceOneShot IfaceOneShot
IfaceOneShot Var
b = Var -> Var
setOneShotLambda Var
b
tcIfaceOneShot IfaceOneShot
_ Var
b = Var
b
tcIfaceExpr (IfaceApp IfaceExpr
fun IfaceExpr
arg)
= CoreExpr -> CoreExpr -> CoreExpr
forall b. Expr b -> Expr b -> Expr b
App (CoreExpr -> CoreExpr -> CoreExpr)
-> IOEnv (Env IfGblEnv IfLclEnv) CoreExpr
-> IOEnv (Env IfGblEnv IfLclEnv) (CoreExpr -> CoreExpr)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> IfaceExpr -> IOEnv (Env IfGblEnv IfLclEnv) CoreExpr
tcIfaceExpr IfaceExpr
fun IOEnv (Env IfGblEnv IfLclEnv) (CoreExpr -> CoreExpr)
-> IOEnv (Env IfGblEnv IfLclEnv) CoreExpr
-> IOEnv (Env IfGblEnv IfLclEnv) CoreExpr
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> IfaceExpr -> IOEnv (Env IfGblEnv IfLclEnv) CoreExpr
tcIfaceExpr IfaceExpr
arg
tcIfaceExpr (IfaceECase IfaceExpr
scrut IfaceType
ty)
= do { CoreExpr
scrut' <- IfaceExpr -> IOEnv (Env IfGblEnv IfLclEnv) CoreExpr
tcIfaceExpr IfaceExpr
scrut
; Type
ty' <- IfaceType -> IfL Type
tcIfaceType IfaceType
ty
; CoreExpr -> IOEnv (Env IfGblEnv IfLclEnv) CoreExpr
forall (m :: * -> *) a. Monad m => a -> m a
return (CoreExpr -> Type -> CoreExpr
castBottomExpr CoreExpr
scrut' Type
ty') }
tcIfaceExpr (IfaceCase IfaceExpr
scrut IfLclName
case_bndr [IfaceAlt]
alts) = do
CoreExpr
scrut' <- IfaceExpr -> IOEnv (Env IfGblEnv IfLclEnv) CoreExpr
tcIfaceExpr IfaceExpr
scrut
Name
case_bndr_name <- OccName -> TcRnIf IfGblEnv IfLclEnv Name
newIfaceName (IfLclName -> OccName
mkVarOccFS IfLclName
case_bndr)
let
scrut_ty :: Type
scrut_ty = CoreExpr -> Type
exprType CoreExpr
scrut'
case_mult :: Type
case_mult = Type
Many
case_bndr' :: Var
case_bndr' = Name -> Type -> Type -> Var
mkLocalIdOrCoVar Name
case_bndr_name Type
case_mult Type
scrut_ty
tc_app :: (TyCon, ThetaType)
tc_app = Type -> (TyCon, ThetaType)
splitTyConApp Type
scrut_ty
[Var]
-> IOEnv (Env IfGblEnv IfLclEnv) CoreExpr
-> IOEnv (Env IfGblEnv IfLclEnv) CoreExpr
forall a. [Var] -> IfL a -> IfL a
extendIfaceIdEnv [Var
case_bndr'] (IOEnv (Env IfGblEnv IfLclEnv) CoreExpr
-> IOEnv (Env IfGblEnv IfLclEnv) CoreExpr)
-> IOEnv (Env IfGblEnv IfLclEnv) CoreExpr
-> IOEnv (Env IfGblEnv IfLclEnv) CoreExpr
forall a b. (a -> b) -> a -> b
$ do
[(AltCon, [Var], CoreExpr)]
alts' <- (IfaceAlt
-> IOEnv (Env IfGblEnv IfLclEnv) (AltCon, [Var], CoreExpr))
-> [IfaceAlt]
-> IOEnv (Env IfGblEnv IfLclEnv) [(AltCon, [Var], CoreExpr)]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM (CoreExpr
-> Type
-> (TyCon, ThetaType)
-> IfaceAlt
-> IOEnv (Env IfGblEnv IfLclEnv) (AltCon, [Var], CoreExpr)
tcIfaceAlt CoreExpr
scrut' Type
case_mult (TyCon, ThetaType)
tc_app) [IfaceAlt]
alts
CoreExpr -> IOEnv (Env IfGblEnv IfLclEnv) CoreExpr
forall (m :: * -> *) a. Monad m => a -> m a
return (CoreExpr -> Var -> Type -> [(AltCon, [Var], CoreExpr)] -> CoreExpr
forall b. Expr b -> b -> Type -> [Alt b] -> Expr b
Case CoreExpr
scrut' Var
case_bndr' ([(AltCon, [Var], CoreExpr)] -> Type
coreAltsType [(AltCon, [Var], CoreExpr)]
alts') [(AltCon, [Var], CoreExpr)]
alts')
tcIfaceExpr (IfaceLet (IfaceNonRec (IfLetBndr IfLclName
fs IfaceType
ty IfaceIdInfo
info IfaceJoinInfo
ji) IfaceExpr
rhs) IfaceExpr
body)
= do { Name
name <- OccName -> TcRnIf IfGblEnv IfLclEnv Name
newIfaceName (IfLclName -> OccName
mkVarOccFS IfLclName
fs)
; Type
ty' <- IfaceType -> IfL Type
tcIfaceType IfaceType
ty
; IdInfo
id_info <- Bool -> TopLevelFlag -> Name -> Type -> IfaceIdInfo -> IfL IdInfo
tcIdInfo Bool
False
TopLevelFlag
NotTopLevel Name
name Type
ty' IfaceIdInfo
info
; let id :: Var
id = HasDebugCallStack => Name -> Type -> Type -> IdInfo -> Var
Name -> Type -> Type -> IdInfo -> Var
mkLocalIdWithInfo Name
name Type
Many Type
ty' IdInfo
id_info
Var -> Maybe Int -> Var
`asJoinId_maybe` IfaceJoinInfo -> Maybe Int
tcJoinInfo IfaceJoinInfo
ji
; CoreExpr
rhs' <- IfaceExpr -> IOEnv (Env IfGblEnv IfLclEnv) CoreExpr
tcIfaceExpr IfaceExpr
rhs
; CoreExpr
body' <- [Var]
-> IOEnv (Env IfGblEnv IfLclEnv) CoreExpr
-> IOEnv (Env IfGblEnv IfLclEnv) CoreExpr
forall a. [Var] -> IfL a -> IfL a
extendIfaceIdEnv [Var
id] (IfaceExpr -> IOEnv (Env IfGblEnv IfLclEnv) CoreExpr
tcIfaceExpr IfaceExpr
body)
; CoreExpr -> IOEnv (Env IfGblEnv IfLclEnv) CoreExpr
forall (m :: * -> *) a. Monad m => a -> m a
return (Bind Var -> CoreExpr -> CoreExpr
forall b. Bind b -> Expr b -> Expr b
Let (Var -> CoreExpr -> Bind Var
forall b. b -> Expr b -> Bind b
NonRec Var
id CoreExpr
rhs') CoreExpr
body') }
tcIfaceExpr (IfaceLet (IfaceRec [(IfaceLetBndr, IfaceExpr)]
pairs) IfaceExpr
body)
= do { [Var]
ids <- (IfaceLetBndr -> IfL Var)
-> [IfaceLetBndr] -> IOEnv (Env IfGblEnv IfLclEnv) [Var]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM IfaceLetBndr -> IfL Var
tc_rec_bndr (((IfaceLetBndr, IfaceExpr) -> IfaceLetBndr)
-> [(IfaceLetBndr, IfaceExpr)] -> [IfaceLetBndr]
forall a b. (a -> b) -> [a] -> [b]
map (IfaceLetBndr, IfaceExpr) -> IfaceLetBndr
forall a b. (a, b) -> a
fst [(IfaceLetBndr, IfaceExpr)]
pairs)
; [Var]
-> IOEnv (Env IfGblEnv IfLclEnv) CoreExpr
-> IOEnv (Env IfGblEnv IfLclEnv) CoreExpr
forall a. [Var] -> IfL a -> IfL a
extendIfaceIdEnv [Var]
ids (IOEnv (Env IfGblEnv IfLclEnv) CoreExpr
-> IOEnv (Env IfGblEnv IfLclEnv) CoreExpr)
-> IOEnv (Env IfGblEnv IfLclEnv) CoreExpr
-> IOEnv (Env IfGblEnv IfLclEnv) CoreExpr
forall a b. (a -> b) -> a -> b
$ do
{ [(Var, CoreExpr)]
pairs' <- ((IfaceLetBndr, IfaceExpr)
-> Var -> IOEnv (Env IfGblEnv IfLclEnv) (Var, CoreExpr))
-> [(IfaceLetBndr, IfaceExpr)]
-> [Var]
-> IOEnv (Env IfGblEnv IfLclEnv) [(Var, CoreExpr)]
forall (m :: * -> *) a b c.
Applicative m =>
(a -> b -> m c) -> [a] -> [b] -> m [c]
zipWithM (IfaceLetBndr, IfaceExpr)
-> Var -> IOEnv (Env IfGblEnv IfLclEnv) (Var, CoreExpr)
tc_pair [(IfaceLetBndr, IfaceExpr)]
pairs [Var]
ids
; CoreExpr
body' <- IfaceExpr -> IOEnv (Env IfGblEnv IfLclEnv) CoreExpr
tcIfaceExpr IfaceExpr
body
; CoreExpr -> IOEnv (Env IfGblEnv IfLclEnv) CoreExpr
forall (m :: * -> *) a. Monad m => a -> m a
return (Bind Var -> CoreExpr -> CoreExpr
forall b. Bind b -> Expr b -> Expr b
Let ([(Var, CoreExpr)] -> Bind Var
forall b. [(b, Expr b)] -> Bind b
Rec [(Var, CoreExpr)]
pairs') CoreExpr
body') } }
where
tc_rec_bndr :: IfaceLetBndr -> IfL Var
tc_rec_bndr (IfLetBndr IfLclName
fs IfaceType
ty IfaceIdInfo
_ IfaceJoinInfo
ji)
= do { Name
name <- OccName -> TcRnIf IfGblEnv IfLclEnv Name
newIfaceName (IfLclName -> OccName
mkVarOccFS IfLclName
fs)
; Type
ty' <- IfaceType -> IfL Type
tcIfaceType IfaceType
ty
; Var -> IfL Var
forall (m :: * -> *) a. Monad m => a -> m a
return (HasDebugCallStack => Name -> Type -> Type -> Var
Name -> Type -> Type -> Var
mkLocalId Name
name Type
Many Type
ty' Var -> Maybe Int -> Var
`asJoinId_maybe` IfaceJoinInfo -> Maybe Int
tcJoinInfo IfaceJoinInfo
ji) }
tc_pair :: (IfaceLetBndr, IfaceExpr)
-> Var -> IOEnv (Env IfGblEnv IfLclEnv) (Var, CoreExpr)
tc_pair (IfLetBndr IfLclName
_ IfaceType
_ IfaceIdInfo
info IfaceJoinInfo
_, IfaceExpr
rhs) Var
id
= do { CoreExpr
rhs' <- IfaceExpr -> IOEnv (Env IfGblEnv IfLclEnv) CoreExpr
tcIfaceExpr IfaceExpr
rhs
; IdInfo
id_info <- Bool -> TopLevelFlag -> Name -> Type -> IfaceIdInfo -> IfL IdInfo
tcIdInfo Bool
False
TopLevelFlag
NotTopLevel (Var -> Name
idName Var
id) (Var -> Type
idType Var
id) IfaceIdInfo
info
; (Var, CoreExpr) -> IOEnv (Env IfGblEnv IfLclEnv) (Var, CoreExpr)
forall (m :: * -> *) a. Monad m => a -> m a
return (Var -> IdInfo -> Var
setIdInfo Var
id IdInfo
id_info, CoreExpr
rhs') }
tcIfaceExpr (IfaceTick IfaceTickish
tickish IfaceExpr
expr) = do
CoreExpr
expr' <- IfaceExpr -> IOEnv (Env IfGblEnv IfLclEnv) CoreExpr
tcIfaceExpr IfaceExpr
expr
Int
dbgLvl <- (DynFlags -> Int)
-> IOEnv (Env IfGblEnv IfLclEnv) DynFlags
-> IOEnv (Env IfGblEnv IfLclEnv) Int
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap DynFlags -> Int
debugLevel IOEnv (Env IfGblEnv IfLclEnv) DynFlags
forall (m :: * -> *). HasDynFlags m => m DynFlags
getDynFlags
case IfaceTickish
tickish of
IfaceSource{} | Int
dbgLvl Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
0
-> CoreExpr -> IOEnv (Env IfGblEnv IfLclEnv) CoreExpr
forall (m :: * -> *) a. Monad m => a -> m a
return CoreExpr
expr'
IfaceTickish
_otherwise -> do
Tickish Var
tickish' <- IfaceTickish -> IfM IfLclEnv (Tickish Var)
forall lcl. IfaceTickish -> IfM lcl (Tickish Var)
tcIfaceTickish IfaceTickish
tickish
CoreExpr -> IOEnv (Env IfGblEnv IfLclEnv) CoreExpr
forall (m :: * -> *) a. Monad m => a -> m a
return (Tickish Var -> CoreExpr -> CoreExpr
forall b. Tickish Var -> Expr b -> Expr b
Tick Tickish Var
tickish' CoreExpr
expr')
tcIfaceTickish :: IfaceTickish -> IfM lcl (Tickish Id)
tcIfaceTickish :: forall lcl. IfaceTickish -> IfM lcl (Tickish Var)
tcIfaceTickish (IfaceHpcTick Module
modl Int
ix) = Tickish Var -> IOEnv (Env IfGblEnv lcl) (Tickish Var)
forall (m :: * -> *) a. Monad m => a -> m a
return (Module -> Int -> Tickish Var
forall id. Module -> Int -> Tickish id
HpcTick Module
modl Int
ix)
tcIfaceTickish (IfaceSCC CostCentre
cc Bool
tick Bool
push) = Tickish Var -> IOEnv (Env IfGblEnv lcl) (Tickish Var)
forall (m :: * -> *) a. Monad m => a -> m a
return (CostCentre -> Bool -> Bool -> Tickish Var
forall id. CostCentre -> Bool -> Bool -> Tickish id
ProfNote CostCentre
cc Bool
tick Bool
push)
tcIfaceTickish (IfaceSource RealSrcSpan
src String
name) = Tickish Var -> IOEnv (Env IfGblEnv lcl) (Tickish Var)
forall (m :: * -> *) a. Monad m => a -> m a
return (RealSrcSpan -> String -> Tickish Var
forall id. RealSrcSpan -> String -> Tickish id
SourceNote RealSrcSpan
src String
name)
tcIfaceLit :: Literal -> IfL Literal
tcIfaceLit :: Literal -> IfL Literal
tcIfaceLit Literal
lit = Literal -> IfL Literal
forall (m :: * -> *) a. Monad m => a -> m a
return Literal
lit
tcIfaceAlt :: CoreExpr -> Mult -> (TyCon, [Type])
-> (IfaceConAlt, [FastString], IfaceExpr)
-> IfL (AltCon, [TyVar], CoreExpr)
tcIfaceAlt :: CoreExpr
-> Type
-> (TyCon, ThetaType)
-> IfaceAlt
-> IOEnv (Env IfGblEnv IfLclEnv) (AltCon, [Var], CoreExpr)
tcIfaceAlt CoreExpr
_ Type
_ (TyCon, ThetaType)
_ (IfaceConAlt
IfaceDefault, [IfLclName]
names, IfaceExpr
rhs)
= ASSERT( null names ) do
rhs' <- tcIfaceExpr rhs
return (DEFAULT, [], rhs')
tcIfaceAlt CoreExpr
_ Type
_ (TyCon, ThetaType)
_ (IfaceLitAlt Literal
lit, [IfLclName]
names, IfaceExpr
rhs)
= ASSERT( null names ) do
lit' <- tcIfaceLit lit
rhs' <- tcIfaceExpr rhs
return (LitAlt lit', [], rhs')
tcIfaceAlt CoreExpr
scrut Type
mult (TyCon
tycon, ThetaType
inst_tys) (IfaceDataAlt Name
data_occ, [IfLclName]
arg_strs, IfaceExpr
rhs)
= do { DataCon
con <- Name -> IOEnv (Env IfGblEnv IfLclEnv) DataCon
tcIfaceDataCon Name
data_occ
; Bool -> TcRnIf IfGblEnv IfLclEnv () -> TcRnIf IfGblEnv IfLclEnv ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (Bool
debugIsOn Bool -> Bool -> Bool
&& Bool -> Bool
not (DataCon
con DataCon -> [DataCon] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` TyCon -> [DataCon]
tyConDataCons TyCon
tycon))
(SDoc -> TcRnIf IfGblEnv IfLclEnv ()
forall a. SDoc -> IfL a
failIfM (CoreExpr -> SDoc
forall a. Outputable a => a -> SDoc
ppr CoreExpr
scrut SDoc -> SDoc -> SDoc
$$ DataCon -> SDoc
forall a. Outputable a => a -> SDoc
ppr DataCon
con SDoc -> SDoc -> SDoc
$$ TyCon -> SDoc
forall a. Outputable a => a -> SDoc
ppr TyCon
tycon SDoc -> SDoc -> SDoc
$$ [DataCon] -> SDoc
forall a. Outputable a => a -> SDoc
ppr (TyCon -> [DataCon]
tyConDataCons TyCon
tycon)))
; Type
-> DataCon
-> ThetaType
-> [IfLclName]
-> IfaceExpr
-> IOEnv (Env IfGblEnv IfLclEnv) (AltCon, [Var], CoreExpr)
tcIfaceDataAlt Type
mult DataCon
con ThetaType
inst_tys [IfLclName]
arg_strs IfaceExpr
rhs }
tcIfaceDataAlt :: Mult -> DataCon -> [Type] -> [FastString] -> IfaceExpr
-> IfL (AltCon, [TyVar], CoreExpr)
tcIfaceDataAlt :: Type
-> DataCon
-> ThetaType
-> [IfLclName]
-> IfaceExpr
-> IOEnv (Env IfGblEnv IfLclEnv) (AltCon, [Var], CoreExpr)
tcIfaceDataAlt Type
mult DataCon
con ThetaType
inst_tys [IfLclName]
arg_strs IfaceExpr
rhs
= do { UniqSupply
us <- TcRnIf IfGblEnv IfLclEnv UniqSupply
forall gbl lcl. TcRnIf gbl lcl UniqSupply
newUniqueSupply
; let uniqs :: [Unique]
uniqs = UniqSupply -> [Unique]
uniqsFromSupply UniqSupply
us
; let ([Var]
ex_tvs, [Var]
arg_ids)
= [IfLclName]
-> [Unique] -> Type -> DataCon -> ThetaType -> FunDep Var
dataConRepFSInstPat [IfLclName]
arg_strs [Unique]
uniqs Type
mult DataCon
con ThetaType
inst_tys
; CoreExpr
rhs' <- [Var]
-> IOEnv (Env IfGblEnv IfLclEnv) CoreExpr
-> IOEnv (Env IfGblEnv IfLclEnv) CoreExpr
forall a. [Var] -> IfL a -> IfL a
extendIfaceEnvs [Var]
ex_tvs (IOEnv (Env IfGblEnv IfLclEnv) CoreExpr
-> IOEnv (Env IfGblEnv IfLclEnv) CoreExpr)
-> IOEnv (Env IfGblEnv IfLclEnv) CoreExpr
-> IOEnv (Env IfGblEnv IfLclEnv) CoreExpr
forall a b. (a -> b) -> a -> b
$
[Var]
-> IOEnv (Env IfGblEnv IfLclEnv) CoreExpr
-> IOEnv (Env IfGblEnv IfLclEnv) CoreExpr
forall a. [Var] -> IfL a -> IfL a
extendIfaceIdEnv [Var]
arg_ids (IOEnv (Env IfGblEnv IfLclEnv) CoreExpr
-> IOEnv (Env IfGblEnv IfLclEnv) CoreExpr)
-> IOEnv (Env IfGblEnv IfLclEnv) CoreExpr
-> IOEnv (Env IfGblEnv IfLclEnv) CoreExpr
forall a b. (a -> b) -> a -> b
$
IfaceExpr -> IOEnv (Env IfGblEnv IfLclEnv) CoreExpr
tcIfaceExpr IfaceExpr
rhs
; (AltCon, [Var], CoreExpr)
-> IOEnv (Env IfGblEnv IfLclEnv) (AltCon, [Var], CoreExpr)
forall (m :: * -> *) a. Monad m => a -> m a
return (DataCon -> AltCon
DataAlt DataCon
con, [Var]
ex_tvs [Var] -> [Var] -> [Var]
forall a. [a] -> [a] -> [a]
++ [Var]
arg_ids, CoreExpr
rhs') }
tcIdDetails :: Type -> IfaceIdDetails -> IfL IdDetails
tcIdDetails :: Type -> IfaceIdDetails -> IfL IdDetails
tcIdDetails Type
_ IfaceIdDetails
IfVanillaId = IdDetails -> IfL IdDetails
forall (m :: * -> *) a. Monad m => a -> m a
return IdDetails
VanillaId
tcIdDetails Type
ty IfaceIdDetails
IfDFunId
= IdDetails -> IfL IdDetails
forall (m :: * -> *) a. Monad m => a -> m a
return (Bool -> IdDetails
DFunId (TyCon -> Bool
isNewTyCon (Class -> TyCon
classTyCon Class
cls)))
where
([Var]
_, ThetaType
_, Class
cls, ThetaType
_) = Type -> ([Var], ThetaType, Class, ThetaType)
tcSplitDFunTy Type
ty
tcIdDetails Type
_ (IfRecSelId Either IfaceTyCon IfaceDecl
tc Bool
naughty)
= do { RecSelParent
tc' <- (IfaceTyCon -> IOEnv (Env IfGblEnv IfLclEnv) RecSelParent)
-> (IfaceDecl -> IOEnv (Env IfGblEnv IfLclEnv) RecSelParent)
-> Either IfaceTyCon IfaceDecl
-> IOEnv (Env IfGblEnv IfLclEnv) RecSelParent
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either ((TyCon -> RecSelParent)
-> IOEnv (Env IfGblEnv IfLclEnv) TyCon
-> IOEnv (Env IfGblEnv IfLclEnv) RecSelParent
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap TyCon -> RecSelParent
RecSelData (IOEnv (Env IfGblEnv IfLclEnv) TyCon
-> IOEnv (Env IfGblEnv IfLclEnv) RecSelParent)
-> (IfaceTyCon -> IOEnv (Env IfGblEnv IfLclEnv) TyCon)
-> IfaceTyCon
-> IOEnv (Env IfGblEnv IfLclEnv) RecSelParent
forall b c a. (b -> c) -> (a -> b) -> a -> c
. IfaceTyCon -> IOEnv (Env IfGblEnv IfLclEnv) TyCon
tcIfaceTyCon)
((TyThing -> RecSelParent)
-> IfL TyThing -> IOEnv (Env IfGblEnv IfLclEnv) RecSelParent
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (PatSyn -> RecSelParent
RecSelPatSyn (PatSyn -> RecSelParent)
-> (TyThing -> PatSyn) -> TyThing -> RecSelParent
forall b c a. (b -> c) -> (a -> b) -> a -> c
. TyThing -> PatSyn
tyThingPatSyn) (IfL TyThing -> IOEnv (Env IfGblEnv IfLclEnv) RecSelParent)
-> (IfaceDecl -> IfL TyThing)
-> IfaceDecl
-> IOEnv (Env IfGblEnv IfLclEnv) RecSelParent
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Bool -> IfaceDecl -> IfL TyThing
tcIfaceDecl Bool
False)
Either IfaceTyCon IfaceDecl
tc
; IdDetails -> IfL IdDetails
forall (m :: * -> *) a. Monad m => a -> m a
return (RecSelId :: RecSelParent -> Bool -> IdDetails
RecSelId { sel_tycon :: RecSelParent
sel_tycon = RecSelParent
tc', sel_naughty :: Bool
sel_naughty = Bool
naughty }) }
where
tyThingPatSyn :: TyThing -> PatSyn
tyThingPatSyn (AConLike (PatSynCon PatSyn
ps)) = PatSyn
ps
tyThingPatSyn TyThing
_ = String -> PatSyn
forall a. String -> a
panic String
"tcIdDetails: expecting patsyn"
tcIdInfo :: Bool -> TopLevelFlag -> Name -> Type -> IfaceIdInfo -> IfL IdInfo
tcIdInfo :: Bool -> TopLevelFlag -> Name -> Type -> IfaceIdInfo -> IfL IdInfo
tcIdInfo Bool
ignore_prags TopLevelFlag
toplvl Name
name Type
ty IfaceIdInfo
info = do
IfLclEnv
lcl_env <- TcRnIf IfGblEnv IfLclEnv IfLclEnv
forall gbl lcl. TcRnIf gbl lcl lcl
getLclEnv
let init_info :: IdInfo
init_info = if IfLclEnv -> IsBootInterface
if_boot IfLclEnv
lcl_env IsBootInterface -> IsBootInterface -> Bool
forall a. Eq a => a -> a -> Bool
== IsBootInterface
IsBoot
then IdInfo
vanillaIdInfo IdInfo -> Unfolding -> IdInfo
`setUnfoldingInfo` Unfolding
BootUnfolding
else IdInfo
vanillaIdInfo
(IdInfo -> IfaceInfoItem -> IfL IdInfo)
-> IdInfo -> IfaceIdInfo -> IfL IdInfo
forall (t :: * -> *) (m :: * -> *) b a.
(Foldable t, Monad m) =>
(b -> a -> m b) -> b -> t a -> m b
foldlM IdInfo -> IfaceInfoItem -> IfL IdInfo
tcPrag IdInfo
init_info (IfaceIdInfo -> IfaceIdInfo
needed_prags IfaceIdInfo
info)
where
needed_prags :: [IfaceInfoItem] -> [IfaceInfoItem]
needed_prags :: IfaceIdInfo -> IfaceIdInfo
needed_prags IfaceIdInfo
items
| Bool -> Bool
not Bool
ignore_prags = IfaceIdInfo
items
| Bool
otherwise = (IfaceInfoItem -> Bool) -> IfaceIdInfo -> IfaceIdInfo
forall a. (a -> Bool) -> [a] -> [a]
filter IfaceInfoItem -> Bool
need_prag IfaceIdInfo
items
need_prag :: IfaceInfoItem -> Bool
need_prag :: IfaceInfoItem -> Bool
need_prag (HsUnfold Bool
_ (IfCompulsory {})) = Bool
True
need_prag IfaceInfoItem
_ = Bool
False
tcPrag :: IdInfo -> IfaceInfoItem -> IfL IdInfo
tcPrag :: IdInfo -> IfaceInfoItem -> IfL IdInfo
tcPrag IdInfo
info IfaceInfoItem
HsNoCafRefs = IdInfo -> IfL IdInfo
forall (m :: * -> *) a. Monad m => a -> m a
return (IdInfo
info IdInfo -> CafInfo -> IdInfo
`setCafInfo` CafInfo
NoCafRefs)
tcPrag IdInfo
info (HsArity Int
arity) = IdInfo -> IfL IdInfo
forall (m :: * -> *) a. Monad m => a -> m a
return (IdInfo
info IdInfo -> Int -> IdInfo
`setArityInfo` Int
arity)
tcPrag IdInfo
info (HsStrictness StrictSig
str) = IdInfo -> IfL IdInfo
forall (m :: * -> *) a. Monad m => a -> m a
return (IdInfo
info IdInfo -> StrictSig -> IdInfo
`setStrictnessInfo` StrictSig
str)
tcPrag IdInfo
info (HsCpr CprSig
cpr) = IdInfo -> IfL IdInfo
forall (m :: * -> *) a. Monad m => a -> m a
return (IdInfo
info IdInfo -> CprSig -> IdInfo
`setCprInfo` CprSig
cpr)
tcPrag IdInfo
info (HsInline InlinePragma
prag) = IdInfo -> IfL IdInfo
forall (m :: * -> *) a. Monad m => a -> m a
return (IdInfo
info IdInfo -> InlinePragma -> IdInfo
`setInlinePragInfo` InlinePragma
prag)
tcPrag IdInfo
info IfaceInfoItem
HsLevity = IdInfo -> IfL IdInfo
forall (m :: * -> *) a. Monad m => a -> m a
return (IdInfo
info HasDebugCallStack => IdInfo -> Type -> IdInfo
IdInfo -> Type -> IdInfo
`setNeverLevPoly` Type
ty)
tcPrag IdInfo
info (HsLFInfo IfaceLFInfo
lf_info) = do
LambdaFormInfo
lf_info <- IfaceLFInfo -> IfL LambdaFormInfo
tcLFInfo IfaceLFInfo
lf_info
IdInfo -> IfL IdInfo
forall (m :: * -> *) a. Monad m => a -> m a
return (IdInfo
info IdInfo -> LambdaFormInfo -> IdInfo
`setLFInfo` LambdaFormInfo
lf_info)
tcPrag IdInfo
info (HsUnfold Bool
lb IfaceUnfolding
if_unf)
= do { Unfolding
unf <- TopLevelFlag
-> Name -> Type -> IdInfo -> IfaceUnfolding -> IfL Unfolding
tcUnfolding TopLevelFlag
toplvl Name
name Type
ty IdInfo
info IfaceUnfolding
if_unf
; let info1 :: IdInfo
info1 | Bool
lb = IdInfo
info IdInfo -> OccInfo -> IdInfo
`setOccInfo` OccInfo
strongLoopBreaker
| Bool
otherwise = IdInfo
info
; IdInfo -> IfL IdInfo
forall (m :: * -> *) a. Monad m => a -> m a
return (IdInfo
info1 IdInfo -> Unfolding -> IdInfo
`setUnfoldingInfo` Unfolding
unf) }
tcJoinInfo :: IfaceJoinInfo -> Maybe JoinArity
tcJoinInfo :: IfaceJoinInfo -> Maybe Int
tcJoinInfo (IfaceJoinPoint Int
ar) = Int -> Maybe Int
forall a. a -> Maybe a
Just Int
ar
tcJoinInfo IfaceJoinInfo
IfaceNotJoinPoint = Maybe Int
forall a. Maybe a
Nothing
tcLFInfo :: IfaceLFInfo -> IfL LambdaFormInfo
tcLFInfo :: IfaceLFInfo -> IfL LambdaFormInfo
tcLFInfo IfaceLFInfo
lfi = case IfaceLFInfo
lfi of
IfLFReEntrant Int
rep_arity ->
LambdaFormInfo -> IfL LambdaFormInfo
forall (m :: * -> *) a. Monad m => a -> m a
return (TopLevelFlag -> Int -> Bool -> ArgDescr -> LambdaFormInfo
LFReEntrant TopLevelFlag
TopLevel Int
rep_arity Bool
True ArgDescr
ArgUnknown)
IfLFThunk Bool
updatable Bool
mb_fun ->
LambdaFormInfo -> IfL LambdaFormInfo
forall (m :: * -> *) a. Monad m => a -> m a
return (TopLevelFlag
-> Bool -> Bool -> StandardFormInfo -> Bool -> LambdaFormInfo
LFThunk TopLevelFlag
TopLevel Bool
True Bool
updatable StandardFormInfo
NonStandardThunk Bool
mb_fun)
IfaceLFInfo
IfLFUnlifted ->
LambdaFormInfo -> IfL LambdaFormInfo
forall (m :: * -> *) a. Monad m => a -> m a
return LambdaFormInfo
LFUnlifted
IfLFCon Name
con_name ->
DataCon -> LambdaFormInfo
LFCon (DataCon -> LambdaFormInfo)
-> IOEnv (Env IfGblEnv IfLclEnv) DataCon -> IfL LambdaFormInfo
forall (m :: * -> *) a b. Monad m => (a -> b) -> m a -> m b
<$!> Name -> IOEnv (Env IfGblEnv IfLclEnv) DataCon
tcIfaceDataCon Name
con_name
IfLFUnknown Bool
fun_flag ->
LambdaFormInfo -> IfL LambdaFormInfo
forall (m :: * -> *) a. Monad m => a -> m a
return (Bool -> LambdaFormInfo
LFUnknown Bool
fun_flag)
tcUnfolding :: TopLevelFlag -> Name -> Type -> IdInfo -> IfaceUnfolding -> IfL Unfolding
tcUnfolding :: TopLevelFlag
-> Name -> Type -> IdInfo -> IfaceUnfolding -> IfL Unfolding
tcUnfolding TopLevelFlag
toplvl Name
name Type
_ IdInfo
info (IfCoreUnfold Bool
stable IfaceExpr
if_expr)
= do { DynFlags
dflags <- IOEnv (Env IfGblEnv IfLclEnv) DynFlags
forall (m :: * -> *). HasDynFlags m => m DynFlags
getDynFlags
; Maybe CoreExpr
mb_expr <- Bool -> TopLevelFlag -> Name -> IfaceExpr -> IfL (Maybe CoreExpr)
tcPragExpr Bool
False TopLevelFlag
toplvl Name
name IfaceExpr
if_expr
; let unf_src :: UnfoldingSource
unf_src | Bool
stable = UnfoldingSource
InlineStable
| Bool
otherwise = UnfoldingSource
InlineRhs
; Unfolding -> IfL Unfolding
forall (m :: * -> *) a. Monad m => a -> m a
return (Unfolding -> IfL Unfolding) -> Unfolding -> IfL Unfolding
forall a b. (a -> b) -> a -> b
$ case Maybe CoreExpr
mb_expr of
Maybe CoreExpr
Nothing -> Unfolding
NoUnfolding
Just CoreExpr
expr -> DynFlags -> UnfoldingSource -> StrictSig -> CoreExpr -> Unfolding
mkFinalUnfolding DynFlags
dflags UnfoldingSource
unf_src StrictSig
strict_sig CoreExpr
expr
}
where
strict_sig :: StrictSig
strict_sig = IdInfo -> StrictSig
strictnessInfo IdInfo
info
tcUnfolding TopLevelFlag
toplvl Name
name Type
_ IdInfo
_ (IfCompulsory IfaceExpr
if_expr)
= do { Maybe CoreExpr
mb_expr <- Bool -> TopLevelFlag -> Name -> IfaceExpr -> IfL (Maybe CoreExpr)
tcPragExpr Bool
True TopLevelFlag
toplvl Name
name IfaceExpr
if_expr
; Unfolding -> IfL Unfolding
forall (m :: * -> *) a. Monad m => a -> m a
return (case Maybe CoreExpr
mb_expr of
Maybe CoreExpr
Nothing -> Unfolding
NoUnfolding
Just CoreExpr
expr -> CoreExpr -> Unfolding
mkCompulsoryUnfolding CoreExpr
expr) }
tcUnfolding TopLevelFlag
toplvl Name
name Type
_ IdInfo
_ (IfInlineRule Int
arity Bool
unsat_ok Bool
boring_ok IfaceExpr
if_expr)
= do { Maybe CoreExpr
mb_expr <- Bool -> TopLevelFlag -> Name -> IfaceExpr -> IfL (Maybe CoreExpr)
tcPragExpr Bool
False TopLevelFlag
toplvl Name
name IfaceExpr
if_expr
; Unfolding -> IfL Unfolding
forall (m :: * -> *) a. Monad m => a -> m a
return (case Maybe CoreExpr
mb_expr of
Maybe CoreExpr
Nothing -> Unfolding
NoUnfolding
Just CoreExpr
expr -> UnfoldingSource
-> Bool -> CoreExpr -> UnfoldingGuidance -> Unfolding
mkCoreUnfolding UnfoldingSource
InlineStable Bool
True CoreExpr
expr UnfoldingGuidance
guidance )}
where
guidance :: UnfoldingGuidance
guidance = UnfWhen :: Int -> Bool -> Bool -> UnfoldingGuidance
UnfWhen { ug_arity :: Int
ug_arity = Int
arity, ug_unsat_ok :: Bool
ug_unsat_ok = Bool
unsat_ok, ug_boring_ok :: Bool
ug_boring_ok = Bool
boring_ok }
tcUnfolding TopLevelFlag
_toplvl Name
name Type
dfun_ty IdInfo
_ (IfDFunUnfold [IfaceBndr]
bs [IfaceExpr]
ops)
= [IfaceBndr] -> ([Var] -> IfL Unfolding) -> IfL Unfolding
forall a. [IfaceBndr] -> ([Var] -> IfL a) -> IfL a
bindIfaceBndrs [IfaceBndr]
bs (([Var] -> IfL Unfolding) -> IfL Unfolding)
-> ([Var] -> IfL Unfolding) -> IfL Unfolding
forall a b. (a -> b) -> a -> b
$ \ [Var]
bs' ->
do { Maybe [CoreExpr]
mb_ops1 <- SDoc
-> IOEnv (Env IfGblEnv IfLclEnv) [CoreExpr]
-> IfL (Maybe [CoreExpr])
forall a. SDoc -> IfL a -> IfL (Maybe a)
forkM_maybe SDoc
doc (IOEnv (Env IfGblEnv IfLclEnv) [CoreExpr]
-> IfL (Maybe [CoreExpr]))
-> IOEnv (Env IfGblEnv IfLclEnv) [CoreExpr]
-> IfL (Maybe [CoreExpr])
forall a b. (a -> b) -> a -> b
$ (IfaceExpr -> IOEnv (Env IfGblEnv IfLclEnv) CoreExpr)
-> [IfaceExpr] -> IOEnv (Env IfGblEnv IfLclEnv) [CoreExpr]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM IfaceExpr -> IOEnv (Env IfGblEnv IfLclEnv) CoreExpr
tcIfaceExpr [IfaceExpr]
ops
; Unfolding -> IfL Unfolding
forall (m :: * -> *) a. Monad m => a -> m a
return (case Maybe [CoreExpr]
mb_ops1 of
Maybe [CoreExpr]
Nothing -> Unfolding
noUnfolding
Just [CoreExpr]
ops1 -> [Var] -> DataCon -> [CoreExpr] -> Unfolding
mkDFunUnfolding [Var]
bs' (Class -> DataCon
classDataCon Class
cls) [CoreExpr]
ops1) }
where
doc :: SDoc
doc = String -> SDoc
text String
"Class ops for dfun" SDoc -> SDoc -> SDoc
<+> Name -> SDoc
forall a. Outputable a => a -> SDoc
ppr Name
name
([Var]
_, ThetaType
_, Class
cls, ThetaType
_) = Type -> ([Var], ThetaType, Class, ThetaType)
tcSplitDFunTy Type
dfun_ty
tcPragExpr :: Bool
-> TopLevelFlag -> Name -> IfaceExpr -> IfL (Maybe CoreExpr)
tcPragExpr :: Bool -> TopLevelFlag -> Name -> IfaceExpr -> IfL (Maybe CoreExpr)
tcPragExpr Bool
is_compulsory TopLevelFlag
toplvl Name
name IfaceExpr
expr
= SDoc
-> IOEnv (Env IfGblEnv IfLclEnv) CoreExpr -> IfL (Maybe CoreExpr)
forall a. SDoc -> IfL a -> IfL (Maybe a)
forkM_maybe SDoc
doc (IOEnv (Env IfGblEnv IfLclEnv) CoreExpr -> IfL (Maybe CoreExpr))
-> IOEnv (Env IfGblEnv IfLclEnv) CoreExpr -> IfL (Maybe CoreExpr)
forall a b. (a -> b) -> a -> b
$ do
CoreExpr
core_expr' <- IfaceExpr -> IOEnv (Env IfGblEnv IfLclEnv) CoreExpr
tcIfaceExpr IfaceExpr
expr
Bool -> TcRnIf IfGblEnv IfLclEnv () -> TcRnIf IfGblEnv IfLclEnv ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (TopLevelFlag -> Bool
isTopLevel TopLevelFlag
toplvl) (TcRnIf IfGblEnv IfLclEnv () -> TcRnIf IfGblEnv IfLclEnv ())
-> TcRnIf IfGblEnv IfLclEnv () -> TcRnIf IfGblEnv IfLclEnv ()
forall a b. (a -> b) -> a -> b
$
GeneralFlag
-> TcRnIf IfGblEnv IfLclEnv () -> TcRnIf IfGblEnv IfLclEnv ()
forall gbl lcl.
GeneralFlag -> TcRnIf gbl lcl () -> TcRnIf gbl lcl ()
whenGOptM GeneralFlag
Opt_DoCoreLinting (TcRnIf IfGblEnv IfLclEnv () -> TcRnIf IfGblEnv IfLclEnv ())
-> TcRnIf IfGblEnv IfLclEnv () -> TcRnIf IfGblEnv IfLclEnv ()
forall a b. (a -> b) -> a -> b
$ do
VarSet
in_scope <- IfL VarSet
get_in_scope
DynFlags
dflags <- IOEnv (Env IfGblEnv IfLclEnv) DynFlags
forall (m :: * -> *). HasDynFlags m => m DynFlags
getDynFlags
case Bool -> DynFlags -> SrcLoc -> VarSet -> CoreExpr -> Maybe SDoc
lintUnfolding Bool
is_compulsory DynFlags
dflags SrcLoc
noSrcLoc VarSet
in_scope CoreExpr
core_expr' of
Maybe SDoc
Nothing -> () -> TcRnIf IfGblEnv IfLclEnv ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
Just SDoc
fail_msg -> do { Module
mod <- IfL Module
getIfModule
; String -> SDoc -> TcRnIf IfGblEnv IfLclEnv ()
forall a. HasCallStack => String -> SDoc -> a
pprPanic String
"Iface Lint failure"
([SDoc] -> SDoc
vcat [ String -> SDoc
text String
"In interface for" SDoc -> SDoc -> SDoc
<+> Module -> SDoc
forall a. Outputable a => a -> SDoc
ppr Module
mod
, SDoc -> Int -> SDoc -> SDoc
hang SDoc
doc Int
2 SDoc
fail_msg
, Name -> SDoc
forall a. Outputable a => a -> SDoc
ppr Name
name SDoc -> SDoc -> SDoc
<+> SDoc
equals SDoc -> SDoc -> SDoc
<+> CoreExpr -> SDoc
forall a. Outputable a => a -> SDoc
ppr CoreExpr
core_expr'
, String -> SDoc
text String
"Iface expr =" SDoc -> SDoc -> SDoc
<+> IfaceExpr -> SDoc
forall a. Outputable a => a -> SDoc
ppr IfaceExpr
expr ]) }
CoreExpr -> IOEnv (Env IfGblEnv IfLclEnv) CoreExpr
forall (m :: * -> *) a. Monad m => a -> m a
return CoreExpr
core_expr'
where
doc :: SDoc
doc = Bool -> SDoc -> SDoc
ppWhen Bool
is_compulsory (String -> SDoc
text String
"Compulsory") SDoc -> SDoc -> SDoc
<+>
String -> SDoc
text String
"Unfolding of" SDoc -> SDoc -> SDoc
<+> Name -> SDoc
forall a. Outputable a => a -> SDoc
ppr Name
name
get_in_scope :: IfL VarSet
get_in_scope :: IfL VarSet
get_in_scope
= do { (IfGblEnv
gbl_env, IfLclEnv
lcl_env) <- TcRnIf IfGblEnv IfLclEnv (IfGblEnv, IfLclEnv)
forall gbl lcl. TcRnIf gbl lcl (gbl, lcl)
getEnvs
; [Var]
rec_ids <- case IfGblEnv -> Maybe (Module, IfG TypeEnv)
if_rec_types IfGblEnv
gbl_env of
Maybe (Module, IfG TypeEnv)
Nothing -> [Var] -> IOEnv (Env IfGblEnv IfLclEnv) [Var]
forall (m :: * -> *) a. Monad m => a -> m a
return []
Just (Module
_, IfG TypeEnv
get_env) -> do
{ TypeEnv
type_env <- () -> IfG TypeEnv -> IOEnv (Env IfGblEnv IfLclEnv) TypeEnv
forall lcl' gbl a lcl.
lcl' -> TcRnIf gbl lcl' a -> TcRnIf gbl lcl a
setLclEnv () IfG TypeEnv
get_env
; [Var] -> IOEnv (Env IfGblEnv IfLclEnv) [Var]
forall (m :: * -> *) a. Monad m => a -> m a
return (TypeEnv -> [Var]
typeEnvIds TypeEnv
type_env) }
; VarSet -> IfL VarSet
forall (m :: * -> *) a. Monad m => a -> m a
return (UniqFM IfLclName Var -> VarSet
bindingsVars (IfLclEnv -> UniqFM IfLclName Var
if_tv_env IfLclEnv
lcl_env) VarSet -> VarSet -> VarSet
`unionVarSet`
UniqFM IfLclName Var -> VarSet
bindingsVars (IfLclEnv -> UniqFM IfLclName Var
if_id_env IfLclEnv
lcl_env) VarSet -> VarSet -> VarSet
`unionVarSet`
[Var] -> VarSet
mkVarSet [Var]
rec_ids) }
bindingsVars :: FastStringEnv Var -> VarSet
bindingsVars :: UniqFM IfLclName Var -> VarSet
bindingsVars UniqFM IfLclName Var
ufm = [Var] -> VarSet
mkVarSet ([Var] -> VarSet) -> [Var] -> VarSet
forall a b. (a -> b) -> a -> b
$ UniqFM IfLclName Var -> [Var]
forall key elt. UniqFM key elt -> [elt]
nonDetEltsUFM UniqFM IfLclName Var
ufm
tcIfaceOneShot :: IfaceOneShot -> OneShotInfo
tcIfaceOneShot :: IfaceOneShot -> OneShotInfo
tcIfaceOneShot IfaceOneShot
IfaceNoOneShot = OneShotInfo
NoOneShotInfo
tcIfaceOneShot IfaceOneShot
IfaceOneShot = OneShotInfo
OneShotLam
tcIfaceGlobal :: Name -> IfL TyThing
tcIfaceGlobal :: Name -> IfL TyThing
tcIfaceGlobal Name
name
| Just TyThing
thing <- Name -> Maybe TyThing
wiredInNameTyThing_maybe Name
name
= do { TyThing -> TcRnIf IfGblEnv IfLclEnv ()
ifCheckWiredInThing TyThing
thing; TyThing -> IfL TyThing
forall (m :: * -> *) a. Monad m => a -> m a
return TyThing
thing }
| Bool
otherwise
= do { IfGblEnv
env <- TcRnIf IfGblEnv IfLclEnv IfGblEnv
forall gbl lcl. TcRnIf gbl lcl gbl
getGblEnv
; case IfGblEnv -> Maybe (Module, IfG TypeEnv)
if_rec_types IfGblEnv
env of {
Just (Module
mod, IfG TypeEnv
get_type_env)
| Module -> Name -> Bool
nameIsLocalOrFrom Module
mod Name
name
-> do
{ TypeEnv
type_env <- () -> IfG TypeEnv -> IOEnv (Env IfGblEnv IfLclEnv) TypeEnv
forall lcl' gbl a lcl.
lcl' -> TcRnIf gbl lcl' a -> TcRnIf gbl lcl a
setLclEnv () IfG TypeEnv
get_type_env
; case TypeEnv -> Name -> Maybe TyThing
forall a. NameEnv a -> Name -> Maybe a
lookupNameEnv TypeEnv
type_env Name
name of
Just TyThing
thing -> TyThing -> IfL TyThing
forall (m :: * -> *) a. Monad m => a -> m a
return TyThing
thing
Maybe TyThing
Nothing -> IfL TyThing
via_external
}
; Maybe (Module, IfG TypeEnv)
_ -> IfL TyThing
via_external }}
where
via_external :: IfL TyThing
via_external = do
{ HscEnv
hsc_env <- TcRnIf IfGblEnv IfLclEnv HscEnv
forall gbl lcl. TcRnIf gbl lcl HscEnv
getTopEnv
; Maybe TyThing
mb_thing <- IO (Maybe TyThing) -> IOEnv (Env IfGblEnv IfLclEnv) (Maybe TyThing)
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (HscEnv -> Name -> IO (Maybe TyThing)
lookupTypeHscEnv HscEnv
hsc_env Name
name)
; case Maybe TyThing
mb_thing of {
Just TyThing
thing -> TyThing -> IfL TyThing
forall (m :: * -> *) a. Monad m => a -> m a
return TyThing
thing ;
Maybe TyThing
Nothing -> do
{ MaybeErr SDoc TyThing
mb_thing <- Name -> IfM IfLclEnv (MaybeErr SDoc TyThing)
forall lcl. Name -> IfM lcl (MaybeErr SDoc TyThing)
importDecl Name
name
; case MaybeErr SDoc TyThing
mb_thing of
Failed SDoc
err -> SDoc -> IfL TyThing
forall a. SDoc -> IfL a
failIfM SDoc
err
Succeeded TyThing
thing -> TyThing -> IfL TyThing
forall (m :: * -> *) a. Monad m => a -> m a
return TyThing
thing
}}}
tcIfaceTyCon :: IfaceTyCon -> IfL TyCon
tcIfaceTyCon :: IfaceTyCon -> IOEnv (Env IfGblEnv IfLclEnv) TyCon
tcIfaceTyCon (IfaceTyCon Name
name IfaceTyConInfo
info)
= do { TyThing
thing <- Name -> IfL TyThing
tcIfaceGlobal Name
name
; TyCon -> IOEnv (Env IfGblEnv IfLclEnv) TyCon
forall (m :: * -> *) a. Monad m => a -> m a
return (TyCon -> IOEnv (Env IfGblEnv IfLclEnv) TyCon)
-> TyCon -> IOEnv (Env IfGblEnv IfLclEnv) TyCon
forall a b. (a -> b) -> a -> b
$ case IfaceTyConInfo -> PromotionFlag
ifaceTyConIsPromoted IfaceTyConInfo
info of
PromotionFlag
NotPromoted -> HasDebugCallStack => TyThing -> TyCon
TyThing -> TyCon
tyThingTyCon TyThing
thing
PromotionFlag
IsPromoted -> DataCon -> TyCon
promoteDataCon (DataCon -> TyCon) -> DataCon -> TyCon
forall a b. (a -> b) -> a -> b
$ HasDebugCallStack => TyThing -> DataCon
TyThing -> DataCon
tyThingDataCon TyThing
thing }
tcIfaceCoAxiom :: Name -> IfL (CoAxiom Branched)
tcIfaceCoAxiom :: Name -> IfL (CoAxiom Branched)
tcIfaceCoAxiom Name
name = do { TyThing
thing <- Name -> IfL TyThing
tcIfaceImplicit Name
name
; CoAxiom Branched -> IfL (CoAxiom Branched)
forall (m :: * -> *) a. Monad m => a -> m a
return (HasDebugCallStack => TyThing -> CoAxiom Branched
TyThing -> CoAxiom Branched
tyThingCoAxiom TyThing
thing) }
tcIfaceCoAxiomRule :: IfLclName -> IfL CoAxiomRule
tcIfaceCoAxiomRule :: IfLclName -> IOEnv (Env IfGblEnv IfLclEnv) CoAxiomRule
tcIfaceCoAxiomRule IfLclName
n
= case IfLclName -> Map IfLclName CoAxiomRule -> Maybe CoAxiomRule
forall k a. Ord k => k -> Map k a -> Maybe a
Map.lookup IfLclName
n Map IfLclName CoAxiomRule
typeNatCoAxiomRules of
Just CoAxiomRule
ax -> CoAxiomRule -> IOEnv (Env IfGblEnv IfLclEnv) CoAxiomRule
forall (m :: * -> *) a. Monad m => a -> m a
return CoAxiomRule
ax
Maybe CoAxiomRule
_ -> String -> SDoc -> IOEnv (Env IfGblEnv IfLclEnv) CoAxiomRule
forall a. HasCallStack => String -> SDoc -> a
pprPanic String
"tcIfaceCoAxiomRule" (IfLclName -> SDoc
forall a. Outputable a => a -> SDoc
ppr IfLclName
n)
tcIfaceDataCon :: Name -> IfL DataCon
tcIfaceDataCon :: Name -> IOEnv (Env IfGblEnv IfLclEnv) DataCon
tcIfaceDataCon Name
name = do { TyThing
thing <- Name -> IfL TyThing
tcIfaceGlobal Name
name
; case TyThing
thing of
AConLike (RealDataCon DataCon
dc) -> DataCon -> IOEnv (Env IfGblEnv IfLclEnv) DataCon
forall (m :: * -> *) a. Monad m => a -> m a
return DataCon
dc
TyThing
_ -> String -> SDoc -> IOEnv (Env IfGblEnv IfLclEnv) DataCon
forall a. HasCallStack => String -> SDoc -> a
pprPanic String
"tcIfaceExtDC" (Name -> SDoc
forall a. Outputable a => a -> SDoc
ppr Name
nameSDoc -> SDoc -> SDoc
$$ TyThing -> SDoc
forall a. Outputable a => a -> SDoc
ppr TyThing
thing) }
tcIfaceExtId :: Name -> IfL Id
tcIfaceExtId :: Name -> IfL Var
tcIfaceExtId Name
name = do { TyThing
thing <- Name -> IfL TyThing
tcIfaceGlobal Name
name
; case TyThing
thing of
AnId Var
id -> Var -> IfL Var
forall (m :: * -> *) a. Monad m => a -> m a
return Var
id
TyThing
_ -> String -> SDoc -> IfL Var
forall a. HasCallStack => String -> SDoc -> a
pprPanic String
"tcIfaceExtId" (Name -> SDoc
forall a. Outputable a => a -> SDoc
ppr Name
nameSDoc -> SDoc -> SDoc
$$ TyThing -> SDoc
forall a. Outputable a => a -> SDoc
ppr TyThing
thing) }
tcIfaceImplicit :: Name -> IfL TyThing
tcIfaceImplicit :: Name -> IfL TyThing
tcIfaceImplicit Name
n = do
IfLclEnv
lcl_env <- TcRnIf IfGblEnv IfLclEnv IfLclEnv
forall gbl lcl. TcRnIf gbl lcl lcl
getLclEnv
case IfLclEnv -> Maybe TypeEnv
if_implicits_env IfLclEnv
lcl_env of
Maybe TypeEnv
Nothing -> Name -> IfL TyThing
tcIfaceGlobal Name
n
Just TypeEnv
tenv ->
case TypeEnv -> Name -> Maybe TyThing
lookupTypeEnv TypeEnv
tenv Name
n of
Maybe TyThing
Nothing -> String -> SDoc -> IfL TyThing
forall a. HasCallStack => String -> SDoc -> a
pprPanic String
"tcIfaceInst" (Name -> SDoc
forall a. Outputable a => a -> SDoc
ppr Name
n SDoc -> SDoc -> SDoc
$$ TypeEnv -> SDoc
forall a. Outputable a => a -> SDoc
ppr TypeEnv
tenv)
Just TyThing
tything -> TyThing -> IfL TyThing
forall (m :: * -> *) a. Monad m => a -> m a
return TyThing
tything
bindIfaceId :: IfaceIdBndr -> (Id -> IfL a) -> IfL a
bindIfaceId :: forall a. IfaceIdBndr -> (Var -> IfL a) -> IfL a
bindIfaceId (IfaceType
w, IfLclName
fs, IfaceType
ty) Var -> IfL a
thing_inside
= do { Name
name <- OccName -> TcRnIf IfGblEnv IfLclEnv Name
newIfaceName (IfLclName -> OccName
mkVarOccFS IfLclName
fs)
; Type
ty' <- IfaceType -> IfL Type
tcIfaceType IfaceType
ty
; Type
w' <- IfaceType -> IfL Type
tcIfaceType IfaceType
w
; let id :: Var
id = Name -> Type -> Type -> Var
mkLocalIdOrCoVar Name
name Type
w' Type
ty'
; [Var] -> IfL a -> IfL a
forall a. [Var] -> IfL a -> IfL a
extendIfaceIdEnv [Var
id] (Var -> IfL a
thing_inside Var
id) }
bindIfaceIds :: [IfaceIdBndr] -> ([Id] -> IfL a) -> IfL a
bindIfaceIds :: forall a. [IfaceIdBndr] -> ([Var] -> IfL a) -> IfL a
bindIfaceIds [] [Var] -> IfL a
thing_inside = [Var] -> IfL a
thing_inside []
bindIfaceIds (IfaceIdBndr
b:[IfaceIdBndr]
bs) [Var] -> IfL a
thing_inside
= IfaceIdBndr -> (Var -> IfL a) -> IfL a
forall a. IfaceIdBndr -> (Var -> IfL a) -> IfL a
bindIfaceId IfaceIdBndr
b ((Var -> IfL a) -> IfL a) -> (Var -> IfL a) -> IfL a
forall a b. (a -> b) -> a -> b
$ \Var
b' ->
[IfaceIdBndr] -> ([Var] -> IfL a) -> IfL a
forall a. [IfaceIdBndr] -> ([Var] -> IfL a) -> IfL a
bindIfaceIds [IfaceIdBndr]
bs (([Var] -> IfL a) -> IfL a) -> ([Var] -> IfL a) -> IfL a
forall a b. (a -> b) -> a -> b
$ \[Var]
bs' ->
[Var] -> IfL a
thing_inside (Var
b'Var -> [Var] -> [Var]
forall a. a -> [a] -> [a]
:[Var]
bs')
bindIfaceBndr :: IfaceBndr -> (CoreBndr -> IfL a) -> IfL a
bindIfaceBndr :: forall a. IfaceBndr -> (Var -> IfL a) -> IfL a
bindIfaceBndr (IfaceIdBndr IfaceIdBndr
bndr) Var -> IfL a
thing_inside
= IfaceIdBndr -> (Var -> IfL a) -> IfL a
forall a. IfaceIdBndr -> (Var -> IfL a) -> IfL a
bindIfaceId IfaceIdBndr
bndr Var -> IfL a
thing_inside
bindIfaceBndr (IfaceTvBndr IfaceTvBndr
bndr) Var -> IfL a
thing_inside
= IfaceTvBndr -> (Var -> IfL a) -> IfL a
forall a. IfaceTvBndr -> (Var -> IfL a) -> IfL a
bindIfaceTyVar IfaceTvBndr
bndr Var -> IfL a
thing_inside
bindIfaceBndrs :: [IfaceBndr] -> ([CoreBndr] -> IfL a) -> IfL a
bindIfaceBndrs :: forall a. [IfaceBndr] -> ([Var] -> IfL a) -> IfL a
bindIfaceBndrs [] [Var] -> IfL a
thing_inside = [Var] -> IfL a
thing_inside []
bindIfaceBndrs (IfaceBndr
b:[IfaceBndr]
bs) [Var] -> IfL a
thing_inside
= IfaceBndr -> (Var -> IfL a) -> IfL a
forall a. IfaceBndr -> (Var -> IfL a) -> IfL a
bindIfaceBndr IfaceBndr
b ((Var -> IfL a) -> IfL a) -> (Var -> IfL a) -> IfL a
forall a b. (a -> b) -> a -> b
$ \ Var
b' ->
[IfaceBndr] -> ([Var] -> IfL a) -> IfL a
forall a. [IfaceBndr] -> ([Var] -> IfL a) -> IfL a
bindIfaceBndrs [IfaceBndr]
bs (([Var] -> IfL a) -> IfL a) -> ([Var] -> IfL a) -> IfL a
forall a b. (a -> b) -> a -> b
$ \ [Var]
bs' ->
[Var] -> IfL a
thing_inside (Var
b'Var -> [Var] -> [Var]
forall a. a -> [a] -> [a]
:[Var]
bs')
bindIfaceForAllBndrs :: [VarBndr IfaceBndr vis] -> ([VarBndr TyCoVar vis] -> IfL a) -> IfL a
bindIfaceForAllBndrs :: forall vis a.
[VarBndr IfaceBndr vis] -> ([VarBndr Var vis] -> IfL a) -> IfL a
bindIfaceForAllBndrs [] [VarBndr Var vis] -> IfL a
thing_inside = [VarBndr Var vis] -> IfL a
thing_inside []
bindIfaceForAllBndrs (VarBndr IfaceBndr vis
bndr:[VarBndr IfaceBndr vis]
bndrs) [VarBndr Var vis] -> IfL a
thing_inside
= VarBndr IfaceBndr vis -> (Var -> vis -> IfL a) -> IfL a
forall vis a.
VarBndr IfaceBndr vis -> (Var -> vis -> IfL a) -> IfL a
bindIfaceForAllBndr VarBndr IfaceBndr vis
bndr ((Var -> vis -> IfL a) -> IfL a) -> (Var -> vis -> IfL a) -> IfL a
forall a b. (a -> b) -> a -> b
$ \Var
tv vis
vis ->
[VarBndr IfaceBndr vis] -> ([VarBndr Var vis] -> IfL a) -> IfL a
forall vis a.
[VarBndr IfaceBndr vis] -> ([VarBndr Var vis] -> IfL a) -> IfL a
bindIfaceForAllBndrs [VarBndr IfaceBndr vis]
bndrs (([VarBndr Var vis] -> IfL a) -> IfL a)
-> ([VarBndr Var vis] -> IfL a) -> IfL a
forall a b. (a -> b) -> a -> b
$ \[VarBndr Var vis]
bndrs' ->
[VarBndr Var vis] -> IfL a
thing_inside (Var -> vis -> VarBndr Var vis
forall var argf. var -> argf -> VarBndr var argf
Bndr Var
tv vis
vis VarBndr Var vis -> [VarBndr Var vis] -> [VarBndr Var vis]
forall a. a -> [a] -> [a]
: [VarBndr Var vis]
bndrs')
bindIfaceForAllBndr :: (VarBndr IfaceBndr vis) -> (TyCoVar -> vis -> IfL a) -> IfL a
bindIfaceForAllBndr :: forall vis a.
VarBndr IfaceBndr vis -> (Var -> vis -> IfL a) -> IfL a
bindIfaceForAllBndr (Bndr (IfaceTvBndr IfaceTvBndr
tv) vis
vis) Var -> vis -> IfL a
thing_inside
= IfaceTvBndr -> (Var -> IfL a) -> IfL a
forall a. IfaceTvBndr -> (Var -> IfL a) -> IfL a
bindIfaceTyVar IfaceTvBndr
tv ((Var -> IfL a) -> IfL a) -> (Var -> IfL a) -> IfL a
forall a b. (a -> b) -> a -> b
$ \Var
tv' -> Var -> vis -> IfL a
thing_inside Var
tv' vis
vis
bindIfaceForAllBndr (Bndr (IfaceIdBndr IfaceIdBndr
tv) vis
vis) Var -> vis -> IfL a
thing_inside
= IfaceIdBndr -> (Var -> IfL a) -> IfL a
forall a. IfaceIdBndr -> (Var -> IfL a) -> IfL a
bindIfaceId IfaceIdBndr
tv ((Var -> IfL a) -> IfL a) -> (Var -> IfL a) -> IfL a
forall a b. (a -> b) -> a -> b
$ \Var
tv' -> Var -> vis -> IfL a
thing_inside Var
tv' vis
vis
bindIfaceTyVar :: IfaceTvBndr -> (TyVar -> IfL a) -> IfL a
bindIfaceTyVar :: forall a. IfaceTvBndr -> (Var -> IfL a) -> IfL a
bindIfaceTyVar (IfLclName
occ,IfaceType
kind) Var -> IfL a
thing_inside
= do { Name
name <- OccName -> TcRnIf IfGblEnv IfLclEnv Name
newIfaceName (IfLclName -> OccName
mkTyVarOccFS IfLclName
occ)
; Var
tyvar <- Name -> IfaceType -> IfL Var
mk_iface_tyvar Name
name IfaceType
kind
; [Var] -> IfL a -> IfL a
forall a. [Var] -> IfL a -> IfL a
extendIfaceTyVarEnv [Var
tyvar] (Var -> IfL a
thing_inside Var
tyvar) }
bindIfaceTyVars :: [IfaceTvBndr] -> ([TyVar] -> IfL a) -> IfL a
bindIfaceTyVars :: forall a. [IfaceTvBndr] -> ([Var] -> IfL a) -> IfL a
bindIfaceTyVars [] [Var] -> IfL a
thing_inside = [Var] -> IfL a
thing_inside []
bindIfaceTyVars (IfaceTvBndr
bndr:[IfaceTvBndr]
bndrs) [Var] -> IfL a
thing_inside
= IfaceTvBndr -> (Var -> IfL a) -> IfL a
forall a. IfaceTvBndr -> (Var -> IfL a) -> IfL a
bindIfaceTyVar IfaceTvBndr
bndr ((Var -> IfL a) -> IfL a) -> (Var -> IfL a) -> IfL a
forall a b. (a -> b) -> a -> b
$ \Var
tv ->
[IfaceTvBndr] -> ([Var] -> IfL a) -> IfL a
forall a. [IfaceTvBndr] -> ([Var] -> IfL a) -> IfL a
bindIfaceTyVars [IfaceTvBndr]
bndrs (([Var] -> IfL a) -> IfL a) -> ([Var] -> IfL a) -> IfL a
forall a b. (a -> b) -> a -> b
$ \[Var]
tvs ->
[Var] -> IfL a
thing_inside (Var
tv Var -> [Var] -> [Var]
forall a. a -> [a] -> [a]
: [Var]
tvs)
mk_iface_tyvar :: Name -> IfaceKind -> IfL TyVar
mk_iface_tyvar :: Name -> IfaceType -> IfL Var
mk_iface_tyvar Name
name IfaceType
ifKind
= do { Type
kind <- IfaceType -> IfL Type
tcIfaceType IfaceType
ifKind
; Var -> IfL Var
forall (m :: * -> *) a. Monad m => a -> m a
return (Name -> Type -> Var
Var.mkTyVar Name
name Type
kind) }
bindIfaceTyConBinders :: [IfaceTyConBinder]
-> ([TyConBinder] -> IfL a) -> IfL a
bindIfaceTyConBinders :: forall a. [IfaceTyConBinder] -> ([TyConBinder] -> IfL a) -> IfL a
bindIfaceTyConBinders [] [TyConBinder] -> IfL a
thing_inside = [TyConBinder] -> IfL a
thing_inside []
bindIfaceTyConBinders (IfaceTyConBinder
b:[IfaceTyConBinder]
bs) [TyConBinder] -> IfL a
thing_inside
= (IfaceBndr -> (Var -> IfL a) -> IfL a)
-> IfaceTyConBinder -> (TyConBinder -> IfL a) -> IfL a
forall a.
(IfaceBndr -> (Var -> IfL a) -> IfL a)
-> IfaceTyConBinder -> (TyConBinder -> IfL a) -> IfL a
bindIfaceTyConBinderX IfaceBndr -> (Var -> IfL a) -> IfL a
forall a. IfaceBndr -> (Var -> IfL a) -> IfL a
bindIfaceBndr IfaceTyConBinder
b ((TyConBinder -> IfL a) -> IfL a)
-> (TyConBinder -> IfL a) -> IfL a
forall a b. (a -> b) -> a -> b
$ \ TyConBinder
b' ->
[IfaceTyConBinder] -> ([TyConBinder] -> IfL a) -> IfL a
forall a. [IfaceTyConBinder] -> ([TyConBinder] -> IfL a) -> IfL a
bindIfaceTyConBinders [IfaceTyConBinder]
bs (([TyConBinder] -> IfL a) -> IfL a)
-> ([TyConBinder] -> IfL a) -> IfL a
forall a b. (a -> b) -> a -> b
$ \ [TyConBinder]
bs' ->
[TyConBinder] -> IfL a
thing_inside (TyConBinder
b'TyConBinder -> [TyConBinder] -> [TyConBinder]
forall a. a -> [a] -> [a]
:[TyConBinder]
bs')
bindIfaceTyConBinders_AT :: [IfaceTyConBinder]
-> ([TyConBinder] -> IfL a) -> IfL a
bindIfaceTyConBinders_AT :: forall a. [IfaceTyConBinder] -> ([TyConBinder] -> IfL a) -> IfL a
bindIfaceTyConBinders_AT [] [TyConBinder] -> IfL a
thing_inside
= [TyConBinder] -> IfL a
thing_inside []
bindIfaceTyConBinders_AT (IfaceTyConBinder
b : [IfaceTyConBinder]
bs) [TyConBinder] -> IfL a
thing_inside
= (IfaceBndr -> (Var -> IfL a) -> IfL a)
-> IfaceTyConBinder -> (TyConBinder -> IfL a) -> IfL a
forall a.
(IfaceBndr -> (Var -> IfL a) -> IfL a)
-> IfaceTyConBinder -> (TyConBinder -> IfL a) -> IfL a
bindIfaceTyConBinderX IfaceBndr -> (Var -> IfL a) -> IfL a
forall a. IfaceBndr -> (Var -> IfL a) -> IfL a
bind_tv IfaceTyConBinder
b ((TyConBinder -> IfL a) -> IfL a)
-> (TyConBinder -> IfL a) -> IfL a
forall a b. (a -> b) -> a -> b
$ \TyConBinder
b' ->
[IfaceTyConBinder] -> ([TyConBinder] -> IfL a) -> IfL a
forall a. [IfaceTyConBinder] -> ([TyConBinder] -> IfL a) -> IfL a
bindIfaceTyConBinders_AT [IfaceTyConBinder]
bs (([TyConBinder] -> IfL a) -> IfL a)
-> ([TyConBinder] -> IfL a) -> IfL a
forall a b. (a -> b) -> a -> b
$ \[TyConBinder]
bs' ->
[TyConBinder] -> IfL a
thing_inside (TyConBinder
b'TyConBinder -> [TyConBinder] -> [TyConBinder]
forall a. a -> [a] -> [a]
:[TyConBinder]
bs')
where
bind_tv :: IfaceBndr
-> (Var -> IOEnv (Env IfGblEnv IfLclEnv) a)
-> IOEnv (Env IfGblEnv IfLclEnv) a
bind_tv IfaceBndr
tv Var -> IOEnv (Env IfGblEnv IfLclEnv) a
thing
= do { Maybe Var
mb_tv <- IfaceBndr -> IfL (Maybe Var)
lookupIfaceVar IfaceBndr
tv
; case Maybe Var
mb_tv of
Just Var
b' -> Var -> IOEnv (Env IfGblEnv IfLclEnv) a
thing Var
b'
Maybe Var
Nothing -> IfaceBndr
-> (Var -> IOEnv (Env IfGblEnv IfLclEnv) a)
-> IOEnv (Env IfGblEnv IfLclEnv) a
forall a. IfaceBndr -> (Var -> IfL a) -> IfL a
bindIfaceBndr IfaceBndr
tv Var -> IOEnv (Env IfGblEnv IfLclEnv) a
thing }
bindIfaceTyConBinderX :: (IfaceBndr -> (TyCoVar -> IfL a) -> IfL a)
-> IfaceTyConBinder
-> (TyConBinder -> IfL a) -> IfL a
bindIfaceTyConBinderX :: forall a.
(IfaceBndr -> (Var -> IfL a) -> IfL a)
-> IfaceTyConBinder -> (TyConBinder -> IfL a) -> IfL a
bindIfaceTyConBinderX IfaceBndr -> (Var -> IfL a) -> IfL a
bind_tv (Bndr IfaceBndr
tv TyConBndrVis
vis) TyConBinder -> IfL a
thing_inside
= IfaceBndr -> (Var -> IfL a) -> IfL a
bind_tv IfaceBndr
tv ((Var -> IfL a) -> IfL a) -> (Var -> IfL a) -> IfL a
forall a b. (a -> b) -> a -> b
$ \Var
tv' ->
TyConBinder -> IfL a
thing_inside (Var -> TyConBndrVis -> TyConBinder
forall var argf. var -> argf -> VarBndr var argf
Bndr Var
tv' TyConBndrVis
vis)