@@ -61,6 +61,7 @@ data MArgTy = IA Name | EA Name | CA deriving Show
6161elabInterface :: ElabInfo
6262 -> SyntaxInfo
6363 -> Docstring (Either Err PTerm)
64+ -> ElabWhat
6465 -> FC
6566 -> [(Name, PTerm)] -- ^ Superclass constraints
6667 -> Name
@@ -72,7 +73,7 @@ elabInterface :: ElabInfo
7273 -> Maybe (Name, FC) -- ^ implementation ctor name and location
7374 -> Docstring (Either Err PTerm) -- ^ implementation ctor docs
7475 -> Idris ()
75−elabInterface info_in syn_in doc fc constraints tn tnfc ps pDocs fds ds mcn cd
76+elabInterface info_in syn_in doc what fc constraints tn tnfc ps pDocs fds ds mcn cd
7677 = do let cn = fromMaybe (SN (ImplementationCtorN tn)) (fst <$> mcn)
7778 let constraint = PApp fc (PRef fc [] tn)
7879 (map (pexp . PRef fc []) (map (\(n, _, _) -> n) ps))
@@ -109,94 +110,98 @@ elabInterface info_in syn_in doc fc constraints tn tnfc ps pDocs fds ds mcn cd
109110 mapM_ (checkConstraintName (map (\(x, _, _) -> x) ps)) constraintNames
110111
111112 let pre_ddecl = PLaterdecl tn NoFC tty
112− -- Elaborate the interface header
113− elabData info (syn { no_imp = no_imp syn ++ mnames,
114− imp_methods = mnames }) doc pDocs fc [] pre_ddecl
115− dets <- findDets tn (map fst fds)
116−
117− logElab 3 $ "Building methods " ++ show fullmnames
118− ims <- mapM (tdecl impps mnames) mdecls
119− defs <- mapM (defdecl (map (\ (x,y,z) -> z) ims) constraint)
120− (filter clause ds)
121− let (methods, imethods)
122− = unzip (map (\ (x, y, z) -> (x, y)) ims)
123− let defaults = map (\ (x, (y, z)) -> (x,y)) defs
124−
125− addInterface tn (CI cn (map nodoc imethods) defaults idecls
126− (map (\(n, _, _) -> n) impps)
127− (map (\(n, _, _) -> n) ps)
128− (map snd constraints)
129− [] dets)
130−
131− -- for each constraint, build a top level function to chase it
132− -- elaborate types now, bodies later (after we've done the constructor
133− -- of the interface)
134− cfns <- mapM (cfun cn constraint syn (map fst imethods)) constraints
135− let (cfnTyDecls, cfnDefs) = unzip cfns
136− mapM_ (rec_elabDecl info EAll info) cfnTyDecls
137−
138− -- for each method, build a top level function
139− -- 'tfun' builds appropriate implicits for the constructor
140− -- declaration
141− fns <- mapM (tfun cn constraint (syn { imp_methods = mnames }) -- mnames })
142− (map fst imethods)) imethods
143− let (fnTyDecls, fnDefs) = unzip fns
144− mapM_ (rec_elabDecl info EAll info) fnTyDecls
145−
146− elabMethTys <- mapM getElabMethTy fullmnames
147−
148− logElab 3 $ "Method types:\n" ++ showSep "\n" (map showTmImpls elabMethTys)
149−
150− let cpos = map (\ (n, ty) -> (n, findConstraint ty))
151− (zip fullmnames elabMethTys)
152− logElab 5 $ "Constraint pos: " ++ show cpos
153−
154− -- Method types to store in the IState, taken from the elaborated
155− -- types with the parameter removed
156− let storemeths = map (mkMethTy True cpos) (zip fullmnames elabMethTys)
157− updateIMethods tn storemeths
158−
159− -- build implementation constructor type
160− let cty = impbind [(pn, pt) | (pn, _, pt) <- impps ++ ps] $
161− conbind constraints $
162− pibind (map (mkMethTy False cpos) (zip fullmnames elabMethTys))
163− constraint
164− logElab 3 $ "Constraint constructor type: " ++ showTmImpls cty
165−
166− let cons = [(cd, pDocs ++ mapMaybe memberDocs ds, cn, NoFC, cty, fc, [])]
167− let ddecl = PDatadecl tn NoFC tty cons
168−
169− logElab 10 $ "Interface " ++ show (showDImp verbosePPOption ddecl)
170−
171−
172− -- Elaborate the data declaration
173− elabData info (syn { no_imp = no_imp syn ++ mnames,
174− imp_methods = [] }) doc pDocs fc [] ddecl
175−
176−
177− logElab 5 $ "Function types " ++ show fnTyDecls
178− logElab 5 $ "Method types now: " ++ show imethods
179−
180− -- Elaborate the the top level constraint chasers
181− -- (Types elaborated earlier)
182− mapM_ (rec_elabDecl info EAll info) cfnDefs
183− -- Elaborate the the top level method bodies
184− mapM_ (rec_elabDecl info EAll info) fnDefs
185−
186− -- Flag all the top level data declarations as injective
187− mapM_ (\n -> do setInjectivity n True
188− addIBC (IBCInjective n True))
189− (map fst (filter (\(_, (inj, _, _, _, _)) -> inj) imethods))
190−
191− -- add the default definitions
192− mapM_ (rec_elabDecl info EAll info) (concatMap (snd.snd) defs)
193− addIBC (IBCInterface tn)
194−
195− sendHighlighting $
196− [(tnfc, AnnName tn Nothing Nothing Nothing)] ++
197− [(pnfc, AnnBoundName pn False) | (pn, pnfc, _) <- ps] ++
198− [(fdfc, AnnBoundName fc False) | (fc, fdfc) <- fds] ++
199− maybe [] (\(conN, conNFC) -> [(conNFC, AnnName conN Nothing Nothing Nothing)]) mcn
113+ -- Elaborate the interface header, as long as we haven't done it
114+ -- in an earlier pass
115+ when (what /= EDefns) $
116+ elabData info (syn { no_imp = no_imp syn ++ mnames,
117+ imp_methods = mnames }) doc pDocs fc [] pre_ddecl
118+ -- Continue only if we're not in the first pass of a mutual block
119+ when (what /= ETypes) $ do
120+ dets <- findDets tn (map fst fds)
121+
122+ logElab 3 $ "Building methods " ++ show fullmnames
123+ ims <- mapM (tdecl impps mnames) mdecls
124+ defs <- mapM (defdecl (map (\ (x,y,z) -> z) ims) constraint)
125+ (filter clause ds)
126+ let (methods, imethods)
127+ = unzip (map (\ (x, y, z) -> (x, y)) ims)
128+ let defaults = map (\ (x, (y, z)) -> (x,y)) defs
129+
130+ addInterface tn (CI cn (map nodoc imethods) defaults idecls
131+ (map (\(n, _, _) -> n) impps)
132+ (map (\(n, _, _) -> n) ps)
133+ (map snd constraints)
134+ [] dets)
135+
136+ -- for each constraint, build a top level function to chase it
137+ -- elaborate types now, bodies later (after we've done the constructor
138+ -- of the interface)
139+ cfns <- mapM (cfun cn constraint syn (map fst imethods)) constraints
140+ let (cfnTyDecls, cfnDefs) = unzip cfns
141+ mapM_ (rec_elabDecl info EAll info) cfnTyDecls
142+
143+ -- for each method, build a top level function
144+ -- 'tfun' builds appropriate implicits for the constructor
145+ -- declaration
146+ fns <- mapM (tfun cn constraint (syn { imp_methods = mnames }) -- mnames })
147+ (map fst imethods)) imethods
148+ let (fnTyDecls, fnDefs) = unzip fns
149+ mapM_ (rec_elabDecl info EAll info) fnTyDecls
150+
151+ elabMethTys <- mapM getElabMethTy fullmnames
152+
153+ logElab 3 $ "Method types:\n" ++ showSep "\n" (map showTmImpls elabMethTys)
154+
155+ let cpos = map (\ (n, ty) -> (n, findConstraint ty))
156+ (zip fullmnames elabMethTys)
157+ logElab 5 $ "Constraint pos: " ++ show cpos
158+
159+ -- Method types to store in the IState, taken from the elaborated
160+ -- types with the parameter removed
161+ let storemeths = map (mkMethTy True cpos) (zip fullmnames elabMethTys)
162+ updateIMethods tn storemeths
163+
164+ -- build implementation constructor type
165+ let cty = impbind [(pn, pt) | (pn, _, pt) <- impps ++ ps] $
166+ conbind constraints $
167+ pibind (map (mkMethTy False cpos) (zip fullmnames elabMethTys))
168+ constraint
169+ logElab 3 $ "Constraint constructor type: " ++ showTmImpls cty
170+
171+ let cons = [(cd, pDocs ++ mapMaybe memberDocs ds, cn, NoFC, cty, fc, [])]
172+ let ddecl = PDatadecl tn NoFC tty cons
173+
174+ logElab 10 $ "Interface " ++ show (showDImp verbosePPOption ddecl)
175+
176+
177+ -- Elaborate the data declaration
178+ elabData info (syn { no_imp = no_imp syn ++ mnames,
179+ imp_methods = [] }) doc pDocs fc [] ddecl
180+
181+
182+ logElab 5 $ "Function types " ++ show fnTyDecls
183+ logElab 5 $ "Method types now: " ++ show imethods
184+
185+ -- Elaborate the the top level constraint chasers
186+ -- (Types elaborated earlier)
187+ mapM_ (rec_elabDecl info EAll info) cfnDefs
188+ -- Elaborate the the top level method bodies
189+ mapM_ (rec_elabDecl info EAll info) fnDefs
190+
191+ -- Flag all the top level data declarations as injective
192+ mapM_ (\n -> do setInjectivity n True
193+ addIBC (IBCInjective n True))
194+ (map fst (filter (\(_, (inj, _, _, _, _)) -> inj) imethods))
195+
196+ -- add the default definitions
197+ mapM_ (rec_elabDecl info EAll info) (concatMap (snd.snd) defs)
198+ addIBC (IBCInterface tn)
199+
200+ sendHighlighting $
201+ [(tnfc, AnnName tn Nothing Nothing Nothing)] ++
202+ [(pnfc, AnnBoundName pn False) | (pn, pnfc, _) <- ps] ++
203+ [(fdfc, AnnBoundName fc False) | (fc, fdfc) <- fds] ++
204+ maybe [] (\(conN, conNFC) -> [(conNFC, AnnName conN Nothing Nothing Nothing)]) mcn
200205
201206 where
202207 info = info_in { noCaseLift = tn : noCaseLift info_in }