@@ -144,7 +144,7 @@ instance Pretty ProofState OutputAnnotation where
144holeName i = sMN i "hole"
144holeName i = sMN i "hole"
146qshow :: Fails -> String
146qshow :: Fails -> String
147−qshow fs = show (map (\ (x, y, _, _, _, t) -> (t, x, y)) fs)
147+qshow fs = show (map (\ (x, y, hs, _, _, _, t) -> (t, x, y, hs)) fs)
149match_unify' :: Context -> Env -> TT Name -> TT Name ->
149match_unify' :: Context -> Env -> TT Name -> TT Name ->
150 StateT TState TC [(Name, TT Name)]
150 StateT TState TC [(Name, TT Name)]
@@ -168,7 +168,8 @@ match_unify' ctxt env topx topy =
169 Error e -> traceWhen (unifylog ps)
169 Error e -> traceWhen (unifylog ps)
170 ("No match " ++ show e) $
170 ("No match " ++ show e) $
171− do put (ps { problems = (topx, topy, env, e, while, Match) :
171+ do put (ps { problems = (topx, topy, True,
172+ env, e, while, Match) :
172 problems ps })
173 problems ps })
173 return []
174 return []
174-- traceWhen (unifylog ps)
175-- traceWhen (unifylog ps)
@@ -186,7 +187,7 @@ mergeSolutions env ns = merge [] ns
186 | Just t' <- lookup n ns
187 | Just t' <- lookup n ns
187 = do ps <- get
188 = do ps <- get
188 let probs = problems ps
189 let probs = problems ps
189− put (ps { problems = probs ++ [(t,t',env,Msg "New problem",
190+ put (ps { problems = probs ++ [(t,t',True,env,Msg "New problem",
190 [], Unify)] })
191 [], Unify)] })
191 merge acc ns
192 merge acc ns
192 | otherwise = merge ((n, t): acc) ns
193 | otherwise = merge ((n, t): acc) ns
@@ -225,12 +226,8 @@ unify' ctxt env topx topy =
225 -- problem for each.
226 -- problem for each.
226 uns <- mergeSolutions env (u' ++ ns)
227 uns <- mergeSolutions env (u' ++ ns)
227 ps <- get
228 ps <- get
228− let (ns', probs') = updateProblems (context ps) uns
229+ let (ns', probs') = updateProblems ps uns (fails ++ problems ps)
229− (fails ++ problems ps)
232− (map fst (notunified ps))
233− let (notu', probs_notu) = mergeNotunified env (notu ++ notunified ps)
230+ let (notu', probs_notu) = mergeNotunified env (holes ps) (notu ++ notunified ps)
234 traceWhen (unifylog ps)
231 traceWhen (unifylog ps)
235 ("Now solved: " ++ show ns' ++
232 ("Now solved: " ++ show ns' ++
236 "\nNow problems: " ++ qshow (probs' ++ probs_notu)) $
233 "\nNow problems: " ++ qshow (probs' ++ probs_notu)) $
@@ -780,7 +777,8 @@ keepGiven du (u : us) hs = keepGiven du us hs
781updateEnv [] e = e
778updateEnv [] e = e
782updateEnv ns [] = []
779updateEnv ns [] = []
780+updateEnv ns ((n, b) : env)
783−updateEnv ns ((n, b) : env) = (n, fmap (updateSolvedTerm ns) b) : updateEnv ns env
781+ = (n, fmap (updateSolvedTerm ns) b) : updateEnv ns env
785updateError [] err = err
783updateError [] err = err
786updateError ns (At f e) = At f (updateError ns e)
784updateError ns (At f e) = At f (updateError ns e)
@@ -796,13 +794,13 @@ solveInProblems x val ((l, r, env, err) : ps)
796 = ((psubst x val l, psubst x val r,
794 = ((psubst x val l, psubst x val r,
797 updateEnv [(x, val)] env, err) : solveInProblems x val ps)
795 updateEnv [(x, val)] env, err) : solveInProblems x val ps)
799−mergeNotunified :: Env -> [(Name, Term)] -> ([(Name, Term)], Fails)
797+mergeNotunified :: Env -> [Name] -> [(Name, Term)] -> ([(Name, Term)], Fails)
800−mergeNotunified env ns = mnu ns [] [] where
798+mergeNotunified env holes ns = mnu ns [] [] where
801 mnu [] ns_acc ps_acc = (reverse ns_acc, reverse ps_acc)
799 mnu [] ns_acc ps_acc = (reverse ns_acc, reverse ps_acc)
802 mnu ((n, t):ns) ns_acc ps_acc
800 mnu ((n, t):ns) ns_acc ps_acc
803 | Just t' <- lookup n ns, t /= t'
801 | Just t' <- lookup n ns, t /= t'
804 = mnu ns ((n,t') : ns_acc)
802 = mnu ns ((n,t') : ns_acc)
805− ((t,t',env,CantUnify True t t' (Msg "") [] 0, [],Match) : ps_acc)
803+ ((t,t',True, env,CantUnify True t t' (Msg "") [] 0, [],Match) : ps_acc)
806 | otherwise = mnu ns ((n,t) : ns_acc) ps_acc
804 | otherwise = mnu ns ((n,t) : ns_acc) ps_acc
808updateNotunified [] nu = nu
806updateNotunified [] nu = nu
@@ -811,42 +809,53 @@ updateNotunified ns nu = up nu where
811 up ((n, t) : nus) = let t' = updateSolvedTerm ns t in
809 up ((n, t) : nus) = let t' = updateSolvedTerm ns t in
812 ((n, t') : up nus)
810 ((n, t') : up nus)
814−-- FIXME: Why not just pass the whole proof state?
815−-- Issue #1716 on the issue tracker.
816−-- https://github.com/idris-lang/Idris-dev/issues/1716
817−updateProblems :: Context -> [(Name, TT Name)] -> Fails -> [Name] -> [Name] -> [Name]
812+updateProblems :: ProofState -> [(Name, TT Name)] -> Fails
818− -> ([(Name, TT Name)], Fails)
813+ -> ([(Name, TT Name)], Fails)
819-- updateProblems ctxt [] ps inj holes = ([], ps)
814-- updateProblems ctxt [] ps inj holes = ([], ps)
820−updateProblems ctxt ns ps inj holes usupp = up ns ps where
815+updateProblems ps updates probs = up updates probs where
819+ usupp = map fst (notunified ps)
821 up ns [] = (ns, [])
821 up ns [] = (ns, [])
822− up ns ((x, y, env, err, while, um) : ps) =
822+ up ns (prob@(x, y, ready, env, err, while, um) : ps) =
823− let x' = updateSolvedTerm ns x
823+ let (x', newx) = updateSolvedTerm' ns x
824− y' = updateSolvedTerm ns y
824+ (y', newy) = updateSolvedTerm' ns y
825 err' = updateError ns err
825 err' = updateError ns err
826 env' = updateEnv ns env in
826 env' = updateEnv ns env in
827−-- trace ("Updating " ++ show (x',y')) $
827+ if newx || newy || ready ||
828+ any (\n -> n `elem` inj) (refsIn x ++ refsIn y) then
828− case unify ctxt env' x' y' inj holes usupp while of
829+ case unify ctxt env' x' y' inj hs usupp while of
829− OK (v, []) -> -- trace ("Added " ++ show v ++ " from " ++ show (x', y')) $
830+ OK (v, []) -> -- trace ("DID " ++ show (x',y',ready,v)) $
830 up (ns ++ v) ps
831 up (ns ++ v) ps
831− e -> -- trace ("Failed " ++ show e) $
832+ e -> -- trace ("FAILED " ++ show (x',y',ready,e)) $
833+ let (ns', ps') = up ns ps in
834+ (ns', (x',y', False, env',err', while, um) : ps')
835+ else -- trace ("SKIPPING " ++ show (x,y,ready)) $
832− let (ns', ps') = up ns ps in
836+ let (ns', ps') = up ns ps in
833− (ns', (x',y',env',err', while, um) : ps')
837+ (ns', (x',y', False, env',err', while, um) : ps')
835-- attempt to solve remaining problems with match_unify
839-- attempt to solve remaining problems with match_unify
836−-- matchProblems :: Bool -> Elab' aux ()
840+matchProblems :: Bool -> ProofState -> [(Name, TT Name)] -> Fails
841+ -> ([(Name, TT Name)], Fails)
837−matchProblems all ns ctxt ps inj holes = up ns ps where
842+matchProblems all ps updates probs = up updates probs where
838 up ns [] = (ns, [])
847 up ns [] = (ns, [])
839− up ns ((x, y, env, err, while, um) : ps)
848+ up ns ((x, y, ready, env, err, while, um) : ps)
840 | all || um == Match =
849 | all || um == Match =
841 let x' = updateSolvedTerm ns x
850 let x' = updateSolvedTerm ns x
842 y' = updateSolvedTerm ns y
851 y' = updateSolvedTerm ns y
843 err' = updateError ns err
852 err' = updateError ns err
844 env' = updateEnv ns env in
853 env' = updateEnv ns env in
845− case match_unify ctxt env' x' y' inj holes while of
854+ case match_unify ctxt env' x' y' inj hs while of
846 OK v -> -- trace ("Added " ++ show v ++ " from " ++ show (x', y')) $
855 OK v -> -- trace ("Added " ++ show v ++ " from " ++ show (x', y')) $
847 up (ns ++ v) ps
856 up (ns ++ v) ps
848 _ -> let (ns', ps') = up ns ps in
857 _ -> let (ns', ps') = up ns ps in
849− (ns', (x', y', env', err', while, um) : ps')
858+ (ns', (x', y', True, env', err', while, um) : ps')
850 up ns (p : ps) = let (ns', ps') = up ns ps in
859 up ns (p : ps) = let (ns', ps') = up ns ps in
851 (ns', p : ps')
860 (ns', p : ps')
@@ -865,9 +874,7 @@ processTactic EndUnify ps
865 = let (h, ns_in) = unified ps
874 = let (h, ns_in) = unified ps
866 ns = dropGiven (dontunify ps) ns_in (holes ps)
875 ns = dropGiven (dontunify ps) ns_in (holes ps)
867 ns' = map (\ (n, t) -> (n, updateSolvedTerm ns t)) ns
876 ns' = map (\ (n, t) -> (n, updateSolvedTerm ns t)) ns
868− (ns'', probs') = updateProblems (context ps) ns' (problems ps)
877+ (ns'', probs') = updateProblems ps ns' (problems ps)
869− (injective ps) (holes ps)
870− (map fst (notunified ps))
871 tm' = updateSolved ns'' (pterm ps) in
878 tm' = updateSolved ns'' (pterm ps) in
872 traceWhen (unifylog ps) ("Dropping holes: " ++ show (map fst ns'')) $
879 traceWhen (unifylog ps) ("Dropping holes: " ++ show (map fst ns'')) $
873 return (ps { pterm = tm',
880 return (ps { pterm = tm',
@@ -890,11 +897,7 @@ processTactic (ComputeLet n) ps
890 computeLet (context ps) n
897 computeLet (context ps) n
891 (getProofTerm (pterm ps)) }, "")
898 (getProofTerm (pterm ps)) }, "")
892processTactic UnifyProblems ps
899processTactic UnifyProblems ps
893− = let (ns', probs') = updateProblems (context ps) []
900+ = let (ns', probs') = updateProblems ps [] (problems ps)
897− (map fst (notunified ps))
898 pterm' = updateSolved ns' (pterm ps) in
901 pterm' = updateSolved ns' (pterm ps) in
899 traceWhen (unifylog ps) ("Dropping holes: " ++ show (map fst ns')) $
902 traceWhen (unifylog ps) ("Dropping holes: " ++ show (map fst ns')) $
900 return (ps { pterm = pterm', solved = Nothing, problems = probs',
903 return (ps { pterm = pterm', solved = Nothing, problems = probs',
@@ -903,14 +906,8 @@ processTactic UnifyProblems ps
903 recents = recents ps ++ map fst ns',
906 recents = recents ps ++ map fst ns',
904 holes = holes ps \\ (map fst ns') }, plog ps)
907 holes = holes ps \\ (map fst ns') }, plog ps)
905processTactic (MatchProblems all) ps
908processTactic (MatchProblems all) ps
906− = let (ns', probs') = matchProblems all [] (context ps)
909+ = let (ns', probs') = matchProblems all ps [] (problems ps)
910− (ns'', probs'') = matchProblems all ns' (context ps)
910+ (ns'', probs'') = matchProblems all ps ns' probs'
914 pterm' = updateSolved ns'' (pterm ps) in
911 pterm' = updateSolved ns'' (pterm ps) in
915 traceWhen (unifylog ps) ("Dropping holes: " ++ show (map fst ns'')) $
912 traceWhen (unifylog ps) ("Dropping holes: " ++ show (map fst ns'')) $
916 return (ps { pterm = pterm', solved = Nothing, problems = probs'',
913 return (ps { pterm = pterm', solved = Nothing, problems = probs'',
@@ -926,11 +923,7 @@ processTactic t ps
926 = case solved ps' of
923 = case solved ps' of
927 Just s -> traceWhen (unifylog ps')
924 Just s -> traceWhen (unifylog ps')
928 ("SOLVED " ++ show s) $
925 ("SOLVED " ++ show s) $
929− updateProblems (context ps')
930− [s] (problems ps')
926+ updateProblems ps [s] (problems ps')
933− (map fst (notunified ps))
934 _ -> ([], problems ps')
927 _ -> ([], problems ps')
935 -- rechecking problems may find more solutions, so
928 -- rechecking problems may find more solutions, so
936 -- apply them here
929 -- apply them here