@@ -26,6 +26,8 @@ import Idris.Core.Execute
26import Idris.Core.Typecheck
26import Idris.Core.Typecheck
27import Idris.Core.CaseTree
27import Idris.Core.CaseTree
29+import Idris.Docstrings
29import Control.DeepSeq
31import Control.DeepSeq
30import Control.Monad
32import Control.Monad
31import Control.Monad.State.Strict as State
33import Control.Monad.State.Strict as State
@@ -63,12 +65,12 @@ checkAddDef add toplvl fc ((n, (i, top, t)) : ns)
63-- return (n, (i, top, t'))) ns
65-- return (n, (i, top, t'))) ns
65-- | Elaborate a top-level type declaration - for example, "foo : Int -> Int".
67-- | 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)] ->
67 FC -> FnOpts -> Name -> PTerm -> Idris Type
69 FC -> FnOpts -> Name -> PTerm -> Idris Type
68elabType = elabType' False
70elabType = elabType' False
70elabType' :: Bool -> -- normalise it
72elabType' :: Bool -> -- normalise it
71− ElabInfo -> SyntaxInfo -> String -> [(Name, String)] ->
73+ ElabInfo -> SyntaxInfo -> Docstring -> [(Name, Docstring)] ->
72 FC -> FnOpts -> Name -> PTerm -> Idris Type
74 FC -> FnOpts -> Name -> PTerm -> Idris Type
73elabType' norm info syn doc argDocs fc opts n ty' = {- let ty' = piBind (params info) ty_in
75elabType' norm info syn doc argDocs fc opts n ty' = {- let ty' = piBind (params info) ty_in
74 n = liftname info n_in in -}
76 n = liftname info n_in in -}
@@ -76,12 +78,12 @@ elabType' norm info syn doc argDocs fc opts n ty' = {- let ty' = piBind (params
76 ctxt <- getContext
78 ctxt <- getContext
77 i <- getIState
79 i <- getIState
79− logLvl 1 $ show n ++ " pre-type " ++ showTmImpls ty'
81+ logLvl 3 $ show n ++ " pre-type " ++ showTmImpls ty'
80 ty' <- addUsingConstraints syn fc ty'
82 ty' <- addUsingConstraints syn fc ty'
81 ty' <- implicit syn n ty'
83 ty' <- implicit syn n ty'
83 let ty = addImpl i ty'
85 let ty = addImpl i ty'
84− logLvl 1 $ show n ++ " type " ++ showTmImpls ty
86+ logLvl 3 $ show n ++ " type " ++ showTmImpls ty
85 ((tyT, defer, is), log) <-
87 ((tyT, defer, is), log) <-
86 tclift $ elaborate ctxt n (TType (UVal 0)) []
88 tclift $ elaborate ctxt n (TType (UVal 0)) []
87 (errAt "type of " n (erun fc (build i info False [] n ty)))
89 (errAt "type of " n (erun fc (build i info False [] n ty)))
@@ -171,7 +173,7 @@ elabType' norm info syn doc argDocs fc opts n ty' = {- let ty' = piBind (params
171 tyIsHandler _ = False
173 tyIsHandler _ = False
174−elabPostulate :: ElabInfo -> SyntaxInfo -> String ->
176+elabPostulate :: ElabInfo -> SyntaxInfo -> Docstring ->
175 FC -> FnOpts -> Name -> PTerm -> Idris ()
177 FC -> FnOpts -> Name -> PTerm -> Idris ()
176elabPostulate info syn doc fc opts n ty
178elabPostulate info syn doc fc opts n ty
177 = do elabType info syn doc [] fc opts n ty
179 = do elabType info syn doc [] fc opts n ty
@@ -195,7 +197,7 @@ elabPostulate info syn doc fc opts n ty
195 -- remove it from the deferred definitions list
197 -- remove it from the deferred definitions list
196 solveDeferred n
198 solveDeferred n
198−elabData :: ElabInfo -> SyntaxInfo -> String -> [(Name, String)] -> FC -> DataOpts -> PData -> Idris ()
200+elabData :: ElabInfo -> SyntaxInfo -> Docstring -> [(Name, Docstring)] -> FC -> DataOpts -> PData -> Idris ()
199elabData info syn doc argDocs fc opts (PLaterdecl n t_in)
201elabData info syn doc argDocs fc opts (PLaterdecl n t_in)
200 = do let codata = Codata `elem` opts
202 = do let codata = Codata `elem` opts
201 iLOG (show (fc, doc))
203 iLOG (show (fc, doc))
@@ -257,8 +259,9 @@ elabData info syn doc argDocs fc opts (PDatadecl n t_in dcons)
257 updateContext (addDatatype (Data n ttag cty cons))
259 updateContext (addDatatype (Data n ttag cty cons))
258 updateContext (setMetaInformation n metainf)
260 updateContext (setMetaInformation n metainf)
259 mapM_ (checkPositive n) cons
261 mapM_ (checkPositive n) cons
262+ if DefaultEliminator `elem` opts
260− if DefaultEliminator `elem` opts then evalStateT (elabEliminator params n t dcons info) Map.empty
263+ then evalStateT (elabEliminator params n t dcons info) Map.empty
261− else return ()
264+ else return ()
263 checkDefinedAs fc n t ctxt
266 checkDefinedAs fc n t ctxt
264 = case lookupDef n ctxt of
267 = case lookupDef n ctxt of
@@ -322,7 +325,7 @@ type EliminatorState = StateT (Map.Map String Int) Idris
323-- TODO: Use uniqueName for generating names, rewrite everything to use idris_implicits instead of manual splitting, generally just rewrite
326-- TODO: Use uniqueName for generating names, rewrite everything to use idris_implicits instead of manual splitting, generally just rewrite
324elabEliminator :: [Int] -> Name -> PTerm ->
327elabEliminator :: [Int] -> Name -> PTerm ->
325− [(String, [(Name, String)], Name, PTerm, FC, [Name])] ->
328+ [(Docstring, [(Name, Docstring)], Name, PTerm, FC, [Name])] ->
326 ElabInfo -> EliminatorState ()
329 ElabInfo -> EliminatorState ()
327elabEliminator paramPos n ty cons info = do
330elabEliminator paramPos n ty cons info = do
328 elimLog $ "Elaborating eliminator"
331 elimLog $ "Elaborating eliminator"
@@ -339,7 +342,7 @@ elabEliminator paramPos n ty cons info = do
339 let motiveConstr = [(motiveName, expl, motive)]
342 let motiveConstr = [(motiveName, expl, motive)]
340 let scrutinee = (scrutineeName, expl, applyCons n (interlievePos paramPos generalParams scrutineeIdxs 0))
343 let scrutinee = (scrutineeName, expl, applyCons n (interlievePos paramPos generalParams scrutineeIdxs 0))
341 let eliminatorTy = piConstr (generalParams ++ motiveConstr ++ consTerms ++ scrutineeIdxs ++ [scrutinee]) (applyMotive (map (\(n,_,_) -> PRef elimFC n) scrutineeIdxs) (PRef elimFC scrutineeName))
344 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
343 let clauseConsElimArgs = map getPiName consTerms
346 let clauseConsElimArgs = map getPiName consTerms
344 let clauseGeneralArgs' = map getPiName generalParams ++ [motiveName] ++ clauseConsElimArgs
347 let clauseGeneralArgs' = map getPiName generalParams ++ [motiveName] ++ clauseConsElimArgs
345 let clauseGeneralArgs = map (\arg -> pexp (PRef elimFC arg)) clauseGeneralArgs'
348 let clauseGeneralArgs = map (\arg -> pexp (PRef elimFC arg)) clauseGeneralArgs'
@@ -488,7 +491,7 @@ elabEliminator paramPos n ty cons info = do
488 splitArgPms _ = ([],[])
491 splitArgPms _ = ([],[])
491− implicitIndexes :: (String, Name, PTerm, FC, [Name]) -> EliminatorState [(Name, Plicity, PTerm)]
494+ implicitIndexes :: (Docstring, Name, PTerm, FC, [Name]) -> EliminatorState [(Name, Plicity, PTerm)]
492 implicitIndexes (cns@(doc, cnm, ty, fc, fs)) = do
495 implicitIndexes (cns@(doc, cnm, ty, fc, fs)) = do
493 i <- State.lift getIState
496 i <- State.lift getIState
494 implargs' <- case lookupCtxt cnm (idris_implicits i) of
497 implargs' <- case lookupCtxt cnm (idris_implicits i) of
@@ -503,7 +506,7 @@ elabEliminator paramPos n ty cons info = do
503 in return $ filter (\(n,_,_) -> not (n `elem` oldParams))implargs
506 in return $ filter (\(n,_,_) -> not (n `elem` oldParams))implargs
504 _ -> return implargs
507 _ -> return implargs
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
507 extractConsTerm (doc, argDocs, cnm, ty, fc, fs) generalParameters = do
510 extractConsTerm (doc, argDocs, cnm, ty, fc, fs) generalParameters = do
508 let cons' = replaceParams paramPos generalParameters ty
511 let cons' = replaceParams paramPos generalParameters ty
509 let (args, resTy) = splitPi cons'
512 let (args, resTy) = splitPi cons'
@@ -539,7 +542,7 @@ elabEliminator paramPos n ty cons info = do
539 convertImplPi (PImp {getTm = t, pname = n}) = Just (n, expl, t)
542 convertImplPi (PImp {getTm = t, pname = n}) = Just (n, expl, t)
540 convertImplPi _ = Nothing
543 convertImplPi _ = Nothing
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
543 generateEliminatorClauses (doc, _, cnm, ty, fc, fs) cnsElim generalArgs generalParameters = do
546 generateEliminatorClauses (doc, _, cnm, ty, fc, fs) cnsElim generalArgs generalParameters = do
544 let cons' = replaceParams paramPos generalParameters ty
547 let cons' = replaceParams paramPos generalParameters ty
545 let (args, resTy) = splitPi cons'
548 let (args, resTy) = splitPi cons'
@@ -561,7 +564,7 @@ elabEliminator paramPos n ty cons info = do
562elabPrims :: Idris ()
565elabPrims :: Idris ()
563elabPrims = do mapM_ (elabDecl EAll toplevel)
566elabPrims = 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)
566 [inferOpts, unitOpts, falseOpts, pairOpts, eqOpts]
569 [inferOpts, unitOpts, falseOpts, pairOpts, eqOpts]
567 [inferDecl, unitDecl, falseDecl, pairDecl, eqDecl]))
570 [inferDecl, unitDecl, falseDecl, pairDecl, eqDecl]))
@@ -656,7 +659,7 @@ elabProvider info syn fc what n ty tm
656 rhs <- execute (mkApp (P Ref (sUN "run__provider") Erased)
659 rhs <- execute (mkApp (P Ref (sUN "run__provider") Erased)
657 [Erased, e])
660 [Erased, e])
658 let rhs' = normalise ctxt [] rhs
661 let rhs' = normalise ctxt [] rhs
659− logLvl 1 $ "Normalised " ++ show n ++ "'s RHS to " ++ show rhs
662+ logLvl 3 $ "Normalised " ++ show n ++ "'s RHS to " ++ show rhs
661 -- Extract the provided term or postulate from the type provider
664 -- Extract the provided term or postulate from the type provider
662 provided <- getProvided fc rhs'
665 provided <- getProvided fc rhs'
@@ -665,16 +668,16 @@ elabProvider info syn fc what n ty tm
665 Provide tm
668 Provide tm
666 | what `elem` [ProvTerm, ProvAny] ->
669 | what `elem` [ProvTerm, ProvAny] ->
667 do -- Finally add a top-level definition of the provided term
670 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
669 elabClauses info fc [] n [PClause fc n (PApp fc (PRef fc n) []) [] (delab i tm) []]
672 elabClauses info fc [] n [PClause fc n (PApp fc (PRef fc n) []) [] (delab i tm) []]
670− logLvl 1 $ "Elaborated provider " ++ show n ++ " as: " ++ show tm
673+ logLvl 3 $ "Elaborated provider " ++ show n ++ " as: " ++ show tm
671 | otherwise ->
674 | otherwise ->
672 ierror . Msg $ "Attempted to provide a term where a postulate was expected."
675 ierror . Msg $ "Attempted to provide a term where a postulate was expected."
673 Postulate
676 Postulate
674 | what `elem` [ProvPostulate, ProvAny] ->
677 | what `elem` [ProvPostulate, ProvAny] ->
675 do -- Add the postulate
678 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
677− logLvl 1 $ "Elaborated provided postulate " ++ show n
680+ logLvl 3 $ "Elaborated provided postulate " ++ show n
678 | otherwise ->
681 | otherwise ->
679 ierror . Msg $ "Attempted to provide a postulate where a term was expected."
682 ierror . Msg $ "Attempted to provide a postulate where a term was expected."
@@ -724,8 +727,8 @@ elabTransform info fc safe lhs_in rhs_in
724 addIBC (IBCTrans (clhs_tm, crhs_tm))
727 addIBC (IBCTrans (clhs_tm, crhs_tm))
727−elabRecord :: ElabInfo -> SyntaxInfo -> String -> FC -> Name ->
730+elabRecord :: ElabInfo -> SyntaxInfo -> Docstring -> FC -> Name ->
728− PTerm -> String -> Name -> PTerm -> Idris ()
731+ PTerm -> Docstring -> Name -> PTerm -> Idris ()
729elabRecord info syn doc fc tyn ty cdoc cn cty
732elabRecord info syn doc fc tyn ty cdoc cn cty
730 = do elabData info syn doc [] fc [] (PDatadecl tyn ty [(cdoc, [], cn, cty, fc, [])])
733 = do elabData info syn doc [] fc [] (PDatadecl tyn ty [(cdoc, [], cn, cty, fc, [])])
731 cty' <- implicit syn cn cty
734 cty' <- implicit syn cn cty
@@ -797,7 +800,7 @@ elabRecord info syn doc fc tyn ty cdoc cn cty
798 mkProj recty substs cimp ((pn_in, pty), pos)
801 mkProj recty substs cimp ((pn_in, pty), pos)
799 = do let pn = expandNS syn pn_in
802 = do let pn = expandNS syn pn_in
800− let pfnTy = PTy "" [] defaultSyntax fc [] pn
803+ let pfnTy = PTy emptyDocstring [] defaultSyntax fc [] pn
801 (PPi expl rec recty
804 (PPi expl rec recty
802 (substMatches substs pty))
805 (substMatches substs pty))
803 let pls = repeat Placeholder
806 let pls = repeat Placeholder
@@ -818,7 +821,7 @@ elabRecord info syn doc fc tyn ty cdoc cn cty
818 let valname = sMN 0 "updateval"
821 let valname = sMN 0 "updateval"
819 let pt = k (PPi expl pn pty
822 let pt = k (PPi expl pn pty
820 (PPi expl rec recty recty))
823 (PPi expl rec recty recty))
821− let pfnTy = PTy "" [] defaultSyntax fc [] setname pt
824+ let pfnTy = PTy emptyDocstring [] defaultSyntax fc [] setname pt
822 let pls = map (\x -> PRef fc (sMN x "field")) [0..num-1]
825 let pls = map (\x -> PRef fc (sMN x "field")) [0..num-1]
823 let lhsArgs = pls
826 let lhsArgs = pls
824 let rhsArgs = take pos pls ++ (PRef fc valname) :
827 let rhsArgs = take pos pls ++ (PRef fc valname) :
@@ -834,7 +837,7 @@ elabRecord info syn doc fc tyn ty cdoc cn cty
834 return (pn, pfnTy, PClauses fc [] setname [pclause])
837 return (pn, pfnTy, PClauses fc [] setname [pclause])
836elabCon :: ElabInfo -> SyntaxInfo -> Name -> Bool ->
839elabCon :: 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)
838elabCon info syn tn codata (doc, argDocs, n, t_in, fc, forcenames)
841elabCon info syn tn codata (doc, argDocs, n, t_in, fc, forcenames)
839 = do checkUndefined fc n
842 = do checkUndefined fc n
840 ctxt <- getContext
843 ctxt <- getContext
@@ -988,7 +991,7 @@ elabClauses info fc opts n_in cs = let n = liftname info n_in in
988 simpleCase tcase False reflect CompileTime fc atys pdef
991 simpleCase tcase False reflect CompileTime fc atys pdef
989 cov <- coverage
992 cov <- coverage
990 pmissing <-
993 pmissing <-
991− if cov
994+ if cov && not (hasDefault cs)
992 then do missing <- genClauses fc n (map getLHS pdef) cs
995 then do missing <- genClauses fc n (map getLHS pdef) cs
993 -- missing <- genMissing n scargs sc
996 -- missing <- genMissing n scargs sc
994 missing' <- filterM (checkPossible info fc True n) missing
997 missing' <- filterM (checkPossible info fc True n) missing
@@ -1092,6 +1095,10 @@ elabClauses info fc opts n_in cs = let n = liftname info n_in in
1092 depat acc (Bind n (PVar t) sc) = depat (n : acc) (instantiate (P Bound n t) sc)
1095 depat acc (Bind n (PVar t) sc) = depat (n : acc) (instantiate (P Bound n t) sc)
1093 depat acc x = (acc, x)
1096 depat acc x = (acc, x)
1098+ hasDefault cs | (PClause _ _ last _ _ _ :_) <- reverse cs
1099+ , (PApp fn s args) <- last = all ((==Placeholder) . getTm) args
1100+ hasDefault _ = False
1095 getLHS (_, l, _) = l
1102 getLHS (_, l, _) = l
1097 simple_lhs ctxt (Right (x, y)) = Right (normalise ctxt [] x,
1104 simple_lhs ctxt (Right (x, y)) = Right (normalise ctxt [] x,
@@ -1162,10 +1169,10 @@ elabPE info fc caller r =
1162 (map (\ (lhs, rhs) ->
1169 (map (\ (lhs, rhs) ->
1163 (showTmImpls lhs ++ " = " ++
1170 (showTmImpls lhs ++ " = " ++
1164 showTmImpls rhs)) pats)
1171 showTmImpls rhs)) pats)
1165− elabType info defaultSyntax "" [] fc opts newnm specTy
1172+ elabType info defaultSyntax emptyDocstring [] fc opts newnm specTy
1166 let def = map (\ (lhs, rhs) -> PClause fc newnm lhs [] rhs []) pats
1173 let def = map (\ (lhs, rhs) -> PClause fc newnm lhs [] rhs []) pats
1167 elabClauses info fc opts newnm def
1174 elabClauses info fc opts newnm def
1168− logLvl 1 $ "Specialised " ++ show newnm)
1175+ logLvl 2 $ "Specialised " ++ show newnm)
1169 -- if it doesn't work, just don't specialise. Could happen for lots
1176 -- if it doesn't work, just don't specialise. Could happen for lots
1170 -- of valid reasons (e.g. local variables in scope which can't be
1177 -- of valid reasons (e.g. local variables in scope which can't be
1171 -- lifted out).
1178 -- lifted out).
@@ -1419,7 +1426,7 @@ elabClause info opts (cnum, PClause fc fname lhs_in withs rhs_in whereblock)
1419 -- Elaborate those with a type *before* RHS, those without *after*
1426 -- Elaborate those with a type *before* RHS, those without *after*
1420 let (wbefore, wafter) = sepBlocks wb
1427 let (wbefore, wafter) = sepBlocks wb
1422− logLvl 1 $ "Where block:\n " ++ show wbefore ++ "\n" ++ show wafter
1429+ logLvl 2 $ "Where block:\n " ++ show wbefore ++ "\n" ++ show wafter
1423 mapM_ (elabDecl' EAll info) wbefore
1430 mapM_ (elabDecl' EAll info) wbefore
1424 -- Now build the RHS, using the type of the LHS as the goal.
1431 -- Now build the RHS, using the type of the LHS as the goal.
1425 i <- getIState -- new implicits from where block
1432 i <- getIState -- new implicits from where block
@@ -1563,7 +1570,7 @@ elabClause info opts (_, PWith fc fname lhs_in withs wval_in withblock)
1564 let params = getParamsInType i [] fn_is fn_ty
1571 let params = getParamsInType i [] fn_is fn_ty
1565 let lhs = propagateParams params fn_ty (addImplPat i (stripLinear i lhs_in))
1572 let lhs = propagateParams params fn_ty (addImplPat i (stripLinear i lhs_in))
1566− logLvl 1 ("LHS: " ++ show lhs)
1573+ logLvl 2 ("LHS: " ++ show lhs)
1567 ((lhs', dlhs, []), _) <-
1574 ((lhs', dlhs, []), _) <-
1568 tclift $ elaborate ctxt (sMN 0 "patLHS") infP []
1575 tclift $ elaborate ctxt (sMN 0 "patLHS") infP []
1569 (errAt "left hand side of with in " fname
1576 (errAt "left hand side of with in " fname
@@ -1721,7 +1728,7 @@ elabClause info opts (_, PWith fc fname lhs_in withs wval_in withblock)
1722data MArgTy = IA | EA | CA deriving Show
1729data MArgTy = IA | EA | CA deriving Show
1724−elabClass :: ElabInfo -> SyntaxInfo -> String ->
1731+elabClass :: ElabInfo -> SyntaxInfo -> Docstring ->
1725 FC -> [PTerm] ->
1732 FC -> [PTerm] ->
1726 Name -> [(Name, PTerm)] -> [PDecl] -> Idris ()
1733 Name -> [(Name, PTerm)] -> [PDecl] -> Idris ()
1727elabClass info syn doc fc constraints tn ps ds
1734elabClass info syn doc fc constraints tn ps ds
@@ -1748,7 +1755,7 @@ elabClass info syn doc fc constraints tn ps ds
1748 let cty = impbind ps $ conbind constraints
1755 let cty = impbind ps $ conbind constraints
1749 $ pibind (map (\ (n, ty) -> (nsroot n, ty)) methods)
1756 $ pibind (map (\ (n, ty) -> (nsroot n, ty)) methods)
1750 constraint
1757 constraint
1751− let cons = [("", [], cn, cty, fc, [])]
1758+ let cons = [(emptyDocstring, [], cn, cty, fc, [])]
1752 let ddecl = PDatadecl tn tty cons
1759 let ddecl = PDatadecl tn tty cons
1753 logLvl 5 $ "Class data " ++ show (showDImp True ddecl)
1760 logLvl 5 $ "Class data " ++ show (showDImp True ddecl)
1754 elabData info (syn { no_imp = no_imp syn ++ mnames }) doc [] fc [] ddecl
1761 elabData info (syn { no_imp = no_imp syn ++ mnames }) doc [] fc [] ddecl
@@ -1803,7 +1810,7 @@ elabClass info syn doc fc constraints tn ps ds
1803 case lookup n mtys of
1810 case lookup n mtys of
1804 Just (syn, o, ty) -> do let ty' = insertConstraint c ty
1811 Just (syn, o, ty) -> do let ty' = insertConstraint c ty
1805 let ds = map (decorateid defaultdec)
1812 let ds = map (decorateid defaultdec)
1806− [PTy "" [] syn fc [] n ty',
1813+ [PTy emptyDocstring [] syn fc [] n ty',
1807 PClauses fc (o ++ opts) n cs]
1814 PClauses fc (o ++ opts) n cs]
1808 iLOG (show ds)
1815 iLOG (show ds)
1809 return (n, ((defaultdec n, ds!!1), ds))
1816 return (n, ((defaultdec n, ds!!1), ds))
@@ -1841,7 +1848,7 @@ elabClass info syn doc fc constraints tn ps ds
1841 addInstance False conn' cfn
1848 addInstance False conn' cfn
1842 addIBC (IBCInstance False conn' cfn)
1849 addIBC (IBCInstance False conn' cfn)
1843-- iputStrLn ("Added " ++ show (conn, cfn, ty))
1850-- iputStrLn ("Added " ++ show (conn, cfn, ty))
1844− return [PTy "" [] syn fc [] cfn ty,
1851+ return [PTy emptyDocstring [] syn fc [] cfn ty,
1845 PClauses fc [Dictionary] cfn [PClause fc cfn lhs [] rhs []]]
1852 PClauses fc [Dictionary] cfn [PClause fc cfn lhs [] rhs []]]
1847 -- Generate a top level function which looks up a method in a given
1854 -- Generate a top level function which looks up a method in a given
@@ -1905,7 +1912,7 @@ elabInstance info syn what fc cs n ps t expn ds = do
1905 let constraint = PApp fc (PRef fc n) (map pexp ps)
1912 let constraint = PApp fc (PRef fc n) (map pexp ps)
1906 let iname = mkiname n ps expn
1913 let iname = mkiname n ps expn
1907 when (what /= EDefns) $ do
1914 when (what /= EDefns) $ do
1908− nty <- elabType' True info syn "" [] fc [] iname t
1915+ nty <- elabType' True info syn emptyDocstring [] fc [] iname t
1909 -- if the instance type matches any of the instances we have already,
1916 -- if the instance type matches any of the instances we have already,
1910 -- and it's not a named instance, then it's overlapping, so report an error
1917 -- and it's not a named instance, then it's overlapping, so report an error
1911 case expn of
1918 case expn of
@@ -1921,7 +1928,7 @@ elabInstance info syn what fc cs n ps t expn ds = do
1921 -- get the implicit parameters that need passing through to the
1928 -- get the implicit parameters that need passing through to the
1922 -- where block
1929 -- where block
1923 wparams <- mapM (\p -> case p of
1930 wparams <- mapM (\p -> case p of
1924− PApp _ _ args -> getWParams args
1931+ PApp _ _ args -> getWParams (map getTm args)
1925 _ -> return []) ps
1932 _ -> return []) ps
1926 let pnames = map pname (concat (nub wparams))
1933 let pnames = map pname (concat (nub wparams))
1927 let superclassInstances = map (substInstance ips pnames) (class_default_superclasses ci)
1934 let superclassInstances = map (substInstance ips pnames) (class_default_superclasses ci)
@@ -1947,9 +1954,24 @@ elabInstance info syn what fc cs n ps t expn ds = do
1947 logLvl 3 $ "Method types " ++ showSep "\n" (map (show . showDeclImp True . mkTyDecl) mtys)
1954 logLvl 3 $ "Method types " ++ showSep "\n" (map (show . showDeclImp True . mkTyDecl) mtys)
1948 logLvl 3 $ "Instance is " ++ show ps ++ " implicits " ++
1955 logLvl 3 $ "Instance is " ++ show ps ++ " implicits " ++
1949 show (concat (nub wparams))
1956 show (concat (nub wparams))
1958+ -- Bring variables in instance head into scope
1960+ let headVars = mapMaybe (\p -> case p of
1962+ case lookupTy n (tt_ctxt ist) of
1966+-- let lhs = PRef fc iname
1950− let lhs = PRef fc iname
1967+ let lhs = PApp fc (PRef fc iname)
1968+ (map (\n -> pimp n (PRef fc n) True) headVars)
1951 let rhs = PApp fc (PRef fc (instanceName ci))
1969 let rhs = PApp fc (PRef fc (instanceName ci))
1952 (map (pexp . mkMethApp) mtys)
1970 (map (pexp . mkMethApp) mtys)
1972+ logLvl 5 $ "Instance LHS " ++ show lhs
1973+ logLvl 5 $ "Instance RHS " ++ show rhs
1953 let idecls = [PClauses fc [Dictionary] iname
1975 let idecls = [PClauses fc [Dictionary] iname
1954 [PClause fc iname lhs [] rhs wb]]
1976 [PClause fc iname lhs [] rhs wb]]
1955 iLOG (show idecls)
1977 iLOG (show idecls)
@@ -2031,7 +2053,7 @@ elabInstance info syn what fc cs n ps t expn ds = do
2032 getWParams [] = return []
2054 getWParams [] = return []
2033 getWParams (p : ps)
2055 getWParams (p : ps)
2034− | PRef _ n <- getTm p
2056+ | PRef _ n <- p
2035 = do ps' <- getWParams ps
2057 = do ps' <- getWParams ps
2036 ctxt <- getContext
2058 ctxt <- getContext
2037 case lookupP n ctxt of
2059 case lookupP n ctxt of
@@ -2042,7 +2064,7 @@ elabInstance info syn what fc cs n ps t expn ds = do
2042 decorate ns iname (UN n) = NS (SN (MethodN (UN n))) ns
2064 decorate ns iname (UN n) = NS (SN (MethodN (UN n))) ns
2043 decorate ns iname (NS (UN n) s) = NS (SN (MethodN (UN n))) ns
2065 decorate ns iname (NS (UN n) s) = NS (SN (MethodN (UN n))) ns
2045− mkTyDecl (n, op, t, _) = PTy "" [] syn fc op n t
2067+ mkTyDecl (n, op, t, _) = PTy emptyDocstring [] syn fc op n t
2047 conbind (ty : ns) x = PPi constraint (sMN 0 "class") ty (conbind ns x)
2069 conbind (ty : ns) x = PPi constraint (sMN 0 "class") ty (conbind ns x)
2048 conbind [] x = x
2070 conbind [] x = x
@@ -2289,7 +2311,7 @@ inferredDiff fc inf user =
2289-- | Check a PTerm against documentation and ensure that every documented
2311-- | Check a PTerm against documentation and ensure that every documented
2290-- argument actually exists. This must be run _after_ implicits have been
2312-- argument actually exists. This must be run _after_ implicits have been
2291-- found, or it will give spurious errors.
2313-- found, or it will give spurious errors.
2292−checkDocs :: FC -> [(Name, String)] -> PTerm -> Idris ()
2314+checkDocs :: FC -> [(Name, Docstring)] -> PTerm -> Idris ()
2293checkDocs fc args tm = cd (Map.fromList args) tm
2315checkDocs fc args tm = cd (Map.fromList args) tm
2294 where cd as (PPi _ n _ sc) = cd (Map.delete n as) sc
2316 where cd as (PPi _ n _ sc) = cd (Map.delete n as) sc
2295 cd as _ | Map.null as = return ()
2317 cd as _ | Map.null as = return ()