+ src, tgt
+ | t ->
+ debug (lazy (
+ NCicPp.ppterm ~metasenv ~subst:[] ~context:[] t));
+ assert false
+ in
+ index_coercion status c src tgt arity arg
+ with
+ | NCicEnvironment.BadDependency _
+ | NCicTypeChecker.TypeCheckerFailure _ -> status)
+ status clist)
+ status (CoercDb.to_list odb)
+;;
+
+let look_for_coercion status metasenv subst context infty expty =
+ let db_src,db_tgt = status#coerc_db in
+ match infty, expty with
+ | (NCic.Meta _ | NCic.Appl (NCic.Meta _::_)),
+ (NCic.Meta _ | NCic.Appl (NCic.Meta _::_)) -> []
+ | _ ->
+
+ debug (lazy ("LOOK FOR COERCIONS: " ^
+ NCicPp.ppterm ~metasenv ~subst ~context infty ^ " |===> " ^
+ NCicPp.ppterm ~metasenv ~subst ~context expty));
+
+ let set_src = DB.retrieve_unifiables db_src infty in
+ let set_tgt = DB.retrieve_unifiables db_tgt expty in
+ let candidates = CoercionSet.inter set_src set_tgt in
+
+ debug (lazy ("CANDIDATES: " ^
+ String.concat "," (List.map (fun (t,_,_) ->
+ NCicPp.ppterm ~metasenv ~subst ~context t)
+ (CoercionSet.elements candidates))));
+
+ List.map
+ (fun (t,arity,arg) ->
+ let ty =
+ try NCicTypeChecker.typeof ~metasenv:[] ~subst:[] [] t
+ with NCicTypeChecker.TypeCheckerFailure s ->
+ prerr_endline ("illtyped coercion: "^Lazy.force s);
+ prerr_endline (NCicPp.ppterm ~metasenv:[] ~subst:[] ~context:[] t);
+ assert false
+ in
+ let ty, metasenv, args =
+ NCicMetaSubst.saturate ~delta:max_int metasenv subst context ty arity
+ in
+
+ debug (lazy (
+ NCicPp.ppterm ~metasenv ~subst:[] ~context:[] ty ^ " --- " ^
+ NCicPp.ppterm ~metasenv ~subst ~context
+ (NCicUntrusted.mk_appl t args) ^ " --- " ^
+ string_of_int (List.length args) ^ " == " ^ string_of_int arg));
+
+ metasenv, NCicUntrusted.mk_appl t args, ty, List.nth args arg)
+ (CoercionSet.elements candidates)