Skip to content

Commit a1d9622

Browse files
author
qvermande
committed
wip
1 parent 43509de commit a1d9622

File tree

3 files changed

+36
-23
lines changed

3 files changed

+36
-23
lines changed

pretyping/evarconv.ml

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -892,12 +892,16 @@ and evar_eqappr_x ?(rhs_is_already_stuck = false) flags env evd pbty
892892
| _ -> UnifFailure (evd,NotSameHead)
893893
in
894894
let tc evd =
895-
let ty = Retyping.get_type_of env evd termF in
896-
match Typeclasses.resolve_one_typeclass env evd ty with
897-
| exception Not_found -> UnifFailure (evd, NotSameHead)
898-
| evd, c -> ise_and evd [
899-
(fun i -> evar_conv_x flags env i CONV termF c);
900-
(fun i -> switch (evar_eqappr_x flags env i pbty keys lastUnfolded) apprF apprR)] in
895+
let (e, _) = EConstr.destEvar evd termF in
896+
if not (Evd.is_typeclass_evar evd e) then UnifFailure (evd, NotSameHead) else
897+
let tc_evars = Evd.get_typeclass_evars evd in
898+
let evd = Evd.set_typeclass_evars evd (Evar.Set.singleton e) in
899+
let evd = Typeclasses.resolve_typeclasses env evd in
900+
if not (Evd.is_defined evd e) then UnifFailure (evd, NotSameHead) else
901+
let tc_evars = Evar.Set.union tc_evars (Evd.get_typeclass_evars evd) in
902+
let tc_evars = Evar.Set.filter (fun e -> not (Evd.is_defined evd e)) tc_evars in
903+
let evd = Evd.set_typeclass_evars evd tc_evars in
904+
evar_eqappr_x flags env evd pbty keys lastUnfolded (whd_nored_state env evd apprF) apprR in
901905
match Stack.list_of_app_stack skF with
902906
| None ->
903907
ise_try evd [consume_stack l2r apprF apprR; eta; tc]

pretyping/keys.ml

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ open Constr
1515
open Libobject
1616
open Globnames
1717

18+
let debug_keys = CDebug.create ~name:"keys" ()
19+
1820
type key =
1921
| KGlob of GlobRef.t
2022
| KLam
@@ -64,6 +66,23 @@ module KeyOrdered = struct
6466
| k, k' -> k == k'
6567
end
6668

69+
let pr_key pr_global k =
70+
let open Pp in
71+
match k with
72+
| KGlob gr -> pr_global gr
73+
| KLam -> str"Lambda"
74+
| KLet -> str"Let"
75+
| KProd -> str"Product"
76+
| KSort -> str"Sort"
77+
| KCase -> str"Case"
78+
| KFix -> str"Fix"
79+
| KCoFix -> str"CoFix"
80+
| KRel -> str"Rel"
81+
| KInt -> str"Int"
82+
| KFloat -> str"Float"
83+
| KString -> str"String"
84+
| KArray -> str"Array"
85+
6786
module Keymap = HMap.Make(KeyOrdered)
6887

6988
(* Mapping structure for references to be considered equivalent *)
@@ -79,8 +98,12 @@ let add_keys k ki v vi =
7998

8099
let equiv_keys k k' =
81100
if k == k' || KeyOrdered.equal k k' then Some ((0, 0)) else
82-
try Some (Keymap.find k' (Keymap.find k !keys))
83-
with Not_found -> None
101+
try let r = Some (Keymap.find k' (Keymap.find k !keys)) in
102+
let () = debug_keys (fun () -> Pp.(v 0 (pr_key Names.GlobRef.print k ++ str " = " ++ pr_key Names.GlobRef.print k' ++ cut ()))) in
103+
r
104+
with Not_found ->
105+
let () = debug_keys (fun () -> Pp.(v 0 (pr_key Names.GlobRef.print k ++ str " != " ++ pr_key Names.GlobRef.print k' ++ cut ()))) in
106+
None
84107

85108
let mkKGlob env gr = KGlob (Environ.QGlobRef.canonize env gr)
86109

@@ -150,21 +173,6 @@ let constr_key env kind c =
150173

151174
open Pp
152175

153-
let pr_key pr_global = function
154-
| KGlob gr -> pr_global gr
155-
| KLam -> str"Lambda"
156-
| KLet -> str"Let"
157-
| KProd -> str"Product"
158-
| KSort -> str"Sort"
159-
| KCase -> str"Case"
160-
| KFix -> str"Fix"
161-
| KCoFix -> str"CoFix"
162-
| KRel -> str"Rel"
163-
| KInt -> str"Int"
164-
| KFloat -> str"Float"
165-
| KString -> str"String"
166-
| KArray -> str"Array"
167-
168176
let pr_keyset pr_global v =
169177
prlist_with_sep spc (fun (k, (i, i')) -> pr_key pr_global k ++ str "(" ++ int i ++ str ", " ++ int i' ++ str ")") (Keymap.bindings v)
170178

pretyping/reductionops.mli

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,7 @@ type state_reduction_function =
302302

303303
val pr_state : env -> evar_map -> state -> Pp.t
304304

305+
(** Removes cast and puts into applicative form *)
305306
val whd_nored_state : ?metas:meta_handler -> state_reduction_function
306307

307308
val whd_betaiota_deltazeta_for_iota_state :

0 commit comments

Comments
 (0)