@@ -6,7 +6,7 @@
7module Idris.Core.ProofState(ProofState(..), newProof, envAtFocus, goalAtFocus,
7module Idris.Core.ProofState(ProofState(..), newProof, envAtFocus, goalAtFocus,
8 Tactic(..), Goal(..), processTactic, nowElaboratingPS, doneElaboratingAppPS,
8 Tactic(..), Goal(..), processTactic, nowElaboratingPS, doneElaboratingAppPS,
9− doneElaboratingArgPS, dropGiven, keepGiven) where
9+ doneElaboratingArgPS, dropGiven, keepGiven, getProvenance) where
11import Idris.Core.Typecheck
11import Idris.Core.Typecheck
12import Idris.Core.Evaluate
12import Idris.Core.Evaluate
@@ -154,9 +154,11 @@ holeName i = sMN i "hole"
154qshow :: Fails -> String
154qshow :: Fails -> String
155qshow fs = show (map (\ (x, y, hs, _, _, _, t) -> (t, x, y, hs)) fs)
155qshow fs = show (map (\ (x, y, hs, _, _, _, t) -> (t, x, y, hs)) fs)
157−match_unify' :: Context -> Env -> TT Name -> TT Name ->
157+match_unify' :: Context -> Env ->
158+ (TT Name, Maybe Provenance) ->
159+ (TT Name, Maybe Provenance) ->
158 StateT TState TC [(Name, TT Name)]
160 StateT TState TC [(Name, TT Name)]
159−match_unify' ctxt env topx topy =
161+match_unify' ctxt env (topx, xfrom) (topy, yfrom) =
160 do ps <- get
162 do ps <- get
161 let while = while_elaborating ps
163 let while = while_elaborating ps
162 let dont = dontunify ps
164 let dont = dontunify ps
@@ -168,7 +170,7 @@ match_unify' ctxt env topx topy =
169 ++ "\n" ++ show (getProofTerm (pterm ps)) ++ "\n\n"
171 ++ "\n" ++ show (getProofTerm (pterm ps)) ++ "\n\n"
171− case match_unify ctxt env topx topy inj (holes ps) while of
173+ case match_unify ctxt env (topx, xfrom) (topy, yfrom) inj (holes ps) while of
172 OK u -> traceWhen (unifylog ps)
174 OK u -> traceWhen (unifylog ps)
173 ("Matched " ++ show u) $
175 ("Matched " ++ show u) $
174 do let (h, ns) = unified ps
176 do let (h, ns) = unified ps
@@ -196,14 +198,16 @@ mergeSolutions env ns = merge [] ns
196 = do ps <- get
198 = do ps <- get
197 let probs = problems ps
199 let probs = problems ps
198 put (ps { problems = probs ++ [(t,t',True,env,
200 put (ps { problems = probs ++ [(t,t',True,env,
199− CantUnify True t t' (Msg "") (errEnv env) 0,
201+ CantUnify True (t, Nothing) (t', Nothing) (Msg "") (errEnv env) 0,
200 [], Unify)] })
202 [], Unify)] })
201 merge acc ns
203 merge acc ns
202 | otherwise = merge ((n, t): acc) ns
204 | otherwise = merge ((n, t): acc) ns
204−unify' :: Context -> Env -> TT Name -> TT Name ->
206+unify' :: Context -> Env ->
207+ (TT Name, Maybe Provenance) ->
208+ (TT Name, Maybe Provenance) ->
205 StateT TState TC [(Name, TT Name)]
209 StateT TState TC [(Name, TT Name)]
206−unify' ctxt env topx topy =
210+unify' ctxt env (topx, xfrom) (topy, yfrom) =
207 do ps <- get
211 do ps <- get
208 let while = while_elaborating ps
212 let while = while_elaborating ps
209 let dont = dontunify ps
213 let dont = dontunify ps
@@ -216,7 +220,7 @@ unify' ctxt env topx topy =
216 "\nHoles: " ++ show (holes ps)
220 "\nHoles: " ++ show (holes ps)
217 ++ "\nInjective: " ++ show (injective ps)
221 ++ "\nInjective: " ++ show (injective ps)
218 ++ "\n") $
222 ++ "\n") $
219− lift $ unify ctxt env topx topy inj (holes ps)
223+ lift $ unify ctxt env (topx, xfrom) (topy, yfrom) inj (holes ps)
220 (map fst (notunified ps)) while
224 (map fst (notunified ps)) while
221 let notu = filter (\ (n, t) -> case t of
225 let notu = filter (\ (n, t) -> case t of
222-- P _ _ _ -> False
226-- P _ _ _ -> False
@@ -456,7 +460,7 @@ regret ctxt env (Bind x (Hole t) _)
456unifyGoal :: Raw -> RunTactic
460unifyGoal :: Raw -> RunTactic
457unifyGoal tm ctxt env h@(Bind x b sc) =
461unifyGoal tm ctxt env h@(Bind x b sc) =
458 do (tmv, _) <- lift $ check ctxt env tm
462 do (tmv, _) <- lift $ check ctxt env tm
459− ns' <- unify' ctxt env (binderTy b) tmv
463+ ns' <- unify' ctxt env (binderTy b, Nothing) (tmv, Nothing)
462exact :: Raw -> RunTactic
466exact :: Raw -> RunTactic
@@ -473,7 +477,8 @@ fill guess ctxt env (Bind x (Hole ty) sc) =
473 do (val, valty) <- lift $ check ctxt env guess
477 do (val, valty) <- lift $ check ctxt env guess
474-- let valtyn = normalise ctxt env valty
478-- let valtyn = normalise ctxt env valty
475-- let tyn = normalise ctxt env ty
479-- let tyn = normalise ctxt env ty
476− ns <- unify' ctxt env valty ty
480+ ns <- unify' ctxt env (valty, Just $ SourceTerm val)
481+ (ty, Just ExpectedType)
477 ps <- get
482 ps <- get
478 let (uh, uns) = unified ps
483 let (uh, uns) = unified ps
479-- put (ps { unified = (uh, uns ++ ns) })
484-- put (ps { unified = (uh, uns ++ ns) })
@@ -488,7 +493,7 @@ match_fill guess ctxt env (Bind x (Hole ty) sc) =
488 do (val, valty) <- lift $ check ctxt env guess
493 do (val, valty) <- lift $ check ctxt env guess
489-- let valtyn = normalise ctxt env valty
494-- let valtyn = normalise ctxt env valty
490-- let tyn = normalise ctxt env ty
495-- let tyn = normalise ctxt env ty
491− ns <- match_unify' ctxt env valty ty
496+ ns <- match_unify' ctxt env (valty, Nothing) (ty, Nothing)
492 ps <- get
497 ps <- get
493 let (uh, uns) = unified ps
498 let (uh, uns) = unified ps
494-- put (ps { unified = (uh, uns ++ ns) })
499-- put (ps { unified = (uh, uns ++ ns) })
@@ -506,7 +511,7 @@ complete_fill :: RunTactic
506complete_fill ctxt env (Bind x (Guess ty val) sc) =
511complete_fill ctxt env (Bind x (Guess ty val) sc) =
507 do let guess = forget val
512 do let guess = forget val
508 (val', valty) <- lift $ check ctxt env guess
513 (val', valty) <- lift $ check ctxt env guess
509− ns <- unify' ctxt env valty ty
514+ ns <- unify' ctxt env (valty, Nothing) (ty, Nothing)
510 ps <- get
515 ps <- get
511 let (uh, uns) = unified ps
516 let (uh, uns) = unified ps
512-- put (ps { unified = (uh, uns ++ ns) })
517-- put (ps { unified = (uh, uns ++ ns) })
@@ -524,7 +529,7 @@ solve ctxt env (Bind x (Guess ty val) sc)
524 dropdots <-
529 dropdots <-
525 case lookup x (notunified ps) of
530 case lookup x (notunified ps) of
526 Just tm -> -- trace ("NEED MATCH: " ++ show (x, tm, val) ++ "\nIN " ++ show (pterm ps)) $
531 Just tm -> -- trace ("NEED MATCH: " ++ show (x, tm, val) ++ "\nIN " ++ show (pterm ps)) $
527− do match_unify' ctxt env tm val
532+ do match_unify' ctxt env (tm, Nothing) (val, Nothing)
528 return [x]
533 return [x]
529 _ -> return []
534 _ -> return []
530 action (\ps -> ps { holes = traceWhen (unifylog ps) ("Dropping hole " ++ show x) $
535 action (\ps -> ps { holes = traceWhen (unifylog ps) ("Dropping hole " ++ show x) $
@@ -567,7 +572,7 @@ introTy ty mn ctxt env (Bind x (Hole t) (P _ x' _)) | x == x' =
567-- ns <- lift $ unify ctxt env tyv t'
572-- ns <- lift $ unify ctxt env tyv t'
568 case t' of
573 case t' of
569 Bind y (Pi _ s _) t -> let t' = subst y (P Bound n s) t in
574 Bind y (Pi _ s _) t -> let t' = subst y (P Bound n s) t in
570− do ns <- unify' ctxt env s tyv
575+ do ns <- unify' ctxt env (s, Nothing) (tyv, Nothing)
571 ps <- get
576 ps <- get
572 let (uh, uns) = unified ps
577 let (uh, uns) = unified ps
573-- put (ps { unified = (uh, uns ++ ns) })
578-- put (ps { unified = (uh, uns ++ ns) })
@@ -593,8 +598,8 @@ intro n ctxt env _ = fail "Can't introduce here."
593forall :: Name -> Maybe ImplicitInfo -> Raw -> RunTactic
598forall :: Name -> Maybe ImplicitInfo -> Raw -> RunTactic
594forall n impl ty ctxt env (Bind x (Hole t) (P _ x' _)) | x == x' =
599forall n impl ty ctxt env (Bind x (Hole t) (P _ x' _)) | x == x' =
595 do (tyv, tyt) <- lift $ check ctxt env ty
600 do (tyv, tyt) <- lift $ check ctxt env ty
596− unify' ctxt env tyt (TType (UVar 0))
601+ unify' ctxt env (tyt, Nothing) (TType (UVar 0), Nothing)
597− unify' ctxt env t (TType (UVar 0))
602+ unify' ctxt env (t, Nothing) (TType (UVar 0), Nothing)
598 return $ Bind n (Pi impl tyv (TType (UVar 0))) (Bind x (Hole t) (P Bound x t))
603 return $ Bind n (Pi impl tyv (TType (UVar 0))) (Bind x (Hole t) (P Bound x t))
599forall n impl ty ctxt env _ = fail "Can't pi bind here"
604forall n impl ty ctxt env _ = fail "Can't pi bind here"
@@ -822,8 +827,8 @@ updateError ns (At f e) = At f (updateError ns e)
822updateError ns (Elaborating s n e) = Elaborating s n (updateError ns e)
827updateError ns (Elaborating s n e) = Elaborating s n (updateError ns e)
823updateError ns (ElaboratingArg f a env e)
828updateError ns (ElaboratingArg f a env e)
824 = ElaboratingArg f a env (updateError ns e)
829 = ElaboratingArg f a env (updateError ns e)
825−updateError ns (CantUnify b l r e xs sc)
830+updateError ns (CantUnify b (l,lp) (r,rp) e xs sc)
826− = CantUnify b (updateSolvedTerm ns l) (updateSolvedTerm ns r) (updateError ns e) xs sc
831+ = CantUnify b (updateSolvedTerm ns l, lp) (updateSolvedTerm ns r, rp) (updateError ns e) xs sc
827updateError ns e = e
832updateError ns e = e
829solveInProblems x val [] = []
834solveInProblems x val [] = []
@@ -837,7 +842,7 @@ mergeNotunified env holes ns = mnu ns [] [] where
837 mnu ((n, t):ns) ns_acc ps_acc
842 mnu ((n, t):ns) ns_acc ps_acc
838 | Just t' <- lookup n ns, t /= t'
843 | Just t' <- lookup n ns, t /= t'
839 = mnu ns ((n,t') : ns_acc)
844 = mnu ns ((n,t') : ns_acc)
840− ((t,t',True, env,CantUnify True t t' (Msg "") [] 0, [],Match) : ps_acc)
845+ ((t,t',True, env,CantUnify True (t, Nothing) (t', Nothing) (Msg "") [] 0, [],Match) : ps_acc)
841 | otherwise = mnu ns ((n,t) : ns_acc) ps_acc
846 | otherwise = mnu ns ((n,t) : ns_acc) ps_acc
843updateNotunified [] nu = nu
848updateNotunified [] nu = nu
@@ -846,6 +851,10 @@ updateNotunified ns nu = up nu where
846 up ((n, t) : nus) = let t' = updateSolvedTerm ns t in
851 up ((n, t) : nus) = let t' = updateSolvedTerm ns t in
847 ((n, t') : up nus)
852 ((n, t') : up nus)
854+getProvenance :: Err -> (Maybe Provenance, Maybe Provenance)
855+getProvenance (CantUnify _ (_, lp) (_, rp) _ _ _) = (lp, rp)
856+getProvenance _ = (Nothing, Nothing)
849updateProblems :: ProofState -> [(Name, TT Name)] -> Fails
858updateProblems :: ProofState -> [(Name, TT Name)] -> Fails
850 -> ([(Name, TT Name)], Fails)
859 -> ([(Name, TT Name)], Fails)
851-- updateProblems ctxt [] ps inj holes = ([], ps)
860-- updateProblems ctxt [] ps inj holes = ([], ps)
@@ -860,11 +869,12 @@ updateProblems ps updates probs = up updates probs where
860 up ns (prob@(x, y, ready, env, err, while, um) : ps) =
869 up ns (prob@(x, y, ready, env, err, while, um) : ps) =
861 let (x', newx) = updateSolvedTerm' ns x
870 let (x', newx) = updateSolvedTerm' ns x
862 (y', newy) = updateSolvedTerm' ns y
871 (y', newy) = updateSolvedTerm' ns y
872+ (lp, rp) = getProvenance err
863 err' = updateError ns err
873 err' = updateError ns err
864 env' = updateEnv ns env in
874 env' = updateEnv ns env in
865 if newx || newy || ready ||
875 if newx || newy || ready ||
866 any (\n -> n `elem` inj) (refsIn x ++ refsIn y) then
876 any (\n -> n `elem` inj) (refsIn x ++ refsIn y) then
867− case unify ctxt env' x' y' inj hs usupp while of
877+ case unify ctxt env' (x', lp) (y', rp) inj hs usupp while of
868 OK (v, []) -> traceWhen ulog ("DID " ++ show (x',y',ready,v)) $
878 OK (v, []) -> traceWhen ulog ("DID " ++ show (x',y',ready,v)) $
869 up (ns ++ v) ps
879 up (ns ++ v) ps
870 e -> -- trace ("FAILED " ++ show (x',y',ready,e)) $
880 e -> -- trace ("FAILED " ++ show (x',y',ready,e)) $
@@ -887,9 +897,10 @@ matchProblems all ps updates probs = up updates probs where
887 | all || um == Match =
897 | all || um == Match =
888 let x' = updateSolvedTerm ns x
898 let x' = updateSolvedTerm ns x
889 y' = updateSolvedTerm ns y
899 y' = updateSolvedTerm ns y
900+ (lp, rp) = getProvenance err
890 err' = updateError ns err
901 err' = updateError ns err
891 env' = updateEnv ns env in
902 env' = updateEnv ns env in
892− case match_unify ctxt env' x' y' inj hs while of
903+ case match_unify ctxt env' (x', lp) (y', rp) inj hs while of
893 OK v -> -- trace ("Added " ++ show v ++ " from " ++ show (x', y')) $
904 OK v -> -- trace ("Added " ++ show v ++ " from " ++ show (x', y')) $
894 up (ns ++ v) ps
905 up (ns ++ v) ps
895 _ -> let (ns', ps') = up ns ps in
906 _ -> let (ns', ps') = up ns ps in