[Git][ghc/ghc][master] Introduce GHC.Tc.Plugin.lookupTHName
Marge Bot (@marge-bot)
gitlab at gitlab.haskell.org
Sat Nov 16 21:22:43 UTC 2024
Marge Bot pushed to branch master at Glasgow Haskell Compiler / GHC
Commits:
8e975032 by Ben Gamari at 2024-11-16T16:21:59-05:00
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.
- - - - -
1 changed file:
- compiler/GHC/Tc/Plugin.hs
Changes:
=====================================
compiler/GHC/Tc/Plugin.hs
=====================================
@@ -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
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/8e9750324309781531d0d7b1dc66ebfa032c44c8
--
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/8e9750324309781531d0d7b1dc66ebfa032c44c8
You're receiving this email because of your account on gitlab.haskell.org.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/ghc-commits/attachments/20241116/ff6bb88f/attachment-0001.html>
More information about the ghc-commits
mailing list