@@ -6,7 +6,7 @@
66
77module Idris.Core.ProofState(ProofState(..), newProof, envAtFocus, goalAtFocus,
88 Tactic(..), Goal(..), processTactic, nowElaboratingPS, doneElaboratingAppPS,
9− doneElaboratingArgPS, dropGiven, keepGiven) where
9+ doneElaboratingArgPS, dropGiven, keepGiven, getProvenance) where
1010
1111import Idris.Core.Typecheck
1212import Idris.Core.Evaluate
@@ -154,9 +154,11 @@ holeName i = sMN i "hole"
154154qshow :: Fails -> String
155155qshow fs = show (map (\ (x, y, hs, _, _, _, t) -> (t, x, y, hs)) fs)
156156
157−match_unify' :: Context -> Env -> TT Name -> TT Name ->
157+match_unify' :: Context -> Env ->
158+ (TT Name, Maybe Provenance) ->
159+ (TT Name, Maybe Provenance) ->
158160 StateT TState TC [(Name, TT Name)]
159−match_unify' ctxt env topx topy =
161+match_unify' ctxt env (topx, xfrom) (topy, yfrom) =
160162 do ps <- get
161163 let while = while_elaborating ps
162164 let dont = dontunify ps
@@ -168,7 +170,7 @@ match_unify' ctxt env topx topy =
168170 ++ "\n"
169171 ++ "\n" ++ show (getProofTerm (pterm ps)) ++ "\n\n"
170172 ) $
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
172174 OK u -> traceWhen (unifylog ps)
173175 ("Matched " ++ show u) $
174176 do let (h, ns) = unified ps
@@ -196,14 +198,16 @@ mergeSolutions env ns = merge [] ns
196198 = do ps <- get
197199 let probs = problems ps
198200 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,
200202 [], Unify)] })
201203 merge acc ns
202204 | otherwise = merge ((n, t): acc) ns
203205
204−unify' :: Context -> Env -> TT Name -> TT Name ->
206+unify' :: Context -> Env ->
207+ (TT Name, Maybe Provenance) ->
208+ (TT Name, Maybe Provenance) ->
205209 StateT TState TC [(Name, TT Name)]
206−unify' ctxt env topx topy =
210+unify' ctxt env (topx, xfrom) (topy, yfrom) =
207211 do ps <- get
208212 let while = while_elaborating ps
209213 let dont = dontunify ps
@@ -216,7 +220,7 @@ unify' ctxt env topx topy =
216220 "\nHoles: " ++ show (holes ps)
217221 ++ "\nInjective: " ++ show (injective ps)
218222 ++ "\n") $
219− lift $ unify ctxt env topx topy inj (holes ps)
223+ lift $ unify ctxt env (topx, xfrom) (topy, yfrom) inj (holes ps)
220224 (map fst (notunified ps)) while
221225 let notu = filter (\ (n, t) -> case t of
222226-- P _ _ _ -> False
@@ -456,7 +460,7 @@ regret ctxt env (Bind x (Hole t) _)
456460unifyGoal :: Raw -> RunTactic
457461unifyGoal tm ctxt env h@(Bind x b sc) =
458462 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)
460464 return h
461465
462466exact :: Raw -> RunTactic
@@ -473,7 +477,7 @@ fill guess ctxt env (Bind x (Hole ty) sc) =
473477 do (val, valty) <- lift $ check ctxt env guess
474478-- let valtyn = normalise ctxt env valty
475479-- let tyn = normalise ctxt env ty
476− ns <- unify' ctxt env valty ty
480+ ns <- unify' ctxt env (valty, Nothing) (ty, Nothing)
477481 ps <- get
478482 let (uh, uns) = unified ps
479483-- put (ps { unified = (uh, uns ++ ns) })
@@ -488,7 +492,7 @@ match_fill guess ctxt env (Bind x (Hole ty) sc) =
488492 do (val, valty) <- lift $ check ctxt env guess
489493-- let valtyn = normalise ctxt env valty
490494-- let tyn = normalise ctxt env ty
491− ns <- match_unify' ctxt env valty ty
495+ ns <- match_unify' ctxt env (valty, Nothing) (ty, Nothing)
492496 ps <- get
493497 let (uh, uns) = unified ps
494498-- put (ps { unified = (uh, uns ++ ns) })
@@ -506,7 +510,7 @@ complete_fill :: RunTactic
506510complete_fill ctxt env (Bind x (Guess ty val) sc) =
507511 do let guess = forget val
508512 (val', valty) <- lift $ check ctxt env guess
509− ns <- unify' ctxt env valty ty
513+ ns <- unify' ctxt env (valty, Nothing) (ty, Nothing)
510514 ps <- get
511515 let (uh, uns) = unified ps
512516-- put (ps { unified = (uh, uns ++ ns) })
@@ -524,7 +528,7 @@ solve ctxt env (Bind x (Guess ty val) sc)
524528 dropdots <-
525529 case lookup x (notunified ps) of
526530 Just tm -> -- trace ("NEED MATCH: " ++ show (x, tm, val) ++ "\nIN " ++ show (pterm ps)) $
527− do match_unify' ctxt env tm val
531+ do match_unify' ctxt env (tm, Nothing) (val, Nothing)
528532 return [x]
529533 _ -> return []
530534 action (\ps -> ps { holes = traceWhen (unifylog ps) ("Dropping hole " ++ show x) $
@@ -567,7 +571,7 @@ introTy ty mn ctxt env (Bind x (Hole t) (P _ x' _)) | x == x' =
567571-- ns <- lift $ unify ctxt env tyv t'
568572 case t' of
569573 Bind y (Pi _ s _) t -> let t' = subst y (P Bound n s) t in
570− do ns <- unify' ctxt env s tyv
574+ do ns <- unify' ctxt env (s, Nothing) (tyv, Nothing)
571575 ps <- get
572576 let (uh, uns) = unified ps
573577-- put (ps { unified = (uh, uns ++ ns) })
@@ -593,8 +597,8 @@ intro n ctxt env _ = fail "Can't introduce here."
593597forall :: Name -> Maybe ImplicitInfo -> Raw -> RunTactic
594598forall n impl ty ctxt env (Bind x (Hole t) (P _ x' _)) | x == x' =
595599 do (tyv, tyt) <- lift $ check ctxt env ty
596− unify' ctxt env tyt (TType (UVar 0))
597− unify' ctxt env t (TType (UVar 0))
600+ unify' ctxt env (tyt, Nothing) (TType (UVar 0), Nothing)
601+ unify' ctxt env (t, Nothing) (TType (UVar 0), Nothing)
598602 return $ Bind n (Pi impl tyv (TType (UVar 0))) (Bind x (Hole t) (P Bound x t))
599603forall n impl ty ctxt env _ = fail "Can't pi bind here"
600604
@@ -822,8 +826,8 @@ updateError ns (At f e) = At f (updateError ns e)
822826updateError ns (Elaborating s n e) = Elaborating s n (updateError ns e)
823827updateError ns (ElaboratingArg f a env e)
824828 = ElaboratingArg f a env (updateError ns e)
825−updateError ns (CantUnify b l r e xs sc)
826− = CantUnify b (updateSolvedTerm ns l) (updateSolvedTerm ns r) (updateError ns e) xs sc
829+updateError ns (CantUnify b (l,lp) (r,rp) e xs sc)
830+ = CantUnify b (updateSolvedTerm ns l, lp) (updateSolvedTerm ns r, rp) (updateError ns e) xs sc
827831updateError ns e = e
828832
829833solveInProblems x val [] = []
@@ -837,7 +841,7 @@ mergeNotunified env holes ns = mnu ns [] [] where
837841 mnu ((n, t):ns) ns_acc ps_acc
838842 | Just t' <- lookup n ns, t /= t'
839843 = mnu ns ((n,t') : ns_acc)
840− ((t,t',True, env,CantUnify True t t' (Msg "") [] 0, [],Match) : ps_acc)
844+ ((t,t',True, env,CantUnify True (t, Nothing) (t', Nothing) (Msg "") [] 0, [],Match) : ps_acc)
841845 | otherwise = mnu ns ((n,t) : ns_acc) ps_acc
842846
843847updateNotunified [] nu = nu
@@ -846,6 +850,10 @@ updateNotunified ns nu = up nu where
846850 up ((n, t) : nus) = let t' = updateSolvedTerm ns t in
847851 ((n, t') : up nus)
848852
853+getProvenance :: Err -> (Maybe Provenance, Maybe Provenance)
854+getProvenance (CantUnify _ (_, lp) (_, rp) _ _ _) = (lp, rp)
855+getProvenance _ = (Nothing, Nothing)
856+
849857updateProblems :: ProofState -> [(Name, TT Name)] -> Fails
850858 -> ([(Name, TT Name)], Fails)
851859-- updateProblems ctxt [] ps inj holes = ([], ps)
@@ -860,11 +868,12 @@ updateProblems ps updates probs = up updates probs where
860868 up ns (prob@(x, y, ready, env, err, while, um) : ps) =
861869 let (x', newx) = updateSolvedTerm' ns x
862870 (y', newy) = updateSolvedTerm' ns y
871+ (lp, rp) = getProvenance err
863872 err' = updateError ns err
864873 env' = updateEnv ns env in
865874 if newx || newy || ready ||
866875 any (\n -> n `elem` inj) (refsIn x ++ refsIn y) then
867− case unify ctxt env' x' y' inj hs usupp while of
876+ case unify ctxt env' (x', lp) (y', rp) inj hs usupp while of
868877 OK (v, []) -> traceWhen ulog ("DID " ++ show (x',y',ready,v)) $
869878 up (ns ++ v) ps
870879 e -> -- trace ("FAILED " ++ show (x',y',ready,e)) $
@@ -887,9 +896,10 @@ matchProblems all ps updates probs = up updates probs where
887896 | all || um == Match =
888897 let x' = updateSolvedTerm ns x
889898 y' = updateSolvedTerm ns y
899+ (lp, rp) = getProvenance err
890900 err' = updateError ns err
891901 env' = updateEnv ns env in
892− case match_unify ctxt env' x' y' inj hs while of
902+ case match_unify ctxt env' (x', lp) (y', rp) inj hs while of
893903 OK v -> -- trace ("Added " ++ show v ++ " from " ++ show (x', y')) $
894904 up (ns ++ v) ps
895905 _ -> let (ns', ps') = up ns ps in