@@ -15,7 +15,7 @@ import Idris.Primitives
15import Idris.Inliner
15import Idris.Inliner
16import Idris.PartialEval
16import Idris.PartialEval
17import Idris.DeepSeq
17import Idris.DeepSeq
18−import Idris.Output (iputStrLn, pshow, iWarn)
18+import Idris.Output (iputStrLn, pshow, iWarn, sendHighlighting)
19import IRTS.Lang
19import IRTS.Lang
21import Idris.Elab.Type
21import Idris.Elab.Type
@@ -54,18 +54,22 @@ data MArgTy = IA Name | EA Name | CA deriving Show
55elabClass :: ElabInfo -> SyntaxInfo -> Docstring (Either Err PTerm) ->
55elabClass :: ElabInfo -> SyntaxInfo -> Docstring (Either Err PTerm) ->
56 FC -> [(Name, PTerm)] ->
56 FC -> [(Name, PTerm)] ->
57− Name -> [(Name, PTerm)] -> [(Name, Docstring (Either Err PTerm))] ->
57+ Name -> FC -> [(Name, FC, PTerm)] -> [(Name, Docstring (Either Err PTerm))] ->
58+ [(Name, FC)] {- ^ determining params -} ->
58− [Name] -> [PDecl] ->
59+ [PDecl] {- ^ class body -} ->
59− Maybe Name {- ^ instance ctor name -} ->
60+ Maybe (Name, FC) {- ^ instance ctor name and location -} ->
60 Docstring (Either Err PTerm) {- ^ instance ctor docs -} ->
61 Docstring (Either Err PTerm) {- ^ instance ctor docs -} ->
62−elabClass info syn_in doc fc constraints tn ps pDocs fds ds mcn cd
63+elabClass info syn_in doc fc constraints tn tnfc ps pDocs fds ds mcn cd
63− = do let cn = fromMaybe (SN (InstanceCtorN tn)) mcn
64+ = do let cn = fromMaybe (SN (InstanceCtorN tn)) (fst <$> mcn)
64− let tty = pibind ps (PType fc)
65+ let tty = pibind (map (\(n, _, ty) -> (n, ty)) ps) (PType fc)
65 let constraint = PApp fc (PRef fc tn)
66 let constraint = PApp fc (PRef fc tn)
66− (map (pexp . PRef fc) (map fst ps))
67+ (map (pexp . PRef fc) (map (\(n, _, _) -> n) ps))
68− let syn = syn_in { using = addToUsing (using syn_in) ps }
70+ syn_in { using = addToUsing (using syn_in)
71+ [(pn, pt) | (pn, _, pt) <- ps]
70 -- build data declaration
74 -- build data declaration
71 let mdecls = filter tydecl ds -- method declarations
75 let mdecls = filter tydecl ds -- method declarations
@@ -77,10 +81,10 @@ elabClass info syn_in doc fc constraints tn ps pDocs fds ds mcn cd
77 defs <- mapM (defdecl (map (\ (x,y,z) -> z) ims) constraint)
81 defs <- mapM (defdecl (map (\ (x,y,z) -> z) ims) constraint)
78 (filter clause ds)
82 (filter clause ds)
79 let (methods, imethods)
83 let (methods, imethods)
80− = unzip (map (\ ( x,y,z) -> (x, y)) ims)
84+ = unzip (map (\ (x, y, z) -> (x, y)) ims)
81 let defaults = map (\ (x, (y, z)) -> (x,y)) defs
85 let defaults = map (\ (x, (y, z)) -> (x,y)) defs
82 -- build instance constructor type
86 -- build instance constructor type
83− let cty = impbind ps $ conbind constraints
87+ let cty = impbind [(pn, pt) | (pn, _, pt) <- ps] $ conbind constraints
84 $ pibind (map (\ (n, ty) -> (nsroot n, ty)) methods)
88 $ pibind (map (\ (n, ty) -> (nsroot n, ty)) methods)
85 constraint
89 constraint
@@ -91,8 +95,8 @@ elabClass info syn_in doc fc constraints tn ps pDocs fds ds mcn cd
91 -- Elaborate the data declaration
95 -- Elaborate the data declaration
92 elabData info (syn { no_imp = no_imp syn ++ mnames,
96 elabData info (syn { no_imp = no_imp syn ++ mnames,
93 imp_methods = mnames }) doc pDocs fc [] ddecl
97 imp_methods = mnames }) doc pDocs fc [] ddecl
94− dets <- findDets cn fds
98+ dets <- findDets cn (map fst fds)
95− addClass tn (CI cn (map nodoc imethods) defaults idecls (map fst ps) [] dets)
99+ addClass tn (CI cn (map nodoc imethods) defaults idecls (map (\(n, _, _) -> n) ps) [] dets)
97 -- for each constraint, build a top level function to chase it
101 -- for each constraint, build a top level function to chase it
98 cfns <- mapM (cfun cn constraint syn (map fst imethods)) constraints
102 cfns <- mapM (cfun cn constraint syn (map fst imethods)) constraints
@@ -108,8 +112,16 @@ elabClass info syn_in doc fc constraints tn ps pDocs fds ds mcn cd
108 -- add the default definitions
112 -- add the default definitions
109 mapM_ (rec_elabDecl info EAll info) (concat (map (snd.snd) defs))
113 mapM_ (rec_elabDecl info EAll info) (concat (map (snd.snd) defs))
110 addIBC (IBCClass tn)
114 addIBC (IBCClass tn)
117+ [(tnfc, AnnName tn Nothing Nothing Nothing)] ++
118+ [(pnfc, AnnBoundName pn False) | (pn, pnfc, _) <- ps] ++
119+ [(fdfc, AnnBoundName fc False) | (fc, fdfc) <- fds] ++
120+ maybe [] (\(conN, conNFC) -> [(conNFC, AnnName conN Nothing Nothing Nothing)]) mcn
112− nodoc (n, (_, o, t)) = (n, (o, t))
123+ nodoc (n, (_, _, o, t)) = (n, (o, t))
113 pibind [] x = x
125 pibind [] x = x
114 pibind ((n, ty): ns) x = PPi expl n NoFC ty (pibind ns (chkUniq ty x))
126 pibind ((n, ty): ns) x = PPi expl n NoFC ty (pibind ns (chkUniq ty x))
@@ -127,7 +139,7 @@ elabClass info syn_in doc fc constraints tn ps pDocs fds ds mcn cd
128 -- TODO: probably should normalise
140 -- TODO: probably should normalise
129 checkDefaultSuperclassInstance :: PDecl -> Idris ()
141 checkDefaultSuperclassInstance :: PDecl -> Idris ()
130− checkDefaultSuperclassInstance (PInstance _ _ _ fc cs n ps _ _ _)
142+ checkDefaultSuperclassInstance (PInstance _ _ _ fc cs n _ ps _ _ _)
131 = do when (not $ null cs) . tclift
143 = do when (not $ null cs) . tclift
132 $ tfail (At fc (Msg $ "Default superclass instances can't have constraints."))
144 $ tfail (At fc (Msg $ "Default superclass instances can't have constraints."))
133 i <- getIState
145 i <- getIState
@@ -147,23 +159,24 @@ elabClass info syn_in doc fc constraints tn ps pDocs fds ds mcn cd
148 getMName (PTy _ _ _ _ _ n nfc _) = nsroot n
160 getMName (PTy _ _ _ _ _ n nfc _) = nsroot n
149 tdecl allmeths (PTy doc _ syn _ o n nfc t)
161 tdecl allmeths (PTy doc _ syn _ o n nfc t)
150− = do t' <- implicit' info syn (map fst ps ++ allmeths) n t
162+ = do t' <- implicit' info syn (map (\(n, _, _) -> n) ps ++ allmeths) n t
151 logLvl 2 $ "Method " ++ show n ++ " : " ++ showTmImpls t'
163 logLvl 2 $ "Method " ++ show n ++ " : " ++ showTmImpls t'
152− return ( (n, (toExp (map fst ps) Exp t')),
164+ return ( (n, (toExp (map (\(pn, _, _) -> pn) ps) Exp t')),
153− (n, (doc, o, (toExp (map fst ps)
165+ (n, (nfc, doc, o, (toExp (map (\(pn, _, _) -> pn) ps)
154− (\ l s p -> Imp l s p Nothing) t'))),
166+ (\ l s p -> Imp l s p Nothing) t'))),
155− (n, (syn, o, t) ) )
167+ (n, (nfc, syn, o, t) ) )
156 tdecl _ _ = ifail "Not allowed in a class declaration"
168 tdecl _ _ = ifail "Not allowed in a class declaration"
158 -- Create default definitions
170 -- Create default definitions
159 defdecl mtys c d@(PClauses fc opts n cs) =
171 defdecl mtys c d@(PClauses fc opts n cs) =
160 case lookup n mtys of
172 case lookup n mtys of
173+ Just (nfc, syn, o, ty) ->
161− Just (syn, o, ty) -> do let ty' = insertConstraint c ty
174+ do let ty' = insertConstraint c ty
162− let ds = map (decorateid defaultdec)
175+ let ds = map (decorateid defaultdec)
163− [PTy emptyDocstring [] syn fc [] n NoFC ty',
176+ [PTy emptyDocstring [] syn fc [] n nfc ty',
164− PClauses fc (o ++ opts) n cs]
177+ PClauses fc (o ++ opts) n cs]
165− iLOG (show ds)
178+ iLOG (show ds)
166− return (n, ((defaultdec n, ds!!1), ds))
179+ return (n, ((defaultdec n, ds!!1), ds))
167 _ -> ifail $ show n ++ " is not a method"
180 _ -> ifail $ show n ++ " is not a method"
168 defdecl _ _ _ = ifail "Can't happen (defdecl)"
181 defdecl _ _ _ = ifail "Can't happen (defdecl)"
@@ -172,7 +185,7 @@ elabClass info syn_in doc fc constraints tn ps pDocs fds ds mcn cd
173 tydecl (PTy _ _ _ _ _ _ _ _) = True
186 tydecl (PTy _ _ _ _ _ _ _ _) = True
174 tydecl _ = False
187 tydecl _ = False
175− instdecl (PInstance _ _ _ _ _ _ _ _ _ _) = True
188+ instdecl (PInstance _ _ _ _ _ _ _ _ _ _ _) = True
176 instdecl _ = False
189 instdecl _ = False
177 clause (PClauses _ _ _ _) = True
190 clause (PClauses _ _ _ _) = True
178 clause _ = False
191 clause _ = False
@@ -204,7 +217,7 @@ elabClass info syn_in doc fc constraints tn ps pDocs fds ds mcn cd
205 -- Generate a top level function which looks up a method in a given
218 -- Generate a top level function which looks up a method in a given
206 -- dictionary (this is inlinable, always)
219 -- dictionary (this is inlinable, always)
207− tfun cn c syn all (m, (doc, o, ty))
220+ tfun cn c syn all (m, (mfc, doc, o, ty))
208 = do let ty' = expandMethNS syn (insertConstraint c ty)
221 = do let ty' = expandMethNS syn (insertConstraint c ty)
209 let mnames = take (length all) $ map (\x -> sMN x "meth") [0..]
222 let mnames = take (length all) $ map (\x -> sMN x "meth") [0..]
210 let capp = PApp fc (PRef fc cn) (map (pexp . PRef fc) mnames)
223 let capp = PApp fc (PRef fc cn) (map (pexp . PRef fc) mnames)
@@ -215,7 +228,7 @@ elabClass info syn_in doc fc constraints tn ps pDocs fds ds mcn cd
215 logLvl 2 ("Top level type: " ++ showTmImpls ty')
228 logLvl 2 ("Top level type: " ++ showTmImpls ty')
216 iLOG (show (m, ty', capp, margs))
229 iLOG (show (m, ty', capp, margs))
217 logLvl 2 ("Definition: " ++ showTmImpls lhs ++ " = " ++ showTmImpls rhs)
230 logLvl 2 ("Definition: " ++ showTmImpls lhs ++ " = " ++ showTmImpls rhs)
218− return [PTy doc [] syn fc o m NoFC ty',
231+ return [PTy doc [] syn fc o m mfc ty',
219 PClauses fc [Inlinable] m [PClause fc m lhs [] rhs []]]
232 PClauses fc [Inlinable] m [PClause fc m lhs [] rhs []]]
221 getMArgs (PPi (Imp _ _ _ _) n _ ty sc) = IA n : getMArgs sc
234 getMArgs (PPi (Imp _ _ _ _) n _ ty sc) = IA n : getMArgs sc
@@ -253,7 +266,7 @@ memberDocs (PTy d _ _ _ _ n _ _) = Just (basename n, d)
253memberDocs (PPostulate _ d _ _ _ n _) = Just (basename n, d)
266memberDocs (PPostulate _ d _ _ _ n _) = Just (basename n, d)
254memberDocs (PData d _ _ _ _ pdata) = Just (basename $ d_name pdata, d)
267memberDocs (PData d _ _ _ _ pdata) = Just (basename $ d_name pdata, d)
255memberDocs (PRecord d _ _ _ n _ _ _ _ _ _ _ ) = Just (basename n, d)
268memberDocs (PRecord d _ _ _ n _ _ _ _ _ _ _ ) = Just (basename n, d)
256−memberDocs (PClass d _ _ _ n _ _ _ _ _ _) = Just (basename n, d)
269+memberDocs (PClass d _ _ _ n _ _ _ _ _ _ _) = Just (basename n, d)
257memberDocs _ = Nothing
270memberDocs _ = Nothing