{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE DeriveGeneric #-}
module Language.Haskell.Liquid.GHC.Plugin.Types
( SpecComment(..)
, LiquidLib
, mkLiquidLib
, mkSpecComment
, libTarget
, libDeps
, allDeps
, addLibDependencies
, PipelineData(..)
, TcData
, tcAllImports
, tcQualifiedImports
, tcResolvedNames
, tcAvailableTyCons
, tcAvailableVars
, mkTcData
) where
import Data.Binary as B
import Data.Foldable
import GHC.Generics hiding ( moduleName )
import qualified Data.HashSet as HS
import Language.Haskell.Liquid.Types.Specs
import Liquid.GHC.API as GHC
import qualified Language.Haskell.Liquid.GHC.Interface as LH
import Language.Haskell.Liquid.GHC.Misc (realSrcLocSourcePos)
import Language.Fixpoint.Types.Names ( Symbol )
import Language.Fixpoint.Types.Spans ( SourcePos, dummyPos )
data LiquidLib = LiquidLib
{ LiquidLib -> LiftedSpec
llTarget :: LiftedSpec
, LiquidLib -> TargetDependencies
llDeps :: TargetDependencies
} deriving (Int -> LiquidLib -> ShowS
[LiquidLib] -> ShowS
LiquidLib -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [LiquidLib] -> ShowS
$cshowList :: [LiquidLib] -> ShowS
show :: LiquidLib -> String
$cshow :: LiquidLib -> String
showsPrec :: Int -> LiquidLib -> ShowS
$cshowsPrec :: Int -> LiquidLib -> ShowS
Show, forall x. Rep LiquidLib x -> LiquidLib
forall x. LiquidLib -> Rep LiquidLib x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep LiquidLib x -> LiquidLib
$cfrom :: forall x. LiquidLib -> Rep LiquidLib x
Generic)
instance B.Binary LiquidLib
mkLiquidLib :: LiftedSpec -> LiquidLib
mkLiquidLib :: LiftedSpec -> LiquidLib
mkLiquidLib LiftedSpec
s = LiftedSpec -> TargetDependencies -> LiquidLib
LiquidLib LiftedSpec
s forall a. Monoid a => a
mempty
addLibDependencies :: TargetDependencies -> LiquidLib -> LiquidLib
addLibDependencies :: TargetDependencies -> LiquidLib -> LiquidLib
addLibDependencies TargetDependencies
deps LiquidLib
lib = LiquidLib
lib { llDeps :: TargetDependencies
llDeps = TargetDependencies
deps forall a. Semigroup a => a -> a -> a
<> LiquidLib -> TargetDependencies
llDeps LiquidLib
lib }
libTarget :: LiquidLib -> LiftedSpec
libTarget :: LiquidLib -> LiftedSpec
libTarget = LiquidLib -> LiftedSpec
llTarget
libDeps :: LiquidLib -> TargetDependencies
libDeps :: LiquidLib -> TargetDependencies
libDeps = LiquidLib -> TargetDependencies
llDeps
allDeps :: Foldable f => f LiquidLib -> TargetDependencies
allDeps :: forall (f :: * -> *).
Foldable f =>
f LiquidLib -> TargetDependencies
allDeps = forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
foldl' (\TargetDependencies
acc LiquidLib
lib -> TargetDependencies
acc forall a. Semigroup a => a -> a -> a
<> LiquidLib -> TargetDependencies
llDeps LiquidLib
lib) forall a. Monoid a => a
mempty
newtype =
(SourcePos, String)
deriving Int -> SpecComment -> ShowS
[SpecComment] -> ShowS
SpecComment -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [SpecComment] -> ShowS
$cshowList :: [SpecComment] -> ShowS
show :: SpecComment -> String
$cshow :: SpecComment -> String
showsPrec :: Int -> SpecComment -> ShowS
$cshowsPrec :: Int -> SpecComment -> ShowS
Show
mkSpecComment :: (Maybe RealSrcLoc, String) -> SpecComment
(Maybe RealSrcLoc
m, String
s) = (SourcePos, String) -> SpecComment
SpecComment (Maybe RealSrcLoc -> SourcePos
sourcePos Maybe RealSrcLoc
m, String
s)
where
sourcePos :: Maybe RealSrcLoc -> SourcePos
sourcePos Maybe RealSrcLoc
Nothing = String -> SourcePos
dummyPos String
"<no source information>"
sourcePos (Just RealSrcLoc
sp) = RealSrcLoc -> SourcePos
realSrcLocSourcePos RealSrcLoc
sp
data PipelineData = PipelineData {
PipelineData -> ModGuts
pdUnoptimisedCore :: ModGuts
, PipelineData -> TcData
pdTcData :: TcData
, :: [SpecComment]
}
data TcData = TcData {
TcData -> HashSet Symbol
tcAllImports :: HS.HashSet Symbol
, TcData -> QImports
tcQualifiedImports :: QImports
, TcData -> [(Name, Maybe TyThing)]
tcResolvedNames :: [(Name, Maybe TyThing)]
, TcData -> [TyCon]
tcAvailableTyCons :: [GHC.TyCon]
, TcData -> [Var]
tcAvailableVars :: [Var]
}
instance Outputable TcData where
ppr :: TcData -> SDoc
ppr (TcData{[(Name, Maybe TyThing)]
[TyCon]
[Var]
HashSet Symbol
QImports
tcAvailableVars :: [Var]
tcAvailableTyCons :: [TyCon]
tcResolvedNames :: [(Name, Maybe TyThing)]
tcQualifiedImports :: QImports
tcAllImports :: HashSet Symbol
tcAvailableVars :: TcData -> [Var]
tcAvailableTyCons :: TcData -> [TyCon]
tcResolvedNames :: TcData -> [(Name, Maybe TyThing)]
tcQualifiedImports :: TcData -> QImports
tcAllImports :: TcData -> HashSet Symbol
..}) =
String -> SDoc
text String
"TcData { imports = " SDoc -> SDoc -> SDoc
<+> String -> SDoc
text (forall a. Show a => a -> String
show forall a b. (a -> b) -> a -> b
$ forall a. HashSet a -> [a]
HS.toList HashSet Symbol
tcAllImports)
SDoc -> SDoc -> SDoc
<+> String -> SDoc
text String
" , qImports = " SDoc -> SDoc -> SDoc
<+> String -> SDoc
text (forall a. Show a => a -> String
show QImports
tcQualifiedImports)
SDoc -> SDoc -> SDoc
<+> String -> SDoc
text String
" , names = " SDoc -> SDoc -> SDoc
<+> forall a. Outputable a => a -> SDoc
ppr [(Name, Maybe TyThing)]
tcResolvedNames
SDoc -> SDoc -> SDoc
<+> String -> SDoc
text String
" , availTyCons = " SDoc -> SDoc -> SDoc
<+> forall a. Outputable a => a -> SDoc
ppr [TyCon]
tcAvailableTyCons
SDoc -> SDoc -> SDoc
<+> String -> SDoc
text String
" }"
mkTcData :: [LImportDecl GhcRn]
-> [(Name, Maybe TyThing)]
-> [TyCon]
-> [Var]
-> TcData
mkTcData :: [LImportDecl GhcRn]
-> [(Name, Maybe TyThing)] -> [TyCon] -> [Var] -> TcData
mkTcData [LImportDecl GhcRn]
imps [(Name, Maybe TyThing)]
resolvedNames [TyCon]
availTyCons [Var]
availVars = TcData {
tcAllImports :: HashSet Symbol
tcAllImports = [LImportDecl GhcRn] -> HashSet Symbol
LH.allImports [LImportDecl GhcRn]
imps
, tcQualifiedImports :: QImports
tcQualifiedImports = [LImportDecl GhcRn] -> QImports
LH.qualifiedImports [LImportDecl GhcRn]
imps
, tcResolvedNames :: [(Name, Maybe TyThing)]
tcResolvedNames = [(Name, Maybe TyThing)]
resolvedNames
, tcAvailableTyCons :: [TyCon]
tcAvailableTyCons = [TyCon]
availTyCons
, tcAvailableVars :: [Var]
tcAvailableVars = [Var]
availVars
}