Skip to content

All dependent files are recompiled on a save #4511

Open
@mpickering

Description

@mpickering
Contributor

When a save a file, recompilation is triggered for all the files which depend on the file I saved.

I tracked down the bug to the fact that

  1. Interfaces are created with -haddock option set.
  2. Recompilation checking is run in a context where -haddock is not set.

This seems to be complicated with all the logic with turning -haddock on in some situations and not in others.

The following diff "fixes" the immediate problem for me, but I don't know if there are some situations where interfaces are created without -haddock being enabled.

--- a/ghcide/src/Development/IDE/Core/Compile.hs
+++ b/ghcide/src/Development/IDE/Core/Compile.hs
@@ -1275,7 +1275,7 @@ loadInterface
   -> RecompilationInfo m
   -> m ([FileDiagnostic], Maybe HiFileResult)
 loadInterface session ms linkableNeeded RecompilationInfo{..} = do
-    let sessionWithMsDynFlags = hscSetFlags (ms_hspp_opts ms) session
+    let sessionWithMsDynFlags = hscSetFlags (gopt_set (ms_hspp_opts ms) Opt_Haddock) session
         mb_old_iface = hirModIface . fst <$> old_value
         mb_old_version = snd <$> old_value

It would be simpler if the options chosen to compile a file were fixed at the start of compilation and not modified in ad-hoc places later on.

In my opinion this is a serious bug.

Activity

added
type: bugSomething isn't right: doesn't work as intended, documentation is missing/outdated, etc..
on Mar 4, 2025
self-assigned this
on Mar 11, 2025
guibou

guibou commented on May 19, 2025

@guibou
Collaborator

@mpickering how did you diagnosticed that the rebuild was due to an haddock flag?

Context: I'm having a lot of rebuild. I've documented an analyzed a bit in #4443, but I would like to know more about how you did understood this specific issue so I may apply a similar approach to understand my issues.

mpickering

mpickering commented on May 19, 2025

@mpickering
ContributorAuthor

@guibou I turned on -ddump-hi-diffs -fwrite-if-self-recomp-flags which needs a GHC which included this patch - https://gitlab.haskell.org/ghc/ghc/-/merge_requests/13792

guibou

guibou commented on May 19, 2025

@guibou
Collaborator

@mpickering Thank you. Indeed, this patch is super interesting. I'll investigate my issues with that.

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

Metadata

Metadata

Assignees

Labels

component: ghcidepriority: highHigh priority itemtype: bugSomething isn't right: doesn't work as intended, documentation is missing/outdated, etc..

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

    Development

    Participants

    @mpickering@fendor@guibou

    Issue actions

      All dependent files are recompiled on a save · Issue #4511 · haskell/haskell-language-server