haskell / haddock

Haskell Documentation Tool
www.haskell.org/haddock/
BSD 2-Clause "Simplified" License
361 stars 241 forks source link

Missing strictness marks when `StrictData`/`Strict` is on? #772

Open TerrorJack opened 6 years ago

TerrorJack commented 6 years ago

When haddock generates docs for a module with StrictData/Strict extensions, the datatype fields in the docs do not have regular ! marks, but they are strict under the hood. Is it possible to detect the extensions and add the missing strictness marks?

alexbiehl commented 6 years ago

Currently haddock only looks at the SrcStrictness of a record field. c.f.

https://github.com/haskell/haddock/blob/22d5e59a9bb7f5ad5612c9dde53419a48101be65/haddock-api/src/Haddock/Backends/Xhtml/Decl.hs#L1037

You would want to get the HsImplBang - the strictness GHC calculates, not the one the user wrote - to do this.

Care to make a PR?

TerrorJack commented 6 years ago

@alexbiehl Thanks for the pointer. I'm not familiar with haddock code base yet, will take a look when I got spare time.

infinity0 commented 4 years ago

I gave it a go, tried it with this diff:

diff --git a/haddock-api/src/Haddock/Convert.hs b/haddock-api/src/Haddock/Convert.hs
index 7735ed0d..cc8391c9 100644
--- a/haddock-api/src/Haddock/Convert.hs
+++ b/haddock-api/src/Haddock/Convert.hs
@@ -313,12 +313,14 @@ synifyDataCon use_gadt_syntax dc =
   ctx = synifyCtx theta

   linear_tys =
-    zipWith (\ty bang ->
+    zipWith3 (\ty (HsSrcBang srcTxt _ _) bang ->
                let tySyn = synifyType WithinType ty
                in case bang of
-                    (HsSrcBang _ NoSrcUnpack NoSrcStrict) -> tySyn
-                    bang' -> noLoc $ HsBangTy noExt bang' tySyn)
-            arg_tys (dataConSrcBangs dc)
+                    HsLazy -> noLoc $ HsBangTy noExt (HsSrcBang srcTxt SrcNoUnpack SrcLazy) tySyn
+                    HsStrict -> noLoc $ HsBangTy noExt (HsSrcBang srcTxt SrcNoUnpack SrcStrict) tySyn
+                    HsUnpack _ -> noLoc $ HsBangTy noExt (HsSrcBang srcTxt SrcUnpack SrcStrict) tySyn
+            )
+            arg_tys (dataConSrcBangs dc) (dataConImplBangs dc)

   field_tys = zipWith con_decl_field (dataConFieldLabels dc) linear_tys
   con_decl_field fl synTy = noLoc $

But it didn't work. :( It's not obvious where else HsImplBangs could be injected... any pointers would be appreciated as one of the things holding me back from switching on StrictData by default is the misleading haddock docs that are generated.