Skip to content

Commit c0628fe

Browse files
committed
rm problematic variables under evars for evar instantiation + shelve new variable when instantiating old shelved variable with the new one in evarsolve/instantiate_evar
1 parent 0cd2a91 commit c0628fe

File tree

3 files changed

+23
-2
lines changed

3 files changed

+23
-2
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
overlay hott https://github.com/Tragicus/Coq-HoTT rocq19822 19822

pretyping/evarsolve.ml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1586,6 +1586,10 @@ let instantiate_evar unify flags env evd evk body =
15861586
let allowed_evars = AllowedEvars.remove evk flags.allowed_evars in
15871587
let flags = { flags with allowed_evars } in
15881588
let evd' = check_evar_instance unify flags env evd evk body in
1589+
let evd' = try
1590+
let evk' = fst (EConstr.destEvar evd' (fst (EConstr.decompose_app evd' body))) in
1591+
if List.mem evk (Evd.shelf evd') then Evd.shelve evd' [evk'] else evd'
1592+
with DestKO -> evd' in
15891593
Evd.define evk body evd'
15901594

15911595
(* We try to instantiate the evar assuming the body won't depend
@@ -1760,6 +1764,20 @@ let rec invert_definition unify flags choose imitate_defs
17601764
map_constr_with_full_binders env' !evdref (fun d (env,k) -> push_rel d env, k+1)
17611765
imitate envk t
17621766
with _ -> progress := p; imitate envk (whd_beta env' !evdref t))
1767+
| App (f, args) when EConstr.isEvar !evdref f ->
1768+
progress := true;
1769+
(* Tries to imitate the arguments. If this fails, i is Some i' with i' the index of the last argument we fail to imitate *)
1770+
let i, args' = Array.fold_left_map_i (fun i k a ->
1771+
try let a' = imitate envk a in (k, a')
1772+
with ex -> (Some i, a)) None args in
1773+
(match i with
1774+
| None ->
1775+
let f' = imitate envk f in
1776+
if f' == f && Array.for_all2 (==) args args' then t else EConstr.mkApp (f', args')
1777+
| Some i ->
1778+
let args, args' = Array.chop (i+1) args in
1779+
let evd, e = Evardefine.evar_absorb_arguments env !evdref (EConstr.destEvar !evdref f) (Array.to_list args) in
1780+
evdref := evd; imitate envk (EConstr.mkApp (EConstr.mkEvar e, args')))
17631781
| _ ->
17641782
progress := true;
17651783
match

test-suite/bugs/bug_3209.v

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,11 @@ Axiom bar : forall (A : Prop) (P : foo A -> Prop), (A -> P (Foo A)) -> Prop.
2727

2828
(* This used to fail with a Not_found, we fail more graciously but a
2929
heuristic could be implemented, e.g. in some smart occur-check
30-
function, to find a solution of then form ?P := fun _ => ?P' *)
30+
function, to find a solution of then form ?P := fun _ => ?P'
3131
32-
Fail Check (fun e : ?[T] => bar ?[A] ?[P] (fun g : ?[A'] => g e)).
32+
Well, now we do.*)
33+
34+
Check (fun e : ?[T] => bar ?[A] ?[P] (fun g : ?[A'] => g e)).
3335

3436
(* This works and tells which solution we could have inferred *)
3537

0 commit comments

Comments
 (0)