@@ -5,7 +5,7 @@
55 evaluation/checking inside the proof system, etc. --}
66
77module Idris.Core.ProofState(ProofState(..), newProof, envAtFocus, goalAtFocus,
8− Tactic(..), Goal(..), processTactic,
8+ Tactic(..), Goal(..), processTactic, now_elaborating, done_elaborating,
99 dropGiven, keepGiven) where
1010
1111import Idris.Core.Typecheck
@@ -39,7 +39,8 @@ data ProofState = PS { thname :: Name,
3939 context :: Context,
4040 plog :: String,
4141 unifylog :: Bool,
42− done :: Bool
42+ done :: Bool,
43+ while_elaborating :: [FailContext]
4344 }
4445
4546data Goal = GD { premises :: Env,
@@ -90,9 +91,9 @@ data Tactic = Attack
9091-- Some utilites on proof and tactic states
9192
9293instance Show ProofState where
93− show (PS nm [] _ _ tm _ _ _ _ _ _ _ _ _ _ _ _ _ _)
94+ show (PS nm [] _ _ tm _ _ _ _ _ _ _ _ _ _ _ _ _ _ _)
9495 = show nm ++ ": no more goals"
95− show (PS nm (h:hs) _ _ tm _ _ _ _ _ _ _ i _ _ ctxt _ _ _)
96+ show (PS nm (h:hs) _ _ tm _ _ _ _ _ _ _ i _ _ ctxt _ _ _ _)
9697 = let OK g = goal (Just h) tm
9798 wkenv = premises g in
9899 "Other goals: " ++ show hs ++ "\n" ++
@@ -115,9 +116,9 @@ instance Show ProofState where
115116 showG ps b = showEnv ps (binderTy b)
116117
117118instance Pretty ProofState OutputAnnotation where
118− pretty (PS nm [] _ _ trm _ _ _ _ _ _ _ _ _ _ _ _ _ _) =
119+ pretty (PS nm [] _ _ trm _ _ _ _ _ _ _ _ _ _ _ _ _ _ _) =
119120 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 _ _ _ _) =
121122 let OK g = goal (Just h) tm in
122123 let wkEnv = premises g in
123124 text "Other goals" <+> colon <+> pretty hs <+>
@@ -148,12 +149,13 @@ hole _ = False
148149holeName i = sMN i "hole"
149150
150151qshow :: 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)
152153
153154match_unify' :: Context -> Env -> TT Name -> TT Name ->
154155 StateT TState TC [(Name, TT Name)]
155156match_unify' ctxt env topx topy =
156157 do ps <- get
158+ let while = while_elaborating ps
157159 let dont = dontunify ps
158160 let inj = injective ps
159161 traceWhen (unifylog ps)
@@ -163,11 +165,11 @@ match_unify' ctxt env topx topy =
163165 ++ "\n"
164166 ++ "\n" ++ show (pterm ps) ++ "\n\n"
165167 ) $
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
167169 OK u -> do let (h, ns) = unified ps
168170 put (ps { unified = (h, u ++ ns) })
169171 return u
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) :
171173 problems ps })
172174 return []
173175-- traceWhen (unifylog ps)
@@ -181,24 +183,25 @@ unify' :: Context -> Env -> TT Name -> TT Name ->
181183 StateT TState TC [(Name, TT Name)]
182184unify' ctxt env topx topy =
183185 do ps <- get
186+ let while = while_elaborating ps
184187 let dont = dontunify ps
185188 let inj = injective ps
186189 (u, fails) <- traceWhen (unifylog ps)
187190 ("Trying " ++ show (topx, topy) ++
188191 "\nNormalised " ++ show (normalise ctxt env topx,
189− normalise ctxt env topy) ++
192+ normalise ctxt env topy) ++
190193 " in " ++ show env ++
191194 "\nHoles: " ++ show (holes ps)
192− ++ "\nInjective: " ++ show (injective ps)
195+ ++ "\nInjective: " ++ show (injective ps)
193196 ++ "\n") $
194− lift $ unify ctxt env topx topy inj (holes ps)
197+ lift $ unify ctxt env topx topy inj (holes ps) while
195198 let notu = filter (\ (n, t) -> case t of
196199 P _ _ _ -> False
197200 _ -> n `elem` dont) u
198201 traceWhen (unifylog ps)
199202 ("Unified " ++ show (topx, topy) ++ " without " ++ show dont ++
200203 "\nSolved: " ++ show u ++ "\nNew problems: " ++ qshow fails
201− ++ "\nNot unified:\n" ++ show (notunified ps)
204+ ++ "\nNot unified:\n" ++ show (notunified ps)
202205 ++ "\nCurrent problems:\n" ++ qshow (problems ps)
203206-- ++ show (pterm ps)
204207 ++ "\n----------") $
@@ -221,6 +224,21 @@ unify' ctxt env topx topy =
221224 updateInj (_ : us) inj = updateInj us inj
222225 updateInj [] inj = inj
223226
227+now_elaborating :: Monad m => FC -> Name -> Name -> StateT TState m ()
228+now_elaborating fc f arg = do ps <- get
229+ put ps {
230+ while_elaborating = FailContext fc f arg : while_elaborating ps
231+ }
232+
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
241+
224242getName :: Monad m => String -> StateT TState m Name
225243getName tag = do ps <- get
226244 let n = nextname ps
@@ -245,7 +263,7 @@ newProof n ctxt ty = let h = holeName 0
245263 (P Bound h ty')) ty [] (h, []) []
246264 Nothing [] []
247265 [] []
248− Nothing ctxt "" False False
266+ Nothing ctxt "" False False []
249267
250268type TState = ProofState -- [TacticAction])
251269type RunTactic = Context -> Env -> Term -> StateT TState TC Term
@@ -795,36 +813,38 @@ updateNotunified ns nu = up nu where
795813 up ((n, t) : nus) = let t' = updateSolved ns t in
796814 ((n, t') : up nus)
797815
816+updateProblems :: Context -> [(Name, TT Name)] -> Fails -> [Name] -> [Name]
817+ -> ([(Name, TT Name)], Fails)
798818updateProblems ctxt [] ps inj holes = ([], ps)
799819updateProblems ctxt ns ps inj holes = up ns ps where
800820 up ns [] = (ns, [])
801− up ns ((x, y, env, err, um) : ps) =
821+ up ns ((x, y, env, err, while, um) : ps) =
802822 let x' = updateSolved ns x
803823 y' = updateSolved ns y
804824 err' = updateError ns err
805825 env' = updateEnv ns env in
806826-- 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
808828 OK (v, []) -> -- trace ("Added " ++ show v ++ " from " ++ show (x', y')) $
809829 up (ns ++ v) ps
810830 e -> -- trace ("Failed " ++ show e) $
811831 let (ns', ps') = up ns ps in
812− (ns', (x',y',env',err', um) : ps')
832+ (ns', (x',y',env',err', while, um) : ps')
813833
814834-- attempt to solve remaining problems with match_unify
815835matchProblems all ns ctxt ps inj holes = up ns ps where
816836 up ns [] = (ns, [])
817− up ns ((x, y, env, err, um) : ps)
837+ up ns ((x, y, env, err, while, um) : ps)
818838 | all || um == Match =
819839 let x' = updateSolved ns x
820840 y' = updateSolved ns y
821841 err' = updateError ns err
822842 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
824844 OK v -> -- trace ("Added " ++ show v ++ " from " ++ show (x', y')) $
825845 up (ns ++ v) ps
826846 _ -> let (ns', ps') = up ns ps in
827− (ns', (x',y',env',err',um) : ps')
847+ (ns', (x', y', env', err', while, um) : ps')
828848 up ns (p : ps) = let (ns', ps') = up ns ps in
829849 (ns', p : ps')
830850