{-# OPTIONS_GHC -fno-warn-duplicate-exports -fno-warn-orphans #-}
module GHC.Plugins
( module GHC.Driver.Plugins
, module GHC.Types.Name.Reader
, module GHC.Types.Name.Occurrence
, module GHC.Types.Name
, module GHC.Types.Var
, module GHC.Types.Id
, module GHC.Types.Id.Info
, module GHC.Core.Opt.Monad
, module GHC.Core
, module GHC.Types.Literal
, module GHC.Core.DataCon
, module GHC.Core.Utils
, module GHC.Core.Make
, module GHC.Core.FVs
, module GHC.Core.Subst
, module GHC.Core.Rules
, module GHC.Types.Annotations
, module GHC.Driver.Session
, module GHC.Unit.State
, module GHC.Unit.Module
, module GHC.Core.Type
, module GHC.Core.TyCon
, module GHC.Core.Coercion
, module GHC.Builtin.Types
, module GHC.Driver.Types
, module GHC.Types.Basic
, module GHC.Types.Var.Set
, module GHC.Types.Var.Env
, module GHC.Types.Name.Set
, module GHC.Types.Name.Env
, module GHC.Types.Unique
, module GHC.Types.Unique.Set
, module GHC.Types.Unique.FM
, module GHC.Data.FiniteMap
, module GHC.Utils.Misc
, module GHC.Serialized
, module GHC.Types.SrcLoc
, module GHC.Utils.Outputable
, module GHC.Types.Unique.Supply
, module GHC.Data.FastString
, module GHC.Tc.Errors.Hole.FitTypes
,
thNameToGhcName
)
where
import GHC.Driver.Plugins
import GHC.Types.Name.Reader
import GHC.Types.Name.Occurrence hiding ( varName )
import GHC.Types.Name hiding ( varName )
import GHC.Types.Var
import GHC.Types.Id hiding ( lazySetIdInfo, setIdExported, setIdNotExported )
import GHC.Types.Id.Info
import GHC.Core.Opt.Monad
import GHC.Core
import GHC.Types.Literal
import GHC.Core.DataCon
import GHC.Core.Utils
import GHC.Core.Make
import GHC.Core.FVs
import GHC.Core.Subst hiding( substTyVarBndr, substCoVarBndr, extendCvSubst )
import GHC.Core.Rules
import GHC.Types.Annotations
import GHC.Driver.Session
import GHC.Unit.State
import GHC.Unit.Module
import GHC.Core.Type hiding
( substTy, extendTvSubst, extendTvSubstList, isInScope )
import GHC.Core.Coercion hiding
( substCo )
import GHC.Core.TyCon
import GHC.Builtin.Types
import GHC.Driver.Types
import GHC.Types.Basic
import GHC.Types.Var.Set
import GHC.Types.Var.Env
import GHC.Types.Name.Set
import GHC.Types.Name.Env
import GHC.Types.Unique.Set
import GHC.Types.Unique.FM
import GHC.Data.FiniteMap
import GHC.Utils.Misc
import GHC.Serialized
import GHC.Types.SrcLoc
import GHC.Utils.Outputable
import GHC.Types.Unique.Supply
import GHC.Types.Unique ( Unique, Uniquable(..) )
import GHC.Data.FastString
import Data.Maybe
import GHC.Iface.Env ( lookupOrigIO )
import GHC.Prelude
import GHC.Utils.Monad ( mapMaybeM )
import GHC.ThToHs ( thRdrNameGuesses )
import GHC.Tc.Utils.Env ( lookupGlobal )
import GHC.Tc.Errors.Hole.FitTypes
import qualified Language.Haskell.TH as TH
instance MonadThings CoreM where
lookupThing :: Name -> CoreM TyThing
lookupThing Name
name = do { HscEnv
hsc_env <- CoreM HscEnv
getHscEnv
; IO TyThing -> CoreM TyThing
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO TyThing -> CoreM TyThing) -> IO TyThing -> CoreM TyThing
forall a b. (a -> b) -> a -> b
$ HscEnv -> Name -> IO TyThing
lookupGlobal HscEnv
hsc_env Name
name }
thNameToGhcName :: TH.Name -> CoreM (Maybe Name)
thNameToGhcName :: Name -> CoreM (Maybe Name)
thNameToGhcName Name
th_name
= do { [Name]
names <- (RdrName -> CoreM (Maybe Name)) -> [RdrName] -> CoreM [Name]
forall (m :: * -> *) a b.
Applicative m =>
(a -> m (Maybe b)) -> [a] -> m [b]
mapMaybeM RdrName -> CoreM (Maybe Name)
lookup (Name -> [RdrName]
thRdrNameGuesses Name
th_name)
; Maybe Name -> CoreM (Maybe Name)
forall (m :: * -> *) a. Monad m => a -> m a
return ([Name] -> Maybe Name
forall a. [a] -> Maybe a
listToMaybe [Name]
names) }
where
lookup :: RdrName -> CoreM (Maybe Name)
lookup RdrName
rdr_name
| Just Name
n <- RdrName -> Maybe Name
isExact_maybe RdrName
rdr_name
= Maybe Name -> CoreM (Maybe Name)
forall (m :: * -> *) a. Monad m => a -> m a
return (Maybe Name -> CoreM (Maybe Name))
-> Maybe Name -> CoreM (Maybe Name)
forall a b. (a -> b) -> a -> b
$ if Name -> Bool
isExternalName Name
n then Name -> Maybe Name
forall a. a -> Maybe a
Just Name
n else Maybe Name
forall a. Maybe a
Nothing
| Just (Module
rdr_mod, OccName
rdr_occ) <- RdrName -> Maybe (Module, OccName)
isOrig_maybe RdrName
rdr_name
= do { HscEnv
hsc_env <- CoreM HscEnv
getHscEnv
; Name -> Maybe Name
forall a. a -> Maybe a
Just (Name -> Maybe Name) -> CoreM Name -> CoreM (Maybe Name)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> IO Name -> CoreM Name
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (HscEnv -> Module -> OccName -> IO Name
lookupOrigIO HscEnv
hsc_env Module
rdr_mod OccName
rdr_occ) }
| Bool
otherwise = Maybe Name -> CoreM (Maybe Name)
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe Name
forall a. Maybe a
Nothing