hint icon indicating copy to clipboard operation
hint copied to clipboard

Qualified module import and -fobject-code result in a GhcException

Open greydot opened this issue 8 years ago • 7 comments

> 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.

greydot avatar Oct 31 '17 19:10 greydot

What would be the best way to check whether this is caused by hint or GHC itself?

greydot avatar Oct 31 '17 19:10 greydot

@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.

mvdan avatar Jan 16 '18 15:01 mvdan

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.

greydot avatar Jan 16 '18 17:01 greydot

If it's at all helpful, setImportsF was just merged which gives you more control over the imports.

mvdan avatar Jan 16 '18 19:01 mvdan

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.

greydot avatar Jan 17 '18 11:01 greydot

You're absolutely right - that was a brain fart.

mvdan avatar Jan 17 '18 11:01 mvdan

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...

gelisam avatar Apr 18 '20 20:04 gelisam