Open TerrorJack opened 6 years ago
Currently haddock only looks at the SrcStrictness
of a record field. c.f.
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?
@alexbiehl Thanks for the pointer. I'm not familiar with haddock
code base yet, will take a look when I got spare time.
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.
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?