@@ -157,7 +157,7 @@ let e_give_exact flags h =
157157 let sigma, c = Hints. fresh_hint env sigma h in
158158 let (sigma, t1) = Typing. type_of (pf_env gl) sigma c in
159159 Proofview.Unsafe. tclEVARS sigma < *>
160- Clenv. unify ~flags t1 < *> exact_no_check c
160+ Clenv. unify ~flags ~cv_pb: CUMUL t1 < *> exact_no_check c
161161 end
162162
163163let unify_resolve ~with_evars flags h diff = match diff with
@@ -257,20 +257,18 @@ and e_my_find_search db_list local_db secvars hdc complete only_classes env sigm
257257 let nprods = List. length prods in
258258 let allowed_evars =
259259 let all = Evarsolve.AllowedEvars. all in
260- try
261- match hdc with
262- | Some (hd ,_ ) when only_classes ->
263- begin match Typeclasses. class_info hd with
264- | Some cl ->
265- if cl.cl_strict then
266- let undefined = lazy (Evarutil. undefined_evars_of_term sigma concl) in
267- let allowed evk = not (Evar.Set. mem evk (Lazy. force undefined)) in
268- Evarsolve.AllowedEvars. from_pred allowed
269- else all
270- | None -> all
271- end
272- | _ -> all
273- with e when CErrors. noncritical e -> all
260+ match hdc with
261+ | Some (hd ,_ ) when only_classes ->
262+ begin match Typeclasses. class_info hd with
263+ | Some cl ->
264+ if cl.cl_strict then
265+ let undefined = lazy (Evarutil. undefined_evars_of_term sigma concl) in
266+ let allowed evk = not (Evar.Set. mem evk (Lazy. force undefined)) in
267+ Evarsolve.AllowedEvars. from_pred allowed
268+ else all
269+ | None -> all
270+ end
271+ | _ -> all
274272 in
275273 let tac_of_hint =
276274 fun (flags , h ) ->
@@ -414,16 +412,12 @@ let evars_to_goals p evm =
414412let make_resolve_hyp env sigma st only_classes decl db =
415413 let id = NamedDecl. get_id decl in
416414 let cty = Evarutil. nf_evar sigma (NamedDecl. get_type decl) in
417- let rec iscl env ty =
415+ let iscl env ty =
418416 let ctx, ar = decompose_prod_decls sigma ty in
419417 match EConstr. kind sigma (fst (decompose_app sigma ar)) with
420418 | Const (c ,_ ) -> is_class (GlobRef. ConstRef c)
421419 | Ind (i ,_ ) -> is_class (GlobRef. IndRef i)
422- | _ ->
423- let env' = push_rel_context ctx env in
424- let ty' = Reductionops. whd_all env' sigma ar in
425- if not (EConstr. eq_constr sigma ty' ar) then iscl env' ty'
426- else false
420+ | _ -> false
427421 in
428422 let is_class = iscl env cty in
429423 let keep = not only_classes || is_class in
@@ -504,11 +498,18 @@ module Search = struct
504498 | _ , _ -> e
505499
506500 (* * Determine if backtracking is needed for this goal.
507- If the type class is unique or in Prop
508- and there are no evars in the goal then we do
509- NOT backtrack. *)
510- let needs_backtrack env evd unique concl =
511- if unique || is_Prop env evd concl then
501+ We generally backtrack except in the following (possibly
502+ overlapping) cases:
503+ - [unique_instances] is [true].
504+ This is the case when the goal's class has [Unique Instances].
505+ - [indep] is [true] and the current goal has no evars.
506+ [indep] is generally [true] and only gets set to [false] if the
507+ current goal's evar is mentioned in other goals.
508+ ([indep] is the negation of [search_dep].)
509+ - The current goal is a [Prop] and has no evars. *)
510+ let needs_backtrack env evd ~unique_instances ~indep concl =
511+ if unique_instances then false else
512+ if indep || is_Prop env evd concl then
512513 occur_existential evd concl
513514 else true
514515
@@ -530,7 +531,15 @@ module Search = struct
530531 else
531532 tclUNIT ()
532533
533- let _ = CErrors. register_handler begin function
534+ let pr_internal_exception ie =
535+ match fst ie with
536+ | ReachedLimit -> str " Proof-search reached its limit."
537+ | NoApplicableHint -> str " Proof-search failed."
538+ | StuckGoal | NonStuckFailure -> str " Proof-search got stuck."
539+ | e -> CErrors. iprint ie
540+
541+ (* XXX Is this handler needed for something? *)
542+ let () = CErrors. register_handler begin function
534543 | NonStuckFailure -> Some (str " NonStuckFailure" )
535544 | NoApplicableHint -> Some (str " NoApplicableHint" )
536545 | _ -> None
@@ -583,12 +592,12 @@ module Search = struct
583592 in
584593 cycle 1 (* Puts the first goal last *) < *>
585594 fixpoint progress tacs ((glid, ev, status, tac) :: stuck) fk (* Launches the search on the rest of the goals *)
586- | Fail ( e , info ) ->
595+ | Fail ie ->
587596 let () = ppdebug 1 (fun () ->
588597 str " Goal " ++ int glid ++ str" has no more solutions, returning exception: "
589- ++ CErrors. iprint (e, info) )
598+ ++ pr_internal_exception ie )
590599 in
591- fk (e, info)
600+ fk ie
592601 | Next (res , fk' ) ->
593602 let () = ppdebug 1 (fun () ->
594603 str " Goal " ++ int glid ++ str" has a success, continuing resolution" )
@@ -677,8 +686,9 @@ module Search = struct
677686 let env = Goal. env gl in
678687 let concl = Goal. concl gl in
679688 let sigma = Goal. sigma gl in
680- let unique = not info.search_dep || is_unique env sigma concl in
681- let backtrack = needs_backtrack env sigma unique concl in
689+ let unique_instances = is_unique env sigma concl in
690+ let indep = not info.search_dep in
691+ let backtrack = needs_backtrack env sigma ~unique_instances ~indep concl in
682692 let () = ppdebug 0 (fun () ->
683693 pr_depth info.search_depth ++ str" : looking for " ++
684694 Printer. pr_econstr_env (Goal. env gl) sigma concl ++
@@ -700,7 +710,11 @@ module Search = struct
700710 let idx = ref 1 in
701711 let foundone = ref false in
702712 let rec onetac e (tac , pat , b , name , pp ) tl =
703- let derivs = path_derivate info.search_cut name in
713+ let path = match name with
714+ | None -> PathAny
715+ | Some gr -> PathHints [gr]
716+ in
717+ let derivs = path_derivate info.search_cut path in
704718 let pr_error ie =
705719 ppdebug 1 (fun () ->
706720 let idx = if fst ie == NoApplicableHint then pred ! idx else ! idx in
@@ -711,14 +725,7 @@ module Search = struct
711725 str" on" ++ spc () ++ pr_ev sigma (Proofview.Goal. goal gl)
712726 else mt () )
713727 in
714- let msg =
715- match fst ie with
716- | ReachedLimit -> str " Proof-search reached its limit."
717- | NoApplicableHint -> str " Proof-search failed."
718- | StuckGoal | NonStuckFailure -> str " Proof-search got stuck."
719- | e -> CErrors. iprint ie
720- in
721- (header ++ str " failed with: " ++ msg))
728+ (header ++ str " failed with: " ++ pr_internal_exception ie))
722729 in
723730 let tac_of gls i j = Goal. enter begin fun gl' ->
724731 let sigma' = Goal. sigma gl' in
@@ -1029,7 +1036,7 @@ module Search = struct
10291036 in
10301037 let nongoals' =
10311038 Evar.Set. fold (fun ev acc -> match Evarutil. advance evm' ev with
1032- | Some ev' -> Evar.Set. add ev acc
1039+ | Some ev -> Evar.Set. add ev acc
10331040 | None -> acc) (Evar.Set. union goals nongoals) (Evd. get_typeclass_evars evm')
10341041 in
10351042 (* FIXME: the need to merge metas seems to come from this being called
@@ -1053,11 +1060,13 @@ module Search = struct
10531060 ~depth ~dep: (unique || dep) hints in
10541061 run_on_evars env evd p eauto_tac
10551062
1056- let typeclasses_eauto env evd ?depth unique ~best_effort st hints p =
1057- evars_eauto env evd depth true ~best_effort unique false st hints p
10581063 (* * Typeclasses eauto is an eauto which tries to resolve only
10591064 goals of typeclass type, and assumes that the initially selected
10601065 evars in evd are independent of the rest of the evars *)
1066+ let typeclasses_eauto env evd ?depth unique ~best_effort st hints p =
1067+ NewProfile. profile " typeclass search" (fun () ->
1068+ evars_eauto env evd depth true ~best_effort unique false st hints p)
1069+ ()
10611070
10621071 let typeclasses_resolve env evd depth unique ~best_effort p =
10631072 let db = searchtable_map typeclasses_db in
@@ -1317,3 +1326,15 @@ let autoapply c i =
13171326 let sigma = Typeclasses. make_unresolvables
13181327 (fun ev -> Typeclasses. all_goals ev (Lazy. from_val (snd (Evd. evar_source (Evd. find_undefined sigma ev))))) sigma in
13191328 Proofview.Unsafe. tclEVARS sigma) end
1329+
1330+ let resolve_tc c =
1331+ let open Proofview.Notations in
1332+ Proofview. tclENV >> = fun env ->
1333+ Proofview. tclEVARMAP >> = fun sigma ->
1334+ let depth = get_typeclasses_depth () in
1335+ let unique = get_typeclasses_unique_solutions () in
1336+ let evars = Evarutil. undefined_evars_of_term sigma c in
1337+ let filter = (fun ev _ -> Evar.Set. mem ev evars) in
1338+ let fail = true in
1339+ let sigma = resolve_all_evars depth unique env (initial_select_evars filter) sigma fail in
1340+ Proofview.Unsafe. tclEVARS sigma
0 commit comments