+ (* generation of the CIC proof *)
+ (* let metasenv' = List.filter (fun i,_,_ -> i<>goalno) metasenv in *)
+ let side_effects =
+ List.filter (fun i -> i <> goalno)
+ (ProofEngineHelpers.compare_metasenvs
+ ~newmetasenv:metasenv ~oldmetasenv:proof_menv) in
+ let goal_proof, side_effects_t =
+ let initial = Equality.add_subst subsumption_subst newproof in
+ Equality.build_goal_proof bag
+ eq_uri goalproof initial type_of_goal side_effects
+ context proof_menv
+ in
+(* Equality.draw_proof bag names goalproof newproof subsumption_id; *)
+ let goal_proof = Subst.apply_subst subsumption_subst goal_proof in
+ let real_menv = fix_metasenv (proof_menv@metasenv) in
+ let real_menv,goal_proof =
+ fix_proof real_menv context false goal_proof in
+(*
+ let real_menv,fixed_proof = fix_proof proof_menv context false goal_proof in
+ (* prerr_endline ("PROOF: " ^ CicPp.pp goal_proof names); *)
+*)
+ let pp_error goal_proof names error exn =
+ prerr_endline "THE PROOF DOES NOT TYPECHECK! <begin>";
+ prerr_endline (CicPp.pp goal_proof names);
+ prerr_endline "THE PROOF DOES NOT TYPECHECK!";
+ prerr_endline error;
+ prerr_endline "THE PROOF DOES NOT TYPECHECK! <end>";
+ raise exn
+ in
+ let old_insert_coercions = !CicRefine.insert_coercions in
+ let goal_proof,goal_ty,real_menv,_ =
+ (* prerr_endline ("parte la refine per: " ^ (CicPp.pp goal_proof names)); *)
+ try
+ debug_print (lazy (CicPp.ppterm goal_proof));
+ CicRefine.insert_coercions := false;
+ let res =
+ CicRefine.type_of_aux'
+ real_menv context goal_proof CicUniv.empty_ugraph
+ in
+ CicRefine.insert_coercions := old_insert_coercions;
+ res
+ with
+ | CicRefine.RefineFailure s
+ | CicRefine.Uncertain s
+ | CicRefine.AssertFailure s as exn ->
+ CicRefine.insert_coercions := old_insert_coercions;
+ pp_error goal_proof names (Lazy.force s) exn
+ | CicUtil.Meta_not_found i as exn ->
+ CicRefine.insert_coercions := old_insert_coercions;
+ pp_error goal_proof names ("META NOT FOUND: "^string_of_int i) exn
+ | Invalid_argument "list_fold_left2" as exn ->
+ CicRefine.insert_coercions := old_insert_coercions;
+ pp_error goal_proof names "Invalid_argument: list_fold_left2" exn
+ | exn ->
+ CicRefine.insert_coercions := old_insert_coercions;
+ raise exn
+ in
+ let subst_side_effects,real_menv,_ =
+ try
+ CicUnification.fo_unif_subst [] context real_menv
+ goal_ty type_of_goal CicUniv.empty_ugraph
+ with
+ | CicUnification.UnificationFailure s
+ | CicUnification.Uncertain s
+ | CicUnification.AssertFailure s -> assert false
+ (* fail "Maybe the local context of metas in the goal was not an IRL" s *)
+ in
+ Utils.debug_print (lazy "+++++++++++++ FINE UNIF");
+ let final_subst =
+ (goalno,(context,goal_proof,type_of_goal))::subst_side_effects
+ in
+(*
+ let metas_of_proof = Utils.metas_of_term goal_proof in
+*)
+ let proof, real_metasenv =
+ ProofEngineHelpers.subst_meta_and_metasenv_in_proof
+ proof goalno final_subst
+ (List.filter (fun i,_,_ -> i<>goalno ) real_menv)
+ in
+ let open_goals =
+ (ProofEngineHelpers.compare_metasenvs
+ ~oldmetasenv:metasenv ~newmetasenv:real_metasenv) in
+(*
+ let open_goals =
+ List.map (fun i,_,_ -> i) real_metasenv in
+*)
+ final_subst, proof, open_goals
+
+
+(*
+