summaryrefslogtreecommitdiff
path: root/compiler/GHC/HsToCore/Docs.hs
diff options
context:
space:
mode:
authorRyan Scott <ryan.gl.scott@gmail.com>2020-07-05 16:15:01 -0400
committerRyan Scott <ryan.gl.scott@gmail.com>2020-10-30 19:38:31 -0400
commite9b2578fa17989f13ec6ba8fae0c35b2dac4d900 (patch)
tree2032245a504f20b62c0980cd84208673f45c2ac4 /compiler/GHC/HsToCore/Docs.hs
parent31fcb55f4ff8c06c5ab100a6817cae8b571295a9 (diff)
downloadhaskell-wip/T16762.tar.gz
Replace HsImplicitBndrs with HsOuterTyVarBndrswip/T16762
This refactors the GHC AST to remove `HsImplicitBndrs` and replace it with `HsOuterTyVarBndrs`, a type which records whether the outermost quantification in a type is explicit (i.e., with an outermost, invisible `forall`) or implicit. As a result of this refactoring, it is now evident in the AST where the `forall`-or-nothing rule applies: it's all the places that use `HsOuterTyVarBndrs`. See the revamped `Note [forall-or-nothing rule]` in `GHC.Hs.Type` (previously in `GHC.Rename.HsType`). Moreover, the places where `ScopedTypeVariables` brings lexically scoped type variables into scope are a subset of the places that adhere to the `forall`-or-nothing rule, so this also makes places that interact with `ScopedTypeVariables` easier to find. See the revamped `Note [Lexically scoped type variables]` in `GHC.Hs.Type` (previously in `GHC.Tc.Gen.Sig`). `HsOuterTyVarBndrs` are used in type signatures (see `HsOuterSigTyVarBndrs`) and type family equations (see `HsOuterFamEqnTyVarBndrs`). The main difference between the former and the latter is that the former cares about specificity but the latter does not. There are a number of knock-on consequences: * There is now a dedicated `HsSigType` type, which is the combination of `HsOuterSigTyVarBndrs` and `HsType`. `LHsSigType` is now an alias for an `XRec` of `HsSigType`. * Working out the details led us to a substantial refactoring of the handling of explicit (user-written) and implicit type-variable bindings in `GHC.Tc.Gen.HsType`. Instead of a confusing family of higher order functions, we now have a local data type, `SkolemInfo`, that controls how these binders are kind-checked. It remains very fiddly, not fully satisfying. But it's better than it was. Fixes #16762. Bumps the Haddock submodule. Co-authored-by: Simon Peyton Jones <simonpj@microsoft.com> Co-authored-by: Richard Eisenberg <rae@richarde.dev> Co-authored-by: Zubin Duggal <zubin@cmi.ac.in>
Diffstat (limited to 'compiler/GHC/HsToCore/Docs.hs')
-rw-r--r--compiler/GHC/HsToCore/Docs.hs30
1 files changed, 15 insertions, 15 deletions
diff --git a/compiler/GHC/HsToCore/Docs.hs b/compiler/GHC/HsToCore/Docs.hs
index 38162298c4..72e4fe99c3 100644
--- a/compiler/GHC/HsToCore/Docs.hs
+++ b/compiler/GHC/HsToCore/Docs.hs
@@ -141,7 +141,7 @@ sigNameNoLoc _ = []
-- instanceMap.
getInstLoc :: InstDecl (GhcPass p) -> SrcSpan
getInstLoc = \case
- ClsInstD _ (ClsInstDecl { cid_poly_ty = ty }) -> getLoc (hsSigType ty)
+ ClsInstD _ (ClsInstDecl { cid_poly_ty = ty }) -> getLoc ty
-- The Names of data and type family instances have their SrcSpan's attached
-- to the *type constructor*. For example, the Name "D:R:Foo:Int" would have
-- its SrcSpan attached here:
@@ -149,12 +149,12 @@ getInstLoc = \case
-- type instance Foo Int = Bool
-- ^^^
DataFamInstD _ (DataFamInstDecl
- { dfid_eqn = HsIB { hsib_body = FamEqn { feqn_tycon = L l _ }}}) -> l
+ { dfid_eqn = FamEqn { feqn_tycon = L l _ }}) -> l
-- Since CoAxioms' Names refer to the whole line for type family instances
-- in particular, we need to dig a bit deeper to pull out the entire
-- equation. This does not happen for data family instances, for some reason.
TyFamInstD _ (TyFamInstDecl
- { tfid_eqn = HsIB { hsib_body = FamEqn { feqn_tycon = L l _ }}}) -> l
+ { tfid_eqn = FamEqn { feqn_tycon = L l _ }}) -> l
-- | Get all subordinate declarations inside a declaration, and their docs.
-- A subordinate declaration is something like the associate type or data
@@ -164,12 +164,12 @@ subordinates :: Map RealSrcSpan Name
-> [(Name, [(HsDocString)], Map Int (HsDocString))]
subordinates instMap decl = case decl of
InstD _ (ClsInstD _ d) -> do
- DataFamInstDecl { dfid_eqn = HsIB { hsib_body =
+ DataFamInstDecl { dfid_eqn =
FamEqn { feqn_tycon = L l _
- , feqn_rhs = defn }}} <- unLoc <$> cid_datafam_insts d
+ , feqn_rhs = defn }} <- unLoc <$> cid_datafam_insts d
[ (n, [], M.empty) | Just n <- [lookupSrcSpan l instMap] ] ++ dataSubs defn
- InstD _ (DataFamInstD _ (DataFamInstDecl (HsIB { hsib_body = d })))
+ InstD _ (DataFamInstD _ (DataFamInstDecl d))
-> dataSubs (feqn_rhs d)
TyClD _ d | isClassDecl d -> classSubs d
| isDataDecl d -> dataSubs (tcdDataDefn d)
@@ -205,12 +205,8 @@ subordinates instMap decl = case decl of
DctMulti _ tys -> mapMaybe extract_deriv_ty tys
extract_deriv_ty :: LHsSigType GhcRn -> Maybe (SrcSpan, LHsDocString)
- extract_deriv_ty (HsIB{hsib_body = L l ty}) =
+ extract_deriv_ty (L l (HsSig{sig_body = L _ ty})) =
case ty of
- -- deriving (forall a. C a {- ^ Doc comment -})
- HsForAllTy{ hst_tele = HsForAllInvis{}
- , hst_body = L _ (HsDocTy _ _ doc) }
- -> Just (l, doc)
-- deriving (C a {- ^ Doc comment -})
HsDocTy _ _ doc -> Just (l, doc)
_ -> Nothing
@@ -259,10 +255,10 @@ classDecls class_ = filterDecls . collectDocs . sortLocated $ decls
-- | Extract function argument docs from inside top-level decls.
declTypeDocs :: HsDecl GhcRn -> Map Int (HsDocString)
declTypeDocs = \case
- SigD _ (TypeSig _ _ ty) -> typeDocs (unLoc (hsSigWcType ty))
- SigD _ (ClassOpSig _ _ _ ty) -> typeDocs (unLoc (hsSigType ty))
- SigD _ (PatSynSig _ _ ty) -> typeDocs (unLoc (hsSigType ty))
- ForD _ (ForeignImport _ _ ty _) -> typeDocs (unLoc (hsSigType ty))
+ SigD _ (TypeSig _ _ ty) -> sigTypeDocs (unLoc (dropWildCards ty))
+ SigD _ (ClassOpSig _ _ _ ty) -> sigTypeDocs (unLoc ty)
+ SigD _ (PatSynSig _ _ ty) -> sigTypeDocs (unLoc ty)
+ ForD _ (ForeignImport _ _ ty _) -> sigTypeDocs (unLoc ty)
TyClD _ (SynDecl { tcdRhs = ty }) -> typeDocs (unLoc ty)
_ -> M.empty
@@ -289,6 +285,10 @@ typeDocs = go 0
HsDocTy _ _ doc -> M.singleton n (unLoc doc)
_ -> M.empty
+-- | Extract function argument docs from inside types.
+sigTypeDocs :: HsSigType GhcRn -> Map Int HsDocString
+sigTypeDocs (HsSig{sig_body = body}) = typeDocs (unLoc body)
+
-- | The top-level declarations of a module that we care about,
-- ordered by source location, with documentation attached if it exists.
topDecls :: HsGroup GhcRn -> [(LHsDecl GhcRn, [HsDocString])]