Skip to content
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

haskellPackages: doHaddockInterfaces #91557

Closed
wants to merge 2 commits into from

Conversation

pepeiborra
Copy link
Contributor

@pepeiborra pepeiborra commented Jun 26, 2020

Motivation for this change

Adds a new builder option doHaddockInterfaces to enable the -haddock flag in GHC,
which results in Haddock comments parsed at compile-time and embedded in
interface files. These are used by the :doc command in GHCi, as well as by IDE
tools like ghcide and hls to display docs on hover.

The -haddock flag has been around since at least 8.2, even though it does not
get a mention in the GHC Users guide.

There are two downsides to turning on this flag:

  1. Increased compile times, since Haddocks must be parsed and then encoded
  2. Haddock parse errors now become compile errors

Item 2 in particular can be quite problematic for benchmarks and test suites,
where Haddock parse errors would not be a consideration.
This explains the default setting for doHaddockInterfaces being doHaddock && !doCheck .
Once the problem is fixed in
GHC, the doHaddockInterfaces default value can be updated to be always on in
certain GHC versions.

Things done
  • Tested using sandboxing (nix.useSandbox on NixOS, or option sandbox in nix.conf on non-NixOS linux)
  • Built on platform(s)
    • NixOS
    • macOS
    • other Linux distributions
  • Tested via one or more NixOS test(s) if existing and applicable for the change (look inside nixos/tests)
  • Tested compilation of all pkgs that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review wip"
  • Tested execution of all binary files (usually in ./result/bin/)
  • Determined the impact on package closure size (by running nix path-info -S before and after)
  • Ensured that relevant documentation is up to date
  • Fits CONTRIBUTING.md.

@cdepillabout
Copy link
Member

@pepeiborra Would you be able to explain a little bit more about what this does, and why we would want to enable it? (And possibly link to upstream documentation? Although it sounds like it might not be documented upstream...)

In my experience, many packages have incorrect haddocks, so I'd be somewhat hesitant to enable this by default if it causes compile errors.

@pepeiborra
Copy link
Contributor Author

@pepeiborra Would you be able to explain a little bit more about what this does, and why we would want to enable it? (And possibly link to upstream documentation? Although it sounds like it might not be documented upstream...)

In my experience, many packages have incorrect haddocks, so I'd be somewhat hesitant to enable this by default if it causes compile errors.

The -haddock flag instructs GHC to parse doc comments with Haddock, and embed the results inside .hi files, which are compilation artifacts and get distributed together with libraries. This makes Haddocks available to ghci and other tools like ghcide/hls, which is the main motivation to enable it.

Your concern is fair, some packages have incorrect haddocks (specially in test suites) and -haddock will break the build. But I believe this PR should not introduce a problem, because:

  • The default value for doHaddockInterfaces is doHaddock && !doCheck which equals False as the default value for doCheck is true
  • There are lib functions to change doHaddockInterfaces on a per library basis.

@cdepillabout
Copy link
Member

@pepeiborra Ah, so you're saying that anywhere we are already building haddocks, then the addition in this PR shouldn't cause any new build failures?

In that case, it seems pretty safe to add this.

Could you rebase this on the haskell-updates branch, as well as change the base branch here on github?


cc @peti and @maralorn about this as well

@pepeiborra
Copy link
Contributor Author

@pepeiborra Ah, so you're saying that anywhere we are already building haddocks, then the addition in this PR shouldn't cause any new build failures?

Kind of, except that cabal haddock doesn't parse comments in exe/test/bench suites, but this change will.

Unfortunately I believe there is no way to instruct Cabal to use a GHC option only in the library stanza. This has been raised in the Cabal issue tracker, but no mention of progress:

@pepeiborra pepeiborra changed the base branch from master to haskell-updates June 26, 2020 08:41
@cdepillabout
Copy link
Member

@pepeiborra Normally what happens with these types of PRs is that @peti will try merging it into the haskell-updates branch, and we see how many additional compilation errors it causes.

If it is just a few, then we fix them up by hand. If it is a bunch, then we merge it in but keep the option off by default.

@cdepillabout
Copy link
Member

Lets see if ofborg is able to build a couple common packages for us:

@GrahamcOfBorg build haskellPackages.lens
@GrahamcOfBorg build haskellPackages.xmonad
@GrahamcOfBorg build haskellPackages.spago

@ofborg ofborg bot added the 8.has: package (new) This PR adds a new package label Jun 26, 2020
@maralorn
Copy link
Member

