From 92156ae1146916d8efb4beba59ffae091241e4e1 Mon Sep 17 00:00:00 2001 From: Enrico Tassi Date: Wed, 18 Apr 2007 09:20:57 +0000 Subject: [PATCH] handles failures (sometimes you can't inject) --- components/tactics/discriminationTactics.ml | 74 +++++++++++++-------- 1 file changed, 45 insertions(+), 29 deletions(-) diff --git a/components/tactics/discriminationTactics.ml b/components/tactics/discriminationTactics.ml index 5a25c00fa..ccbf17ae6 100644 --- a/components/tactics/discriminationTactics.ml +++ b/components/tactics/discriminationTactics.ml @@ -25,7 +25,10 @@ (* $Id$ *) -let debug_print = fun _ -> () +let debug = false +let debug_print = + if debug then (fun x -> prerr_endline (Lazy.force x)) else (fun _ -> ()) +;; (* term ha tipo t1=t2; funziona solo se t1 e t2 hanno in testa costruttori diversi *) @@ -220,7 +223,6 @@ let rec injection_tac ~first_time ~term ~liftno ~continuation = let module T = Tacticals in let module PST = ProofEngineStructuralRules in let module PET = ProofEngineTypes in -(* let prerr_endline s = prerr_endline (String.make liftno ' ' ^ s) in *) let are_convertible hd1 hd2 metasenv context = fst (CR.are_convertible ~metasenv context hd1 hd2 CicUniv.empty_ugraph) in @@ -232,7 +234,7 @@ let rec injection_tac ~first_time ~term ~liftno ~continuation = let termty,_ = CicTypeChecker.type_of_aux' metasenv context term CicUniv.empty_ugraph in -(* prerr_endline ("\ninjection su: " ^ pp context termty); *) + debug_print (lazy ("\ninjection su: " ^ pp context termty)); let tac = match termty with | C.Appl [(C.MutInd (equri, 0, [])) ; tty ; t1 ; t2] @@ -322,7 +324,6 @@ and injection1_tac ~term ~i ~liftno ~continuation = let module P = PrimitiveTactics in let module PET = ProofEngineTypes in let module T = Tacticals in -(* let prerr_endline s = prerr_endline (String.make liftno ' ' ^ s) in *) let give_name seed = function | C.Name _ as name -> name | C.Anonymous -> C.Name (incr seed; "y" ^ string_of_int !seed) @@ -339,7 +340,7 @@ and injection1_tac ~term ~i ~liftno ~continuation = let termty,_ = CicTypeChecker.type_of_aux' metasenv context term CicUniv.empty_ugraph in -(* prerr_endline ("\ninjection1 su : " ^ pp context termty); *) + debug_print (lazy ("\ninjection1 su : " ^ pp context termty)); match termty with (* an equality *) | C.Appl [(C.MutInd (equri, 0, [])) ; tty ; t1 ; t2] when LibraryObjects.is_eq_URI equri -> @@ -405,10 +406,15 @@ and injection1_tac ~term ~i ~liftno ~continuation = | _, _ -> assert false in let abstracted_tty = - match CicSubstitution.lift paramsno tty with + let tty = + List.fold_left (fun x y -> CicSubstitution.subst y x) tty left_params + in + (* non lift, ma subst coi left! *) + match S.lift 1 tty with | C.MutInd _ as tty' -> tty' | C.Appl l -> let keep,abstract = HExtlib.split_nth (paramsno +1) l in + let keep = List.map (S.lift paramsno) keep in C.Appl (keep@mk_rels (List.length abstract)) | _ -> assert false in @@ -418,7 +424,7 @@ and injection1_tac ~term ~i ~liftno ~continuation = (* this is in general wrong, do as in cases_tac *) to_lambdas (skip_prods left_params ty) (C.Lambda - (C.Name "x", abstracted_tty, + (C.Name "cased", abstracted_tty, (* here we should capture right parameters *) (* 1 for his Lambda, one for the Lambda outside the match * and then one for each to_lambda *) @@ -428,7 +434,25 @@ and injection1_tac ~term ~i ~liftno ~continuation = | _ -> raise exn_discrnonind in let cutted = C.Appl [C.MutInd (equri,0,[]) ; tty' ; t1' ; t2'] in -(* prerr_endline ("CUT: " ^ pp context cutted); *) + let changed = + C.Appl [ C.Lambda (C.Name "x", tty, + C.MutCase (turi,typeno,outtype,C.Rel 1,patterns)) ; t1] + in + (* check if cutted and changed are well typed and if t1' ~ changed *) + let go_on = + try + let _,g = CicTypeChecker.type_of_aux' metasenv context cutted + CicUniv.empty_ugraph + in + let _,g = CicTypeChecker.type_of_aux' metasenv context changed g in + fst (CicReduction.are_convertible ~metasenv context t1' changed g) + with + | CicTypeChecker.TypeCheckerFailure _ -> false + in + if not go_on then + PET.apply_tactic Tacticals.id_tac status + else + (debug_print (lazy ("CUT: " ^ pp context cutted)); PET.apply_tactic (T.thens ~start: (P.cut_tac cutted) ~continuations: @@ -441,7 +465,7 @@ and injection1_tac ~term ~i ~liftno ~continuation = ;T.then_ ~start:(PET.mk_tactic (fun status -> -(* prerr_endline "riempo il cut"; *) + debug_print (lazy "riempo il cut"); let (proof, goal) = status in let _,metasenv,_,_, _ = proof in let _,context,gty =CicUtil.lookup_meta goal metasenv in @@ -451,25 +475,17 @@ and injection1_tac ~term ~i ~liftno ~continuation = | (C.Appl (C.MutInd (_,_,_)::_::t::_)) -> t | _ -> raise exn_injwronggoal in - let changed = - C.Appl [ - C.Lambda (C.Name "x", tty, - C.MutCase (turi,typeno,outtype,C.Rel 1,patterns)) - ; t1] - in -(* - prerr_endline - ("metto questo: " ^ pp context changed); - prerr_endline - ("al posto di questo: " ^ pp context new_t1'); - prerr_endline - ("nel goal: " ^ pp context gty); - prerr_endline - ("nel contesto:\n" ^ CicPp.ppcontext context); - prerr_endline - ("e poi rewrite con: "^pp context term); -*) - let rc = + debug_print + (lazy ("metto questo: " ^ pp context changed)); + debug_print + (lazy ("al posto di questo: " ^ pp context new_t1')); + debug_print + (lazy ("nel goal: " ^ pp context gty)); + debug_print + (lazy ("nel contesto:\n" ^ CicPp.ppcontext context)); + debug_print + (lazy ("e poi rewrite con: "^pp context term)); + let rc = PET.apply_tactic (ReductionTactics.change_tac ~pattern:(None, [], @@ -488,7 +504,7 @@ and injection1_tac ~term ~i ~liftno ~continuation = term []) ~continuation:EqualityTactics.reflexivity_tac) ]) - status + status) | _ -> raise exn_noneq in PET.mk_tactic (injection1_tac ~term ~i) -- 2.39.2