Amend TcPluginM interface
[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 -- * Finding Modules and Names
14 FindResult(..),
15 findImportedModule,
16 lookupOrig,
17
18 -- * Looking up Names in the typechecking environment
19 tcLookupGlobal,
20 tcLookupTyCon,
21 tcLookupDataCon,
22 tcLookupClass,
23 tcLookup,
24 tcLookupId,
25
26 -- * Getting the TcM state
27 getTopEnv,
28 getEnvs,
29 getInstEnvs,
30 getFamInstEnvs,
31 matchFam,
32
33 -- * Type variables
34 newFlexiTyVar,
35 isTouchableTcPluginM,
36
37 -- * Zonking
38 zonkTcType,
39 zonkCt
40 #endif
41 ) where
42
43 #ifdef GHCI
44 import qualified TcRnMonad
45 import qualified TcSMonad
46 import qualified TcEnv
47 import qualified TcMType
48 import qualified Inst
49 import qualified FamInst
50 import qualified IfaceEnv
51 import qualified Finder
52
53 import FamInstEnv ( FamInstEnv )
54 import TcRnMonad ( TcGblEnv, TcLclEnv, Ct, TcPluginM
55 , unsafeTcPluginTcM, liftIO, traceTc )
56 import TcMType ( TcTyVar, TcType )
57 import TcEnv ( TcTyThing )
58 import TcEvidence ( TcCoercion )
59
60 import Module
61 import Name
62 import TyCon
63 import DataCon
64 import Class
65 import HscTypes
66 import Outputable
67 import Type
68 import Id
69 import InstEnv
70 import FastString
71
72
73 -- | Perform some IO, typically to interact with an external tool.
74 tcPluginIO :: IO a -> TcPluginM a
75 tcPluginIO a = unsafeTcPluginTcM (liftIO a)
76
77 -- | Output useful for debugging the compiler.
78 tcPluginTrace :: String -> SDoc -> TcPluginM ()
79 tcPluginTrace a b = unsafeTcPluginTcM (traceTc a b)
80
81
82 findImportedModule :: ModuleName -> Maybe FastString -> TcPluginM FindResult
83 findImportedModule mod_name mb_pkg = do
84 hsc_env <- getTopEnv
85 tcPluginIO $ Finder.findImportedModule hsc_env mod_name mb_pkg
86
87 lookupOrig :: Module -> OccName -> TcPluginM Name
88 lookupOrig mod = unsafeTcPluginTcM . IfaceEnv.lookupOrig mod
89
90
91 tcLookupGlobal :: Name -> TcPluginM TyThing
92 tcLookupGlobal = unsafeTcPluginTcM . TcEnv.tcLookupGlobal
93
94 tcLookupTyCon :: Name -> TcPluginM TyCon
95 tcLookupTyCon = unsafeTcPluginTcM . TcEnv.tcLookupTyCon
96
97 tcLookupDataCon :: Name -> TcPluginM DataCon
98 tcLookupDataCon = unsafeTcPluginTcM . TcEnv.tcLookupDataCon
99
100 tcLookupClass :: Name -> TcPluginM Class
101 tcLookupClass = unsafeTcPluginTcM . TcEnv.tcLookupClass
102
103 tcLookup :: Name -> TcPluginM TcTyThing
104 tcLookup = unsafeTcPluginTcM . TcEnv.tcLookup
105
106 tcLookupId :: Name -> TcPluginM Id
107 tcLookupId = unsafeTcPluginTcM . TcEnv.tcLookupId
108
109
110 getTopEnv :: TcPluginM HscEnv
111 getTopEnv = unsafeTcPluginTcM TcRnMonad.getTopEnv
112
113 getEnvs :: TcPluginM (TcGblEnv, TcLclEnv)
114 getEnvs = unsafeTcPluginTcM TcRnMonad.getEnvs
115
116 getInstEnvs :: TcPluginM InstEnvs
117 getInstEnvs = unsafeTcPluginTcM Inst.tcGetInstEnvs
118
119 getFamInstEnvs :: TcPluginM (FamInstEnv, FamInstEnv)
120 getFamInstEnvs = unsafeTcPluginTcM FamInst.tcGetFamInstEnvs
121
122 matchFam :: TyCon -> [Type] -> TcPluginM (Maybe (TcCoercion, TcType))
123 matchFam tycon args = unsafeTcPluginTcM $ TcSMonad.matchFamTcM tycon args
124
125
126 newFlexiTyVar :: Kind -> TcPluginM TcTyVar
127 newFlexiTyVar = unsafeTcPluginTcM . TcMType.newFlexiTyVar
128
129 isTouchableTcPluginM :: TcTyVar -> TcPluginM Bool
130 isTouchableTcPluginM = unsafeTcPluginTcM . TcRnMonad.isTouchableTcM
131
132
133 zonkTcType :: TcType -> TcPluginM TcType
134 zonkTcType = unsafeTcPluginTcM . TcMType.zonkTcType
135
136 zonkCt :: Ct -> TcPluginM Ct
137 zonkCt = unsafeTcPluginTcM . TcMType.zonkCt
138 #endif