Skip to content

Commit 7a2c34a

Browse files
authored
Merge pull request #608 from LPCIC/fix-solution-to-coq
fix uvamp synchronization
2 parents f911a33 + 6912740 commit 7a2c34a

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

src/coq_elpi_HOAS.ml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -845,6 +845,7 @@ module UVMap = struct
845845
let s = S.update UVElabMap.uvmap s (UVElabMap.add elab k) in
846846
s
847847

848+
(* should we remove this "unsafe" API? *)
848849
let host elab s =
849850
try
850851
UVElabMap.host elab (S.get UVElabMap.uvmap s)
@@ -2326,11 +2327,37 @@ let show_coq_elpi_engine_mapping state =
23262327

23272328
let show_all_engine state = show_coq_engine ~with_univs:true state ^ "\n" ^ show_coq_elpi_engine_mapping state
23282329

2330+
let is_uvar ~depth t =
2331+
match E.look ~depth t with
2332+
| E.UnifVar(e,_) -> Some e
2333+
| _ -> None
2334+
23292335
let elpi_solution_to_coq_solution ~calldepth syntactic_constraints state =
23302336
let { sigma; global_env } as e = S.get engine state in
23312337

23322338
debug Pp.(fun () -> str"elpi sigma -> coq sigma: before:\n" ++ str (show_all_engine state));
23332339

2340+
(* if ?X <-> Y = Z, we have two cases:
2341+
- Z unknown ---> we update the link, i.e. ?X <-> Z (no update, the code below does it)
2342+
- ?B <-> Z ---> we propagate the unif to Coq, i.e. ?X = ?B
2343+
*)
2344+
let updates =
2345+
UVMap.fold (fun k er e elpi_solution updates ->
2346+
match elpi_solution with
2347+
| None -> updates
2348+
| Some t ->
2349+
match is_uvar ~depth:0 t with
2350+
| None -> updates
2351+
| Some e' when UVMap.mem_elpi e' state && not @@ Evar.equal k (UVMap.host_failsafe e' state) -> updates
2352+
| Some e' -> (k,er,e') :: updates
2353+
) state [] in
2354+
let state = List.fold_left (fun state (k,r,e) ->
2355+
let state = UVMap.remove_host k state in
2356+
UVMap.add k r e state
2357+
) state updates in
2358+
2359+
debug Pp.(fun () -> str"elpi sigma -> coq sigma: synchronized:\n" ++ str (show_all_engine state));
2360+
23342361
let state, assigned, changed, extra_gls =
23352362
UVMap.fold (fun k _ _ elpi_solution (state, assigned, changed, extra) ->
23362363
match elpi_solution with

0 commit comments

Comments
 (0)