Skip to content

tcLookup in plugins seems broken on HEAD

The operation of looking up names in a typechecker plugin seems to have been broken sometime recently. For instance:

-- MyModule
type family MyFam a b where

-- MyPlugin
tcPluginInit :: TcPluginM ()
tcPluginInit = do
  myModule     <- findModule myPackage myModuleName
  lookupResult <- tcLookupGlobal =<< lookupOrig myModule ( mkTcOcc "MyFam" )
  pprPanic "Result was:" ( ppr lookupResult )

findModule :: String -> String -> TcPluginM Module
findModule pkg modName = do
  findResult <- findImportedModule ( mkModuleName modName ) ( Just $ fsLit pkg )
  case findResult of
    Found _ res     -> pure res
    FoundMultiple _ -> error $ "MyPlugin: found multiple modules named " <> modName <> "."
    _               -> error $ "MyPlugin: could not find any module named " <> modName <> "."

On GHC 9.2.1 (alpha1), I get the expected result:

  GHC version 9.2.0.20210331:
        Result was:
  Type constructor `MyFam'

On GHC HEAD, when running in ghci I get:

 GHC version 9.3.20210604:
        Result was:
  Identifier `disableBuffering'

and when compiling normally, I get:

  GHC version 9.3.20210604:
        Result was:
  Identifier `plugin'

I have only checked 7a05185a and 79d12d34 and they both present the same issue. Note that this is on Windows 10 x64 (10.0.19041).
See here for full reproducer: tclookup.zip

Edited by sheaf
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information