-
Notifications
You must be signed in to change notification settings - Fork 43
Add reload #26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add reload #26
Conversation
mvdan
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall sounds like a good idea, but would like to have someone else's input too.
cc @gelisam
src/Hint/Context.hs
Outdated
| doLoad fs `catchIE` (\e -> reset >> throwM e) | ||
| targets <- mapM (\f->runGhc2 GHC.guessTarget f Nothing) fs | ||
| runGhc1 GHC.setTargets targets | ||
| doLoad GHC.LoadAllTargets `catchIE` (\e -> reset >> throwM e) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line is exactly what reload runs too. Deduplicate code?
src/Language/Haskell/Interpreter.hs
Outdated
| -- ** Context handling | ||
| ModuleName, isModuleInterpreted, | ||
| loadModules, getLoadedModules, setTopLevelModules, | ||
| reload, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please put it in the reset line like the other file.
| -- | ||
| runGhc1 GHC.setTargets targets | ||
| res <- runGhc1 GHC.load GHC.LoadAllTargets | ||
| reload :: MonadInterpreter m => m () |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this will be exported, it will need documentation. See how it is done for reset.
|
Also please use a slightly more detailed commit message, like |
26bb948 to
80ac231
Compare
|
Thanks for the feedback. I've found I need to call |
mvdan
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've found I need to call setTopLevelModules after calling reload. Maybe this should perform getContext / setContext also, to behave a little more like GHCi. What do you think?
setTopLevelModules seems to call setContext, so I would think not.
In any case, if we're wrong about this, I'm not too worried as we could fix it later without changing the exposed API.
src/Hint/Context.hs
Outdated
| res <- runGhc1 GHC.load GHC.LoadAllTargets | ||
| targets <- mapM (\f->runGhc2 GHC.guessTarget f Nothing) fs | ||
| runGhc1 GHC.setTargets targets | ||
| catchReset (doLoad GHC.LoadAllTargets) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I meant that this line could just call reload, unless I'm missing something. Then, catchReset would be unnecessary.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed. Apologies for my density!
80ac231 to
edddb9c
Compare
|
Thanks for the updates. Code looks good, but since I'm not familiar with ghci's |
|
I'm not familiar with it either, sorry. |
|
Could I suggest adding a unit test for this function? It will make it easier to convince people that this actually works as intended, and it will make the life of @mvdan infinitely easier the next time the ghc api changes and |
Sounds good. I expect to be using this functionality for some internal developer tooling pretty shortly, so we'll know pretty quickly if it misbehaves or (more likely) is annoying to use.
In the absence of this person, I'll try to convince you of my reasoning. here is the implementation from It also reverts CAFs after every load/reload. I noticed Hint has a few comments wondering if we should do that or not, I certainly don't know the answer :) though it seems the consequences mostly affect magic constants like The other step in
I'll add some tests similar to those for |
| -- | ||
| liftIO $ writeFile mod_file_a mod_a_v2 | ||
| liftIO $ writeFile mod_file_b mod_b | ||
| set [searchPath := ["."]] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not quite sure why this is necessary, will need to spend some time debugging. It breaks if you move it to the top, which isn't good!
|
Thanks for adding the test!
Let me know when you're happy with the PR. |
mvdan
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just to remind myself and everyone that this isn't ready to merge, I'm marking it as "changes requested".
|
Thanks, I'll get to this pretty soon. Just restating the reason for block, for future archaeologists: something odd is happening when working on modules in |
|
Friendly ping - any news? I'm not in a rush, but I'm not a fan of leaving pull requests open for a long time either. Perhaps we should move this to an issue after the summer if it's still not ready to merge by then. |
|
Sorry for the delay! The project I needed this for has been postponed for a while. If I haven't addressed it the next time you come around to it I'm happy for it to be turned into an issue.
While this mostly works as-is, I feel the quirks of GHC's module resolution should be better understood and documented before this is made available to users. It can be quite surprising. I was able to build large commercial applications and do incremental reloading with the current implementation, but you need to be holding it right, as my testing woes above suggest.
… On 12 Jun. 2017, at 7:54 pm, Daniel Martí ***@***.***> wrote:
Friendly ping - any news? I'm not in a rush, but I'm not a fan of leaving pull requests open for a long time either.
Perhaps we should move this to an issue after the summer if it's still not ready to merge by then.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub, or mute the thread.
|
|
It has been a full year without activity, so I'm going to close this pull request for now. Please feel free to reopen it if you do find time to work on it again. Or, if you think there's useful information for others here, but you're not planning on using it yourself soon, feel free to move the thread to an issue as well. |
Howdy maintainers,
I've been using hint for dynamic reloading of web applications, where filesystem events or other signals trigger a reload and restart. The implicit
resetinloadModulesmade this quite slow, so I wrote this GHCi-style incrementalreloadfunction.Let me know if there are any changes required, or if there are safety concerns that might prevent it being merged. It seems to be roughly equivalent to GHCi's reload command.
Thanks for building and maintaining this library, it saved me a lot of GHC API pain.