haddock icon indicating copy to clipboard operation
haddock copied to clipboard

Haddock fails to run plugins with GHC 8.6.1 alpha

Open mpickering opened this issue 7 years ago • 18 comments

GHC has changed so that plugins are only loaded once rather than just before each time they are used. I suspect that Haddock needs to follow this change and explicitly loads the plugins as well.

@christiaanb suggested some code like this in a suitable place would fix things.

https://github.com/clash-lang/clash-compiler/commit/8d32505b84a4f597bd995a4c39234b74be1b1e66#diff-c50e1570ba401340dde73490fed2c8cdR189

mpickering avatar Aug 06 '18 14:08 mpickering

I suspect https://github.com/haskell/haddock/blob/1c4076328cfdd3aadbbbd494a240e25bd7309b0c/haddock-api/src/Haddock.hs#L428-L445

would be a good place for that.

alexbiehl avatar Aug 06 '18 14:08 alexbiehl

This doesn't seem to work on Windows. See https://github.com/haskell/haddock/pull/905#issuecomment-431852530.

sheaf avatar Oct 22 '18 14:10 sheaf

It doesn't work on (my) linux either.

Here is a simple testcase that fails with haddock-2.22.0 and ghc-8.6.2

leonschoorl avatar Nov 08 '18 16:11 leonschoorl

It doesn't work on (my) linux either.

Here is a simple testcase that fails with haddock-2.22.0 and ghc-8.6.2

Thanks! doesn't work on my Mac either. I really like small test cases. 😄 I'll investigate.

harpocrates avatar Nov 08 '18 17:11 harpocrates

I've been digging myself.

The documentation for initializePlugins says:

... Should be re-called if pluginModNames or pluginModNameOpts changes. ..

But is seems that the pluginModNames never gets set from the pragma.

The reason this works in clash is because we manually setup our plugins before we call initializePlugins, the plugins from the OPTIONS_GHC pragma aren't actually being used.

leonschoorl avatar Nov 08 '18 18:11 leonschoorl

The DynFlags which contain the plugins are cached in the ModSummary of the ParsedModule.

Unpacking them, calling initializePlugins, and repacking everything up, kind of works. Like this: https://github.com/leonschoorl/haddock/commit/6dffdef6cd7a1ac5a982532fd9efcdc3d840ad3b There might be a better ways to do this through the GHC api, but I haven't found them yet.

And it fails to load local plugins like this: https://github.com/leonschoorl/haddock/commit/ee81152084ab23cf648ca29201d2bee3544fceec

leonschoorl avatar Nov 09 '18 17:11 leonschoorl

Any news on this? I currently can't build the docs for my package locally because it uses typechecker plugins.

LukaHorvat avatar Dec 18 '18 22:12 LukaHorvat

@leonschoorl Do you have a particular use case for local plugins? I'm tempted to just cherry-pick https://github.com/leonschoorl/haddock/commit/6dffdef6cd7a1ac5a982532fd9efcdc3d840ad3b for now, since it is definitely what we need for non-local plugins.

The issue about local plugins seems to be related to Haddock's forcing of hscTarget = HscNothing and ghcLink = NoLink. You can get the same panic (During interactive linking, GHCi couldn't find the following symbol...) by appending -fno-code to a regular ghc --make compilation for your example here: https://github.com/leonschoorl/haddock/commit/ee81152084ab23cf648ca29201d2bee3544fceec.

harpocrates avatar Dec 19 '18 19:12 harpocrates

No I don't have a use case for local plugins, it's just something I stumbled upon when trying to write a test for this issue.

leonschoorl avatar Jan 03 '19 15:01 leonschoorl

Just an experience report. Thanks for resolving this!

2.22.0 from Hackage failed to work for me. I eventually found this Issue. It took me a while to realize what to do, but I eventually cloned the 8.6-release branch, v2-intsalled that haddock Cabal project, and then successfully used v2-haddock --with-haddock=${HOME}/.cabal/bin/haddock in my actual Cabal project (in which one of the packages defines a plugin and the other packages uses it via {-# OPTIONS_GHC -fplugin ... #-} pragmas).

nfrisby avatar May 06 '19 09:05 nfrisby

I've been working around this by enabling deferred type errors during haddock generation via cabal.project:

package my-package
  haddock-options: --optghc=-fdefer-type-errors

leonschoorl avatar May 06 '19 12:05 leonschoorl

Going off of @leonschoorl's suggestions, if you are using stack, you can add this to your stack.yaml for a temporary workaround:

build:
  haddock-arguments:
    haddock-args:
    - --optghc=-fdefer-type-errors

mstksg avatar Jun 13 '19 19:06 mstksg

I've also been stuck using GHC 8.4 because of this issue. I personally use ghc-typelits-natnormalise and ghc-typelits-knownnat for my work with type safe vectors. The aforementioned solution with deferred type errors unfortunately does not work for me.

Thanks for all your hard work, I just wanted to add a datapoint that some people do rely on this feature.

alex404 avatar Jun 14 '19 12:06 alex404

I just have stumbled again on this problem. Another workaround for multiple GHC versions is to add these haddock options via custom-setup Setup.hs. Useful for building a library, since it should work with both, stack and cabal-install.

achirkin avatar Aug 08 '19 09:08 achirkin

To whom this may concern, I was able to fix my issues by using defer-type-errors. I had had my calls for the plugins listed in the cabal files directly, but moving them to OPTION_GHC pragmas in each module fixed the problem.

alex404 avatar Aug 18 '19 12:08 alex404

Hi, I met the same error with the option(--optghc=-fdefer-type-errors).

https://github.com/hasktorch/hasktorch/issues/177

junjihashimoto avatar Nov 28 '19 07:11 junjihashimoto

I've had luck with --optghc=-fobject-code, as inspired by https://gitlab.haskell.org/ghc/ghc/-/issues/16093.

goldfirere avatar May 31 '21 23:05 goldfirere

Looking at this comment trail, I am going to reopen this issue, as it seems people are still running into problems. In my use-case (and others?) the plugin is defined and used in the same package. My use-case is not "real" -- I am just trying to demonstrate the use of a plugin -- but there should still at least be a better error message in this case. Figuring this all out was quite non-trivial.

goldfirere avatar May 31 '21 23:05 goldfirere