How to specify import paths for a frontend plugin

Ben Gamari ben at smart-cactus.org
Mon Jan 6 15:14:01 UTC 2020


Derek Lam <derek at lam.io> writes:

> Hi ghc-devs,
>
Hi Derek,

> I’m making a first attempt to make a frontend plugin, to resolve cabal
> packages in the GHC API. However I’m running into troubles with module
> resolution in the GHC API, because I can’t control where it will
> search for modules at all. I've attached a minimal example, with a
> frontend plugin definition that can’t find modules (Plugin.hs), and an
> equivalent standalone program that does (Main.hs).
>
> Specifically, I'm following a solution Edward Yang published in 2017
> (http://blog.ezyang.com/2017/02/how-to-integrate-ghc-api-programs-with-cabal/),
> where the frontend plugin is called through a helper script that
> passes flags forwarded from `cabal repl`. To test the plugin directly
> with GHC, I collected the args through the helper script and filtered
> them to the minimal set that made the plugin run:
>
>   ghc --frontend Plugin -itarget -package-db
> dist-newstyle/packagedb/ghc-8.6.5 Plugin -plugin-package sandbox
> -hide-all-packages
>
> This, as well as the full argument set, would complain that it can't
> find the target module under `./target/A.hs`:
>
>   <no location info>: error: module ‘A’ cannot be found locally
>
> It does when the import path arg `-itarget` is absolute.

By "it does" do you mean "it still fails"?

> Still, its `importPaths` are what I expect: [".", "target"], and the
> standalone program finds the target module with the same
> `importPaths`. I've tested this in GHC 8.6.5, 8.4.2 and 8.2.2, making
> me sure I'm just missing something, but I haven’t found help in the
> docs yet. I really appreciate some help to draw my hours over this to
> a close!
>
Hmm, very interesting. If I recall correctly, the relevant codepath in
GHC is Finder.findImportedModule which should find the module via
Finder.findHomeModule. Unfortunately, in my cursory look I didn't see
any obvious issues; it looks like this might require a build of GHC and
a bit of debugging. If you can produce a minimal, concrete reproducer
(e.g. your plugin and a set of specific instructions to reproduce the
issue) it's possible I can have a look.

Cheers,

- Ben
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 487 bytes
Desc: not available
URL: <http://mail.haskell.org/pipermail/ghc-devs/attachments/20200106/00e486cb/attachment.sig>


More information about the ghc-devs mailing list