@@ -14,6 +14,7 @@ import Idris.Error
15import Control.Applicative ((<$>))
15import Control.Applicative ((<$>))
16import Control.Monad
16import Control.Monad
17+import Control.Monad.State.Strict
17import Data.List
18import Data.List
18import Debug.Trace
19import Debug.Trace
@@ -37,16 +38,26 @@ trivial elab ist = try' (do elab (PRefl (fileFC "prf") Placeholder)
37 (tryAll xs) True
38 (tryAll xs) True
38 else tryAll xs
39 else tryAll xs
41+cantSolveGoal :: ElabD ()
42+cantSolveGoal = do g <- goal
45+ CantSolveGoal g (map (\(n,b) -> (n, binderTy b)) env)
40−proofSearch :: Bool ->
47+proofSearch :: Bool ->
48+ Bool -> -- invoked from a tactic proof. If so, making
49+ -- new metavariables is meaningless, and there shoudl
50+ -- be an error reported instead.
41 (PTerm -> ElabD ()) -> Maybe Name -> Name -> [Name] ->
51 (PTerm -> ElabD ()) -> Maybe Name -> Name -> [Name] ->
42 IState -> ElabD ()
52 IState -> ElabD ()
43−proofSearch False elab _ nroot [fn] ist
53+proofSearch False fromProver elab _ nroot [fn] ist
44 = do -- get all possible versions of the name, take the first one that
54 = do -- get all possible versions of the name, take the first one that
46 let all_imps = lookupCtxtName fn (idris_implicits ist)
56 let all_imps = lookupCtxtName fn (idris_implicits ist)
47 tryAllFns all_imps
57 tryAllFns all_imps
49 -- if nothing worked, make a new metavariable
59 -- if nothing worked, make a new metavariable
60+ tryAllFns _ | fromProver = cantSolveGoal
50 tryAllFns [] = do attack; defer nroot; solve
61 tryAllFns [] = do attack; defer nroot; solve
51 tryAllFns (f : fs) = try' (tryFn f) (tryAllFns fs) True
62 tryAllFns (f : fs) = try' (tryFn f) (tryAllFns fs) True
@@ -60,15 +71,17 @@ proofSearch False elab _ nroot [fn] ist
60 -- Make metavariables for new holes
71 -- Make metavariables for new holes
61 hs' <- get_holes
72 hs' <- get_holes
62 ptm <- get_term
73 ptm <- get_term
74+ if fromProver then cantSolveGoal
63− mapM_ (\ h -> do focus h
76+ mapM_ (\ h -> do focus h
64− attack; defer nroot; solve)
77+ attack; defer nroot; solve)
65− (hs' \\ hs)
78+ (hs' \\ hs)
66−-- (filter (\ (x, y) -> not x) (zip (map fst imps) args))
79+-- (filter (\ (x, y) -> not x) (zip (map fst imps) args))
69 isImp (PImp p _ _ _ _) = (True, p)
82 isImp (PImp p _ _ _ _) = (True, p)
70 isImp arg = (True, priority arg) -- try to get all of them by unification
83 isImp arg = (True, priority arg) -- try to get all of them by unification
71−proofSearch rec elab fn nroot hints ist
84+proofSearch rec fromProver elab fn nroot hints ist
72 = case lookupCtxt nroot (idris_tyinfodata ist) of
85 = case lookupCtxt nroot (idris_tyinfodata ist) of
73 [TISolution ts] -> findInferredTy ts
86 [TISolution ts] -> findInferredTy ts
74 _ -> psRec rec maxDepth
87 _ -> psRec rec maxDepth
@@ -83,13 +96,16 @@ proofSearch rec elab fn nroot hints ist
83 toUN (App f a) = App (toUN f) (toUN a)
96 toUN (App f a) = App (toUN f) (toUN a)
84 toUN t = t
97 toUN t = t
99+ psRec _ _ | fromProver = cantSolveGoal
86 psRec rec 0 = do attack; defer nroot; solve --fail "Maximum depth reached"
100 psRec rec 0 = do attack; defer nroot; solve --fail "Maximum depth reached"
87 psRec False d = tryCons d hints
101 psRec False d = tryCons d hints
88 psRec True d = try' (trivial elab ist)
102 psRec True d = try' (trivial elab ist)
89 (try' (try' (resolveByCon (d - 1)) (resolveByLocals (d - 1))
103 (try' (try' (resolveByCon (d - 1)) (resolveByLocals (d - 1))
91 -- if all else fails, make a new metavariable
105 -- if all else fails, make a new metavariable
92− (do attack; defer nroot; solve) True) True
108+ else do attack; defer nroot; solve) True) True
94 getFn d Nothing = []
110 getFn d Nothing = []
95 getFn d (Just f) | d < maxDepth-1 = [f]
111 getFn d (Just f) | d < maxDepth-1 = [f]