@@ -871,6 +871,9 @@ updateError ns (CantUnify b (l,lp) (r,rp) e xs sc)
871 (updateSolvedTerm ns r, fmap (updateProv ns) rp) (updateError ns e) xs sc
871 (updateSolvedTerm ns r, fmap (updateProv ns) rp) (updateError ns e) xs sc
872updateError ns e = e
872updateError ns e = e
875+updateRes ns ((x, t) : ts) = (x, updateSolvedTerm ns t) : updateRes ns ts
874solveInProblems x val [] = []
877solveInProblems x val [] = []
875solveInProblems x val ((l, r, env, err) : ps)
878solveInProblems x val ((l, r, env, err) : ps)
876 = ((psubst x val l, psubst x val r,
879 = ((psubst x val l, psubst x val r,
@@ -898,7 +901,15 @@ getProvenance _ = (Nothing, Nothing)
898updateProblems :: ProofState -> [(Name, TT Name)] -> Fails
901updateProblems :: ProofState -> [(Name, TT Name)] -> Fails
899 -> ([(Name, TT Name)], Fails)
902 -> ([(Name, TT Name)], Fails)
900-- updateProblems ctxt [] ps inj holes = ([], ps)
903-- updateProblems ctxt [] ps inj holes = ([], ps)
901−updateProblems ps updates probs = up updates probs where
904+updateProblems ps updates probs = rec 10 updates probs
906+ -- keep trying if we make progress, but not too many times...
907+ rec 0 us fs = (us, fs)
908+ rec n us fs = case up us [] fs of
910+ res@(us', _) | length us' == length us -> res
911+ (us', fs') -> rec (n - 1) us' fs'
902 hs = holes ps
913 hs = holes ps
903 inj = injective ps
914 inj = injective ps
904 ctxt = context ps
915 ctxt = context ps
@@ -906,8 +917,8 @@ updateProblems ps updates probs = up updates probs where
906 usupp = map fst (notunified ps)
917 usupp = map fst (notunified ps)
907 dont = dontunify ps
918 dont = dontunify ps
909− up ns [] = (ns, [])
920+ up ns acc [] = (ns, map (updateNs ns) (reverse acc))
910− up ns (prob@(x, y, ready, env, err, while, um) : ps) =
921+ up ns acc (prob@(x, y, ready, env, err, while, um) : ps) =
911 let (x', newx) = updateSolvedTerm' ns x
922 let (x', newx) = updateSolvedTerm' ns x
912 (y', newy) = updateSolvedTerm' ns y
923 (y', newy) = updateSolvedTerm' ns y
913 (lp, rp) = getProvenance err
924 (lp, rp) = getProvenance err
@@ -918,13 +929,17 @@ updateProblems ps updates probs = up updates probs where
918 case unify ctxt env' (x', lp) (y', rp) inj hs usupp while of
929 case unify ctxt env' (x', lp) (y', rp) inj hs usupp while of
919 OK (v, []) -> traceWhen ulog ("DID " ++ show (x',y',ready,v,dont)) $
930 OK (v, []) -> traceWhen ulog ("DID " ++ show (x',y',ready,v,dont)) $
920 let v' = filter (\(n, _) -> n `notElem` dont) v in
931 let v' = filter (\(n, _) -> n `notElem` dont) v in
921− up (ns ++ v') ps
932+ up (ns ++ v') acc ps
922 e -> -- trace ("FAILED " ++ show (x',y',ready,e)) $
933 e -> -- trace ("FAILED " ++ show (x',y',ready,e)) $
923− let (ns', ps') = up ns ps in
924− (ns', (x',y', False, env',err', while, um) : ps')
934+ up ns ((x',y',False,env',err',while,um) : acc) ps
925 else -- trace ("SKIPPING " ++ show (x,y,ready)) $
935 else -- trace ("SKIPPING " ++ show (x,y,ready)) $
926− let (ns', ps') = up ns ps in
927− (ns', (x',y', False, env',err', while, um) : ps')
936+ up ns ((x',y', False, env',err', while, um) : acc) ps
938+ updateNs ns (x, y, t, env, err, fc, fa)
939+ = let (x', newx) = updateSolvedTerm' ns x
940+ (y', newy) = updateSolvedTerm' ns y in
941+ (x', y', newx || newy,
942+ updateEnv ns env, updateError ns err, fc, fa)
929-- attempt to solve remaining problems with match_unify
944-- attempt to solve remaining problems with match_unify
930matchProblems :: Bool -> ProofState -> [(Name, TT Name)] -> Fails
945matchProblems :: Bool -> ProofState -> [(Name, TT Name)] -> Fails
@@ -995,7 +1010,9 @@ processTactic UnifyProblems ps
995 previous = Just ps, plog = "",
1010 previous = Just ps, plog = "",
996 notunified = updateNotunified ns' (notunified ps),
1011 notunified = updateNotunified ns' (notunified ps),
997 recents = recents ps ++ map fst ns',
1012 recents = recents ps ++ map fst ns',
1013+ dotted = filter (notIn ns') (dotted ps),
998 holes = holes ps \\ (map fst ns') }, plog ps)
1014 holes = holes ps \\ (map fst ns') }, plog ps)
1015+ where notIn ns (h, _) = h `notElem` map fst ns
999processTactic (MatchProblems all) ps
1016processTactic (MatchProblems all) ps
1000 = do let (ns', probs') = matchProblems all ps [] (problems ps)
1017 = do let (ns', probs') = matchProblems all ps [] (problems ps)
1001 (ns'', probs'') = matchProblems all ps ns' probs'
1018 (ns'', probs'') = matchProblems all ps ns' probs'
@@ -1022,14 +1039,16 @@ processTactic t ps
1022 let pterm'' = updateSolved ns' (pterm ps')
1039 let pterm'' = updateSolved ns' (pterm ps')
1023 traceWhen (unifylog ps)
1040 traceWhen (unifylog ps)
1024 ("Updated problems after solve " ++ qshow probs' ++ "\n" ++
1041 ("Updated problems after solve " ++ qshow probs' ++ "\n" ++
1025− "(Toplevel) Dropping holes: " ++ show (map fst ns')) $
1042+ "(Toplevel) Dropping holes: " ++ show (map fst ns') ++ "\n" ++
1043+ "Holes were: " ++ show (holes ps')) $
1026 return (ps' { pterm = pterm'',
1044 return (ps' { pterm = pterm'',
1027 solved = Nothing,
1045 solved = Nothing,
1028 problems = probs',
1046 problems = probs',
1029 notunified = updateNotunified ns' (notunified ps'),
1047 notunified = updateNotunified ns' (notunified ps'),
1030 previous = Just ps, plog = "",
1048 previous = Just ps, plog = "",
1031 recents = recents ps' ++ map fst ns',
1049 recents = recents ps' ++ map fst ns',
1032− holes = holes ps' \\ (map fst ns')}, plog ps')
1050+ holes = holes ps' \\ (map fst ns')
1034process :: Tactic -> Name -> StateT TState TC ()
1053process :: Tactic -> Name -> StateT TState TC ()
1035process EndUnify _
1054process EndUnify _