@@ -144,7 +144,7 @@ instance Pretty ProofState OutputAnnotation where
144144holeName i = sMN i "hole"
145145
146146qshow :: 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)
148148
149149match_unify' :: Context -> Env -> TT Name -> TT Name ->
150150 StateT TState TC [(Name, TT Name)]
@@ -168,7 +168,8 @@ match_unify' ctxt env topx topy =
168168 return u
169169 Error e -> traceWhen (unifylog ps)
170170 ("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) :
172173 problems ps })
173174 return []
174175-- traceWhen (unifylog ps)
@@ -186,7 +187,7 @@ mergeSolutions env ns = merge [] ns
186187 | Just t' <- lookup n ns
187188 = do ps <- get
188189 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",
190191 [], Unify)] })
191192 merge acc ns
192193 | otherwise = merge ((n, t): acc) ns
@@ -225,12 +226,8 @@ unify' ctxt env topx topy =
225226 -- problem for each.
226227 uns <- mergeSolutions env (u' ++ ns)
227228 ps <- get
228− let (ns', probs') = updateProblems (context ps) uns
229− (fails ++ problems ps)
230− (injective ps)
231− (holes ps)
232− (map fst (notunified ps))
233− let (notu', probs_notu) = mergeNotunified env (notu ++ notunified ps)
229+ let (ns', probs') = updateProblems ps uns (fails ++ problems ps)
230+ let (notu', probs_notu) = mergeNotunified env (holes ps) (notu ++ notunified ps)
234231 traceWhen (unifylog ps)
235232 ("Now solved: " ++ show ns' ++
236233 "\nNow problems: " ++ qshow (probs' ++ probs_notu)) $
@@ -780,7 +777,8 @@ keepGiven du (u : us) hs = keepGiven du us hs
780777
781778updateEnv [] e = e
782779updateEnv ns [] = []
783−updateEnv ns ((n, b) : env) = (n, fmap (updateSolvedTerm ns) b) : updateEnv ns env
780+updateEnv ns ((n, b) : env)
781+ = (n, fmap (updateSolvedTerm ns) b) : updateEnv ns env
784782
785783updateError [] err = err
786784updateError ns (At f e) = At f (updateError ns e)
@@ -796,13 +794,13 @@ solveInProblems x val ((l, r, env, err) : ps)
796794 = ((psubst x val l, psubst x val r,
797795 updateEnv [(x, val)] env, err) : solveInProblems x val ps)
798796
799−mergeNotunified :: Env -> [(Name, Term)] -> ([(Name, Term)], Fails)
800−mergeNotunified env ns = mnu ns [] [] where
797+mergeNotunified :: Env -> [Name] -> [(Name, Term)] -> ([(Name, Term)], Fails)
798+mergeNotunified env holes ns = mnu ns [] [] where
801799 mnu [] ns_acc ps_acc = (reverse ns_acc, reverse ps_acc)
802800 mnu ((n, t):ns) ns_acc ps_acc
803801 | Just t' <- lookup n ns, t /= t'
804802 = 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)
806804 | otherwise = mnu ns ((n,t) : ns_acc) ps_acc
807805
808806updateNotunified [] nu = nu
@@ -811,42 +809,53 @@ updateNotunified ns nu = up nu where
811809 up ((n, t) : nus) = let t' = updateSolvedTerm ns t in
812810 ((n, t') : up nus)
813811
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]
818− -> ([(Name, TT Name)], Fails)
812+updateProblems :: ProofState -> [(Name, TT Name)] -> Fails
813+ -> ([(Name, TT Name)], Fails)
819814-- 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
816+ hs = holes ps
817+ inj = injective ps
818+ ctxt = context ps
819+ usupp = map fst (notunified ps)
820+
821821 up ns [] = (ns, [])
822− up ns ((x, y, env, err, while, um) : ps) =
823− let x' = updateSolvedTerm ns x
824− y' = updateSolvedTerm ns y
822+ up ns (prob@(x, y, ready, env, err, while, um) : ps) =
823+ let (x', newx) = updateSolvedTerm' ns x
824+ (y', newy) = updateSolvedTerm' ns y
825825 err' = updateError ns err
826826 env' = updateEnv ns env in
827−-- trace ("Updating " ++ show (x',y')) $
828− case unify ctxt env' x' y' inj holes usupp while of
829− OK (v, []) -> -- trace ("Added " ++ show v ++ " from " ++ show (x', y')) $
827+ if newx || newy || ready ||
828+ any (\n -> n `elem` inj) (refsIn x ++ refsIn y) then
829+ case unify ctxt env' x' y' inj hs usupp while of
830+ OK (v, []) -> -- trace ("DID " ++ show (x',y',ready,v)) $
830831 up (ns ++ v) ps
831− e -> -- trace ("Failed " ++ show e) $
832− let (ns', ps') = up ns ps in
833− (ns', (x',y',env',err', while, um) : ps')
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)) $
836+ let (ns', ps') = up ns ps in
837+ (ns', (x',y', False, env',err', while, um) : ps')
834838
835839-- attempt to solve remaining problems with match_unify
836−-- matchProblems :: Bool -> Elab' aux ()
837−matchProblems all ns ctxt ps inj holes = up ns ps where
840+matchProblems :: Bool -> ProofState -> [(Name, TT Name)] -> Fails
841+ -> ([(Name, TT Name)], Fails)
842+matchProblems all ps updates probs = up updates probs where
843+ hs = holes ps
844+ inj = injective ps
845+ ctxt = context ps
846+
838847 up ns [] = (ns, [])
839− up ns ((x, y, env, err, while, um) : ps)
848+ up ns ((x, y, ready, env, err, while, um) : ps)
840849 | all || um == Match =
841850 let x' = updateSolvedTerm ns x
842851 y' = updateSolvedTerm ns y
843852 err' = updateError ns err
844853 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
846855 OK v -> -- trace ("Added " ++ show v ++ " from " ++ show (x', y')) $
847856 up (ns ++ v) ps
848857 _ -> 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')
850859 up ns (p : ps) = let (ns', ps') = up ns ps in
851860 (ns', p : ps')
852861
@@ -865,9 +874,7 @@ processTactic EndUnify ps
865874 = let (h, ns_in) = unified ps
866875 ns = dropGiven (dontunify ps) ns_in (holes ps)
867876 ns' = map (\ (n, t) -> (n, updateSolvedTerm ns t)) ns
868− (ns'', probs') = updateProblems (context ps) ns' (problems ps)
869− (injective ps) (holes ps)
870− (map fst (notunified ps))
877+ (ns'', probs') = updateProblems ps ns' (problems ps)
871878 tm' = updateSolved ns'' (pterm ps) in
872879 traceWhen (unifylog ps) ("Dropping holes: " ++ show (map fst ns'')) $
873880 return (ps { pterm = tm',
@@ -890,11 +897,7 @@ processTactic (ComputeLet n) ps
890897 computeLet (context ps) n
891898 (getProofTerm (pterm ps)) }, "")
892899processTactic UnifyProblems ps
893− = let (ns', probs') = updateProblems (context ps) []
894− (problems ps)
895− (injective ps)
896− (holes ps)
897− (map fst (notunified ps))
900+ = let (ns', probs') = updateProblems ps [] (problems ps)
898901 pterm' = updateSolved ns' (pterm ps) in
899902 traceWhen (unifylog ps) ("Dropping holes: " ++ show (map fst ns')) $
900903 return (ps { pterm = pterm', solved = Nothing, problems = probs',
@@ -903,14 +906,8 @@ processTactic UnifyProblems ps
903906 recents = recents ps ++ map fst ns',
904907 holes = holes ps \\ (map fst ns') }, plog ps)
905908processTactic (MatchProblems all) ps
906− = let (ns', probs') = matchProblems all [] (context ps)
907− (problems ps)
908− (injective ps)
909− (holes ps)
910− (ns'', probs'') = matchProblems all ns' (context ps)
911− probs'
912− (injective ps)
913− (holes ps)
909+ = let (ns', probs') = matchProblems all ps [] (problems ps)
910+ (ns'', probs'') = matchProblems all ps ns' probs'
914911 pterm' = updateSolved ns'' (pterm ps) in
915912 traceWhen (unifylog ps) ("Dropping holes: " ++ show (map fst ns'')) $
916913 return (ps { pterm = pterm', solved = Nothing, problems = probs'',
@@ -926,11 +923,7 @@ processTactic t ps
926923 = case solved ps' of
927924 Just s -> traceWhen (unifylog ps')
928925 ("SOLVED " ++ show s) $
929− updateProblems (context ps')
930− [s] (problems ps')
931− (injective ps')
932− (holes ps')
933− (map fst (notunified ps))
926+ updateProblems ps [s] (problems ps')
934927 _ -> ([], problems ps')
935928 -- rechecking problems may find more solutions, so
936929 -- apply them here