Skip to content
Snippets Groups Projects
Commit 8e975032 authored by Ben Gamari's avatar Ben Gamari Committed by Marge Bot
Browse files

Introduce GHC.Tc.Plugin.lookupTHName

This makes it significantly more convenient (and less
GHC-version-dependent) to resolve a template-haskell name into a GHC
Name.

As proposed in #24741.
parent f120e427
No related tags found
No related merge requests found
Pipeline #103300 canceled
......@@ -15,6 +15,7 @@ module GHC.Tc.Plugin (
lookupOrig,
-- * Looking up Names in the typechecking environment
lookupTHName,
tcLookupGlobal,
tcLookupTyCon,
tcLookupDataCon,
......@@ -74,6 +75,7 @@ import GHC.Tc.Utils.Env ( TcTyThing )
import GHC.Tc.Types.Evidence ( CoercionHole, EvTerm(..)
, EvExpr, EvBindsVar, EvBind, mkGivenEvBind )
import GHC.Types.Var ( EvVar )
import GHC.Plugins ( thNameToGhcNameIO )
import GHC.Unit.Module ( ModuleName, Module )
import GHC.Types.Name ( OccName, Name )
......@@ -90,6 +92,7 @@ import GHC.Core.InstEnv ( InstEnvs )
import GHC.Types.Unique ( Unique )
import GHC.Types.PkgQual ( PkgQual )
import qualified GHC.Internal.TH.Syntax as TH
-- | Perform some IO, typically to interact with an external tool.
tcPluginIO :: IO a -> TcPluginM a
......@@ -108,6 +111,13 @@ findImportedModule mod_name mb_pkg = do
lookupOrig :: Module -> OccName -> TcPluginM Name
lookupOrig mod = unsafeTcPluginTcM . IfaceEnv.lookupOrig mod
-- | Resolve a @template-haskell@ 'TH.Name' to a GHC 'Name'.
--
-- @since 9.14.1
lookupTHName :: TH.Name -> TcPluginM (Maybe Name)
lookupTHName th = do
nc <- hsc_NC <$> getTopEnv
tcPluginIO $ thNameToGhcNameIO nc th
tcLookupGlobal :: Name -> TcPluginM TyThing
tcLookupGlobal = unsafeTcPluginTcM . TcM.tcLookupGlobal
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment