Fastest way to reload module with GHC API

Hello, I just want to be sure of what's the fastest way to reload a module with the GHC API. I have a file whose path is fp I load the module with: addTarget Target { targetId = TargetFile fp Nothing, targetAllowObjCode = True, targetContents = Nothing } Then I load the module load LoadAllTargets And when I want to reload the module (the contents of fp have changed) I do: removeTarget (TargetFile fp Nothing) load LoadAllTargets and then I rerun my initial code (addTarget, load) This works well, I don't get any errors about duplicates, the information I extract from the module is updated properly. But is it the most efficient, or can I achieve the same thing faster (I'm looking at improving the performance of my BuildWrapper code and by consequence of EclipseFP)? Thanks! -- JP Moresmau http://jpmoresmau.blogspot.com/

On 25/01/13 14:30, JP Moresmau wrote:
Hello, I just want to be sure of what's the fastest way to reload a module with the GHC API. I have a file whose path is fp I load the module with: addTarget Target { targetId = TargetFile fp Nothing, targetAllowObjCode = True, targetContents = Nothing } Then I load the module load LoadAllTargets And when I want to reload the module (the contents of fp have changed) I do: removeTarget (TargetFile fp Nothing) load LoadAllTargets and then I rerun my initial code (addTarget, load)
You should be able to just invoke 'load LoadAllTargets' and omit the intermediate remove/load step. Or is there a reason you want to remove the target? Cheers, Simon

When I do that (only adding the target once and just doing load after the
file has changed) the changes in the file are not taken into account
(getNamesInScope for example doesn't give me the name of a type added
inside the file). I probably have my stupid hat on (friday afternoon...),
but when I do remove/load in between it works...
Thanks
On Fri, Jan 25, 2013 at 4:33 PM, Simon Marlow
On 25/01/13 14:30, JP Moresmau wrote:
Hello, I just want to be sure of what's the fastest way to reload a module with the GHC API. I have a file whose path is fp I load the module with: addTarget Target { targetId = TargetFile fp Nothing, targetAllowObjCode = True, targetContents = Nothing } Then I load the module load LoadAllTargets And when I want to reload the module (the contents of fp have changed) I do: removeTarget (TargetFile fp Nothing) load LoadAllTargets and then I rerun my initial code (addTarget, load)
You should be able to just invoke 'load LoadAllTargets' and omit the intermediate remove/load step. Or is there a reason you want to remove the target?
Cheers, Simon
-- JP Moresmau http://jpmoresmau.blogspot.com/

Has the file's modification time changed? If you're doing this very quickly (within 1 second) then you might run into this: http://hackage.haskell.org/trac/ghc/ticket/7473 Cheers, Simon On 25/01/13 16:02, JP Moresmau wrote:
When I do that (only adding the target once and just doing load after the file has changed) the changes in the file are not taken into account (getNamesInScope for example doesn't give me the name of a type added inside the file). I probably have my stupid hat on (friday afternoon...), but when I do remove/load in between it works...
Thanks
On Fri, Jan 25, 2013 at 4:33 PM, Simon Marlow
mailto:marlowsd@gmail.com> wrote: On 25/01/13 14:30, JP Moresmau wrote:
Hello, I just want to be sure of what's the fastest way to reload a module with the GHC API. I have a file whose path is fp I load the module with: addTarget Target { targetId = TargetFile fp Nothing, targetAllowObjCode = True, targetContents = Nothing } Then I load the module load LoadAllTargets And when I want to reload the module (the contents of fp have changed) I do: removeTarget (TargetFile fp Nothing) load LoadAllTargets and then I rerun my initial code (addTarget, load)
You should be able to just invoke 'load LoadAllTargets' and omit the intermediate remove/load step. Or is there a reason you want to remove the target?
Cheers, Simon
-- JP Moresmau http://jpmoresmau.blogspot.com/

Yes, thank you Simon, my test works if I wait at least 1 second before the
two loads, so I'd say I run exactly into that issue. So I can adapt my code
to only remove the target if the files do not give me a time difference.
Thanks a million!
JP
On Fri, Jan 25, 2013 at 5:29 PM, Simon Marlow
Has the file's modification time changed? If you're doing this very quickly (within 1 second) then you might run into this:
http://hackage.haskell.org/**trac/ghc/ticket/7473http://hackage.haskell.org/trac/ghc/ticket/7473
Cheers, Simon
On 25/01/13 16:02, JP Moresmau wrote:
When I do that (only adding the target once and just doing load after the file has changed) the changes in the file are not taken into account (getNamesInScope for example doesn't give me the name of a type added inside the file). I probably have my stupid hat on (friday afternoon...), but when I do remove/load in between it works...
Thanks
On Fri, Jan 25, 2013 at 4:33 PM, Simon Marlow
mailto:marlowsd@gmail.com> wrote: On 25/01/13 14:30, JP Moresmau wrote:
Hello, I just want to be sure of what's the fastest way to reload a module with the GHC API. I have a file whose path is fp I load the module with: addTarget Target { targetId = TargetFile fp Nothing, targetAllowObjCode = True, targetContents = Nothing } Then I load the module load LoadAllTargets And when I want to reload the module (the contents of fp have changed) I do: removeTarget (TargetFile fp Nothing) load LoadAllTargets and then I rerun my initial code (addTarget, load)
You should be able to just invoke 'load LoadAllTargets' and omit the intermediate remove/load step. Or is there a reason you want to remove the target?
Cheers, Simon
-- JP Moresmau http://jpmoresmau.blogspot.**com/ http://jpmoresmau.blogspot.com/
-- JP Moresmau http://jpmoresmau.blogspot.com/
participants (2)
-
JP Moresmau
-
Simon Marlow