Skip to content

Introduce `lookupTHName` in TC plugin interface

It is quite common for typechecking plugins to want to lookup Names. In principle, one great way of doing this is via TemplateHaskellQuotes and thNameToGhcNameIO. However, using this function is quite non-trivial as it requires a NameCache, which requires reaching into GHC internals to find. While addressing #24680, I found the following to be quite useful:

lookupTHName :: TH.Name -> TcPluginM (Maybe Name)
lookupTHName th = do
    nc <- unsafeTcPluginTcM (hsc_NC . env_top <$> getEnv)
    tcPluginIO $ thNameToGhcNameIO nc th

I suggest that we expose this from GHC.Tc.Plugin for use by end users.