You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
cabal new-build does not track files added via TH’s addDependentFile #4746
BTW, is there a way to force ghc --make always rerun a TH function? E.g. if I'm doing some kind of I/O at compile-time, like reading from an environment variable.
Yep, but sometimes you want that in a build system. For example, Shake rules can be marked alwaysRerun.
Re: extra-source-files, that field is package-global and commonly used for things like README and changelog. So we'd need to allow per-component extra-source-files to avoid unnecessary recompilation.
An alternative way to fix this is to get the list of files to be monitored from ghc --make via -ddump-module-graph (a new feature that is going to be in 8.4).
@cocreature With old versions we can simulate that feature with ghc -M (which will be slower because we'll have to do dependency resolution twice - once for ghc -M and once for ghc --make, but for legacy GHC versions we can afford to not care). BTW, ghc -M does support addDependentFile dependencies:
# DO NOT DELETE: Beginning of Haskell dependencies
Data/FileEmbed.so : Data/FileEmbed.hs
Main.so : Main.hs
Main.so : Data/FileEmbed.shi
# DO NOT DELETE: End of Haskell dependencies
@23Skidoo btw, we can avoid paying for the slow-legacy fallback when it's not needed, because we know when TH is needed (we already require TemplateHaskell to be declared in *-extensions in order to enable other logic specific to TH). So I think that's a workable fallback.
PS: Screen-scraping GHC's dump-hi output would be an obvious but terrible hack for the obvious reasons and since it's not intended to be consumed by tooling its format is neither documented nor guaranteed to be correct and can change without notice.
Upvoting this issue. It is critical for larger web-dev shops that have people who are totally focused on front-end web UI development. They require instant reload; they don't have time to poke around at files manually every time to induce rebuilds.
We are a yesod shop, so we are using stack. For comparison, stack detects this by parsing dump-hi files. The syntax change in dump-hi files in GHC 8.4 caused a similar issue in stack for a time, now fixed.
I'm very surprised to see this being labeled as "priority:low" given that I consider this a dealbreaking "cannot consider cabal usable until fixed"-bug.
@NorfairKing: I've bumped priority. PRs welcome. Actually, design welcome first, IIRC? Especially that it's marked as blocked on GHC, so we either need to create a patch for GHC or devise a special workaround?
Me neither, but it's a long time since I looked into this long discussion thread (assuming I understood it then). Do you think things may have changed since then? Would you like to re-assess?
@Mikolaj I don't understand how this is blocked on GHC when stack has not had this bug since 2015.
Only GHC knows the result of running TH (do you really want cabal duplicating enough of GHC that it can run TH itself? Remember that you can do conditionals) so it would have been blocked on GHC exporting that information usefully. Later messages in this thread indicate it's now part of the .hi file, so presumably this can proceed now.
@phadej has also educated me on this issue just now:
"
The #4746 is softly fixed in Cabal too. If you add a file to extra-source-files, it will track its dirtyness. Maybe stack just tracks everything (i.e. overestimates even more). To fix that issue exactly, GHC must tell what files were actually used, so they could be recorded as an exact dependency.
like CPP implementation tell which headers were actually included when you preprocess a source file.
(FWIW, these aren't recorded either, it's just not so obvious) https://gitlab.haskell.org/ghc/ghc/-/issues/25017
addDependentFile dependencies are at least recorded in the interface files, so if one really wants, then by parsing ghc --show-iface output one can figure those out.
"
So maybe we could look into the .hi files. Worth investigating. Volunteers welcome.
Stack does some not so good design choices, and that's a good example of a bad design.
But if you want one more thing to slow down making recent ghc compatible releases, go ahead: AFAICT, hi-file-parser doesn't support GHC-9.10, at the very least it's not tested: the last commit is from 7 months ago.
Reading Mikolaj's post above, I thought that Oleg supports the idea of parsing .hi files. Is there anything wrong with hi-file-parser in particular or is there anything else that is both better and achievable with our limited resources?
This issue looks important for some amount of users. Feature-parity with stack is a desirable goal too (modulo some things like installing GHC). I wish we could come to an agreement on some way forward for this.
Activity
phadej commentedon Sep 6, 2017
One hack solution is to watch
extra-source-filestoo. But that won't solve dynamic (e.g. whatinline-cuses?) stuff.23Skidoo commentedon Sep 6, 2017
BTW, is there a way to force
ghc --makealways rerun a TH function? E.g. if I'm doing some kind of I/O at compile-time, like reading from an environment variable.phadej commentedon Sep 6, 2017
@23Skidoo that would force GHC to always build that module, that doesn't sound like a very good idea.
23Skidoo commentedon Sep 6, 2017
Yep, but sometimes you want that in a build system. For example, Shake rules can be marked
alwaysRerun.Re:
extra-source-files, that field is package-global and commonly used for things likeREADMEandchangelog. So we'd need to allow per-componentextra-source-filesto avoid unnecessary recompilation.23Skidoo commentedon Sep 7, 2017
An alternative way to fix this is to get the list of files to be monitored from
ghc --makevia-ddump-module-graph(a new feature that is going to be in 8.4).phadej commentedon Sep 7, 2017
Does
-ddump-module-graphdumpaddDependentFile& co stuff?23Skidoo commentedon Sep 7, 2017
@phadej If you click that link, you'll see that I asked that exact question there.
cocreature commentedon Sep 7, 2017
Given that this feature will only be in
GHC 8.4I don’t think that’s a reasonable solution at this point.23Skidoo commentedon Sep 7, 2017
@cocreature With old versions we can simulate that feature with
ghc -M(which will be slower because we'll have to do dependency resolution twice - once forghc -Mand once forghc --make, but for legacy GHC versions we can afford to not care). BTW,ghc -Mdoes supportaddDependentFiledependencies:hvr commentedon Sep 7, 2017
@23Skidoo btw, we can avoid paying for the slow-legacy fallback when it's not needed, because we know when TH is needed (we already require
TemplateHaskellto be declared in*-extensionsin order to enable other logic specific to TH). So I think that's a workable fallback.hvr commentedon Aug 8, 2018
Unfortunately we not only missed the boat for GHC 8.4, but most likely also for GHC 8.6 to get supporting features into GHC... as https://phabricator.haskell.org/D3898 got stuck on a decision which design path to go down... :-/
PS: Screen-scraping GHC's
dump-hioutput would be an obvious but terrible hack for the obvious reasons and since it's not intended to be consumed by tooling its format is neither documented nor guaranteed to be correct and can change without notice.ygale commentedon Nov 18, 2018
Upvoting this issue. It is critical for larger web-dev shops that have people who are totally focused on front-end web UI development. They require instant reload; they don't have time to poke around at files manually every time to induce rebuilds.
We are a yesod shop, so we are using stack. For comparison, stack detects this by parsing
dump-hifiles. The syntax change indump-hifiles in GHC 8.4 caused a similar issue in stack for a time, now fixed.55 remaining items
KristianBalaj commentedon Feb 27, 2024
I think this is a related issue I've just created - #9745
NorfairKing commentedon Jun 23, 2024
I'm very surprised to see this being labeled as "priority:low" given that I consider this a dealbreaking "cannot consider cabal usable until fixed"-bug.
Mikolaj commentedon Jun 24, 2024
@NorfairKing: I've bumped priority. PRs welcome. Actually, design welcome first, IIRC? Especially that it's marked as blocked on GHC, so we either need to create a patch for GHC or devise a special workaround?
NorfairKing commentedon Jun 24, 2024
@Mikolaj I don't understand how this is blocked on GHC when stack has not had this bug since 2015.
Mikolaj commentedon Jun 24, 2024
Me neither, but it's a long time since I looked into this long discussion thread (assuming I understood it then). Do you think things may have changed since then? Would you like to re-assess?
TeofilC commentedon Jun 24, 2024
My understanding is that stack gets this information by parsing binary
.hifiles using (See: commercialhaskell/stack#5134).https://gitlab.haskell.org/ghc/ghc/-/merge_requests/11994 is some movement towards getting a proper interface for exposing the dependency graph from the GHC side. Though I'm not sure if that includes TH dependencies
geekosaur commentedon Jun 24, 2024
Only GHC knows the result of running TH (do you really want cabal duplicating enough of GHC that it can run TH itself? Remember that you can do conditionals) so it would have been blocked on GHC exporting that information usefully. Later messages in this thread indicate it's now part of the
.hifile, so presumably this can proceed now.Mikolaj commentedon Jun 24, 2024
Thank you for your remarks.
@phadej has also educated me on this issue just now:
"
The #4746 is softly fixed in Cabal too. If you add a file to extra-source-files, it will track its dirtyness. Maybe stack just tracks everything (i.e. overestimates even more). To fix that issue exactly, GHC must tell what files were actually used, so they could be recorded as an exact dependency.
like CPP implementation tell which headers were actually included when you preprocess a source file.
(FWIW, these aren't recorded either, it's just not so obvious)
https://gitlab.haskell.org/ghc/ghc/-/issues/25017
addDependentFile dependencies are at least recorded in the interface files, so if one really wants, then by parsing ghc --show-iface output one can figure those out.
"
So maybe we could look into the
.hifiles. Worth investigating. Volunteers welcome.ulysses4ever commentedon Jun 24, 2024
That's what Sylvain said above: Stack parses hi for this reason (not sure alone or not) with https://github.com/commercialhaskell/hi-file-parser, and we should adopt it.
phadej commentedon Jun 25, 2024
@ulysses4ever
No you shouldn't. see e.g. commercialhaskell/stack#5134.
Stack does some not so good design choices, and that's a good example of a bad design.
But if you want one more thing to slow down making recent ghc compatible releases, go ahead: AFAICT,
hi-file-parserdoesn't support GHC-9.10, at the very least it's not tested: the last commit is from 7 months ago.mpickering commentedon Jun 25, 2024
I completely agree with Oleg that depending on "hi-file-parser" is a bad idea.
ulysses4ever commentedon Jun 28, 2024
@phadej @mpickering what are our options?
Reading Mikolaj's post above, I thought that Oleg supports the idea of parsing
.hifiles. Is there anything wrong withhi-file-parserin particular or is there anything else that is both better and achievable with our limited resources?This issue looks important for some amount of users. Feature-parity with stack is a desirable goal too (modulo some things like installing GHC). I wish we could come to an agreement on some way forward for this.
phadej commentedon Jun 28, 2024
I didn't say that, and I only implied that one could parse
ghc --show-ifaceoutput, but even that is fragile, and thus bad idea.