@@ -14,6 +14,7 @@ import Idris.Error
1414
1515import Control.Applicative ((<$>))
1616import Control.Monad
17+import Control.Monad.State.Strict
1718import Data.List
1819import Debug.Trace
1920
@@ -37,16 +38,26 @@ trivial elab ist = try' (do elab (PRefl (fileFC "prf") Placeholder)
3738 (tryAll xs) True
3839 else tryAll xs
3940
40−proofSearch :: Bool ->
41+cantSolveGoal :: ElabD ()
42+cantSolveGoal = do g <- goal
43+ env <- get_env
44+ lift $ tfail $
45+ CantSolveGoal g (map (\(n,b) -> (n, binderTy b)) env)
46+
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.
4151 (PTerm -> ElabD ()) -> Maybe Name -> Name -> [Name] ->
4252 IState -> ElabD ()
43−proofSearch False elab _ nroot [fn] ist
53+proofSearch False fromProver elab _ nroot [fn] ist
4454 = do -- get all possible versions of the name, take the first one that
4555 -- works
4656 let all_imps = lookupCtxtName fn (idris_implicits ist)
4757 tryAllFns all_imps
4858 where
4959 -- if nothing worked, make a new metavariable
60+ tryAllFns _ | fromProver = cantSolveGoal
5061 tryAllFns [] = do attack; defer nroot; solve
5162 tryAllFns (f : fs) = try' (tryFn f) (tryAllFns fs) True
5263
@@ -60,15 +71,17 @@ proofSearch False elab _ nroot [fn] ist
6071 -- Make metavariables for new holes
6172 hs' <- get_holes
6273 ptm <- get_term
63− mapM_ (\ h -> do focus h
64− attack; defer nroot; solve)
65− (hs' \\ hs)
66−-- (filter (\ (x, y) -> not x) (zip (map fst imps) args))
67− solve
74+ if fromProver then cantSolveGoal
75+ else do
76+ mapM_ (\ h -> do focus h
77+ attack; defer nroot; solve)
78+ (hs' \\ hs)
79+-- (filter (\ (x, y) -> not x) (zip (map fst imps) args))
80+ solve
6881
6982 isImp (PImp p _ _ _ _) = (True, p)
7083 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
7285 = case lookupCtxt nroot (idris_tyinfodata ist) of
7386 [TISolution ts] -> findInferredTy ts
7487 _ -> psRec rec maxDepth
@@ -83,13 +96,16 @@ proofSearch rec elab fn nroot hints ist
8396 toUN (App f a) = App (toUN f) (toUN a)
8497 toUN t = t
8598
99+ psRec _ _ | fromProver = cantSolveGoal
86100 psRec rec 0 = do attack; defer nroot; solve --fail "Maximum depth reached"
87101 psRec False d = tryCons d hints
88102 psRec True d = try' (trivial elab ist)
89103 (try' (try' (resolveByCon (d - 1)) (resolveByLocals (d - 1))
90104 True)
91105 -- if all else fails, make a new metavariable
92− (do attack; defer nroot; solve) True) True
106+ (if fromProver
107+ then cantSolveGoal
108+ else do attack; defer nroot; solve) True) True
93109
94110 getFn d Nothing = []
95111 getFn d (Just f) | d < maxDepth-1 = [f]