(* $Id$ *)
+module GT = GrafiteTypes
+
open Printf
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
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
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)
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
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)
| 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
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
| (name,true) ->
Some
(UriManager.uri_of_string
- (GrafiteTypes.qualify status name ^ ".con"))
+ (GT.qualify status name ^ ".con"))
| _ -> None)
fields
in
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 =
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
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
(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
(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
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
module P = PrimitiveTactics
module T = Tacticals
module R = CicReduction
+module S = CicSubstitution
module TC = CicTypeChecker
module LO = LibraryObjects
module DTI = DoubleTypeInference
(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
(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 =
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
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 =
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 =
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:(
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"
| _ -> 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
(** 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
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
with
e ->
match e with
- | (ProofEngineTypes.Fail _)
+ | (PET.Fail _)
| (CicTypeChecker.TypeCheckerFailure _)
| (CicUnification.UnificationFailure _) ->
info (lazy (
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)
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));
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)) ;
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
| _ -> 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))
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
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