Skip to content

cabal new-build does not track files added via TH’s addDependentFile #4746

Open

Description

@cocreature

Steps to reproduce

Expected behavior

cabal new-build rebuilds because fileinput has changed.

Actual behavior

cabal new-build exits without rebuilding after saying Up to date.

This issue affects both cabal-2.0 as well as the master branch.

Activity

  1. added
    cabal-install: v2-build system
    on Sep 6, 2017
  2. phadej commented on Sep 6, 2017

    @phadej
    Collaborator

    One hack solution is to watch extra-source-files too. But that won't solve dynamic (e.g. what inline-c uses?) stuff.

  3. 23Skidoo commented on Sep 6, 2017

    @23Skidoo
    Member

    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.

  4. phadej commented on Sep 6, 2017

    @phadej
    Collaborator

    @23Skidoo that would force GHC to always build that module, that doesn't sound like a very good idea.

  5. 23Skidoo commented on Sep 6, 2017

    @23Skidoo
    Member

    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.

  6. 23Skidoo commented on Sep 7, 2017

    @23Skidoo
    Member

    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).

  7. phadej commented on Sep 7, 2017

    @phadej
    Collaborator

    Does -ddump-module-graph dump addDependentFile & co stuff?

  8. 23Skidoo commented on Sep 7, 2017

    @23Skidoo
    Member

    @phadej If you click that link, you'll see that I asked that exact question there.

  9. cocreature commented on Sep 7, 2017

    @cocreature
    CollaboratorAuthor

    Given that this feature will only be in GHC 8.4 I don’t think that’s a reasonable solution at this point.

  10. 23Skidoo commented on Sep 7, 2017

    @23Skidoo
    Member

    @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
    
  11. hvr commented on Sep 7, 2017

    @hvr
    Member

    @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.

  12. hvr commented on Aug 8, 2018

    @hvr
    Member

    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-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.

  13. ygale commented on Nov 18, 2018

    @ygale
    Contributor

    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.

  14. 55 remaining items

  15. KristianBalaj commented on Feb 27, 2024

    @KristianBalaj

    I think this is a related issue I've just created - #9745

  16. NorfairKing commented on Jun 23, 2024

    @NorfairKing

    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.

  17. Mikolaj commented on Jun 24, 2024

    @Mikolaj
    Member

    @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?

  18. NorfairKing commented on Jun 24, 2024

    @NorfairKing

    @Mikolaj I don't understand how this is blocked on GHC when stack has not had this bug since 2015.

  19. Mikolaj commented on Jun 24, 2024

    @Mikolaj
    Member

    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?

  20. TeofilC commented on Jun 24, 2024

    @TeofilC
    Member

    My understanding is that stack gets this information by parsing binary .hi files 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

  21. geekosaur commented on Jun 24, 2024

    @geekosaur
    Collaborator

    @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.

  22. Mikolaj commented on Jun 24, 2024

    @Mikolaj
    Member

    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 .hi files. Worth investigating. Volunteers welcome.

  23. ulysses4ever commented on Jun 24, 2024

    @ulysses4ever
    Collaborator

    So maybe we could look into the .hi files.

    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.

  24. phadej commented on Jun 25, 2024

    @phadej
    Collaborator

    @ulysses4ever

    https://github.com/commercialhaskell/hi-file-parser, and we should adopt it.

    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-parser doesn't support GHC-9.10, at the very least it's not tested: the last commit is from 7 months ago.

  25. mpickering commented on Jun 25, 2024

    @mpickering
    Collaborator

    I completely agree with Oleg that depending on "hi-file-parser" is a bad idea.

  26. ulysses4ever commented on Jun 28, 2024

    @ulysses4ever
    Collaborator

    @phadej @mpickering what are our options?

    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.

  27. phadej commented on Jun 28, 2024

    @phadej
    Collaborator

    I thought that Oleg supports the idea of parsing .hi files.

    I didn't say that, and I only implied that one could parse ghc --show-iface output, but even that is fragile, and thus bad idea.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    blocked: ghcblocked: upstreamcabal-install: v2-build systemre: extra-source-filestype: discussiontype: enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions