Skip to content

Commit 54e54ad

Browse files
committed
try hard to find coq goals
1 parent c71ef7b commit 54e54ad

File tree

1 file changed

+34
-3
lines changed

1 file changed

+34
-3
lines changed

src/coq_elpi_HOAS.ml

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -874,6 +874,34 @@ module UVMap = struct
874874
let ruv = UVRawMap.elpi ev (S.get UVRawMap.uvmap s) in
875875
f ev ruv uv sol acc)
876876
(S.get UVElabMap.uvmap s) acc
877+
878+
exception Return of Evar.t
879+
880+
let rec morally_same_uvar ~depth uv bo =
881+
match E.look ~depth bo with
882+
| E.Lam x -> morally_same_uvar ~depth:(depth+1) uv x
883+
| E.UnifVar(ev,_) -> F.Elpi.equal ev uv
884+
| _ -> false
885+
886+
let host_upto_assignment f s =
887+
try
888+
UVElabMap.fold (fun ev _ sol _ ->
889+
match sol with
890+
| None -> () (* the fast lookup can only fail if the uvar was instantiated (as is expanded or pruned)*)
891+
| Some sol ->
892+
if f ev sol then raise (Return ev) else ())
893+
(S.get UVElabMap.uvmap s) ();
894+
raise Not_found
895+
with Return a -> a
896+
897+
let host_failsafe elab s =
898+
try
899+
UVElabMap.host elab (S.get UVElabMap.uvmap s)
900+
with Not_found ->
901+
try
902+
UVRawMap.host elab (S.get UVRawMap.uvmap s)
903+
with Not_found ->
904+
host_upto_assignment (fun evar bo -> morally_same_uvar ~depth:0 elab bo) s
877905

878906
let remove_host evar s =
879907
let s = S.update UVRawMap.uvmap s (UVRawMap.remove_host evar) in
@@ -2249,8 +2277,10 @@ let get_goal_ref ~depth syntactic_constraints state t =
22492277
| E.UnifVar(ev,scope) ->
22502278
begin try
22512279
let uv = find_evar ev syntactic_constraints in
2252-
Open {ctx; evar = UVMap.host uv state; scope; args = U.lp_list_to_list ~depth i}
2253-
with Not_found -> Not_a_goal
2280+
let evar = UVMap.host_failsafe uv state in
2281+
Open {ctx; evar; scope; args = U.lp_list_to_list ~depth i}
2282+
with Not_found ->
2283+
Not_a_goal
22542284
end
22552285
| _ -> Closed_by_side_effect
22562286
end
@@ -3375,7 +3405,8 @@ let get_global_env_current_sigma ~depth hyps constraints state =
33753405

33763406
let lp2goal ~depth hyps syntactic_constraints state t =
33773407
match get_goal_ref ~depth (E.constraints syntactic_constraints) state t with
3378-
| Closed_by_side_effect | Not_a_goal -> assert false
3408+
| Closed_by_side_effect -> assert false
3409+
| Not_a_goal -> assert false
33793410
| Open {ctx; evar = k; scope; args} ->
33803411
let state, _, changed, gl1 =
33813412
elpi_solution_to_coq_solution ~calldepth:depth syntactic_constraints state in

0 commit comments

Comments
 (0)