Skip to content

Avoid unnecessary recompilation due to -haddock #4596

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

fendor
Copy link
Collaborator

@fendor fendor commented May 21, 2025

Due to unprincipled adding and removing the -haddock flag during compilation and recompilation checking, we were performing more work than necessary.
We avoid this by compiling everything with -haddock by default. This is safe nowadays, we have essentially been doing this for many releases, and know this is fine.
For the occasion where we actually want to parse without the -haddock flag, we keep explicitly disabling it.

We enable -haddock flag during session loading, since we already perform a number of DynFlags tweaks.
This behaviour is dependent on the OptHaddockParse option, which can, currently, only be modified at compile-time.

Closes #4511

@fendor fendor requested a review from wz1000 as a code owner May 21, 2025 16:59
@fendor
Copy link
Collaborator Author

fendor commented May 21, 2025

I would love to implement a regression test for this, but I am currently unsure how.

@fendor
Copy link
Collaborator Author

fendor commented May 26, 2025

I manually tested it on GHC and think I can confirm this fixes the recompilation issue but I struggle to come up with a test case in HLS itself.

@cassandracomar
Copy link

possible issue with this PR -- the haddocks for definitions in the local module don't appear to be available in the completion details. I instead see:

2025-06-02T17:03:10.743161Z | Warning | No plugin handles this "completionItem/resolve" request.

in the lsp server's log output. non-local details DO appear to be resolvable, however, and that warning isn't printed. if I just use master instead of applying this PR, this warning is never printed for either local or non-local bindings.

@fendor
Copy link
Collaborator Author

fendor commented Jun 2, 2025

Thank you for testing this change! I will look into it.

@fendor fendor force-pushed the fix/haddock-recompilation branch 2 times, most recently from af7a56d to e66c922 Compare June 13, 2025 09:12
@fendor
Copy link
Collaborator Author

fendor commented Jun 20, 2025

Can't reproduce, with GHC 9.6.7, I get:
image

and the logs are clear.

@fendor fendor force-pushed the fix/haddock-recompilation branch 2 times, most recently from fd3ee2d to d3d1869 Compare June 20, 2025 11:31
@fendor fendor force-pushed the fix/haddock-recompilation branch from d3d1869 to 5456c1d Compare July 15, 2025 08:30
fendor added 2 commits July 17, 2025 16:18
Due to unprincipled adding and removing the `-haddock` flag during
compilation and recompilation checking, we were performing more work
than necessary.
We avoid this by compiling everything with `-haddock` by default. This
is safe nowadays, we have essentially been doing this for many releases,
and know this is fine.
For the occasion where we actually want to parse without the `-haddock`
flag, we keep explicitly disabling it.

We enable `-haddock` flag during session loading, since we already
perform a number of DynFlags tweaks.
This behaviour is dependent on the `OptHaddockParse` opton, which can,
currently, only be modified at compile-time.
@fendor fendor force-pushed the fix/haddock-recompilation branch from 5456c1d to 67bda98 Compare July 17, 2025 14:18
@fendor fendor requested review from soulomoon and jhrcek July 17, 2025 14:34
@fendor
Copy link
Collaborator Author

fendor commented Jul 17, 2025

I am unsure how to test this, I manually verified that the behaviour reported in #4511 doesn't seem to be occurring in GHC.

Are we fine with merging this as is?

Copy link
Collaborator

@soulomoon soulomoon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good work @fendor .
A few nitpicks for comments.

Before this commit, we do not repect optHaddockParse, and now we correctly repect it in the session loader. Is my understanding correct?

Comment on lines 973 to +974
-- Embed haddocks in the interface file
(diags, mb_pm) <- liftIO $ getParsedModuleDefinition hsc opt f (withOptHaddock ms)
(diags, mb_pm) <- liftIO $ getParsedModuleDefinition hsc opt f ms
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We do still need the comment above ?

-- Otherwise, return the result of parsing without Opt_Haddock, so
-- that the parsed module contains the result of Opt_KeepRawTokenStream,
-- which might be necessary for hlint.
-- Otherwise, return the result of parsing without Opt_Haddock.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OptHaddockParse is not a boolean so we do not need -- Otherwise, return the result of parsing without Opt_Haddock., I think.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

All dependent files are recompiled on a save
3 participants