diff options
author | Luke Lau <luke_lau@icloud.com> | 2020-05-22 17:34:57 +0100 |
---|---|---|
committer | Ben Gamari <ben@smart-cactus.org> | 2021-03-10 15:55:09 -0500 |
commit | 8a59f49ae2204dbf58ef50ea8c0a50ee2c7aa64a (patch) | |
tree | be7327cba2bc8b2d3187baebb92986a20e61d7af /compiler/GHC/Runtime | |
parent | e687ba83b0506bc800ceb79e6ee8cb0f8ed31ed6 (diff) | |
download | haskell-8a59f49ae2204dbf58ef50ea8c0a50ee2c7aa64a.tar.gz |
template-haskell: Add putDoc, getDoc, withDecDoc and friends
This adds two new methods to the Quasi class, putDoc and getDoc. They
allow Haddock documentation to be added to declarations, module headers,
function arguments and class/type family instances, as well as looked
up.
It works by building up a map of names to attach pieces of
documentation to, which are then added in the extractDocs function in
GHC.HsToCore.Docs. However because these template haskell names need to
be resolved to GHC names at the time they are added, putDoc cannot
directly add documentation to declarations that are currently being
spliced. To remedy this, withDecDoc/withDecsDoc wraps the operation with
addModFinalizer, and provides a more ergonomic interface for doing so.
Similarly, the funD_doc, dataD_doc etc. combinators provide a more
ergonomic interface for documenting functions and their arguments
simultaneously.
This also changes ArgDocMap to use an IntMap rather than an Map Int, for
efficiency.
Part of the work towards #5467
Diffstat (limited to 'compiler/GHC/Runtime')
-rw-r--r-- | compiler/GHC/Runtime/Eval.hs | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/compiler/GHC/Runtime/Eval.hs b/compiler/GHC/Runtime/Eval.hs index c2626ce6b3..fc2f8b8ab3 100644 --- a/compiler/GHC/Runtime/Eval.hs +++ b/compiler/GHC/Runtime/Eval.hs @@ -117,9 +117,9 @@ import GHC.Unit.Home.ModInfo import System.Directory import Data.Dynamic import Data.Either +import Data.IntMap (IntMap) import qualified Data.IntMap as IntMap import Data.List (find,intercalate) -import Data.Map (Map) import qualified Data.Map as Map import Control.Monad import Control.Monad.Catch as MC @@ -879,7 +879,7 @@ parseName str = withSession $ \hsc_env -> liftIO $ getDocs :: GhcMonad m => Name - -> m (Either GetDocsFailure (Maybe HsDocString, Map Int HsDocString)) + -> m (Either GetDocsFailure (Maybe HsDocString, IntMap HsDocString)) -- TODO: What about docs for constructors etc.? getDocs name = withSession $ \hsc_env -> do @@ -896,7 +896,7 @@ getDocs name = if isNothing mb_doc_hdr && Map.null dmap && Map.null amap then pure (Left (NoDocsInIface mod compiled)) else pure (Right ( Map.lookup name dmap - , Map.findWithDefault Map.empty name amap)) + , Map.findWithDefault mempty name amap)) where compiled = -- TODO: Find a more direct indicator. |