@@ -133,8 +133,8 @@ elabRecord info syn fc tyn ty cn cty
133133
134134 tryElabDecl info (fn, ty, val)
135135 = do i <- get
136− idrisCatch (do elabDecl' info ty
137− elabDecl' info val)
136+ idrisCatch (do elabDecl' EAll info ty
137+ elabDecl' EAll info val)
138138 (\v -> do iputStrLn $ show fc ++
139139 ":Warning - can't generate setter for " ++
140140 show fn ++ " (" ++ show ty ++ ")"
@@ -295,7 +295,8 @@ elabClauses info fc opts n_in cs = let n = liftname info n_in in
295295 logLvl 5 $ "Optimised patterns:\n" ++ show optpats
296296
297297 let optpdef = map debind $ map (simpl (tt_ctxt ist)) optpats
298− tree@(CaseDef scargs sc _) <- tclift $ simpleCase tcase False CompileTime fc pdef
298+ tree@(CaseDef scargs sc _) <- tclift $
299+ simpleCase tcase False CompileTime fc pdef
299300 cov <- coverage
300301 pmissing <-
301302 if cov
@@ -325,9 +326,9 @@ elabClauses info fc opts n_in cs = let n = liftname info n_in in
325326 case tree of
326327 CaseDef _ _ [] -> return ()
327328 CaseDef _ _ xs -> mapM_ (\x ->
328− iputStrLn $ show fc ++
329− ":warning - Unreachable case: " ++
330− show (delab ist x)) xs
329+ iputStrLn $ show fc ++
330+ ":warning - Unreachable case: " ++
331+ show (delab ist x)) xs
331332 tree' <- tclift $ simpleCase tcase pcover RunTime fc pdef'
332333 logLvl 3 (show tree)
333334 logLvl 3 $ "Optimised: " ++ show tree'
@@ -336,18 +337,20 @@ elabClauses info fc opts n_in cs = let n = liftname info n_in in
336337 put (ist { idris_patdefs = addDef n pdef' (idris_patdefs ist) })
337338 case lookupTy (namespace info) n ctxt of
338339 [ty] -> do updateContext (addCasedef n (inlinable opts)
339− tcase pcover pdef pdef' ty)
340+ tcase pcover pats
341+ pdef pdef' ty)
340342 addIBC (IBCDef n)
341343 setTotality n tot
342344 totcheck (fc, n)
343345 when (tot /= Unchecked) $ addIBC (IBCTotal n tot)
344346 i <- get
345347 case lookupDef Nothing n (tt_ctxt i) of
346− (CaseOp _ _ _ scargs sc scargs' sc' : _) ->
348+ (CaseOp _ _ _ _ scargs sc scargs' sc' : _) ->
347349 do let calls = findCalls sc' scargs'
348350 let used = findUsedArgs sc' scargs'
349− let scg = buildSCG i sc scargs
350− let cg = CGInfo scargs' calls scg used []
351+ -- let scg = buildSCG i sc scargs
352+ -- add SCG later, when checking totality
353+ let cg = CGInfo scargs' calls [] used []
351354 logLvl 2 $ "Called names: " ++ show cg
352355 addToCG n cg
353356 addToCalledG n (nub (map fst calls)) -- plus names in type!
@@ -441,7 +444,7 @@ elabClause info tcgen (PClause fc fname lhs_in withs rhs_in whereblock)
441444 let newargs = pvars ist lhs_tm
442445 let wb = map (expandParamsD ist decorate newargs decls) whereblock
443446 logLvl 5 $ "Where block: " ++ show wb
444− mapM_ (elabDecl' info) wb
447+ mapM_ (elabDecl' EAll info) wb
445448 -- Now build the RHS, using the type of the LHS as the goal.
446449 i <- get -- new implicits from where block
447450 logLvl 5 (showImp True (expandParams decorate newargs decls rhs_in))
@@ -475,7 +478,7 @@ elabClause info tcgen (PClause fc fname lhs_in withs rhs_in whereblock)
475478 checkInferred fc (delab' i crhs True) rhs
476479 return $ Right (clhs, crhs)
477480 where
478− decorate x = UN (show fname ++ "#" ++ show x)
481+ decorate x = UN (show x ++ "#" ++ show fname)
479482 pinfo ns ps i
480483 = let ds = concatMap declared ps
481484 newps = params info ++ ns
@@ -765,16 +768,20 @@ elabInstance info syn fc cs n ps t expn ds
765768 _ -> []
766769 let mtys = map (\ (n, (op, t)) ->
767770 let t' = substMatches ips t in
768− (decorate ns n, op, coninsert cs t', t'))
771+ (decorate ns iname n,
772+ op, coninsert cs t', t'))
769773 (class_methods ci)
770774 logLvl 3 (show (mtys, ips))
771− let ds' = insertDefaults i (class_defaults ci) ns ds
775+ let ds' = insertDefaults i iname (class_defaults ci) ns ds
772776 iLOG ("Defaults inserted: " ++ show ds' ++ "\n" ++ show ci)
773− mapM_ (warnMissing ds' ns) (map fst (class_methods ci))
777+ mapM_ (warnMissing ds' ns iname) (map fst (class_methods ci))
774778 mapM_ (checkInClass (map fst (class_methods ci))) (concatMap defined ds')
775− let wb = map mkTyDecl mtys ++ map (decorateid (decorate ns)) ds'
779+ let wbTys = map mkTyDecl mtys
780+ let wbVals = map (decorateid (decorate ns iname)) ds'
781+ let wb = wbTys ++ wbVals
776782 logLvl 3 $ "Method types " ++ showSep "\n" (map (showDeclImp True . mkTyDecl) mtys)
777− -- get the implicit parameters that need passing through to the where block
783+ -- get the implicit parameters that need passing through to the
784+ -- where block
778785 wparams <- mapM (\p -> case p of
779786 PApp _ _ args -> getWParams args
780787 _ -> return []) ps
@@ -785,10 +792,10 @@ elabInstance info syn fc cs n ps t expn ds
785792 as -> PApp fc (PRef fc iname) as
786793 let rhs = PApp fc (PRef fc (instanceName ci))
787794 (map (pexp . mkMethApp) mtys)
788− let idecl = PClauses fc [Inlinable, TCGen] iname
789− [PClause fc iname lhs [] rhs wb]
790− iLOG (show idecl)
791− elabDecl info idecl
795+ let idecls = [PClauses fc [Inlinable, TCGen] iname
796+ [PClause fc iname lhs [] rhs wb]]
797+ iLOG (show idecls)
798+ mapM (elabDecl info) idecls
792799 addIBC (IBCInstance intInst n iname)
793800 where
794801 intInst = case ps of
@@ -838,8 +845,8 @@ elabInstance info syn fc cs n ps t expn ds
838845 _ -> return ps'
839846 getWParams (_ : ps) = getWParams ps
840847
841− decorate ns (UN n) = NS (UN ('!':n)) ns
842− decorate ns (NS (UN n) s) = NS (UN ('!':n)) ns
848+ decorate ns iname (UN n) = NS (UN ('!':n)) ns
849+ decorate ns iname (NS (UN n) s) = NS (UN ('!':n)) ns
843850
844851 mkTyDecl (n, op, t, _) = PTy syn fc op n t
845852
@@ -849,20 +856,22 @@ elabInstance info syn fc cs n ps t expn ds
849856 coninsert cs (PPi p@(Imp _ _) n t sc) = PPi p n t (coninsert cs sc)
850857 coninsert cs sc = conbind cs sc
851858
852− insertDefaults :: IState -> [(Name, (Name, PDecl))] -> [String] -> [PDecl] -> [PDecl]
853− insertDefaults i [] ns ds = ds
854− insertDefaults i ((n,(dn, clauses)) : defs) ns ds
855− = insertDefaults i defs ns (insertDef i n dn clauses ns ds)
859+ insertDefaults :: IState -> Name ->
860+ [(Name, (Name, PDecl))] -> [String] ->
861+ [PDecl] -> [PDecl]
862+ insertDefaults i iname [] ns ds = ds
863+ insertDefaults i iname ((n,(dn, clauses)) : defs) ns ds
864+ = insertDefaults i iname defs ns (insertDef i n dn clauses ns iname ds)
856865
857− insertDef i meth def clauses ns decls
858− | null $ filter (clauseFor meth ns) decls
866+ insertDef i meth def clauses ns iname decls
867+ | null $ filter (clauseFor meth iname ns) decls
859868 = let newd = expandParamsD i (\n -> meth) [] [def] clauses in
860869 -- trace (show newd) $
861870 decls ++ [newd]
862871 | otherwise = decls
863872
864− warnMissing decls ns meth
865− | null $ filter (clauseFor meth ns) decls
873+ warnMissing decls ns iname meth
874+ | null $ filter (clauseFor meth iname ns) decls
866875 = iWarn fc $ "method " ++ show meth ++ " not defined"
867876 | otherwise = return ()
868877
@@ -873,8 +882,9 @@ elabInstance info syn fc cs n ps t expn ds
873882
874883 eqRoot x y = nsroot x == nsroot y
875884
876− clauseFor m ns (PClauses _ _ m' _) = decorate ns m == decorate ns m'
877− clauseFor m ns _ = False
885+ clauseFor m iname ns (PClauses _ _ m' _)
886+ = decorate ns iname m == decorate ns iname m'
887+ clauseFor m iname ns _ = False
878888
879889decorateid decorate (PTy s f o n t) = PTy s f o (decorate n) t
880890decorateid decorate (PClauses f o n cs)
@@ -902,31 +912,40 @@ psolve tm = return ()
902912pvars ist (Bind n (PVar t) sc) = (n, delab ist t) : pvars ist sc
903913pvars ist _ = []
904914
905−-- TODO: Also build a 'binary' version of each declaration for fast reloading
915+data ElabWhat = ETypes | EDefns | EAll
916+ deriving (Show, Eq)
906917
907918elabDecl :: ElabInfo -> PDecl -> Idris ()
908−elabDecl info d = idrisCatch (elabDecl' info d)
919+elabDecl info d = idrisCatch (elabDecl' EAll info d)
909920 (\e -> do let msg = show e
910921 setErrLine (getErrLine msg)
911922 iputStrLn msg)
912923
913−elabDecl' info (PFix _ _ _) = return () -- nothing to elaborate
914−elabDecl' info (PSyntax _ p) = return () -- nothing to elaborate
915−elabDecl' info (PTy s f o n ty) = do iLOG $ "Elaborating type decl " ++ show n ++ show o
916− elabType info s f o n ty
917−elabDecl' info (PData s f co d) = do iLOG $ "Elaborating " ++ show (d_name d)
918− elabData info s f co d
919−elabDecl' info d@(PClauses f o n ps) = do iLOG $ "Elaborating clause " ++ show n
920− i <- get -- get the type options too
921− let o' = case lookupCtxt Nothing n (idris_flags i) of
922− [fs] -> fs
923− [] -> []
924− elabClauses info f (o ++ o') n ps
925−elabDecl' info (PParams f ns ps)
924+elabDecl' _ info (PFix _ _ _)
925+ = return () -- nothing to elaborate
926+elabDecl' _ info (PSyntax _ p)
927+ = return () -- nothing to elaborate
928+elabDecl' what info (PTy s f o n ty)
929+ | what /= EDefns
930+ = do iLOG $ "Elaborating type decl " ++ show n ++ show o
931+ elabType info s f o n ty
932+elabDecl' what info (PData s f co d)
933+ | what /= EDefns
934+ = do iLOG $ "Elaborating " ++ show (d_name d)
935+ elabData info s f co d
936+elabDecl' what info d@(PClauses f o n ps)
937+ | what /= ETypes
938+ = do iLOG $ "Elaborating clause " ++ show n
939+ i <- get -- get the type options too
940+ let o' = case lookupCtxt Nothing n (idris_flags i) of
941+ [fs] -> fs
942+ [] -> []
943+ elabClauses info f (o ++ o') n ps
944+elabDecl' what info (PParams f ns ps)
926945 = do i <- get
927946 iLOG $ "Expanding params block with " ++ show (concatMap declared ps)
928947 let nblock = pblock i
929− mapM_ (elabDecl' info) nblock
948+ mapM_ (elabDecl' what info) nblock
930949 where
931950 pinfo = let ds = concatMap declared ps
932951 newps = params info ++ ns
@@ -936,29 +955,35 @@ elabDecl' info (PParams f ns ps)
936955 inblock = newb }
937956 pblock i = map (expandParamsD i id ns (concatMap declared ps)) ps
938957
939−elabDecl' info (PNamespace n ps) = mapM_ (elabDecl' ninfo) ps
958+elabDecl' what info (PNamespace n ps) = mapM_ (elabDecl' what ninfo) ps
940959 where
941960 ninfo = case namespace info of
942961 Nothing -> info { namespace = Just [n] }
943962 Just ns -> info { namespace = Just (n:ns) }
944−elabDecl' info (PClass s f cs n ps ds) = do iLOG $ "Elaborating class " ++ show n
945− elabClass info s f cs n ps ds
946−elabDecl' info (PInstance s f cs n ps t expn ds)
963+elabDecl' what info (PClass s f cs n ps ds)
964+ | what /= EDefns
965+ = do iLOG $ "Elaborating class " ++ show n
966+ elabClass info s f cs n ps ds
967+elabDecl' what info (PInstance s f cs n ps t expn ds)
968+ | what /= EDefns
947969 = do iLOG $ "Elaborating instance " ++ show n
948970 elabInstance info s f cs n ps t expn ds
949−elabDecl' info (PRecord s f tyn ty cn cty)
971+elabDecl' what info (PRecord s f tyn ty cn cty)
972+ | what /= EDefns
950973 = do iLOG $ "Elaborating record " ++ show tyn
951974 elabRecord info s f tyn ty cn cty
952−elabDecl' info (PDSL n dsl)
975+elabDecl' _ info (PDSL n dsl)
953976 = do i <- get
954977 put (i { idris_dsls = addDef n dsl (idris_dsls i) })
955978 addIBC (IBCDSL n)
956−elabDecl' info (PDirective i) = i
979+elabDecl' what info (PDirective i)
980+ | what /= EDefns = i
981+elabDecl' _ _ _ = return () -- skipped this time
957982
958983elabCaseBlock info d@(PClauses f o n ps)
959984 = do addIBC (IBCDef n)
960985-- iputStrLn $ "CASE BLOCK: " ++ show (n, d)
961− elabDecl' info d
986+ elabDecl' EAll info d
962987
963988-- elabDecl' info (PImport i) = loadModule i
964989