hint
hint copied to clipboard
Qualified module import and -fobject-code result in a GhcException
> runInterpreter (setImportsQ [("Data.Int", Just "Int")])
Right ()
> runInterpreter (unsafeSetGhcOption "-fobject-code" >> setImportsQ [("Data.Int", Nothing)])
Right ()
> runInterpreter (unsafeSetGhcOption "-fobject-code" >> setImportsQ [("Data.Int", Just "Int")])
Left (GhcException "Cannot add module M874651652984698804717859 to context: not interpreted")
Basically, this. Both lts-9.11 and latest nightly (ghc versions 8.0.2 and 8.2.1) are affected.
What would be the best way to check whether this is caused by hint or GHC itself?
@greydot is this still an issue? Did you try doing the same on ghci? If it works on ghci, it should work on Hint. If it errors on both, then it's likely something wrong with what you're doing, or something wrong in GHC itself.
I believe, the problem is in how GHC handles phantom modules supplied by hint. I haven't dug further yet though. Obviously, importing qualified modules works in GHCi regardless of -fobject-code present.
If it's at all helpful, setImportsF was just merged which gives you more control over the imports.
Yup, I know, I wrote it after all. The problem is that unless a module is imported without qualification or import/hiding lists, it will be imported through a phantom module.
You're absolutely right - that was a brain fart.
I get a different error now, with ghc-8.6.4 and hint-0.9.0:
> runInterpreter (unsafeSetGhcOption "-fobject-code" >> setImportsQ [("Data.Int", Just "Int")])
*** Exception: /var/folders/vt/k170lq_x09n8r_0n0pml2_8w0000gp/T/hint-3f9ad8640c47b3f6: removeDirectory: unsatisfied constraints (Directory not empty)
The original error was more helpful though, as it clearly indicates that the problem is that the "phantom module" which hint creates behind the scenes cannot be loaded with -fobject-code. Since I can :load source files just fine in ghci -fobject-code, I don't see any fundamental reason why the phantom module cannot be loaded, nor why a directory would now need to be empty. This needs more investigation...