<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<p>This looks like a bug.<br>
<br>
-hidir documentation says<br>
<br>
> Redirects all generated interface files into ⟨dir⟩, instead
of the default.<br>
> Please also note that when doing incremental compilation (by
ghc --make or ghc -c), this directory is where GHC looks into to
find interface files.<br>
<br>
And documentation for -i doesn't mention looking for interface
files.<br>
<br>
So by doing<br>
<br>
% ghc -dynamic-too -c lib/Lib.hs -odir odir -hidir hidir_Lib<br>
% ghc -dynamic-too -c Main.hs -odir odir -hidir hidir_Main
-ihidir_Lib<br>
1<br>
% ghc odir/Lib.o odir/Main.o -o
Demo <br>
%
./Demo
<br>
True<br>
<br>
everything compiles, TH is run, and demo works. The result files
are<br>
<br>
% find .<br>
.<br>
./Demo<br>
./Main.hs<br>
./hidir_Main<br>
./hidir_Main/Main.dyn_hi<br>
./hidir_Main/Main.hi<br>
./odir<br>
./odir/Main.dyn_o<br>
./odir/Main.o<br>
./odir/Lib.dyn_o<br>
./odir/Lib.o<br>
./hidir_Lib<br>
./hidir_Lib/Lib.dyn_hi<br>
./hidir_Lib/Lib.hi<br>
./lib<br>
./lib/Lib.hs<br>
<br>
---<br>
<br>
The confusing error is caused by Lib module in libiserv:<br>
<a class="moz-txt-link-freetext" href="https://hackage.haskell.org/package/libiserv">https://hackage.haskell.org/package/libiserv</a><br>
which GHC picks!<br>
<br>
If we rename your Lib module to Library, the error is way better:
Could not find module ‘Library’<br>
<br>
I also tried using same -hidir when compiling both modules, then
GHC still cannot find the Library interface, even the
documentation says it should.<br>
<br>
Please open a GHC issue at
<a class="moz-txt-link-freetext" href="https://gitlab.haskell.org/ghc/ghc/-/issues">https://gitlab.haskell.org/ghc/ghc/-/issues</a><br>
<br>
- Oleg<br>
</p>
<div class="moz-cite-prefix">On 22.10.2021 19.16, Domínguez, Facundo
wrote:<br>
</div>
<blockquote type="cite"
cite="mid:CAF7SUTQk-4ekHCbZ8bOaMsBn2QSK_PyvSF6RyQ0bStSRSFGGbQ@mail.gmail.com">
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<div dir="ltr">Dear devs,
<div><br>
</div>
<div>I'm confused about the meaning of -hidir and -i. Here's my
experiment with both ghc-9.2.0 and ghc-8.10.4.</div>
<div><br>
</div>
<div>> $ find</div>
<div>> ./Main.hs<br>
> ./lib/Lib.hs</div>
<div>></div>
<div>> $ ghc -dynamic-too -c lib/Lib.hs -odir odir -hidir
hidir_Lib</div>
<div>></div>
<div>> $ ghc -dynamic-too -c Main.hs -odir odir -ihidir_Lib
-hidir hidir_Main</div>
<div>></div>
<div>> Main.hs:3:1: error:<br>
> Bad interface file: hidir_Main/Lib.hi<br>
> hidir_Main/Lib.hi: openBinaryFile: does not exist
(No such file or directory)<br>
> |<br>
> 3 | import Lib<br>
> | ^^^^^^^^^^<br>
</div>
<div><br>
</div>
<div>If I only use -hidir, it still fails with another error</div>
<div><br>
</div>
<div>> $ ghc -dynamic-too -c Main.hs -odir odir -hidir
hidir_Lib</div>
><br>
> Main.hs:7:29: error: Variable not in scope: f<br>
> |<br>
> 7 | main = print $(runIO (print f) >> [| True |])<br>
> | ^<br>
<div><br>
</div>
<div>If I use both -i and -hidir pointing to the same folder,
then it works!</div>
<div><br>
</div>
<div>> $ ghc -dynamic-too -c Main.hs -odir odir -ihidir_Lib
-hidir hidir_Lib<br>
</div>
<div><br>
</div>
<div>Now, is this behavior a bug or a feature? And if it is a
bug, what is the expected behavior?</div>
<div><br>
</div>
<div>Programs copied below.</div>
<div><br>
</div>
<div>Thank you!</div>
<div>Facundo</div>
<div><br>
</div>
<div>> $ cat lib/Lib.hs<br>
> module Lib where<br>
><br>
> f :: Int<br>
> f = 1<br>
</div>
<div>></div>
<div>> $ cat Main.hs<br>
> {-# LANGUAGE TemplateHaskell #-}<br>
><br>
> import Lib<br>
> import <a href="http://language.haskell.th/"
target="_blank" moz-do-not-send="true">Language.Haskell.TH</a><br>
><br>
> main :: IO ()<br>
> main = print $(runIO (print f) >> [| True |])</div>
</div>
<br>
<fieldset class="mimeAttachmentHeader"></fieldset>
<pre class="moz-quote-pre" wrap="">_______________________________________________
ghc-devs mailing list
<a class="moz-txt-link-abbreviated" href="mailto:ghc-devs@haskell.org">ghc-devs@haskell.org</a>
<a class="moz-txt-link-freetext" href="http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs">http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs</a>
</pre>
</blockquote>
</body>
</html>