From: Ferruccio Guidi Date: Thu, 31 Aug 2006 17:41:07 +0000 (+0000) Subject: - semantics of tactic subst allmost fixed X-Git-Tag: 0.4.95@7852~1097 X-Git-Url: http://matita.cs.unibo.it/gitweb/?a=commitdiff_plain;h=dab40d3f522ad5e31a6b8967840c7b36937de83c;p=helm.git - semantics of tactic subst allmost fixed - new tactical progress implemented (not working yet :( ) --- diff --git a/components/grafite/grafiteAst.ml b/components/grafite/grafiteAst.ml index 54924ff4c..b4c18726c 100644 --- a/components/grafite/grafiteAst.ml +++ b/components/grafite/grafiteAst.ml @@ -143,6 +143,7 @@ type ('term, 'lazy_term, 'reduction, 'ident) tactical = | Try of loc * ('term, 'lazy_term, 'reduction, 'ident) tactical (* try a tactical and mask failures *) | Solve of loc * ('term, 'lazy_term, 'reduction, 'ident) tactical list + | Progress of loc * ('term, 'lazy_term, 'reduction, 'ident) tactical | Dot of loc | Semicolon of loc diff --git a/components/grafite/grafiteAstPp.ml b/components/grafite/grafiteAstPp.ml index e1855014d..c7db02872 100644 --- a/components/grafite/grafiteAstPp.ml +++ b/components/grafite/grafiteAstPp.ml @@ -248,6 +248,7 @@ let rec pp_tactical ~term_pp ~lazy_term_pp = | First (_, tacs) -> sprintf "tries [%s]" (pp_tacticals ~sep:" | " tacs) | Try (_, tac) -> "try " ^ pp_tactical ~term_pp ~lazy_term_pp tac | Solve (_, tac) -> sprintf "solve [%s]" (pp_tacticals ~sep:" | " tac) + | Progress (_, tac) -> "progress " ^ pp_tactical ~term_pp ~lazy_term_pp tac | Dot _ -> "." | Semicolon _ -> ";" diff --git a/components/grafite_engine/grafiteEngine.ml b/components/grafite_engine/grafiteEngine.ml index 4a9254845..9e524b377 100644 --- a/components/grafite_engine/grafiteEngine.ml +++ b/components/grafite_engine/grafiteEngine.ml @@ -25,6 +25,8 @@ (* $Id$ *) +module GT = GrafiteTypes + open Printf exception Drop @@ -32,7 +34,7 @@ exception Drop exception IncludedFileNotCompiled of string * string exception Macro of GrafiteAst.loc * - (Cic.context -> GrafiteTypes.status * Cic.term GrafiteAst.macro) + (Cic.context -> GT.status * Cic.term GrafiteAst.macro) exception ReadOnlyUri of string type 'a disambiguator_input = string * int * 'a @@ -297,13 +299,13 @@ let reorder_metasenv start refine tactic goals current_goal always_opens_a_goal= let apply_tactic ~disambiguate_tactic (text,prefix_len,tactic) (status, goal) = (* prerr_endline "apply_tactic"; *) -(* prerr_endline (Continuationals.Stack.pp (GrafiteTypes.get_stack status)); *) - let starting_metasenv = GrafiteTypes.get_proof_metasenv status in +(* prerr_endline (Continuationals.Stack.pp (GT.get_stack status)); *) + let starting_metasenv = GT.get_proof_metasenv status in let before = List.map (fun g, _, _ -> g) starting_metasenv in (* prerr_endline "disambiguate"; *) let status, tactic = disambiguate_tactic status goal (text,prefix_len,tactic) in - let metasenv_after_refinement = GrafiteTypes.get_proof_metasenv status in - let proof = GrafiteTypes.get_current_proof status in + let metasenv_after_refinement = GT.get_proof_metasenv status in + let proof = GT.get_current_proof status in let proof_status = proof, goal in let needs_reordering, always_opens_a_goal = classify_tactic tactic in let tactic = tactic_of_ast tactic in @@ -335,82 +337,82 @@ prerr_endline("closed_goals: " ^ String.concat ", " (List.map string_of_int clos proof, opened_goals in let incomplete_proof = - match status.GrafiteTypes.proof_status with - | GrafiteTypes.Incomplete_proof p -> p + match status.GT.proof_status with + | GT.Incomplete_proof p -> p | _ -> assert false in - { status with GrafiteTypes.proof_status = - GrafiteTypes.Incomplete_proof - { incomplete_proof with GrafiteTypes.proof = proof } }, + { status with GT.proof_status = + GT.Incomplete_proof + { incomplete_proof with GT.proof = proof } }, opened_goals, closed_goals type eval_ast = {ea_go: 'term 'lazy_term 'reduction 'obj 'ident. disambiguate_tactic: - (GrafiteTypes.status -> + (GT.status -> ProofEngineTypes.goal -> (('term, 'lazy_term, 'reduction, 'ident) GrafiteAst.tactic) disambiguator_input -> - GrafiteTypes.status * + GT.status * (Cic.term, Cic.lazy_term, Cic.lazy_term GrafiteAst.reduction, string) GrafiteAst.tactic) -> disambiguate_command: - (GrafiteTypes.status -> + (GT.status -> ('obj GrafiteAst.command) disambiguator_input -> - GrafiteTypes.status * Cic.obj GrafiteAst.command) -> + GT.status * Cic.obj GrafiteAst.command) -> disambiguate_macro: - (GrafiteTypes.status -> + (GT.status -> ('term GrafiteAst.macro) disambiguator_input -> - Cic.context -> GrafiteTypes.status * Cic.term GrafiteAst.macro) -> + Cic.context -> GT.status * Cic.term GrafiteAst.macro) -> ?do_heavy_checks:bool -> ?clean_baseuri:bool -> - GrafiteTypes.status -> + GT.status -> (('term, 'lazy_term, 'reduction, 'obj, 'ident) GrafiteAst.statement) disambiguator_input -> - GrafiteTypes.status * UriManager.uri list + GT.status * UriManager.uri list } type 'a eval_command = {ec_go: 'term 'obj. disambiguate_command: - (GrafiteTypes.status -> ('obj GrafiteAst.command) disambiguator_input -> - GrafiteTypes.status * Cic.obj GrafiteAst.command) -> - options -> GrafiteTypes.status -> + (GT.status -> ('obj GrafiteAst.command) disambiguator_input -> + GT.status * Cic.obj GrafiteAst.command) -> + options -> GT.status -> ('obj GrafiteAst.command) disambiguator_input -> - GrafiteTypes.status * UriManager.uri list + GT.status * UriManager.uri list } type 'a eval_executable = {ee_go: 'term 'lazy_term 'reduction 'obj 'ident. disambiguate_tactic: - (GrafiteTypes.status -> + (GT.status -> ProofEngineTypes.goal -> (('term, 'lazy_term, 'reduction, 'ident) GrafiteAst.tactic) disambiguator_input -> - GrafiteTypes.status * + GT.status * (Cic.term, Cic.lazy_term, Cic.lazy_term GrafiteAst.reduction, string) GrafiteAst.tactic) -> disambiguate_command: - (GrafiteTypes.status -> + (GT.status -> ('obj GrafiteAst.command) disambiguator_input -> - GrafiteTypes.status * Cic.obj GrafiteAst.command) -> + GT.status * Cic.obj GrafiteAst.command) -> disambiguate_macro: - (GrafiteTypes.status -> + (GT.status -> ('term GrafiteAst.macro) disambiguator_input -> - Cic.context -> GrafiteTypes.status * Cic.term GrafiteAst.macro) -> + Cic.context -> GT.status * Cic.term GrafiteAst.macro) -> options -> - GrafiteTypes.status -> + GT.status -> (('term, 'lazy_term, 'reduction, 'obj, 'ident) GrafiteAst.code) disambiguator_input -> - GrafiteTypes.status * UriManager.uri list + GT.status * UriManager.uri list } type 'a eval_from_moo = - { efm_go: GrafiteTypes.status -> string -> GrafiteTypes.status } + { efm_go: GT.status -> string -> GT.status } let coercion_moo_statement_of uri = GrafiteAst.Coercion (HExtlib.dummy_floc, uri, false) @@ -444,18 +446,18 @@ let eval_coercion status ~add_composites uri = let moo_content = List.map coercion_moo_statement_of (uri::compounds) in - let status = GrafiteTypes.add_moo_content moo_content status in - {status with GrafiteTypes.proof_status = GrafiteTypes.No_proof}, + let status = GT.add_moo_content moo_content status in + {status with GT.proof_status = GT.No_proof}, compounds let eval_tactical ~disambiguate_tactic status tac = let apply_tactic = apply_tactic ~disambiguate_tactic in let module MatitaStatus = struct - type input_status = GrafiteTypes.status * ProofEngineTypes.goal + type input_status = GT.status * ProofEngineTypes.goal type output_status = - GrafiteTypes.status * ProofEngineTypes.goal list * ProofEngineTypes.goal list + GT.status * ProofEngineTypes.goal list * ProofEngineTypes.goal list type tactic = input_status -> output_status @@ -464,10 +466,20 @@ let eval_tactical ~disambiguate_tactic status tac = let apply_tactic tac = tac let goals (_, opened, closed) = opened, closed let set_goals (opened, closed) (status, _, _) = (status, opened, closed) - let get_stack (status, _) = GrafiteTypes.get_stack status + let get_stack (status, _) = GT.get_stack status + + let get_status (status, goal) = + match status.GT.proof_status with + | GT.Incomplete_proof incomplete -> incomplete.GT.proof, goal + | _ -> assert false + + let get_proof (status, _, _) = + match status.GT.proof_status with + | GT.Incomplete_proof incomplete -> incomplete.GT.proof + | _ -> assert false let set_stack stack (status, opened, closed) = - GrafiteTypes.set_stack stack status, opened, closed + GT.set_stack stack status, opened, closed let inject (status, _) = (status, [], []) let focus goal (status, _, _) = (status, goal) @@ -499,6 +511,8 @@ let eval_tactical ~disambiguate_tactic status tac = | GrafiteAst.Solve (loc, tacticals) -> MatitaTacticals.solve_tactics ~tactics:(List.map (fun t -> "", tactical_of_ast (l+1) t) tacticals) + | GrafiteAst.Progress (loc, tactical) -> + MatitaTacticals.progress_tactic ~tactic:(tactical_of_ast (l+1) tactical) | GrafiteAst.Skip _loc -> MatitaTacticals.skip | GrafiteAst.Dot _loc -> MatitaTacticals.dot @@ -513,11 +527,11 @@ let eval_tactical ~disambiguate_tactic status tac = in let status, _, _ = tactical_of_ast 0 tac (status, ~-1) in let status = (* is proof completed? *) - match status.GrafiteTypes.proof_status with - | GrafiteTypes.Incomplete_proof - { GrafiteTypes.stack = stack; proof = proof } + match status.GT.proof_status with + | GT.Incomplete_proof + { GT.stack = stack; proof = proof } when Continuationals.Stack.is_empty stack -> - { status with GrafiteTypes.proof_status = GrafiteTypes.Proof proof } + { status with GT.proof_status = GT.Proof proof } | _ -> status in status @@ -550,7 +564,7 @@ let add_coercions_of_record_to_moo obj lemmas status = | (name,true) -> Some (UriManager.uri_of_string - (GrafiteTypes.qualify status name ^ ".con")) + (GT.qualify status name ^ ".con")) | _ -> None) fields in @@ -579,9 +593,9 @@ let add_coercions_of_record_to_moo obj lemmas status = List.iter (fun u -> prerr_endline (UriManager.string_of_uri u)) lemmas; *) - let status = GrafiteTypes.add_moo_content moo_content status in + let status = GT.add_moo_content moo_content status in {status with - GrafiteTypes.coercions = coercions @ status.GrafiteTypes.coercions}, + GT.coercions = coercions @ status.GT.coercions}, lemmas let add_obj uri obj status = @@ -594,13 +608,13 @@ let rec eval_command = {ec_go = fun ~disambiguate_command opts status let status,uris = match cmd with | GrafiteAst.Print (_,"proofterm") -> - let _,_,p,_ = GrafiteTypes.get_current_proof status in + let _,_,p,_ = GT.get_current_proof status in print_endline (AutoTactic.pp_proofterm p); status,[] | GrafiteAst.Print (_,_) -> status,[] | GrafiteAst.Default (loc, what, uris) as cmd -> LibraryObjects.set_default what uris; - GrafiteTypes.add_moo_content [cmd] status,[] + GT.add_moo_content [cmd] status,[] | GrafiteAst.Include (loc, baseuri) -> let moopath_rw, moopath_r = LibraryMisc.obj_file_of_baseuri @@ -621,7 +635,7 @@ let rec eval_command = {ec_go = fun ~disambiguate_command opts status let v = Http_getter_misc.strip_trailing_slash value in try ignore (String.index v ' '); - GrafiteTypes.command_error "baseuri can't contain spaces" + GT.command_error "baseuri can't contain spaces" with Not_found -> v in if Http_getter_storage.is_read_only value then begin @@ -643,29 +657,29 @@ let rec eval_command = {ec_go = fun ~disambiguate_command opts status (Filename.dirname (Http_getter.filename ~writable:true (value ^ "/foo.con"))); end; - GrafiteTypes.set_option status name value,[] + GT.set_option status name value,[] | GrafiteAst.Drop loc -> raise Drop | GrafiteAst.Qed loc -> let uri, metasenv, bo, ty = - match status.GrafiteTypes.proof_status with - | GrafiteTypes.Proof (Some uri, metasenv, body, ty) -> + match status.GT.proof_status with + | GT.Proof (Some uri, metasenv, body, ty) -> uri, metasenv, body, ty - | GrafiteTypes.Proof (None, metasenv, body, ty) -> - raise (GrafiteTypes.Command_error + | GT.Proof (None, metasenv, body, ty) -> + raise (GT.Command_error ("Someone allows to start a theorem without giving the "^ "name/uri. This should be fixed!")) | _-> raise - (GrafiteTypes.Command_error "You can't Qed an incomplete theorem") + (GT.Command_error "You can't Qed an incomplete theorem") in if metasenv <> [] then raise - (GrafiteTypes.Command_error + (GT.Command_error "Proof not completed! metasenv is not empty!"); let name = UriManager.name_of_uri uri in let obj = Cic.Constant (name,Some bo,ty,[],[]) in let status, lemmas = add_obj uri obj status in - {status with GrafiteTypes.proof_status = GrafiteTypes.No_proof}, + {status with GT.proof_status = GT.No_proof}, uri::lemmas | GrafiteAst.Coercion (loc, uri, add_composites) -> eval_coercion status ~add_composites uri @@ -679,9 +693,9 @@ let rec eval_command = {ec_go = fun ~disambiguate_command opts status (match types with (name,_,_,_)::_ -> name | _ -> assert false) | _ -> assert false in let uri = - UriManager.uri_of_string (GrafiteTypes.qualify status name ^ ext) in + UriManager.uri_of_string (GT.qualify status name ^ ext) in let obj = CicRefine.pack_coercion_obj obj in - let metasenv = GrafiteTypes.get_proof_metasenv status in + let metasenv = GT.get_proof_metasenv status in match obj with | Cic.CurrentProof (_,metasenv',bo,ty,_,_) -> let name = UriManager.name_of_uri uri in @@ -717,25 +731,25 @@ let rec eval_command = {ec_go = fun ~disambiguate_command opts status end; let initial_proof = (Some uri, metasenv', bo, ty) in let initial_stack = Continuationals.Stack.of_metasenv metasenv' in - { status with GrafiteTypes.proof_status = - GrafiteTypes.Incomplete_proof - { GrafiteTypes.proof = initial_proof; stack = initial_stack } }, + { status with GT.proof_status = + GT.Incomplete_proof + { GT.proof = initial_proof; stack = initial_stack } }, [] | _ -> if metasenv <> [] then - raise (GrafiteTypes.Command_error ( + raise (GT.Command_error ( "metasenv not empty while giving a definition with body: " ^ CicMetaSubst.ppmetasenv [] metasenv)); let status, lemmas = add_obj uri obj status in let status,new_lemmas = add_coercions_of_record_to_moo obj lemmas status in - {status with GrafiteTypes.proof_status = GrafiteTypes.No_proof}, + {status with GT.proof_status = GT.No_proof}, uri::new_lemmas@lemmas in - match status.GrafiteTypes.proof_status with - GrafiteTypes.Intermediate _ -> - {status with GrafiteTypes.proof_status = GrafiteTypes.No_proof},uris + match status.GT.proof_status with + GT.Intermediate _ -> + {status with GT.proof_status = GT.No_proof},uris | _ -> status,uris } and eval_executable = {ee_go = fun ~disambiguate_tactic ~disambiguate_command diff --git a/components/grafite_parser/grafiteParser.ml b/components/grafite_parser/grafiteParser.ml index 16f7998d1..c4e12ac08 100644 --- a/components/grafite_parser/grafiteParser.ml +++ b/components/grafite_parser/grafiteParser.ml @@ -327,6 +327,7 @@ EXTEND | IDENT "solve"; SYMBOL "["; tacs = LIST0 SELF SEP SYMBOL "|"; SYMBOL "]"-> GrafiteAst.Solve (loc, tacs) + | IDENT "progress"; tac = SELF -> GrafiteAst.Progress (loc, tac) | LPAREN; tac = SELF; RPAREN -> tac | tac = tactic -> GrafiteAst.Tactic (loc, tac) ] diff --git a/components/tactics/continuationals.ml b/components/tactics/continuationals.ml index 93695fa93..6bb419c03 100644 --- a/components/tactics/continuationals.ml +++ b/components/tactics/continuationals.ml @@ -180,6 +180,8 @@ sig val mk_tactic : (input_status -> output_status) -> tactic val apply_tactic : tactic -> input_status -> output_status + val get_status: input_status -> ProofEngineTypes.status + val get_proof: output_status -> ProofEngineTypes.proof val goals : output_status -> goal list * goal list (** opened, closed goals *) val set_goals: goal list * goal list -> output_status -> output_status val get_stack : input_status -> Stack.t diff --git a/components/tactics/continuationals.mli b/components/tactics/continuationals.mli index 6383b97bf..f9a17a942 100644 --- a/components/tactics/continuationals.mli +++ b/components/tactics/continuationals.mli @@ -84,6 +84,8 @@ sig val mk_tactic : (input_status -> output_status) -> tactic val apply_tactic : tactic -> input_status -> output_status + val get_status: input_status -> ProofEngineTypes.status + val get_proof: output_status -> ProofEngineTypes.proof val goals : output_status -> goal list * goal list (** opened, closed goals *) val set_goals: goal list * goal list -> output_status -> output_status val get_stack : input_status -> Stack.t diff --git a/components/tactics/equalityTactics.ml b/components/tactics/equalityTactics.ml index 8760f36ef..5a07e4e63 100644 --- a/components/tactics/equalityTactics.ml +++ b/components/tactics/equalityTactics.ml @@ -34,6 +34,7 @@ module PESR = ProofEngineStructuralRules module P = PrimitiveTactics module T = Tacticals module R = CicReduction +module S = CicSubstitution module TC = CicTypeChecker module LO = LibraryObjects module DTI = DoubleTypeInference @@ -52,7 +53,7 @@ let rec rewrite_tac ~direction ~(pattern: ProofEngineTypes.lazy_pattern) equalit (rewrite_tac ~direction ~pattern:(None,[he],None) equality) (rewrite_tac ~direction ~pattern:(None,tl,concl_pat) - (CicSubstitution.lift 1 equality)) + (S.lift 1 equality)) ) status | [_] as hyps_pat when concl_pat <> None -> PET.apply_tactic @@ -60,7 +61,7 @@ let rec rewrite_tac ~direction ~(pattern: ProofEngineTypes.lazy_pattern) equalit (rewrite_tac ~direction ~pattern:(None,hyps_pat,None) equality) (rewrite_tac ~direction ~pattern:(None,[],concl_pat) - (CicSubstitution.lift 1 equality)) + (S.lift 1 equality)) ) status | _ -> let arg,dir2,tac,concl_pat,gty = @@ -71,7 +72,7 @@ let rec rewrite_tac ~direction ~(pattern: ProofEngineTypes.lazy_pattern) equalit function [] -> assert false | Some (Cic.Name s,Cic.Decl ty)::_ when name = s -> - Cic.Rel n, CicSubstitution.lift n ty + Cic.Rel n, S.lift n ty | Some (Cic.Name s,Cic.Def _)::_ -> assert false (*CSC: not implemented yet! But does this make any sense?*) | _::tl -> find_hyp (n+1) tl in @@ -129,15 +130,15 @@ let rec rewrite_tac ~direction ~(pattern: ProofEngineTypes.lazy_pattern) equalit let fresh_name = FreshNamesGenerator.mk_fresh_name ~subst:[] metasenv' context C.Anonymous ~typ:ty in - let lifted_t1 = CicSubstitution.lift 1 t1x in - let lifted_gty = CicSubstitution.lift 1 gty in + let lifted_t1 = S.lift 1 t1x in + let lifted_gty = S.lift 1 gty in let lifted_conjecture = metano,(Some (fresh_name,Cic.Decl ty))::context,lifted_gty in let lifted_pattern = let lifted_concl_pat = match concl_pat with | None -> None - | Some term -> Some (CicSubstitution.lift 1 term) in + | Some term -> Some (S.lift 1 term) in Some (fun _ m u -> lifted_t1, m, u),[],lifted_concl_pat in let subst,metasenv',ugraph,_,selected_terms_with_context = @@ -168,13 +169,13 @@ let rec rewrite_tac ~direction ~(pattern: ProofEngineTypes.lazy_pattern) equalit let metasenv',arg,newtyp = match arg with None -> - let gty' = CicSubstitution.subst t2 abstr_gty in + let gty' = S.subst t2 abstr_gty in let irl = CicMkImplicit.identity_relocation_list_for_metavariable context in let metasenv' = (fresh_meta,context,gty')::metasenv' in metasenv', C.Meta (fresh_meta,irl), Cic.Rel (-1) (* dummy term, never used *) | Some arg -> - let gty' = CicSubstitution.subst t1 abstr_gty in + let gty' = S.subst t1 abstr_gty in metasenv',arg,gty' in let exact_proof = @@ -278,9 +279,9 @@ let replace_tac ~(pattern: ProofEngineTypes.lazy_pattern) ~with_what = match whats with [] -> ProofEngineTypes.apply_tactic T.id_tac status | (what,lazy_pattern)::tl -> - let what = CicSubstitution.lift n what in - let with_what = CicSubstitution.lift n with_what in - let ty_of_with_what = CicSubstitution.lift n ty_of_with_what in + let what = S.lift n what in + let with_what = S.lift n with_what in + let ty_of_with_what = S.lift n ty_of_with_what in ProofEngineTypes.apply_tactic (T.thens ~start:( @@ -374,6 +375,18 @@ let try_tactic ~tactic = in PET.mk_tactic try_tactic +let rec lift_rewrite_tac ~context ~direction ~pattern equality = + let lift_rewrite_tac status = + let (proof, goal) = status in + let (_, metasenv, _, _) = proof in + let _, new_context, _ = CicUtil.lookup_meta goal metasenv in + let n = List.length new_context - List.length context in + let equality = if n > 0 then S.lift n equality else equality in + PET.apply_tactic (rewrite_tac ~direction ~pattern equality) status + in + PET.mk_tactic lift_rewrite_tac + + let msg0 = lazy "Subst: not found in context" let msg1 = lazy "Subst: not a simple equality" let msg2 = lazy "Subst: recursive equation" @@ -397,7 +410,8 @@ let subst_tac ~hyp = | _ -> raise (PET.Fail msg1) in let rewrite pattern = - try_tactic ~tactic:(rewrite_tac ~direction ~pattern what) + let tactic = lift_rewrite_tac ~context ~direction ~pattern what in + try_tactic ~tactic in let var = match PEH.get_name context i with | Some name -> name diff --git a/components/tactics/tacticals.ml b/components/tactics/tacticals.ml index 88e2f4b9e..28bd71b2d 100644 --- a/components/tactics/tacticals.ml +++ b/components/tactics/tacticals.ml @@ -38,23 +38,25 @@ let debug_print = fun _ -> () (** debugging print *) let info s = debug_print (lazy ("TACTICALS INFO: " ^ (Lazy.force s))) +module PET = ProofEngineTypes + let id_tac = let id_tac (proof,goal) = let _, metasenv, _, _ = proof in let _, _, _ = CicUtil.lookup_meta goal metasenv in (proof,[goal]) in - ProofEngineTypes.mk_tactic id_tac + PET.mk_tactic id_tac let fail_tac = let fail_tac (proof,goal) = let _, metasenv, _, _ = proof in let _, _, _ = CicUtil.lookup_meta goal metasenv in - raise (ProofEngineTypes.Fail (lazy "fail tactical")) + raise (PET.Fail (lazy "fail tactical")) in - ProofEngineTypes.mk_tactic fail_tac + PET.mk_tactic fail_tac -type goal = ProofEngineTypes.goal +type goal = PET.goal (** TODO needed until tactics start returning both opened and closed goals * First part of the function performs a diff among goals ~before tactic @@ -97,6 +99,7 @@ sig val do_tactic: n: int -> tactic: tactic -> tactic val try_tactic: tactic: tactic -> tactic val solve_tactics: tactics: (string * tactic) list -> tactic + val progress_tactic: tactic: tactic -> tactic val tactic: tactic -> tactic val skip: tactic @@ -141,7 +144,7 @@ struct with e -> match e with - | (ProofEngineTypes.Fail _) + | (PET.Fail _) | (CicTypeChecker.TypeCheckerFailure _) | (CicUnification.UnificationFailure _) -> info (lazy ( @@ -149,7 +152,7 @@ struct Printexc.to_string e)); first ~tactics istatus | _ -> raise e) (* [e] must not be caught ; let's re-raise it *) - | [] -> raise (ProofEngineTypes.Fail (lazy "first: no tactics left")) + | [] -> raise (PET.Fail (lazy "first: no tactics left")) in S.mk_tactic (first ~tactics) @@ -210,7 +213,7 @@ struct in S.set_goals (opened', closed') output_status with - (ProofEngineTypes.Fail _) as e -> + (PET.Fail _) as e -> info (lazy ("Tacticals.repeat_tactic failed after nth time with exception: " ^ Printexc.to_string e)); @@ -232,7 +235,7 @@ struct in S.set_goals (opened', closed') output_status with - (ProofEngineTypes.Fail _) as e -> + (PET.Fail _) as e -> info (lazy ("Tacticals.do_tactic failed after nth time with exception: " ^ Printexc.to_string e)) ; @@ -247,7 +250,7 @@ struct try S.apply_tactic tactic status with - (ProofEngineTypes.Fail _) as e -> + (PET.Fail _) as e -> info (lazy ( "Tacticals.try_tactic failed with exn: " ^ Printexc.to_string e)); S.apply_tactic S.id_tactic status @@ -275,18 +278,35 @@ struct | _ -> info (lazy ("Tacticals.solve_tactics: try the next tactic")); solve_tactics ~tactics:(moretactics) status with - (ProofEngineTypes.Fail _) as e -> + (PET.Fail _) as e -> info (lazy ( "Tacticals.solve_tactics: current tactic failed with exn: " ^ Printexc.to_string e)); solve_tactics ~tactics status ) | [] -> - raise (ProofEngineTypes.Fail + raise (PET.Fail (lazy "solve_tactics cannot solve the goal")) in S.mk_tactic (solve_tactics ~tactics) + let progress_tactic ~tactic = + let msg = lazy "Failed to progress" in + let get_sequent (proof, goal) = + let (_, metasenv, _, _) = proof in + let _, context, ty = CicUtil.lookup_meta goal metasenv in + context, ty + in + let progress_tactic ist = + let before = get_sequent (S.get_status ist) in + let ost = S.apply_tactic tactic ist in + match S.goals ost with + | [goal], _ when before <> get_sequent (S.get_proof ost, goal) -> + raise (PET.Fail msg) + | _ -> ost + in + S.mk_tactic progress_tactic + let cont_proxy cont = S.mk_tactic (C.eval cont) let tactic t = cont_proxy (C.Tactical (C.Tactic t)) @@ -307,17 +327,17 @@ struct module Stack = Continuationals.Stack type input_status = - ProofEngineTypes.status (* (proof, goal) *) * Stack.t + PET.status (* (proof, goal) *) * Stack.t type output_status = - (ProofEngineTypes.proof * goal list * goal list) * Stack.t + (PET.proof * goal list * goal list) * Stack.t - type tactic = ProofEngineTypes.tactic + type tactic = PET.tactic let id_tactic = id_tac let mk_tactic f = - ProofEngineTypes.mk_tactic + PET.mk_tactic (fun (proof, goal) as pstatus -> let stack = [ [ 1, Stack.Open goal ], [], [], `NoTag ] in let istatus = pstatus, stack in @@ -328,14 +348,17 @@ struct proof, opened) let apply_tactic tac ((proof, _) as pstatus, stack) = - let proof', opened = ProofEngineTypes.apply_tactic tac pstatus in + let proof', opened = PET.apply_tactic tac pstatus in (* let _ = prerr_endline ("goal aperti dalla tattica " ^ String.concat "," (List.map string_of_int opened)) in *) - let before = ProofEngineTypes.goals_of_proof proof in - let after = ProofEngineTypes.goals_of_proof proof' in + let before = PET.goals_of_proof proof in + let after = PET.goals_of_proof proof' in let opened_goals, closed_goals = goals_diff ~before ~after ~opened in (* let _ = prerr_endline ("goal ritornati dalla tattica " ^ String.concat "," (List.map string_of_int opened_goals)) in *) (proof', opened_goals, closed_goals), stack + let get_status (status, _) = status + let get_proof ((proof, _, _), _) = proof + let goals ((_, opened, closed), _) = opened, closed let set_goals (opened, closed) ((proof, _, _), stack) = (proof, opened, closed), stack diff --git a/components/tactics/tacticals.mli b/components/tactics/tacticals.mli index e8d245cd1..83e00d106 100644 --- a/components/tactics/tacticals.mli +++ b/components/tactics/tacticals.mli @@ -63,6 +63,7 @@ sig val do_tactic: n: int -> tactic: tactic -> tactic val try_tactic: tactic: tactic -> tactic val solve_tactics: tactics: (string * tactic) list -> tactic + val progress_tactic: tactic: tactic -> tactic (* module C: sig *) diff --git a/matita/matita.lang b/matita/matita.lang index 13c88e480..b3ffdf943 100644 --- a/matita/matita.lang +++ b/matita/matita.lang @@ -169,6 +169,7 @@ first focus unfocus + progress