@@ -36,11 +36,13 @@ data ProofState = PS { thname :: Name,
36 injective :: [Name],
36 injective :: [Name],
37 deferred :: [Name], -- names we'll need to define
37 deferred :: [Name], -- names we'll need to define
38 instances :: [Name], -- instance arguments (for type classes)
38 instances :: [Name], -- instance arguments (for type classes)
39+ autos :: [(Name, [Name])], -- unsolved 'auto' implicits with their holes
39 previous :: Maybe ProofState, -- for undo
40 previous :: Maybe ProofState, -- for undo
40 context :: Context,
41 context :: Context,
41 plog :: String,
42 plog :: String,
42 unifylog :: Bool,
43 unifylog :: Bool,
43 done :: Bool,
44 done :: Bool,
44 while_elaborating :: [FailContext]
46 while_elaborating :: [FailContext]
@@ -78,6 +80,7 @@ data Tactic = Attack
78 | Defer [Name] Name
80 | Defer [Name] Name
79 | DeferType Name Raw [Name]
81 | DeferType Name Raw [Name]
80 | Instance Name
82 | Instance Name
81 | SetInjective Name
84 | SetInjective Name
82 | MoveLast Name
85 | MoveLast Name
83 | MatchProblems Bool
86 | MatchProblems Bool
@@ -90,9 +93,9 @@ data Tactic = Attack
90-- Some utilites on proof and tactic states
93-- Some utilites on proof and tactic states
92instance Show ProofState where
95instance Show ProofState where
93− show (PS nm [] _ _ tm _ _ _ _ _ _ _ _ _ _ _ _ _ _ _)
96+ show (PS nm [] _ _ tm _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _)
94 = show nm ++ ": no more goals"
97 = show nm ++ ": no more goals"
95− show (PS nm (h:hs) _ _ tm _ _ _ _ _ _ _ i _ _ ctxt _ _ _ _)
98+ show (PS nm (h:hs) _ _ tm _ _ _ _ _ _ _ i _ _ _ ctxt _ _ _ _ _)
96 = let OK g = goal (Just h) tm
99 = let OK g = goal (Just h) tm
97 wkenv = premises g in
100 wkenv = premises g in
98 "Other goals: " ++ show hs ++ "\n" ++
101 "Other goals: " ++ show hs ++ "\n" ++
@@ -115,9 +118,9 @@ instance Show ProofState where
115 showG ps b = showEnv ps (binderTy b)
118 showG ps b = showEnv ps (binderTy b)
117instance Pretty ProofState OutputAnnotation where
120instance Pretty ProofState OutputAnnotation where
118− pretty (PS nm [] _ _ trm _ _ _ _ _ _ _ _ _ _ _ _ _ _ _) =
121+ pretty (PS nm [] _ _ trm _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _) =
119 pretty nm <+> colon <+> text " no more goals."
122 pretty nm <+> colon <+> text " no more goals."
120− pretty p@(PS nm (h:hs) _ _ tm _ _ _ _ _ _ _ i _ _ ctxt _ _ _ _) =
123+ pretty p@(PS nm (h:hs) _ _ tm _ _ _ _ _ _ _ i _ _ _ ctxt _ _ _ _ _) =
121 let OK g = goal (Just h) tm in
124 let OK g = goal (Just h) tm in
122 let wkEnv = premises g in
125 let wkEnv = premises g in
123 text "Other goals" <+> colon <+> pretty hs <+>
126 text "Other goals" <+> colon <+> pretty hs <+>
@@ -285,8 +288,8 @@ newProof n ctxt ty = let h = holeName 0
285 PS n [h] [] 1 (mkProofTerm (Bind h (Hole ty')
288 PS n [h] [] 1 (mkProofTerm (Bind h (Hole ty')
286 (P Bound h ty'))) ty [] (h, []) []
289 (P Bound h ty'))) ty [] (h, []) []
287 Nothing [] []
290 Nothing [] []
289− Nothing ctxt "" False False []
292+ Nothing ctxt "" False False [] []
291type TState = ProofState -- [TacticAction])
294type TState = ProofState -- [TacticAction])
292type RunTactic = RunTactic' TState
295type RunTactic = RunTactic' TState
@@ -381,6 +384,16 @@ instanceArg n ctxt env (Bind x (Hole t) sc)
381 instances = x:is })
384 instances = x:is })
382 return (Bind x (Hole t) sc)
385 return (Bind x (Hole t) sc)
387+autoArg :: Name -> RunTactic
388+autoArg n ctxt env (Bind x (Hole t) sc)
389+ = do action (\ps -> case lookup x (autos ps) of
391+ let hs = holes ps in
392+ ps { holes = (hs \\ [x]) ++ [x],
393+ autos = (x, refsIn t) : autos ps }
395+ return (Bind x (Hole t) sc)
384setinj :: Name -> RunTactic
397setinj :: Name -> RunTactic
385setinj n ctxt env (Bind x b sc)
398setinj n ctxt env (Bind x b sc)
386 = do action (\ps -> let is = injective ps in
399 = do action (\ps -> let is = injective ps in
@@ -494,6 +507,7 @@ solve ctxt env (Bind x (Guess ty val) sc)
494 solved = Just (x, val),
507 solved = Just (x, val),
495 notunified = updateNotunified [(x,val)]
508 notunified = updateNotunified [(x,val)]
496 (notunified ps),
509 (notunified ps),
510+ recents = x : recents ps,
497 instances = instances ps \\ [x] })
511 instances = instances ps \\ [x] })
498 let tm' = subst x val sc in
512 let tm' = subst x val sc in
499 return tm'
513 return tm'
@@ -647,7 +661,8 @@ casetac tm induction ctxt env (Bind x (Hole t) (P _ x' _)) | x == x' = do
647 consargs' <- query (\ps -> map (flip (uniqueNameCtxt (context ps)) (holes ps ++ allTTNames (getProofTerm (pterm ps))) *** uniqueBindersCtxt (context ps) (holes ps ++ allTTNames (getProofTerm (pterm ps)))) consargs)
661 consargs' <- query (\ps -> map (flip (uniqueNameCtxt (context ps)) (holes ps ++ allTTNames (getProofTerm (pterm ps))) *** uniqueBindersCtxt (context ps) (holes ps ++ allTTNames (getProofTerm (pterm ps)))) consargs)
648 let res = flip (foldr substV) params $ (substV prop $ bindConsArgs consargs' (mkApp (P Ref (SN (tacn tnm)) (TType (UVal 0)))
662 let res = flip (foldr substV) params $ (substV prop $ bindConsArgs consargs' (mkApp (P Ref (SN (tacn tnm)) (TType (UVal 0)))
649 (params ++ [prop] ++ map makeConsArg consargs' ++ indicies ++ [tmv])))
663 (params ++ [prop] ++ map makeConsArg consargs' ++ indicies ++ [tmv])))
650− action (\ps -> ps {holes = holes ps \\ [x]})
664+ action (\ps -> ps {holes = holes ps \\ [x],
665+ recents = x : recents ps })
651 mapM_ addConsHole (reverse consargs')
666 mapM_ addConsHole (reverse consargs')
652 let res' = forget $ res
667 let res' = forget $ res
653 (scv, sct) <- lift $ check ctxt env res'
668 (scv, sct) <- lift $ check ctxt env res'
@@ -739,7 +754,8 @@ solve_unified ctxt env tm =
739 let (_, ns) = unified ps
754 let (_, ns) = unified ps
740 let unify = dropGiven (dontunify ps) ns (holes ps)
755 let unify = dropGiven (dontunify ps) ns (holes ps)
741 action (\ps -> ps { holes = traceWhen (unifylog ps) ("Dropping holes " ++ show (map fst unify)) $
756 action (\ps -> ps { holes = traceWhen (unifylog ps) ("Dropping holes " ++ show (map fst unify)) $
742− holes ps \\ map fst unify })
757+ holes ps \\ map fst unify,
758+ recents = recents ps ++ map fst unify })
743 action (\ps -> ps { pterm = updateSolved unify (pterm ps) })
759 action (\ps -> ps { pterm = updateSolved unify (pterm ps) })
744 return (updateSolvedTerm unify tm)
760 return (updateSolvedTerm unify tm)
@@ -858,11 +874,13 @@ processTactic EndUnify ps
858 unified = (h, []),
874 unified = (h, []),
859 problems = probs',
875 problems = probs',
860 notunified = updateNotunified ns'' (notunified ps),
876 notunified = updateNotunified ns'' (notunified ps),
877+ recents = recents ps ++ map fst ns'',
861 holes = holes ps \\ map fst ns'' }, "")
878 holes = holes ps \\ map fst ns'' }, "")
862processTactic UnifyAll ps
879processTactic UnifyAll ps
863 = let tm' = updateSolved (notunified ps) (pterm ps) in
880 = let tm' = updateSolved (notunified ps) (pterm ps) in
864 return (ps { pterm = tm',
881 return (ps { pterm = tm',
865 notunified = [],
882 notunified = [],
883+ recents = recents ps ++ map fst (notunified ps),
866 holes = holes ps \\ map fst (notunified ps) }, "")
884 holes = holes ps \\ map fst (notunified ps) }, "")
867processTactic (Reorder n) ps
885processTactic (Reorder n) ps
868 = do ps' <- execStateT (tactic (Just n) reorder_claims) ps
886 = do ps' <- execStateT (tactic (Just n) reorder_claims) ps
@@ -882,6 +900,7 @@ processTactic UnifyProblems ps
882 return (ps { pterm = pterm', solved = Nothing, problems = probs',
900 return (ps { pterm = pterm', solved = Nothing, problems = probs',
883 previous = Just ps, plog = "",
901 previous = Just ps, plog = "",
884 notunified = updateNotunified ns' (notunified ps),
902 notunified = updateNotunified ns' (notunified ps),
903+ recents = recents ps ++ map fst ns',
885 holes = holes ps \\ (map fst ns') }, plog ps)
904 holes = holes ps \\ (map fst ns') }, plog ps)
886processTactic (MatchProblems all) ps
905processTactic (MatchProblems all) ps
887 = let (ns', probs') = matchProblems all [] (context ps)
906 = let (ns', probs') = matchProblems all [] (context ps)
@@ -897,6 +916,7 @@ processTactic (MatchProblems all) ps
897 return (ps { pterm = pterm', solved = Nothing, problems = probs'',
916 return (ps { pterm = pterm', solved = Nothing, problems = probs'',
898 previous = Just ps, plog = "",
917 previous = Just ps, plog = "",
899 notunified = updateNotunified ns'' (notunified ps),
918 notunified = updateNotunified ns'' (notunified ps),
919+ recents = recents ps ++ map fst ns'',
900 holes = holes ps \\ (map fst ns'') }, plog ps)
920 holes = holes ps \\ (map fst ns'') }, plog ps)
901processTactic t ps
921processTactic t ps
902 = case holes ps of
922 = case holes ps of
@@ -921,6 +941,7 @@ processTactic t ps
921 problems = probs',
941 problems = probs',
922 notunified = updateNotunified ns' (notunified ps'),
942 notunified = updateNotunified ns' (notunified ps'),
923 previous = Just ps, plog = "",
943 previous = Just ps, plog = "",
944+ recents = recents ps' ++ map fst ns',
924 holes = holes ps' \\ (map fst ns')}, plog ps')
945 holes = holes ps' \\ (map fst ns')}, plog ps')
926process :: Tactic -> Name -> StateT TState TC ()
947process :: Tactic -> Name -> StateT TState TC ()
@@ -959,5 +980,6 @@ process t h = tactic (Just h) (mktac t)
959 mktac (Defer ns n) = defer ns n
980 mktac (Defer ns n) = defer ns n
960 mktac (DeferType n t a) = deferType n t a
981 mktac (DeferType n t a) = deferType n t a
961 mktac (Instance n) = instanceArg n
982 mktac (Instance n) = instanceArg n
983+ mktac (AutoArg n) = autoArg n
962 mktac (SetInjective n) = setinj n
984 mktac (SetInjective n) = setinj n
963 mktac (MoveLast n) = movelast n
985 mktac (MoveLast n) = movelast n