@@ -26,6 +26,8 @@ import Idris.Core.Execute
2626import Idris.Core.Typecheck
2727import Idris.Core.CaseTree
2828
29+import Idris.Docstrings
30+
2931import Control.DeepSeq
3032import Control.Monad
3133import Control.Monad.State.Strict as State
@@ -63,12 +65,12 @@ checkAddDef add toplvl fc ((n, (i, top, t)) : ns)
6365-- return (n, (i, top, t'))) ns
6466
6567-- | Elaborate a top-level type declaration - for example, "foo : Int -> Int".
66−elabType :: ElabInfo -> SyntaxInfo -> String -> [(Name, String)] ->
68+elabType :: ElabInfo -> SyntaxInfo -> Docstring -> [(Name, Docstring)] ->
6769 FC -> FnOpts -> Name -> PTerm -> Idris Type
6870elabType = elabType' False
6971
7072elabType' :: Bool -> -- normalise it
71− ElabInfo -> SyntaxInfo -> String -> [(Name, String)] ->
73+ ElabInfo -> SyntaxInfo -> Docstring -> [(Name, Docstring)] ->
7274 FC -> FnOpts -> Name -> PTerm -> Idris Type
7375elabType' norm info syn doc argDocs fc opts n ty' = {- let ty' = piBind (params info) ty_in
7476 n = liftname info n_in in -}
@@ -171,7 +173,7 @@ elabType' norm info syn doc argDocs fc opts n ty' = {- let ty' = piBind (params
171173 tyIsHandler _ = False
172174
173175
174−elabPostulate :: ElabInfo -> SyntaxInfo -> String ->
176+elabPostulate :: ElabInfo -> SyntaxInfo -> Docstring ->
175177 FC -> FnOpts -> Name -> PTerm -> Idris ()
176178elabPostulate info syn doc fc opts n ty
177179 = do elabType info syn doc [] fc opts n ty
@@ -195,7 +197,7 @@ elabPostulate info syn doc fc opts n ty
195197 -- remove it from the deferred definitions list
196198 solveDeferred n
197199
198−elabData :: ElabInfo -> SyntaxInfo -> String -> [(Name, String)] -> FC -> DataOpts -> PData -> Idris ()
200+elabData :: ElabInfo -> SyntaxInfo -> Docstring -> [(Name, Docstring)] -> FC -> DataOpts -> PData -> Idris ()
199201elabData info syn doc argDocs fc opts (PLaterdecl n t_in)
200202 = do let codata = Codata `elem` opts
201203 iLOG (show (fc, doc))
@@ -257,8 +259,9 @@ elabData info syn doc argDocs fc opts (PDatadecl n t_in dcons)
257259 updateContext (addDatatype (Data n ttag cty cons))
258260 updateContext (setMetaInformation n metainf)
259261 mapM_ (checkPositive n) cons
260− if DefaultEliminator `elem` opts then evalStateT (elabEliminator params n t dcons info) Map.empty
261− else return ()
262+ if DefaultEliminator `elem` opts
263+ then evalStateT (elabEliminator params n t dcons info) Map.empty
264+ else return ()
262265 where
263266 checkDefinedAs fc n t ctxt
264267 = case lookupDef n ctxt of
@@ -322,7 +325,7 @@ type EliminatorState = StateT (Map.Map String Int) Idris
322325
323326-- TODO: Use uniqueName for generating names, rewrite everything to use idris_implicits instead of manual splitting, generally just rewrite
324327elabEliminator :: [Int] -> Name -> PTerm ->
325− [(String, [(Name, String)], Name, PTerm, FC, [Name])] ->
328+ [(Docstring, [(Name, Docstring)], Name, PTerm, FC, [Name])] ->
326329 ElabInfo -> EliminatorState ()
327330elabEliminator paramPos n ty cons info = do
328331 elimLog $ "Elaborating eliminator"
@@ -339,7 +342,7 @@ elabEliminator paramPos n ty cons info = do
339342 let motiveConstr = [(motiveName, expl, motive)]
340343 let scrutinee = (scrutineeName, expl, applyCons n (interlievePos paramPos generalParams scrutineeIdxs 0))
341344 let eliminatorTy = piConstr (generalParams ++ motiveConstr ++ consTerms ++ scrutineeIdxs ++ [scrutinee]) (applyMotive (map (\(n,_,_) -> PRef elimFC n) scrutineeIdxs) (PRef elimFC scrutineeName))
342− let eliminatorTyDecl = PTy (show n) [] defaultSyntax elimFC [TotalFn] elimDeclName eliminatorTy
345+ let eliminatorTyDecl = PTy (parseDocstring . T.pack $ show n) [] defaultSyntax elimFC [TotalFn] elimDeclName eliminatorTy
343346 let clauseConsElimArgs = map getPiName consTerms
344347 let clauseGeneralArgs' = map getPiName generalParams ++ [motiveName] ++ clauseConsElimArgs
345348 let clauseGeneralArgs = map (\arg -> pexp (PRef elimFC arg)) clauseGeneralArgs'
@@ -488,7 +491,7 @@ elabEliminator paramPos n ty cons info = do
488491 splitArgPms _ = ([],[])
489492
490493
491− implicitIndexes :: (String, Name, PTerm, FC, [Name]) -> EliminatorState [(Name, Plicity, PTerm)]
494+ implicitIndexes :: (Docstring, Name, PTerm, FC, [Name]) -> EliminatorState [(Name, Plicity, PTerm)]
492495 implicitIndexes (cns@(doc, cnm, ty, fc, fs)) = do
493496 i <- State.lift getIState
494497 implargs' <- case lookupCtxt cnm (idris_implicits i) of
@@ -503,7 +506,7 @@ elabEliminator paramPos n ty cons info = do
503506 in return $ filter (\(n,_,_) -> not (n `elem` oldParams))implargs
504507 _ -> return implargs
505508
506− extractConsTerm :: (String, [(Name, String)], Name, PTerm, FC, [Name]) -> [(Name, Plicity, PTerm)] -> EliminatorState PTerm
509+ extractConsTerm :: (Docstring, [(Name, Docstring)], Name, PTerm, FC, [Name]) -> [(Name, Plicity, PTerm)] -> EliminatorState PTerm
507510 extractConsTerm (doc, argDocs, cnm, ty, fc, fs) generalParameters = do
508511 let cons' = replaceParams paramPos generalParameters ty
509512 let (args, resTy) = splitPi cons'
@@ -539,7 +542,7 @@ elabEliminator paramPos n ty cons info = do
539542 convertImplPi (PImp {getTm = t, pname = n}) = Just (n, expl, t)
540543 convertImplPi _ = Nothing
541544
542− generateEliminatorClauses :: (String, [(Name, String)], Name, PTerm, FC, [Name]) -> Name -> [PArg] -> [(Name, Plicity, PTerm)] -> EliminatorState PClause
545+ generateEliminatorClauses :: (Docstring, [(Name, Docstring)], Name, PTerm, FC, [Name]) -> Name -> [PArg] -> [(Name, Plicity, PTerm)] -> EliminatorState PClause
543546 generateEliminatorClauses (doc, _, cnm, ty, fc, fs) cnsElim generalArgs generalParameters = do
544547 let cons' = replaceParams paramPos generalParameters ty
545548 let (args, resTy) = splitPi cons'
@@ -561,7 +564,7 @@ elabEliminator paramPos n ty cons info = do
561564
562565elabPrims :: Idris ()
563566elabPrims = do mapM_ (elabDecl EAll toplevel)
564− (map (\(opt, decl) -> PData "" [] defaultSyntax (fileFC "builtin") opt decl)
567+ (map (\(opt, decl) -> PData emptyDocstring [] defaultSyntax (fileFC "builtin") opt decl)
565568 (zip
566569 [inferOpts, unitOpts, falseOpts, pairOpts, eqOpts]
567570 [inferDecl, unitDecl, falseDecl, pairDecl, eqDecl]))
@@ -665,7 +668,7 @@ elabProvider info syn fc what n ty tm
665668 Provide tm
666669 | what `elem` [ProvTerm, ProvAny] ->
667670 do -- Finally add a top-level definition of the provided term
668− elabType info syn "" [] fc [] n ty
671+ elabType info syn emptyDocstring [] fc [] n ty
669672 elabClauses info fc [] n [PClause fc n (PApp fc (PRef fc n) []) [] (delab i tm) []]
670673 logLvl 3 $ "Elaborated provider " ++ show n ++ " as: " ++ show tm
671674 | otherwise ->
@@ -673,7 +676,7 @@ elabProvider info syn fc what n ty tm
673676 Postulate
674677 | what `elem` [ProvPostulate, ProvAny] ->
675678 do -- Add the postulate
676− elabPostulate info syn "Provided postulate" fc [] n ty
679+ elabPostulate info syn (parseDocstring $ T.pack "Provided postulate") fc [] n ty
677680 logLvl 3 $ "Elaborated provided postulate " ++ show n
678681 | otherwise ->
679682 ierror . Msg $ "Attempted to provide a postulate where a term was expected."
@@ -724,8 +727,8 @@ elabTransform info fc safe lhs_in rhs_in
724727 addIBC (IBCTrans (clhs_tm, crhs_tm))
725728
726729
727−elabRecord :: ElabInfo -> SyntaxInfo -> String -> FC -> Name ->
728− PTerm -> String -> Name -> PTerm -> Idris ()
730+elabRecord :: ElabInfo -> SyntaxInfo -> Docstring -> FC -> Name ->
731+ PTerm -> Docstring -> Name -> PTerm -> Idris ()
729732elabRecord info syn doc fc tyn ty cdoc cn cty
730733 = do elabData info syn doc [] fc [] (PDatadecl tyn ty [(cdoc, [], cn, cty, fc, [])])
731734 cty' <- implicit syn cn cty
@@ -797,7 +800,7 @@ elabRecord info syn doc fc tyn ty cdoc cn cty
797800
798801 mkProj recty substs cimp ((pn_in, pty), pos)
799802 = do let pn = expandNS syn pn_in
800− let pfnTy = PTy "" [] defaultSyntax fc [] pn
803+ let pfnTy = PTy emptyDocstring [] defaultSyntax fc [] pn
801804 (PPi expl rec recty
802805 (substMatches substs pty))
803806 let pls = repeat Placeholder
@@ -818,7 +821,7 @@ elabRecord info syn doc fc tyn ty cdoc cn cty
818821 let valname = sMN 0 "updateval"
819822 let pt = k (PPi expl pn pty
820823 (PPi expl rec recty recty))
821− let pfnTy = PTy "" [] defaultSyntax fc [] setname pt
824+ let pfnTy = PTy emptyDocstring [] defaultSyntax fc [] setname pt
822825 let pls = map (\x -> PRef fc (sMN x "field")) [0..num-1]
823826 let lhsArgs = pls
824827 let rhsArgs = take pos pls ++ (PRef fc valname) :
@@ -834,7 +837,7 @@ elabRecord info syn doc fc tyn ty cdoc cn cty
834837 return (pn, pfnTy, PClauses fc [] setname [pclause])
835838
836839elabCon :: ElabInfo -> SyntaxInfo -> Name -> Bool ->
837− (String, [(Name, String)], Name, PTerm, FC, [Name]) -> Idris (Name, Type)
840+ (Docstring, [(Name, Docstring)], Name, PTerm, FC, [Name]) -> Idris (Name, Type)
838841elabCon info syn tn codata (doc, argDocs, n, t_in, fc, forcenames)
839842 = do checkUndefined fc n
840843 ctxt <- getContext
@@ -1166,7 +1169,7 @@ elabPE info fc caller r =
11661169 (map (\ (lhs, rhs) ->
11671170 (showTmImpls lhs ++ " = " ++
11681171 showTmImpls rhs)) pats)
1169− elabType info defaultSyntax "" [] fc opts newnm specTy
1172+ elabType info defaultSyntax emptyDocstring [] fc opts newnm specTy
11701173 let def = map (\ (lhs, rhs) -> PClause fc newnm lhs [] rhs []) pats
11711174 elabClauses info fc opts newnm def
11721175 logLvl 2 $ "Specialised " ++ show newnm)
@@ -1725,7 +1728,7 @@ elabClause info opts (_, PWith fc fname lhs_in withs wval_in withblock)
17251728
17261729data MArgTy = IA | EA | CA deriving Show
17271730
1728−elabClass :: ElabInfo -> SyntaxInfo -> String ->
1731+elabClass :: ElabInfo -> SyntaxInfo -> Docstring ->
17291732 FC -> [PTerm] ->
17301733 Name -> [(Name, PTerm)] -> [PDecl] -> Idris ()
17311734elabClass info syn doc fc constraints tn ps ds
@@ -1752,7 +1755,7 @@ elabClass info syn doc fc constraints tn ps ds
17521755 let cty = impbind ps $ conbind constraints
17531756 $ pibind (map (\ (n, ty) -> (nsroot n, ty)) methods)
17541757 constraint
1755− let cons = [("", [], cn, cty, fc, [])]
1758+ let cons = [(emptyDocstring, [], cn, cty, fc, [])]
17561759 let ddecl = PDatadecl tn tty cons
17571760 logLvl 5 $ "Class data " ++ show (showDImp True ddecl)
17581761 elabData info (syn { no_imp = no_imp syn ++ mnames }) doc [] fc [] ddecl
@@ -1807,7 +1810,7 @@ elabClass info syn doc fc constraints tn ps ds
18071810 case lookup n mtys of
18081811 Just (syn, o, ty) -> do let ty' = insertConstraint c ty
18091812 let ds = map (decorateid defaultdec)
1810− [PTy "" [] syn fc [] n ty',
1813+ [PTy emptyDocstring [] syn fc [] n ty',
18111814 PClauses fc (o ++ opts) n cs]
18121815 iLOG (show ds)
18131816 return (n, ((defaultdec n, ds!!1), ds))
@@ -1845,7 +1848,7 @@ elabClass info syn doc fc constraints tn ps ds
18451848 addInstance False conn' cfn
18461849 addIBC (IBCInstance False conn' cfn)
18471850-- iputStrLn ("Added " ++ show (conn, cfn, ty))
1848− return [PTy "" [] syn fc [] cfn ty,
1851+ return [PTy emptyDocstring [] syn fc [] cfn ty,
18491852 PClauses fc [Dictionary] cfn [PClause fc cfn lhs [] rhs []]]
18501853
18511854 -- Generate a top level function which looks up a method in a given
@@ -1909,7 +1912,7 @@ elabInstance info syn what fc cs n ps t expn ds = do
19091912 let constraint = PApp fc (PRef fc n) (map pexp ps)
19101913 let iname = mkiname n ps expn
19111914 when (what /= EDefns) $ do
1912− nty <- elabType' True info syn "" [] fc [] iname t
1915+ nty <- elabType' True info syn emptyDocstring [] fc [] iname t
19131916 -- if the instance type matches any of the instances we have already,
19141917 -- and it's not a named instance, then it's overlapping, so report an error
19151918 case expn of
@@ -2061,7 +2064,7 @@ elabInstance info syn what fc cs n ps t expn ds = do
20612064 decorate ns iname (UN n) = NS (SN (MethodN (UN n))) ns
20622065 decorate ns iname (NS (UN n) s) = NS (SN (MethodN (UN n))) ns
20632066
2064− mkTyDecl (n, op, t, _) = PTy "" [] syn fc op n t
2067+ mkTyDecl (n, op, t, _) = PTy emptyDocstring [] syn fc op n t
20652068
20662069 conbind (ty : ns) x = PPi constraint (sMN 0 "class") ty (conbind ns x)
20672070 conbind [] x = x
@@ -2308,7 +2311,7 @@ inferredDiff fc inf user =
23082311-- | Check a PTerm against documentation and ensure that every documented
23092312-- argument actually exists. This must be run _after_ implicits have been
23102313-- found, or it will give spurious errors.
2311−checkDocs :: FC -> [(Name, String)] -> PTerm -> Idris ()
2314+checkDocs :: FC -> [(Name, Docstring)] -> PTerm -> Idris ()
23122315checkDocs fc args tm = cd (Map.fromList args) tm
23132316 where cd as (PPi _ n _ sc) = cd (Map.delete n as) sc
23142317 cd as _ | Map.null as = return ()