@@ -481,6 +481,16 @@ let restrict_evar evd evk filter candidates =
481
481
| Some [] -> raise (ClearDependencyError (* FIXME*) (Id. of_string " blah" , (NoCandidatesLeft evk), None ))
482
482
| _ -> Evd. restrict evk filter ?candidates evd
483
483
484
+ let check_vars env sigma ids c =
485
+ let rec check_rec c =
486
+ match EConstr. destRef sigma c with
487
+ | gr , _ ->
488
+ let vars = vars_of_global env gr in
489
+ Id.Map. iter (fun id _ -> if Id.Set. mem id vars then raise (Depends id)) ids
490
+ | exception DestKO -> EConstr. iter sigma check_rec c
491
+ in
492
+ check_rec c
493
+
484
494
let rec check_and_clear_in_constr ~is_section_variable env evdref err ids ~global c =
485
495
(* returns a new constr where all the evars have been 'cleaned'
486
496
(ie the hypotheses ids have been removed from the contexts of
@@ -531,29 +541,29 @@ let rec check_and_clear_in_constr ~is_section_variable env evdref err ids ~globa
531
541
(* Check if some rid to clear in the context of ev
532
542
has dependencies in another hyp of the context of ev
533
543
and transitively remember the dependency *)
534
- let check id _ =
535
- if occur_var_in_decl env ! evdref id h
536
- then raise ( Depends id)
544
+ let () =
545
+ if not @@ Id.Map. is_empty ri then
546
+ NamedDecl. iter_constr ( fun c -> check_vars env ! evdref ri c) h
537
547
in
538
- let () = Id.Map. iter check ri in
539
548
(* No dependency at all, we can keep this ev's context hyp *)
540
549
(ri, true ::filter)
541
550
with Depends id -> (Id.Map. add (NamedDecl. get_id h) id ri, false ::filter)
542
551
in
543
552
let (rids, filter) = fold (Id.Map. empty, [] ) ctxt l in
544
- (* Check if some rid to clear in the context of ev has dependencies
545
- in the type of ev and adjust the source of the dependency *)
546
- let _nconcl : EConstr.t =
547
- try
548
- let nids = Id.Map. domain rids in
549
- let global = Id.Set. exists is_section_variable nids in
550
- let concl = evar_concl evi in
551
- check_and_clear_in_constr ~is_section_variable env evdref (EvarTypingBreak ev) nids ~global concl
552
- with ClearDependencyError (rid ,err ,where ) ->
553
- raise (ClearDependencyError (Id.Map. find rid rids,err,where)) in
554
553
555
554
if Id.Map. is_empty rids then c
556
555
else
556
+ (* Check if some rid to clear in the context of ev has dependencies
557
+ in the type of ev and adjust the source of the dependency *)
558
+ let _nconcl : EConstr.t =
559
+ try
560
+ let nids = Id.Map. domain rids in
561
+ let global = Id.Set. exists is_section_variable nids in
562
+ let concl = evar_concl evi in
563
+ check_and_clear_in_constr ~is_section_variable env evdref (EvarTypingBreak ev) nids ~global concl
564
+ with ClearDependencyError (rid ,err ,where ) ->
565
+ raise (ClearDependencyError (Id.Map. find rid rids,err,where))
566
+ in
557
567
let origfilter = Evd. evar_filter evi in
558
568
let filter = Evd.Filter. apply_subfilter origfilter filter in
559
569
let evd = ! evdref in
0 commit comments