module Language.Haskell.Liquid.Bare.Types
(
Env (..)
, TyThingMap
, ModSpecs
, LocalVars
, TycEnv (..)
, DataConMap
, RT.TyConMap
, SigEnv (..)
, MeasEnv (..)
, PlugTV (..)
, plugSrc
, varRSort
, varSortedReft
, failMaybe
) where
import qualified Text.PrettyPrint.HughesPJ as PJ
import qualified Data.HashSet as S
import qualified Data.HashMap.Strict as M
import qualified Language.Fixpoint.Types as F
import qualified Language.Haskell.Liquid.Measure as Ms
import qualified Language.Haskell.Liquid.Types.RefType as RT
import Language.Haskell.Liquid.Types.Types
import Language.Haskell.Liquid.Types.Specs hiding (BareSpec)
import Liquid.GHC.API as Ghc hiding (Located, Env)
import Language.Haskell.Liquid.GHC.Types (StableName)
type ModSpecs = M.HashMap ModName Ms.BareSpec
data PlugTV v
= HsTV v
| LqTV v
| GenTV
| RawTV
deriving (Int -> PlugTV v -> ShowS
forall v. Show v => Int -> PlugTV v -> ShowS
forall v. Show v => [PlugTV v] -> ShowS
forall v. Show v => PlugTV v -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [PlugTV v] -> ShowS
$cshowList :: forall v. Show v => [PlugTV v] -> ShowS
show :: PlugTV v -> String
$cshow :: forall v. Show v => PlugTV v -> String
showsPrec :: Int -> PlugTV v -> ShowS
$cshowsPrec :: forall v. Show v => Int -> PlugTV v -> ShowS
Show)
instance (Show v, F.PPrint v) => F.PPrint (PlugTV v) where
pprintTidy :: Tidy -> PlugTV v -> Doc
pprintTidy Tidy
_ = String -> Doc
PJ.text forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Show a => a -> String
show
plugSrc :: PlugTV v -> Maybe v
plugSrc :: forall v. PlugTV v -> Maybe v
plugSrc (HsTV v
v) = forall a. a -> Maybe a
Just v
v
plugSrc (LqTV v
v) = forall a. a -> Maybe a
Just v
v
plugSrc PlugTV v
_ = forall a. Maybe a
Nothing
data Env = RE
{ Env -> LogicMap
reLMap :: !LogicMap
, Env -> [(Symbol, Var)]
reSyms :: ![(F.Symbol, Ghc.Var)]
, Env -> Subst
_reSubst :: !F.Subst
, Env -> TyThingMap
_reTyThings :: !TyThingMap
, Env -> Config
reCfg :: !Config
, Env -> QImports
reQualImps :: !QImports
, Env -> HashSet Symbol
reAllImps :: !(S.HashSet F.Symbol)
, Env -> LocalVars
reLocalVars :: !LocalVars
, Env -> HashSet Symbol
reGlobSyms :: !(S.HashSet F.Symbol)
, Env -> GhcSrc
reSrc :: !GhcSrc
}
instance HasConfig Env where
getConfig :: Env -> Config
getConfig = Env -> Config
reCfg
type LocalVars = M.HashMap F.Symbol [(Int, Ghc.Var)]
type TyThingMap = M.HashMap F.Symbol [(F.Symbol, Ghc.TyThing)]
data SigEnv = SigEnv
{ SigEnv -> TCEmb TyCon
sigEmbs :: !(F.TCEmb Ghc.TyCon)
, SigEnv -> TyConMap
sigTyRTyMap :: !RT.TyConMap
, SigEnv -> HashSet StableName
sigExports :: !(S.HashSet StableName)
, SigEnv -> BareRTEnv
sigRTEnv :: !BareRTEnv
}
data TycEnv = TycEnv
{ TycEnv -> [TyConP]
tcTyCons :: ![TyConP]
, TycEnv -> [DataConP]
tcDataCons :: ![DataConP]
, TycEnv -> [Measure SpecType DataCon]
tcSelMeasures :: ![Measure SpecType Ghc.DataCon]
, TycEnv -> [(Var, LocSpecType)]
tcSelVars :: ![(Ghc.Var, LocSpecType)]
, TycEnv -> TyConMap
tcTyConMap :: !RT.TyConMap
, TycEnv -> [DataDecl]
tcAdts :: ![F.DataDecl]
, TycEnv -> DataConMap
tcDataConMap :: !DataConMap
, TycEnv -> TCEmb TyCon
tcEmbs :: !(F.TCEmb Ghc.TyCon)
, TycEnv -> ModName
tcName :: !ModName
}
type DataConMap = M.HashMap (F.Symbol, Int) F.Symbol
data MeasEnv = MeasEnv
{ MeasEnv -> MSpec SpecType DataCon
meMeasureSpec :: !(MSpec SpecType Ghc.DataCon)
, MeasEnv -> [(Symbol, Located (RRType Reft))]
meClassSyms :: ![(F.Symbol, Located (RRType F.Reft))]
, MeasEnv -> [(Symbol, Located (RRType Reft))]
meSyms :: ![(F.Symbol, Located (RRType F.Reft))]
, MeasEnv -> [(Var, LocSpecType)]
meDataCons :: ![(Ghc.Var, LocSpecType)]
, MeasEnv -> [DataConP]
meClasses :: ![DataConP]
, MeasEnv -> [(ModName, Var, LocSpecType)]
meMethods :: ![(ModName, Ghc.Var, LocSpecType)]
, MeasEnv -> [(Class, [(ModName, Var, LocSpecType)])]
meCLaws :: ![(Ghc.Class, [(ModName, Ghc.Var, LocSpecType)])]
}
instance Semigroup MeasEnv where
<> :: MeasEnv -> MeasEnv -> MeasEnv
(<>) = forall a. HasCallStack => String -> a
error String
"FIXME:1773"
instance Monoid MeasEnv where
mempty :: MeasEnv
mempty = forall a. HasCallStack => String -> a
error String
"FIXME:1773"
varSortedReft :: F.TCEmb Ghc.TyCon -> Ghc.Var -> F.SortedReft
varSortedReft :: TCEmb TyCon -> Var -> SortedReft
varSortedReft TCEmb TyCon
emb = forall r.
(PPrint r, Reftable r, SubsTy RTyVar (RType RTyCon RTyVar ()) r,
Reftable (RTProp RTyCon RTyVar r)) =>
TCEmb TyCon -> RRType r -> SortedReft
RT.rTypeSortedReft TCEmb TyCon
emb forall b c a. (b -> c) -> (a -> b) -> a -> c
. Var -> RType RTyCon RTyVar ()
varRSort
varRSort :: Ghc.Var -> RSort
varRSort :: Var -> RType RTyCon RTyVar ()
varRSort = forall r. Monoid r => Type -> RRType r
RT.ofType forall b c a. (b -> c) -> (a -> b) -> a -> c
. Var -> Type
Ghc.varType
failMaybe :: Env -> ModName -> Either e r -> Either e (Maybe r)
failMaybe :: forall e r. Env -> ModName -> Either e r -> Either e (Maybe r)
failMaybe Env
env ModName
name Either e r
res = case Either e r
res of
Right r
r -> forall a b. b -> Either a b
Right (forall a. a -> Maybe a
Just r
r)
Left e
e -> if Env -> ModName -> Bool
isTargetModName Env
env ModName
name
then forall a b. a -> Either a b
Left e
e
else forall a b. b -> Either a b
Right forall a. Maybe a
Nothing
isTargetModName :: Env -> ModName -> Bool
isTargetModName :: Env -> ModName -> Bool
isTargetModName Env
env ModName
name = ModName
name forall a. Eq a => a -> a -> Bool
== GhcSrc -> ModName
_giTargetMod (Env -> GhcSrc
reSrc Env
env)