[Git][ghc/ghc][wip/T24741] Introduce GHC.Tc.Plugin.lookupTHName
Ben Gamari (@bgamari)
gitlab at gitlab.haskell.org
Fri Nov 15 19:02:21 UTC 2024
Ben Gamari pushed to branch wip/T24741 at Glasgow Haskell Compiler / GHC
Commits:
c829fe20 by Ben Gamari at 2024-11-15T14:02:13-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/c829fe20eea714e344ca2cfd9b85926f585ac021
--
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/c829fe20eea714e344ca2cfd9b85926f585ac021
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/20241115/dd9d3b58/attachment-0001.html>
More information about the ghc-commits
mailing list