<div dir="ltr">I think the only path for loading a dependency that doesn't involve loading object code of some kind is the {-# SOURCE #-} hack as part of .hs-boot files, which isn't general enough to be reused here as I understand it. A decent chunk of the compiler would need to be duplicated to avoid this, and it might use a fair amount of memory and end up generating at least part of the object into memory.<div><br></div><div>Also recall that if any TH or quasiquotation is involved, it'll need to load object code in support of that; and it might well need to prepare for this in the general case rather than again having to duplicate a bunch of code to support different no-TH and TH paths.</div><div><br></div><div>Cabal will build all that stuff the first time and then reuse it the next, so it's not quite the same thing. Since you told ghc no object code, it discards what it generates here and may not use existing compiled modules; or you may have specified settings incompatible with any it did find.</div><div><br></div><div>In short, you may want to rethink this; ghc is a compiler, not an IDE, and doesn't quite work the way you had hoped.</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, Oct 8, 2019 at 10:15 AM Sam Halliday <<a href="mailto:sam.halliday@gmail.com">sam.halliday@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Hello all,<br>
<br>
I am writing an interactive tool using the ghc api. It is able to load<br>
and typecheck a source file in a user's package.<br>
<br>
I obtain the flags that cabal uses to compile the user's package via the<br>
hie-bios trick, and I `parseDynamicFlagsCmdLine' them inside my tool,<br>
then I `setTargets' all the home modules (with targetAllowObjCode=True).<br>
<br>
I use HscNothing and NoLink because I only want access to the trees, I<br>
don't want to produce any output files.<br>
<br>
For the file that I wish to inspect, I `removeTarget' the module and<br>
`addTarget` it again but this time providing the full path to the file<br>
and don't allow object code.<br>
<br>
Then I LoadUpTo and typecheck. For the sake of simplicity, let's assume<br>
that the file under inspection only has a module definiton and no<br>
imports or top levels.<br>
<br>
Functionally, my code is working great and I am able to do what I want<br>
with the typechecked tree.<br>
<br>
However, load is very slow (~10 seconds user time) on large projects.<br>
Here is a cpu time trace of my program (milliseconds):<br>
<br>
  main              1<br>
  parse flags      93<br>
  load          20436<br>
  typecheck     20437<br>
<br>
I can enable a bit more ghc timing info via -Rghc-timings and I see<br>
<br>
  !!! Chasing dependencies: finished in 157.20 milliseconds, allocated<br>
      528.112 megabytes<br>
<br>
This seems fine, anything sub-second is ok.<br>
<br>
But then I see a bunch of home modules in CodeGen that I was not expecting:<br>
<br>
   !!! CodeGen [My.Module.Dependency]:<br>
       finished in 3335.62 milliseconds, allocated 270.615 megabytes<br>
<br>
So it looks like the targetAllowObjCode is being ignored... is there any<br>
way to force it? Actually I'd prefer to fail fast than to ever compile<br>
or codegen a dependency module.<br>
<br>
<br>
I know that it should be possible to load the module a lot faster<br>
because if I make a small change in the file under inspection and ask<br>
cabal to recompile the module it is super fast (less than a second).<br>
<br>
Could somebody who understands how incremental/partial compiles work<br>
please help me out?<br>
<br>
<br>
PS: If this textual description is confusing, I could put together a<br>
minimal reproduction and example project but it will take me some time<br>
to do that.<br>
<br>
-- <br>
Best regards,<br>
Sam<br>
_______________________________________________<br>
ghc-devs mailing list<br>
<a href="mailto:ghc-devs@haskell.org" target="_blank">ghc-devs@haskell.org</a><br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs" rel="noreferrer" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs</a><br>
</blockquote></div><br clear="all"><div><br></div>-- <br><div dir="ltr" class="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div>brandon s allbery kf8nh</div><div><a href="mailto:allbery.b@gmail.com" target="_blank">allbery.b@gmail.com</a></div></div></div></div></div>