What I really don‘t like about this change is, that it favors package without tests.
I think having incentive "I wish I had haddock informations in this hover" -> "lets just disable the tests in nixpkgs" could be a bad idea.

On the other hand I am obviously hugely in favor for improving the IDE experience. And if we regard this as an experiment to be improved upon, I am in favor.

@maralorn
Copy link
Member

Also: This shows that I would be awesome to have better tuned control over different cabal outputs in nix.

@pepeiborra
Copy link
Contributor Author

What I really don‘t like about this change is, that it favors package without tests.
I think having incentive "I wish I had haddock informations in this hover" -> "lets just disable the tests in nixpkgs" could be a bad idea.

On the other hand I am obviously hugely in favor for improving the IDE experience. And if we regard this as an experiment to be improved upon, I am in favor.

I am not a huge fan either, but this is what I arrived at after much thinking and tinkering. If you have a better idea, I would love to hear it.

Even when/if the issue gets fixed in GHC, backwards compatibility with previous GHC releases will limit our options here.

@cdepillabout
Copy link
Member

At the very least, this now works with lens, spago, and xmonad (and all their dependencies).

@peti peti force-pushed the haskell-updates branch 3 times, most recently from 2afb81a to c7cadae Compare June 26, 2020 20:45
@peti
Copy link
Member

peti commented Jun 26, 2020

I don't like the constraint doHaddock && !doCheck very much. "Haddock information" feels like a totally different thing than "test suites", and I'd rather not create some connection between the two ... because there is none.

How about we enable the new Haddock feature for all packages, test build the package set, and see how many actual errors we'll have? If it's just a handful, then we could simply open PRs for the respective upstreams and fix those issues?

@pepeiborra
Copy link
Contributor Author

I don't like the constraint doHaddock && !doCheck very much. "Haddock information" feels like a totally different thing than "test suites", and I'd rather not create some connection between the two ... because there is none.

How about we enable the new Haddock feature for all packages, test build the package set, and see how many actual errors we'll have? If it's just a handful, then we could simply open PRs for the respective upstreams and fix those issues?

I suspect it's quite a few packages that have comments in their test suites that trip up the Haddock parser. Even if we open PRs for all of them, it would take a long time for all those PRs to get merged and eventually released. And it looks like this issue will be fixed in GHC 8.12 anyway.

Would you object to this PR if the default value for the new option was doHaddockInterfaces ? false ?

@peti
Copy link
Member

peti commented Jul 1, 2020

I suspect it's quite a few packages that have comments in their test suites that trip up the Haddock parser. Even if we open PRs for all of them, it would take a long time for all those PRs to get merged and eventually released.

This is speculation, though. I'd rather know how many packages actually break, and we have the means to find out thanks to Hydra.

Would you object to this PR if the default value for the new option was doHaddockInterfaces ? false ?

No, I think that would be perfectly fine.

@pepeiborra
Copy link
Contributor Author

I suspect it's quite a few packages that have comments in their test suites that trip up the Haddock parser. Even if we open PRs for all of them, it would take a long time for all those PRs to get merged and eventually released.

This is speculation, though. I'd rather know how many packages actually break, and we have the means to find out thanks to Hydra.

I'm not that familiar with Nix and Hydra. Do I just push a change to my branch to turn the setting on and wait for results?

@pepeiborra
Copy link
Contributor Author

I have pushed a change to turn on DoHaddockInterfaces by default. What's next?

@peti
Copy link
Member

peti commented Jul 3, 2020

I have merged your changes into the branch pr-91557. That branch is built continuously by https://hydra.nixos.org/jobset/nixpkgs/pr-91557, so any changes we'll push there will be tested by Hydra (with a slightly delay because our job doesn't have a very high priority).

@peti peti changed the base branch from haskell-updates to pr-91557 July 3, 2020 18:54
@ofborg ofborg bot added the 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin label Jul 3, 2020
@pepeiborra
Copy link
Contributor Author

pepeiborra commented Jul 4, 2020

4131 failures, most of them caused by a parse error in the random-1.1 testsuite.
It's not even clear what causes the parse error: https://github.com/haskell/random/blob/v1.1/tests/T7936.hs

