PUBLIC
Hi,
I’m writing a type checker plugin that should do things whenever used in the context of a module that already has some definitions loaded. I’ve hacked together the following
function using internal details that I feel I should not be using:
lookupOrigMaybe :: Module -> OccName -> TcPluginM (Maybe Name)
lookupOrigMaybe mod occ = do
hsc_env <- getTopEnv
unsafeTcPluginTcM $ liftIO $ updateNameCache (hsc_NC hsc_env) mod occ $ \cache0 -> do
let name = lookupOrigNameCache cache0 mod occ
return (cache0, name)
I would like to do this in a nicer way instead. It should be enough to check that the given module is already loaded, since for my use case, if the module is there but the name
isn’t, then all bets are off and my plugin might as well just error out. So I was hoping I could use `findImportedModule` followed by `lookupOrig`, but alas, `findImportedModule` fails me in one of two ways:
attempting to use module ‘main:Cortex.Stem.Relation.Types’ (Cortex.Stem.Relation.Types) which is not loaded
ghc-mu-core-to-exp: panic! (the 'impossible' happened)
GHC version 9.5.20220830:
findImportModule
Cortex.Stem.Relation.Types
"main"
Just ghc-bignum
main
[ghc-bignum, cortex-prim]
Call stack:
CallStack (from HasCallStack):
callStackDoc, called at compiler/GHC/Utils/Panic.hs:188:37 in ghc-lib-0.20220830-FvKByKwp6ri5ICk6wiQO8W:GHC.Utils.Panic
pprPanic, called at compiler/GHC/Unit/Finder.hs:160:32 in ghc-lib-0.20220830-FvKByKwp6ri5ICk6wiQO8W:GHC.Unit.Finder
Please report this as a GHC bug:
https://www.haskell.org/ghc/reportabug
So my question then, is what is the recommended way of looking up a loaded definition opportunistically from a type checker plugin?
Thanks,
Gergo