@@ -5,7 +5,7 @@
5 evaluation/checking inside the proof system, etc. --}
5 evaluation/checking inside the proof system, etc. --}
7module Idris.Core.ProofState(ProofState(..), newProof, envAtFocus, goalAtFocus,
7module Idris.Core.ProofState(ProofState(..), newProof, envAtFocus, goalAtFocus,
8− Tactic(..), Goal(..), processTactic,
8+ Tactic(..), Goal(..), processTactic, now_elaborating, done_elaborating,
9 dropGiven, keepGiven) where
9 dropGiven, keepGiven) where
11import Idris.Core.Typecheck
11import Idris.Core.Typecheck
@@ -39,7 +39,8 @@ data ProofState = PS { thname :: Name,
39 context :: Context,
39 context :: Context,
40 plog :: String,
40 plog :: String,
41 unifylog :: Bool,
41 unifylog :: Bool,
42− done :: Bool
42+ done :: Bool,
43+ while_elaborating :: [FailContext]
45data Goal = GD { premises :: Env,
46data Goal = GD { premises :: Env,
@@ -90,9 +91,9 @@ data Tactic = Attack
90-- Some utilites on proof and tactic states
91-- Some utilites on proof and tactic states
92instance Show ProofState where
93instance Show ProofState where
93− show (PS nm [] _ _ tm _ _ _ _ _ _ _ _ _ _ _ _ _ _)
94+ show (PS nm [] _ _ tm _ _ _ _ _ _ _ _ _ _ _ _ _ _ _)
94 = show nm ++ ": no more goals"
95 = show nm ++ ": no more goals"
95− show (PS nm (h:hs) _ _ tm _ _ _ _ _ _ _ i _ _ ctxt _ _ _)
96+ show (PS nm (h:hs) _ _ tm _ _ _ _ _ _ _ i _ _ ctxt _ _ _ _)
96 = let OK g = goal (Just h) tm
97 = let OK g = goal (Just h) tm
97 wkenv = premises g in
98 wkenv = premises g in
98 "Other goals: " ++ show hs ++ "\n" ++
99 "Other goals: " ++ show hs ++ "\n" ++
@@ -115,9 +116,9 @@ instance Show ProofState where
115 showG ps b = showEnv ps (binderTy b)
116 showG ps b = showEnv ps (binderTy b)
117instance Pretty ProofState OutputAnnotation where
118instance Pretty ProofState OutputAnnotation where
118− pretty (PS nm [] _ _ trm _ _ _ _ _ _ _ _ _ _ _ _ _ _) =
119+ pretty (PS nm [] _ _ trm _ _ _ _ _ _ _ _ _ _ _ _ _ _ _) =
119 pretty nm <+> colon <+> text " no more goals."
120 pretty nm <+> colon <+> text " no more goals."
120− pretty p@(PS nm (h:hs) _ _ tm _ _ _ _ _ _ _ i _ _ ctxt _ _ _) =
121+ pretty p@(PS nm (h:hs) _ _ tm _ _ _ _ _ _ _ i _ _ ctxt _ _ _ _) =
121 let OK g = goal (Just h) tm in
122 let OK g = goal (Just h) tm in
122 let wkEnv = premises g in
123 let wkEnv = premises g in
123 text "Other goals" <+> colon <+> pretty hs <+>
124 text "Other goals" <+> colon <+> pretty hs <+>
@@ -148,12 +149,13 @@ hole _ = False
148holeName i = sMN i "hole"
149holeName i = sMN i "hole"
150qshow :: Fails -> String
151qshow :: Fails -> String
151−qshow fs = show (map (\ (x, y, _, _, t) -> (t, x, y)) fs)
152+qshow fs = show (map (\ (x, y, _, _, _, t) -> (t, x, y)) fs)
153match_unify' :: Context -> Env -> TT Name -> TT Name ->
154match_unify' :: Context -> Env -> TT Name -> TT Name ->
154 StateT TState TC [(Name, TT Name)]
155 StateT TState TC [(Name, TT Name)]
155match_unify' ctxt env topx topy =
156match_unify' ctxt env topx topy =
156 do ps <- get
157 do ps <- get
158+ let while = while_elaborating ps
157 let dont = dontunify ps
159 let dont = dontunify ps
158 let inj = injective ps
160 let inj = injective ps
159 traceWhen (unifylog ps)
161 traceWhen (unifylog ps)
@@ -163,11 +165,11 @@ match_unify' ctxt env topx topy =
164 ++ "\n" ++ show (pterm ps) ++ "\n\n"
166 ++ "\n" ++ show (pterm ps) ++ "\n\n"
166− case match_unify ctxt env topx topy inj (holes ps) of
168+ case match_unify ctxt env topx topy inj (holes ps) while of
167 OK u -> do let (h, ns) = unified ps
169 OK u -> do let (h, ns) = unified ps
168 put (ps { unified = (h, u ++ ns) })
170 put (ps { unified = (h, u ++ ns) })
170− Error e -> do put (ps { problems = (topx, topy, env, e, Match) :
172+ Error e -> do put (ps { problems = (topx, topy, env, e, while, Match) :
171 problems ps })
173 problems ps })
172 return []
174 return []
173-- traceWhen (unifylog ps)
175-- traceWhen (unifylog ps)
@@ -181,24 +183,25 @@ unify' :: Context -> Env -> TT Name -> TT Name ->
181 StateT TState TC [(Name, TT Name)]
183 StateT TState TC [(Name, TT Name)]
182unify' ctxt env topx topy =
184unify' ctxt env topx topy =
183 do ps <- get
185 do ps <- get
186+ let while = while_elaborating ps
184 let dont = dontunify ps
187 let dont = dontunify ps
185 let inj = injective ps
188 let inj = injective ps
186 (u, fails) <- traceWhen (unifylog ps)
189 (u, fails) <- traceWhen (unifylog ps)
187 ("Trying " ++ show (topx, topy) ++
190 ("Trying " ++ show (topx, topy) ++
188 "\nNormalised " ++ show (normalise ctxt env topx,
191 "\nNormalised " ++ show (normalise ctxt env topx,
189− normalise ctxt env topy) ++
192+ normalise ctxt env topy) ++
190 " in " ++ show env ++
193 " in " ++ show env ++
191 "\nHoles: " ++ show (holes ps)
194 "\nHoles: " ++ show (holes ps)
192− ++ "\nInjective: " ++ show (injective ps)
195+ ++ "\nInjective: " ++ show (injective ps)
193 ++ "\n") $
196 ++ "\n") $
194− lift $ unify ctxt env topx topy inj (holes ps)
197+ lift $ unify ctxt env topx topy inj (holes ps) while
195 let notu = filter (\ (n, t) -> case t of
198 let notu = filter (\ (n, t) -> case t of
196 P _ _ _ -> False
199 P _ _ _ -> False
197 _ -> n `elem` dont) u
200 _ -> n `elem` dont) u
198 traceWhen (unifylog ps)
201 traceWhen (unifylog ps)
199 ("Unified " ++ show (topx, topy) ++ " without " ++ show dont ++
202 ("Unified " ++ show (topx, topy) ++ " without " ++ show dont ++
200 "\nSolved: " ++ show u ++ "\nNew problems: " ++ qshow fails
203 "\nSolved: " ++ show u ++ "\nNew problems: " ++ qshow fails
201− ++ "\nNot unified:\n" ++ show (notunified ps)
204+ ++ "\nNot unified:\n" ++ show (notunified ps)
202 ++ "\nCurrent problems:\n" ++ qshow (problems ps)
205 ++ "\nCurrent problems:\n" ++ qshow (problems ps)
203-- ++ show (pterm ps)
206-- ++ show (pterm ps)
204 ++ "\n----------") $
207 ++ "\n----------") $
@@ -221,6 +224,21 @@ unify' ctxt env topx topy =
221 updateInj (_ : us) inj = updateInj us inj
224 updateInj (_ : us) inj = updateInj us inj
222 updateInj [] inj = inj
225 updateInj [] inj = inj
227+now_elaborating :: Monad m => FC -> Name -> Name -> StateT TState m ()
228+now_elaborating fc f arg = do ps <- get
230+ while_elaborating = FailContext fc f arg : while_elaborating ps
233+done_elaborating :: Monad m => Name -> Name -> StateT TState m ()
234+done_elaborating f x = do ps <- get
235+ let while = while_elaborating ps
236+ let while' = dropUntil (\ (FailContext _ f' x') -> f == f' && x == x') while
237+ put ps { while_elaborating = while' }
238+ where dropUntil p [] = []
239+ dropUntil p (x:xs) | p x = xs
240+ | otherwise = dropUntil p xs
224getName :: Monad m => String -> StateT TState m Name
242getName :: Monad m => String -> StateT TState m Name
225getName tag = do ps <- get
243getName tag = do ps <- get
226 let n = nextname ps
244 let n = nextname ps
@@ -245,7 +263,7 @@ newProof n ctxt ty = let h = holeName 0
245 (P Bound h ty')) ty [] (h, []) []
263 (P Bound h ty')) ty [] (h, []) []
246 Nothing [] []
264 Nothing [] []
248− Nothing ctxt "" False False
266+ Nothing ctxt "" False False []
250type TState = ProofState -- [TacticAction])
268type TState = ProofState -- [TacticAction])
251type RunTactic = Context -> Env -> Term -> StateT TState TC Term
269type RunTactic = Context -> Env -> Term -> StateT TState TC Term
@@ -795,36 +813,38 @@ updateNotunified ns nu = up nu where
795 up ((n, t) : nus) = let t' = updateSolved ns t in
813 up ((n, t) : nus) = let t' = updateSolved ns t in
796 ((n, t') : up nus)
814 ((n, t') : up nus)
816+updateProblems :: Context -> [(Name, TT Name)] -> Fails -> [Name] -> [Name]
817+ -> ([(Name, TT Name)], Fails)
798updateProblems ctxt [] ps inj holes = ([], ps)
818updateProblems ctxt [] ps inj holes = ([], ps)
799updateProblems ctxt ns ps inj holes = up ns ps where
819updateProblems ctxt ns ps inj holes = up ns ps where
800 up ns [] = (ns, [])
820 up ns [] = (ns, [])
801− up ns ((x, y, env, err, um) : ps) =
821+ up ns ((x, y, env, err, while, um) : ps) =
802 let x' = updateSolved ns x
822 let x' = updateSolved ns x
803 y' = updateSolved ns y
823 y' = updateSolved ns y
804 err' = updateError ns err
824 err' = updateError ns err
805 env' = updateEnv ns env in
825 env' = updateEnv ns env in
806-- trace ("Updating " ++ show (x',y')) $
826-- trace ("Updating " ++ show (x',y')) $
807− case unify ctxt env' x' y' inj holes of
827+ case unify ctxt env' x' y' inj holes while of
808 OK (v, []) -> -- trace ("Added " ++ show v ++ " from " ++ show (x', y')) $
828 OK (v, []) -> -- trace ("Added " ++ show v ++ " from " ++ show (x', y')) $
809 up (ns ++ v) ps
829 up (ns ++ v) ps
810 e -> -- trace ("Failed " ++ show e) $
830 e -> -- trace ("Failed " ++ show e) $
811 let (ns', ps') = up ns ps in
831 let (ns', ps') = up ns ps in
812− (ns', (x',y',env',err', um) : ps')
832+ (ns', (x',y',env',err', while, um) : ps')
814-- attempt to solve remaining problems with match_unify
834-- attempt to solve remaining problems with match_unify
815matchProblems all ns ctxt ps inj holes = up ns ps where
835matchProblems all ns ctxt ps inj holes = up ns ps where
816 up ns [] = (ns, [])
836 up ns [] = (ns, [])
817− up ns ((x, y, env, err, um) : ps)
837+ up ns ((x, y, env, err, while, um) : ps)
818 | all || um == Match =
838 | all || um == Match =
819 let x' = updateSolved ns x
839 let x' = updateSolved ns x
820 y' = updateSolved ns y
840 y' = updateSolved ns y
821 err' = updateError ns err
841 err' = updateError ns err
822 env' = updateEnv ns env in
842 env' = updateEnv ns env in
823− case match_unify ctxt env' x' y' inj holes of
843+ case match_unify ctxt env' x' y' inj holes while of
824 OK v -> -- trace ("Added " ++ show v ++ " from " ++ show (x', y')) $
844 OK v -> -- trace ("Added " ++ show v ++ " from " ++ show (x', y')) $
825 up (ns ++ v) ps
845 up (ns ++ v) ps
826 _ -> let (ns', ps') = up ns ps in
846 _ -> let (ns', ps') = up ns ps in
827− (ns', (x',y',env',err',um) : ps')
847+ (ns', (x', y', env', err', while, um) : ps')
828 up ns (p : ps) = let (ns', ps') = up ns ps in
848 up ns (p : ps) = let (ns', ps') = up ns ps in
829 (ns', p : ps')
849 (ns', p : ps')