@@ -285,18 +285,7 @@ let update_var src tgt subst =
285285 let csubst_var = Id.Map. add id (Constr. mkVar tgt) subst.csubst_var in
286286 { subst with csubst_var; csubst_rev }
287287
288- module VarSet =
289- struct
290- type t = Id .t -> bool
291- let empty _ = false
292- let full _ = true
293- let variables env id = is_section_variable env id
294- end
295-
296- type naming_mode = VarSet .t
297-
298288let push_rel_decl_to_named_context
299- ~hypnaming
300289 sigma decl (ext : ext_named_context ) =
301290 let open EConstr in
302291 let open Vars in
@@ -327,7 +316,7 @@ let push_rel_decl_to_named_context
327316 in
328317 match extract_if_neq id na with
329318 | Some id0 ->
330- if hypnaming id0 then
319+ if Id.Map. mem id0 ext.ext_ctx.env_named_map && is_section_variable_sign ext.ext_ctx id0 then
331320 (* spiwack: if [id0] is a section variable renaming it is
332321 incorrect. We revert to a less robust behaviour where
333322 the new binder has name [id]. Which amounts to the same
@@ -370,7 +359,7 @@ let ext_rev_subst { ext_subst = subst } id0 =
370359let default_ext_instance { ext_subst = subst ; ext_ctx = ctx } =
371360 csubst_instance subst (named_context_of_val ctx)
372361
373- let push_rel_context_to_named_context ~ hypnaming env sigma typ =
362+ let push_rel_context_to_named_context env sigma typ =
374363 (* compute the instances relative to the named context and rel_context *)
375364 let open EConstr in
376365 let ctx = named_context_val env in
@@ -384,15 +373,15 @@ let push_rel_context_to_named_context ~hypnaming env sigma typ =
384373 (* We do keep the instances corresponding to local definition (see above) *)
385374 let init = { ext_subst = empty_csubst; ext_avoid = avoid; ext_ctx = ctx } in
386375 let ext =
387- Context.Rel. fold_outside (fun d acc -> push_rel_decl_to_named_context ~hypnaming sigma d acc)
376+ Context.Rel. fold_outside (fun d acc -> push_rel_decl_to_named_context sigma d acc)
388377 (rel_context env) ~init in
389378 let inst = default_ext_instance ext in
390379 (ext.ext_ctx, csubst_subst sigma ext.ext_subst typ, inst, ext.ext_subst)
391380
392- let ext_named_context_of_env ~ hypnaming env sigma =
381+ let ext_named_context_of_env env sigma =
393382 let avoid = Environ. ids_of_named_context_val (Environ. named_context_val env) in
394383 let init = { ext_subst = empty_csubst; ext_avoid = avoid; ext_ctx = named_context_val env } in
395- Context.Rel. fold_outside (fun d acc -> push_rel_decl_to_named_context ~hypnaming sigma d acc)
384+ Context.Rel. fold_outside (fun d acc -> push_rel_decl_to_named_context sigma d acc)
396385 (EConstr. rel_context env) ~init
397386
398387(* ------------------------------------*
@@ -409,13 +398,9 @@ let next_evar_name naming = match naming with
409398(* [new_evar] declares a new existential in an env env with type typ *)
410399(* Converting the env into the sign of the evar to define *)
411400let new_evar ?src ?filter ?relevance ?abstract_arguments ?candidates ?(naming = IntroAnonymous ) ?parent ?typeclass_candidate
412- ?rrpat ? hypnaming env evd typ =
401+ ?rrpat env evd typ =
413402 let name = next_evar_name naming in
414- let hypnaming = match hypnaming with
415- | Some n -> n
416- | None -> VarSet. variables (Global. env () )
417- in
418- let sign,typ',instance,subst = push_rel_context_to_named_context ~hypnaming env evd typ in
403+ let sign,typ',instance,subst = push_rel_context_to_named_context env evd typ in
419404 let map c = csubst_subst evd subst c in
420405 let candidates = Option. map (fun l -> List. map map l) candidates in
421406 let instance =
@@ -430,10 +415,10 @@ let new_evar ?src ?filter ?relevance ?abstract_arguments ?candidates ?(naming =
430415 ?typeclass_candidate in
431416 (evd, EConstr. mkEvar (evk, instance))
432417
433- let new_type_evar ?src ?filter ?naming ? hypnaming env evd rigid =
418+ let new_type_evar ?src ?filter ?naming env evd rigid =
434419 let (evd', s) = new_sort_variable rigid evd in
435420 let relevance = EConstr.ESorts. relevance_of_sort s in
436- let (evd', e) = new_evar env evd' ?src ?filter ~relevance ?naming ~typeclass_candidate: false ?hypnaming (EConstr. mkSort s) in
421+ let (evd', e) = new_evar env evd' ?src ?filter ~relevance ?naming ~typeclass_candidate: false (EConstr. mkSort s) in
437422 evd', (e, s)
438423
439424let new_Type ?(rigid =Evd. univ_flexible) evd =
@@ -518,7 +503,7 @@ let check_vars env sigma ids c =
518503 in
519504 check_rec c
520505
521- let rec check_and_clear_in_constr ~ is_section_variable env evdref err ids ~global c =
506+ let rec check_and_clear_in_constr env evdref err ids ~global c =
522507 (* returns a new constr where all the evars have been 'cleaned'
523508 (ie the hypotheses ids have been removed from the contexts of
524509 evars). [global] should be true iff there is some variable of [ids] which
@@ -585,9 +570,10 @@ let rec check_and_clear_in_constr ~is_section_variable env evdref err ids ~globa
585570 let _nconcl : EConstr.t =
586571 try
587572 let nids = Id.Map. domain rids in
588- let global = Id.Set. exists is_section_variable nids in
573+ let env = evar_filtered_env env evi in
574+ let global = Id.Set. exists (is_section_variable' env) nids in
589575 let concl = evar_concl evi in
590- check_and_clear_in_constr ~is_section_variable env evdref (EvarTypingBreak ev) nids ~global concl
576+ check_and_clear_in_constr env evdref (EvarTypingBreak ev) nids ~global concl
591577 with ClearDependencyError (rid ,err ,where ) ->
592578 raise (ClearDependencyError (Id.Map. find rid rids,err,where))
593579 in
@@ -599,31 +585,31 @@ let rec check_and_clear_in_constr ~is_section_variable env evdref err ids ~globa
599585 evdref := evd;
600586 Evd. existential_value ! evdref ev
601587
602- | _ -> EConstr. map ! evdref (check_and_clear_in_constr ~is_section_variable env evdref err ids ~global ) c
588+ | _ -> EConstr. map ! evdref (check_and_clear_in_constr env evdref err ids ~global ) c
603589
604590let clear_hyps_in_evi_main env sigma hyps terms ids =
605591 (* clear_hyps_in_evi erases hypotheses ids in hyps, checking if some
606592 hypothesis does not depend on a element of ids, and erases ids in
607593 the contexts of the evars occurring in evi *)
608594 let evdref = ref sigma in
609- let is_section_variable id = is_section_variable (Global. env () ) id in
610- let global = Id.Set. exists is_section_variable ids in
595+ let global = Id.Set. exists (is_section_variable' env) ids in
611596 let terms =
612- List. map (check_and_clear_in_constr ~is_section_variable env evdref (OccurHypInSimpleClause None ) ids ~global ) terms in
597+ List. map (check_and_clear_in_constr env evdref (OccurHypInSimpleClause None ) ids ~global ) terms in
613598 let nhyps =
614599 let check_context decl =
615600 let decl = EConstr. of_named_decl decl in
616601 let err = OccurHypInSimpleClause (Some (NamedDecl. get_id decl)) in
617- EConstr.Unsafe. to_named_decl @@ NamedDecl. map_constr (check_and_clear_in_constr ~is_section_variable env evdref err ids ~global ) decl
602+ EConstr.Unsafe. to_named_decl @@ NamedDecl. map_constr (check_and_clear_in_constr env evdref err ids ~global ) decl
618603 in
619604 remove_hyps ids check_context hyps
620605 in
621606 (! evdref, nhyps, terms)
622607
623608let check_and_clear_in_constr env evd err ids c =
624609 let evdref = ref evd in
610+ let global = Id.Set. exists (is_section_variable' env) ids in
625611 let _ : EConstr.constr = check_and_clear_in_constr
626- ~is_section_variable: ( fun _ -> true ) ~ global: true
612+ ~global
627613 env evdref err ids c
628614 in
629615 ! evdref
0 commit comments