My view is that this is a bug in GHC, not something that needs to be fixed in packages downstream, and the bugfix will be included in 8.12 (or 8.14 if it doesn't make the cut).

With that in mind, I have changed the default value to enable the setting only in GHC >= 8.12

@ofborg ofborg bot added the 2.status: merge conflict This PR has merge conflicts with the target branch label Jul 4, 2020
@cdepillabout
Copy link
Member

@GrahamcOfBorg build haskellPackages.lens
@GrahamcOfBorg build haskellPackages.xmonad
@GrahamcOfBorg build haskellPackages.spago
@GrahamcOfBorg build haskellPackages.random

@ofborg ofborg bot added 10.rebuild-darwin: 501+ 10.rebuild-darwin: 5001+ 10.rebuild-linux: 501+ 10.rebuild-linux: 5001+ and removed 2.status: merge conflict This PR has merge conflicts with the target branch 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin 10.rebuild-linux: 0 This PR does not cause any packages to rebuild on Linux labels Jul 4, 2020
@pepeiborra
Copy link
Contributor Author

good to merge now or are there any changes requested?

@@ -53,7 +53,7 @@ in
, maintainers ? []
, doCoverage ? false
, doHaddock ? !(ghc.isHaLVM or false)
, doHaddockInterfaces ? true
, doHaddockInterfaces ? stdenv.lib.versionAtLeast ghc.version "8.12"
Copy link
Member

Choose a reason for hiding this comment

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

What does ghc-8.12.x have to do with this PR?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

8.12.x will turn Haddock errors into warnings, provided !2377 lands before the cut

@peti
Copy link
Member

peti commented Jul 6, 2020

4131 failures, most of them caused by a parse error in the random-1.1 testsuite.

Now is the time to start fixing those failures ...

My view is that this is a bug in GHC.

Really? That doesn't look like a compiler bug to me at all. You just re-format the line

--- a/test-legacy/T7936.hs
+++ b/test-legacy/T7936.hs
@@ -3,8 +3,8 @@
 --
 -- Used to fail with:
 --
--- $ cabal test T7936 --test-options="+RTS -M1M -RTS"
--- T7936: Heap exhausted;
+-- > $ cabal test T7936 --test-options="+RTS -M1M -RTS"
+-- > T7936: Heap exhausted;
 
 module T7936 where

properly, and then it compiles just fine.

@pepeiborra
Copy link
Contributor Author

4131 failures, most of them caused by a parse error in the random-1.1 testsuite.

Now is the time to start fixing those failures ...

Respectfully, we don't know how many failures there are, maintainers will be reluctant to cut a release just to change a comment in a test suite, and all that is wasted effort once !2377 is merged.

My view is that this is a bug in GHC.

Really? That doesn't look like a compiler bug to me at all. You just re-format the line

There is no error message referencing the problematic markup, Haddock, or even the line that caused the error:

tests/T7936.hs:9:1: error: parse error on input ‘module’
  |
9 | module Main where
  | ^^^^^^

The -haddock option is not mentioned in the GHC Users' guide and Cabal doesn't know about it, so even if we fixed all the problems in Hackage, it would only be a short matter of time before they appeared again. Imho the only viable way forward is waiting until !2377 is merged to enable the option.

@peti
Copy link
Member

peti commented Jul 17, 2020

I have changed the default value to enable the setting only in GHC >= 8.12

I'd rather not a time bomb like that included in Nixpkgs. If you are not going to support any efforts to fix those errors, then the only way I want that new feature included is if it's off by default.

@pepeiborra
Copy link
Contributor Author

That's fine by me, I'll submit another PR to enable conditionally once !2377 has landed in GHC.

@pepeiborra
Copy link
Contributor Author

!2377 has been scheduled for merging[1], so I would like to amend this PR to enable doHaddockInterfaces by default on 8.12

[1] https://gitlab.haskell.org/ghc/ghc/-/merge_requests/2377#note_289455

@maralorn
Copy link
Member

I think @peti's point about the time bomb here is, that while this might be perfectly reasonable code, we can't test this before we have 8.12 in nixpkgs.

Maybe we can merge this PR now and instantly create a new Pr which switches the default on 8.12, but only merge that one, when have tested it? I mean we don't loose anything by merging something that only affects 8.12 only when we actually have 8.12, right?

@pepeiborra pepeiborra closed this Aug 8, 2020
@pepeiborra pepeiborra deleted the haddock branch August 8, 2020 15:38
@expipiplus1
Copy link
Contributor

How badly does this affect compile times?

Haskell compile times are already bad, and Haskell compile times with Nix are already worse (frequent rebuilds, ×2 time for profiling builds, ineffective CPU utilization), it would be sad to see this get even worse.

@Janik-Haag Janik-Haag added the 12. first-time contribution This PR is the author's first one; please be gentle! label Jun 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants