Implement typechecker plugins
[ghc.git] / compiler / typecheck / TcPluginM.hs
1 {-# LANGUAGE CPP #-}
2 -- | This module provides an interface for typechecker plugins to
3 -- access select functions of the 'TcM', principally those to do with
4 -- reading parts of the state.
5 module TcPluginM (
6 #ifdef GHCI
7 -- * Basic TcPluginM functionality
8 TcPluginM,
9 tcPluginIO,
10 tcPluginTrace,
11 unsafeTcPluginTcM,
12
13 -- * Lookup
14 lookupRdrName,
15 tcLookupGlobal,
16 tcLookupTyCon,
17 tcLookupDataCon,
18 tcLookupClass,
19 tcLookup,
20 tcLookupId,
21
22 -- * Getting the TcM state
23 getTopEnv,
24 getEnvs,
25 getInstEnvs,
26 getFamInstEnvs,
27
28 -- * Type variables
29 newFlexiTyVar,
30 isTouchableTcPluginM,
31
32 -- * Zonking
33 zonkTcType,
34 zonkCt
35 #endif
36 ) where
37
38 #ifdef GHCI
39 import qualified TcRnMonad
40 import qualified TcEnv
41 import qualified TcMType
42 import qualified Inst
43 import qualified FamInst
44
45 import FamInstEnv ( FamInstEnv )
46 import TcRnMonad ( TcGblEnv, TcLclEnv, Ct, TcPluginM
47 , unsafeTcPluginTcM, liftIO, traceTc )
48 import TcMType ( TcTyVar, TcType )
49 import TcEnv ( TcTyThing )
50
51 import Module
52 import Name
53 import RdrName
54 import TyCon
55 import DataCon
56 import Class
57 import HscTypes
58 import Outputable
59 import Type
60 import DynamicLoading
61 import Id
62 import InstEnv
63
64
65 -- | Perform some IO, typically to interact with an external tool.
66 tcPluginIO :: IO a -> TcPluginM a
67 tcPluginIO a = unsafeTcPluginTcM (liftIO a)
68
69 -- | Output useful for debugging the compiler.
70 tcPluginTrace :: String -> SDoc -> TcPluginM ()
71 tcPluginTrace a b = unsafeTcPluginTcM (traceTc a b)
72
73
74 lookupRdrName :: ModuleName -> RdrName -> TcPluginM (Maybe Name)
75 lookupRdrName mod rdr = do
76 hsc_env <- getTopEnv
77 tcPluginIO $ lookupRdrNameInModuleForPlugins hsc_env mod rdr
78
79 tcLookupGlobal :: Name -> TcPluginM TyThing
80 tcLookupGlobal = unsafeTcPluginTcM . TcEnv.tcLookupGlobal
81
82 tcLookupTyCon :: Name -> TcPluginM TyCon
83 tcLookupTyCon = unsafeTcPluginTcM . TcEnv.tcLookupTyCon
84
85 tcLookupDataCon :: Name -> TcPluginM DataCon
86 tcLookupDataCon = unsafeTcPluginTcM . TcEnv.tcLookupDataCon
87
88 tcLookupClass :: Name -> TcPluginM Class
89 tcLookupClass = unsafeTcPluginTcM . TcEnv.tcLookupClass
90
91 tcLookup :: Name -> TcPluginM TcTyThing
92 tcLookup = unsafeTcPluginTcM . TcEnv.tcLookup
93
94 tcLookupId :: Name -> TcPluginM Id
95 tcLookupId = unsafeTcPluginTcM . TcEnv.tcLookupId
96
97
98 getTopEnv :: TcPluginM HscEnv
99 getTopEnv = unsafeTcPluginTcM TcRnMonad.getTopEnv
100
101 getEnvs :: TcPluginM (TcGblEnv, TcLclEnv)
102 getEnvs = unsafeTcPluginTcM TcRnMonad.getEnvs
103
104 getInstEnvs :: TcPluginM (InstEnv, InstEnv)
105 getInstEnvs = unsafeTcPluginTcM Inst.tcGetInstEnvs
106
107 getFamInstEnvs :: TcPluginM (FamInstEnv, FamInstEnv)
108 getFamInstEnvs = unsafeTcPluginTcM FamInst.tcGetFamInstEnvs
109
110
111 newFlexiTyVar :: Kind -> TcPluginM TcTyVar
112 newFlexiTyVar = unsafeTcPluginTcM . TcMType.newFlexiTyVar
113
114 isTouchableTcPluginM :: TcTyVar -> TcPluginM Bool
115 isTouchableTcPluginM = unsafeTcPluginTcM . TcRnMonad.isTouchableTcM
116
117
118 zonkTcType :: TcType -> TcPluginM TcType
119 zonkTcType = unsafeTcPluginTcM . TcMType.zonkTcType
120
121 zonkCt :: Ct -> TcPluginM Ct
122 zonkCt = unsafeTcPluginTcM . TcMType.zonkCt
123 #endif