@@ -133,8 +133,8 @@ elabRecord info syn fc tyn ty cn cty
134 tryElabDecl info (fn, ty, val)
134 tryElabDecl info (fn, ty, val)
135 = do i <- get
135 = do i <- get
136− idrisCatch (do elabDecl' info ty
136+ idrisCatch (do elabDecl' EAll info ty
137− elabDecl' info val)
137+ elabDecl' EAll info val)
138 (\v -> do iputStrLn $ show fc ++
138 (\v -> do iputStrLn $ show fc ++
139 ":Warning - can't generate setter for " ++
139 ":Warning - can't generate setter for " ++
140 show fn ++ " (" ++ show ty ++ ")"
140 show fn ++ " (" ++ show ty ++ ")"
@@ -295,7 +295,8 @@ elabClauses info fc opts n_in cs = let n = liftname info n_in in
295 logLvl 5 $ "Optimised patterns:\n" ++ show optpats
295 logLvl 5 $ "Optimised patterns:\n" ++ show optpats
297 let optpdef = map debind $ map (simpl (tt_ctxt ist)) optpats
297 let optpdef = map debind $ map (simpl (tt_ctxt ist)) optpats
298+ tree@(CaseDef scargs sc _) <- tclift $
298− tree@(CaseDef scargs sc _) <- tclift $ simpleCase tcase False CompileTime fc pdef
299+ simpleCase tcase False CompileTime fc pdef
299 cov <- coverage
300 cov <- coverage
300 pmissing <-
301 pmissing <-
@@ -325,9 +326,9 @@ elabClauses info fc opts n_in cs = let n = liftname info n_in in
325 case tree of
326 case tree of
326 CaseDef _ _ [] -> return ()
327 CaseDef _ _ [] -> return ()
327 CaseDef _ _ xs -> mapM_ (\x ->
328 CaseDef _ _ xs -> mapM_ (\x ->
328− iputStrLn $ show fc ++
329+ iputStrLn $ show fc ++
329− ":warning - Unreachable case: " ++
330+ ":warning - Unreachable case: " ++
330− show (delab ist x)) xs
331+ show (delab ist x)) xs
331 tree' <- tclift $ simpleCase tcase pcover RunTime fc pdef'
332 tree' <- tclift $ simpleCase tcase pcover RunTime fc pdef'
332 logLvl 3 (show tree)
333 logLvl 3 (show tree)
333 logLvl 3 $ "Optimised: " ++ show tree'
334 logLvl 3 $ "Optimised: " ++ show tree'
@@ -336,18 +337,20 @@ elabClauses info fc opts n_in cs = let n = liftname info n_in in
336 put (ist { idris_patdefs = addDef n pdef' (idris_patdefs ist) })
337 put (ist { idris_patdefs = addDef n pdef' (idris_patdefs ist) })
337 case lookupTy (namespace info) n ctxt of
338 case lookupTy (namespace info) n ctxt of
338 [ty] -> do updateContext (addCasedef n (inlinable opts)
339 [ty] -> do updateContext (addCasedef n (inlinable opts)
339− tcase pcover pdef pdef' ty)
341+ pdef pdef' ty)
340 addIBC (IBCDef n)
342 addIBC (IBCDef n)
341 setTotality n tot
343 setTotality n tot
342 totcheck (fc, n)
344 totcheck (fc, n)
343 when (tot /= Unchecked) $ addIBC (IBCTotal n tot)
345 when (tot /= Unchecked) $ addIBC (IBCTotal n tot)
345 case lookupDef Nothing n (tt_ctxt i) of
347 case lookupDef Nothing n (tt_ctxt i) of
346− (CaseOp _ _ _ scargs sc scargs' sc' : _) ->
348+ (CaseOp _ _ _ _ scargs sc scargs' sc' : _) ->
347 do let calls = findCalls sc' scargs'
349 do let calls = findCalls sc' scargs'
348 let used = findUsedArgs sc' scargs'
350 let used = findUsedArgs sc' scargs'
349− let scg = buildSCG i sc scargs
351+ -- let scg = buildSCG i sc scargs
352+ -- add SCG later, when checking totality
350− let cg = CGInfo scargs' calls scg used []
353+ let cg = CGInfo scargs' calls [] used []
351 logLvl 2 $ "Called names: " ++ show cg
354 logLvl 2 $ "Called names: " ++ show cg
352 addToCG n cg
355 addToCG n cg
353 addToCalledG n (nub (map fst calls)) -- plus names in type!
356 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)
441 let newargs = pvars ist lhs_tm
444 let newargs = pvars ist lhs_tm
442 let wb = map (expandParamsD ist decorate newargs decls) whereblock
445 let wb = map (expandParamsD ist decorate newargs decls) whereblock
443 logLvl 5 $ "Where block: " ++ show wb
446 logLvl 5 $ "Where block: " ++ show wb
444− mapM_ (elabDecl' info) wb
447+ mapM_ (elabDecl' EAll info) wb
445 -- Now build the RHS, using the type of the LHS as the goal.
448 -- Now build the RHS, using the type of the LHS as the goal.
446 i <- get -- new implicits from where block
449 i <- get -- new implicits from where block
447 logLvl 5 (showImp True (expandParams decorate newargs decls rhs_in))
450 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)
475 checkInferred fc (delab' i crhs True) rhs
478 checkInferred fc (delab' i crhs True) rhs
476 return $ Right (clhs, crhs)
479 return $ Right (clhs, crhs)
478− decorate x = UN (show fname ++ "#" ++ show x)
481+ decorate x = UN (show x ++ "#" ++ show fname)
479 pinfo ns ps i
482 pinfo ns ps i
480 = let ds = concatMap declared ps
483 = let ds = concatMap declared ps
481 newps = params info ++ ns
484 newps = params info ++ ns
@@ -765,16 +768,20 @@ elabInstance info syn fc cs n ps t expn ds
766 let mtys = map (\ (n, (op, t)) ->
769 let mtys = map (\ (n, (op, t)) ->
767 let t' = substMatches ips t in
770 let t' = substMatches ips t in
771+ (decorate ns iname n,
768− (decorate ns n, op, coninsert cs t', t'))
772+ op, coninsert cs t', t'))
769 (class_methods ci)
773 (class_methods ci)
770 logLvl 3 (show (mtys, ips))
774 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
772 iLOG ("Defaults inserted: " ++ show ds' ++ "\n" ++ show ci)
776 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))
774 mapM_ (checkInClass (map fst (class_methods ci))) (concatMap defined ds')
778 mapM_ (checkInClass (map fst (class_methods ci))) (concatMap defined ds')
779+ let wbTys = map mkTyDecl mtys
775− let wb = map mkTyDecl mtys ++ map (decorateid (decorate ns)) ds'
780+ let wbVals = map (decorateid (decorate ns iname)) ds'
781+ let wb = wbTys ++ wbVals
776 logLvl 3 $ "Method types " ++ showSep "\n" (map (showDeclImp True . mkTyDecl) mtys)
782 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
778 wparams <- mapM (\p -> case p of
785 wparams <- mapM (\p -> case p of
779 PApp _ _ args -> getWParams args
786 PApp _ _ args -> getWParams args
780 _ -> return []) ps
787 _ -> return []) ps
@@ -785,10 +792,10 @@ elabInstance info syn fc cs n ps t expn ds
785 as -> PApp fc (PRef fc iname) as
792 as -> PApp fc (PRef fc iname) as
786 let rhs = PApp fc (PRef fc (instanceName ci))
793 let rhs = PApp fc (PRef fc (instanceName ci))
787 (map (pexp . mkMethApp) mtys)
794 (map (pexp . mkMethApp) mtys)
788− let idecl = PClauses fc [Inlinable, TCGen] iname
795+ let idecls = [PClauses fc [Inlinable, TCGen] iname
789− [PClause fc iname lhs [] rhs wb]
796+ [PClause fc iname lhs [] rhs wb]]
790− iLOG (show idecl)
797+ iLOG (show idecls)
791− elabDecl info idecl
798+ mapM (elabDecl info) idecls
792 addIBC (IBCInstance intInst n iname)
799 addIBC (IBCInstance intInst n iname)
794 intInst = case ps of
801 intInst = case ps of
@@ -838,8 +845,8 @@ elabInstance info syn fc cs n ps t expn ds
838 _ -> return ps'
845 _ -> return ps'
839 getWParams (_ : ps) = getWParams ps
846 getWParams (_ : ps) = getWParams ps
841− decorate ns (UN n) = NS (UN ('!':n)) ns
848+ decorate ns iname (UN n) = NS (UN ('!':n)) ns
842− decorate ns (NS (UN n) s) = NS (UN ('!':n)) ns
849+ decorate ns iname (NS (UN n) s) = NS (UN ('!':n)) ns
844 mkTyDecl (n, op, t, _) = PTy syn fc op n t
851 mkTyDecl (n, op, t, _) = PTy syn fc op n t
@@ -849,20 +856,22 @@ elabInstance info syn fc cs n ps t expn ds
849 coninsert cs (PPi p@(Imp _ _) n t sc) = PPi p n t (coninsert cs sc)
856 coninsert cs (PPi p@(Imp _ _) n t sc) = PPi p n t (coninsert cs sc)
850 coninsert cs sc = conbind cs sc
857 coninsert cs sc = conbind cs sc
859+ insertDefaults :: IState -> Name ->
852− insertDefaults :: IState -> [(Name, (Name, PDecl))] -> [String] -> [PDecl] -> [PDecl]
860+ [(Name, (Name, PDecl))] -> [String] ->
853− insertDefaults i [] ns ds = ds
862+ insertDefaults i iname [] ns ds = ds
854− insertDefaults i ((n,(dn, clauses)) : defs) ns ds
863+ insertDefaults i iname ((n,(dn, clauses)) : defs) ns ds
855− = insertDefaults i defs ns (insertDef i n dn clauses ns ds)
864+ = insertDefaults i iname defs ns (insertDef i n dn clauses ns iname ds)
857− insertDef i meth def clauses ns decls
866+ insertDef i meth def clauses ns iname decls
858− | null $ filter (clauseFor meth ns) decls
867+ | null $ filter (clauseFor meth iname ns) decls
859 = let newd = expandParamsD i (\n -> meth) [] [def] clauses in
868 = let newd = expandParamsD i (\n -> meth) [] [def] clauses in
860 -- trace (show newd) $
869 -- trace (show newd) $
861 decls ++ [newd]
870 decls ++ [newd]
862 | otherwise = decls
871 | otherwise = decls
864− warnMissing decls ns meth
873+ warnMissing decls ns iname meth
865− | null $ filter (clauseFor meth ns) decls
874+ | null $ filter (clauseFor meth iname ns) decls
866 = iWarn fc $ "method " ++ show meth ++ " not defined"
875 = iWarn fc $ "method " ++ show meth ++ " not defined"
867 | otherwise = return ()
876 | otherwise = return ()
@@ -873,8 +882,9 @@ elabInstance info syn fc cs n ps t expn ds
874 eqRoot x y = nsroot x == nsroot y
883 eqRoot x y = nsroot x == nsroot y
876− clauseFor m ns (PClauses _ _ m' _) = decorate ns m == decorate ns m'
885+ clauseFor m iname ns (PClauses _ _ m' _)
886+ = decorate ns iname m == decorate ns iname m'
877− clauseFor m ns _ = False
887+ clauseFor m iname ns _ = False
879decorateid decorate (PTy s f o n t) = PTy s f o (decorate n) t
889decorateid decorate (PTy s f o n t) = PTy s f o (decorate n) t
880decorateid decorate (PClauses f o n cs)
890decorateid decorate (PClauses f o n cs)
@@ -902,31 +912,40 @@ psolve tm = return ()
902pvars ist (Bind n (PVar t) sc) = (n, delab ist t) : pvars ist sc
912pvars ist (Bind n (PVar t) sc) = (n, delab ist t) : pvars ist sc
903pvars ist _ = []
913pvars ist _ = []
905−-- TODO: Also build a 'binary' version of each declaration for fast reloading
915+data ElabWhat = ETypes | EDefns | EAll
907elabDecl :: ElabInfo -> PDecl -> Idris ()
918elabDecl :: ElabInfo -> PDecl -> Idris ()
908−elabDecl info d = idrisCatch (elabDecl' info d)
919+elabDecl info d = idrisCatch (elabDecl' EAll info d)
909 (\e -> do let msg = show e
920 (\e -> do let msg = show e
910 setErrLine (getErrLine msg)
921 setErrLine (getErrLine msg)
911 iputStrLn msg)
922 iputStrLn msg)
924+elabDecl' _ info (PFix _ _ _)
913−elabDecl' info (PFix _ _ _) = return () -- nothing to elaborate
925+ = return () -- nothing to elaborate
926+elabDecl' _ info (PSyntax _ p)
914−elabDecl' info (PSyntax _ p) = return () -- nothing to elaborate
927+ = return () -- nothing to elaborate
928+elabDecl' what info (PTy s f o n ty)
915−elabDecl' info (PTy s f o n ty) = do iLOG $ "Elaborating type decl " ++ show n ++ show o
930+ = do iLOG $ "Elaborating type decl " ++ show n ++ show o
916− elabType info s f o n ty
931+ elabType info s f o n ty
932+elabDecl' what info (PData s f co d)
917−elabDecl' info (PData s f co d) = do iLOG $ "Elaborating " ++ show (d_name d)
934+ = do iLOG $ "Elaborating " ++ show (d_name d)
918− elabData info s f co d
935+ elabData info s f co d
936+elabDecl' what info d@(PClauses f o n ps)
919−elabDecl' info d@(PClauses f o n ps) = do iLOG $ "Elaborating clause " ++ show n
938+ = do iLOG $ "Elaborating clause " ++ show n
920− i <- get -- get the type options too
939+ i <- get -- get the type options too
921− let o' = case lookupCtxt Nothing n (idris_flags i) of
940+ let o' = case lookupCtxt Nothing n (idris_flags i) of
922− [fs] -> fs
941+ [fs] -> fs
923− [] -> []
942+ [] -> []
924− elabClauses info f (o ++ o') n ps
943+ elabClauses info f (o ++ o') n ps
925−elabDecl' info (PParams f ns ps)
944+elabDecl' what info (PParams f ns ps)
926 = do i <- get
945 = do i <- get
927 iLOG $ "Expanding params block with " ++ show (concatMap declared ps)
946 iLOG $ "Expanding params block with " ++ show (concatMap declared ps)
928 let nblock = pblock i
947 let nblock = pblock i
929− mapM_ (elabDecl' info) nblock
948+ mapM_ (elabDecl' what info) nblock
931 pinfo = let ds = concatMap declared ps
950 pinfo = let ds = concatMap declared ps
932 newps = params info ++ ns
951 newps = params info ++ ns
@@ -936,29 +955,35 @@ elabDecl' info (PParams f ns ps)
936 inblock = newb }
955 inblock = newb }
937 pblock i = map (expandParamsD i id ns (concatMap declared ps)) ps
956 pblock i = map (expandParamsD i id ns (concatMap declared ps)) ps
939−elabDecl' info (PNamespace n ps) = mapM_ (elabDecl' ninfo) ps
958+elabDecl' what info (PNamespace n ps) = mapM_ (elabDecl' what ninfo) ps
941 ninfo = case namespace info of
960 ninfo = case namespace info of
942 Nothing -> info { namespace = Just [n] }
961 Nothing -> info { namespace = Just [n] }
943 Just ns -> info { namespace = Just (n:ns) }
962 Just ns -> info { namespace = Just (n:ns) }
963+elabDecl' what info (PClass s f cs n ps ds)
944−elabDecl' info (PClass s f cs n ps ds) = do iLOG $ "Elaborating class " ++ show n
965+ = do iLOG $ "Elaborating class " ++ show n
945− elabClass info s f cs n ps ds
966+ elabClass info s f cs n ps ds
946−elabDecl' info (PInstance s f cs n ps t expn ds)
967+elabDecl' what info (PInstance s f cs n ps t expn ds)
947 = do iLOG $ "Elaborating instance " ++ show n
969 = do iLOG $ "Elaborating instance " ++ show n
948 elabInstance info s f cs n ps t expn ds
970 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)
950 = do iLOG $ "Elaborating record " ++ show tyn
973 = do iLOG $ "Elaborating record " ++ show tyn
951 elabRecord info s f tyn ty cn cty
974 elabRecord info s f tyn ty cn cty
952−elabDecl' info (PDSL n dsl)
975+elabDecl' _ info (PDSL n dsl)
953 = do i <- get
976 = do i <- get
954 put (i { idris_dsls = addDef n dsl (idris_dsls i) })
977 put (i { idris_dsls = addDef n dsl (idris_dsls i) })
955 addIBC (IBCDSL n)
978 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
958elabCaseBlock info d@(PClauses f o n ps)
983elabCaseBlock info d@(PClauses f o n ps)
959 = do addIBC (IBCDef n)
984 = do addIBC (IBCDef n)
960-- iputStrLn $ "CASE BLOCK: " ++ show (n, d)
985-- iputStrLn $ "CASE BLOCK: " ++ show (n, d)
961− elabDecl' info d
986+ elabDecl' EAll info d
963-- elabDecl' info (PImport i) = loadModule i
988-- elabDecl' info (PImport i) = loadModule i