From 7d515acbc5d83aa2300b71a9b7712b3da1d3d2e3 Mon Sep 17 00:00:00 2001 From: herbelin Date: Mon, 4 Aug 2008 18:10:48 +0000 Subject: Évolutions diverses et variées. - Correction divers messages d'erreur - lorsque rien à réécrire dans une hyp, - lorsqu'une variable ltac n'est pas liée, - correction anomalie en présence de ?id dans le "as" de induction, - correction mauvais env dans message d'erreur de unify_0. - Diverses extensions et améliorations - "specialize" : - extension au cas (fun x1 ... xn => H u1 ... un), - renommage au même endroit. - "assert" et "pose proof" peuvent réutiliser la même hyp comme "specialize". - "induction" - intro des IH toujours au sommet même si induction sur var quantifiée, - ajout d'un hack pour la reconnaissance de schémas inductifs comme N_ind_double mais il reste du boulot pour reconnaître (et/ou réordonner) les composantes d'un schéma dont les hypothèses ne sont pas dans l'ordre standard, - vérification de longueur et éventuelle complétion des intropatterns dans le cas de sous-patterns destructifs dans induction (par exemple "destruct n as [|[|]]" sur "forall n, n=0" ne mettait pas le n dans le contexte), - localisation des erreurs d'intropattern, - ajout d'un pattern optionnel après "as" pour forcer une égalité et la nommer (*). - "apply" accepte plusieurs arguments séparés par des virgules (*). - Plus de robustesse pour clear en présence d'evars. - Amélioration affichage TacFun dans Print Ltac. - Vieux pb espace en trop en tête d'affichage des tactiques EXTEND résolu (incidemment, ça remodifie une nouvelle fois le test output Fixpoint.v !). - Fusion VTactic/VFun dans l'espoir. - Mise en place d'un système de trace de la pile des appels Ltac (tout en préservant certains aspects de la récursivité terminale - cf bug #468). - Tactiques primitives - ajout de "move before" dans les tactiques primitives et ajout des syntaxes move before et move dependent au niveau utilisateur (*), - internal_cut peuvent faire du remplacement de nom d'hypothèse existant, - suppression de Intro_replacing et du code sous-traitant - Nettoyage - Suppression cible et fichiers minicoq non portés depuis longtemps. (*) Extensions de syntaxe qu'il pourrait être opportun de discuter git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/coq/trunk@11300 85f007b7-540e-0410-9357-904b9bb8a0f7 --- CHANGES | 8 + Makefile | 1 - Makefile.build | 8 - Makefile.common | 28 +- contrib/funind/functional_principles_proofs.ml | 10 +- contrib/funind/g_indfun.ml4 | 14 +- contrib/funind/indfun.ml | 2 +- contrib/funind/invfun.ml | 10 +- contrib/funind/recdef.ml | 2 +- contrib/interface/depends.ml | 16 +- contrib/interface/pbp.ml | 22 +- contrib/interface/showproof.ml | 4 +- contrib/interface/xlate.ml | 60 +-- contrib/subtac/subtac.ml | 3 +- contrib/subtac/subtac_obligations.ml | 1 + contrib/xml/proofTree2Xml.ml4 | 3 +- dev/doc/style.txt | 26 ++ doc/common/macros.tex | 2 + doc/refman/RefMan-tac.tex | 207 ++++++--- interp/genarg.ml | 22 +- interp/genarg.mli | 21 +- kernel/environ.ml | 11 +- kernel/environ.mli | 2 +- kernel/term.ml | 21 +- kernel/term.mli | 4 + lib/flags.ml | 4 +- lib/util.ml | 33 ++ lib/util.mli | 3 + parsing/g_minicoq.ml4 | 177 ------- parsing/g_tactic.ml4 | 143 +++--- parsing/pcoq.mli | 2 +- parsing/ppconstr.ml | 6 - parsing/ppconstr.mli | 1 - parsing/pptactic.ml | 243 +++++----- parsing/pptactic.mli | 2 + parsing/ppvernac.ml | 5 +- parsing/printer.ml | 19 +- parsing/printer.mli | 1 + parsing/q_coqast.ml4 | 41 +- parsing/q_util.ml4 | 5 + parsing/q_util.mli | 4 + pretyping/evarutil.ml | 98 ++-- pretyping/evarutil.mli | 6 +- pretyping/evd.ml | 2 + pretyping/evd.mli | 3 + pretyping/reductionops.mli | 1 - pretyping/unification.ml | 4 +- proofs/evar_refiner.ml | 21 +- proofs/logic.ml | 195 +++----- proofs/proof_type.ml | 18 +- proofs/proof_type.mli | 19 +- proofs/refiner.ml | 27 +- proofs/tacexpr.ml | 46 +- proofs/tacmach.ml | 31 +- proofs/tacmach.mli | 15 +- tactics/auto.ml | 2 +- tactics/class_tactics.ml4 | 2 +- tactics/decl_proof_instr.ml | 19 +- tactics/elim.ml | 4 +- tactics/elim.mli | 2 +- tactics/equality.ml | 2 +- tactics/equality.mli | 5 +- tactics/extratactics.ml4 | 10 +- tactics/hiddentac.ml | 35 +- tactics/hiddentac.mli | 31 +- tactics/inv.ml | 30 +- tactics/inv.mli | 13 +- tactics/tacinterp.ml | 365 ++++++++------- tactics/tacinterp.mli | 10 +- tactics/tacticals.ml | 19 +- tactics/tacticals.mli | 22 +- tactics/tactics.ml | 607 +++++++++++++------------ tactics/tactics.mli | 39 +- tactics/tauto.ml4 | 14 +- test-suite/failure/evarclear1.v | 10 + test-suite/failure/evarclear2.v | 9 + test-suite/output/Fixpoint.out | 10 +- test-suite/output/Tactics.out | 2 +- theories/Init/Tactics.v | 4 +- toplevel/auto_ind_decl.ml | 28 +- toplevel/cerrors.ml | 13 +- toplevel/fhimsg.ml | 355 --------------- toplevel/himsg.ml | 44 +- toplevel/himsg.mli | 3 + toplevel/minicoq.ml | 149 ------ toplevel/vernacentries.ml | 2 +- 86 files changed, 1605 insertions(+), 1938 deletions(-) delete mode 100644 parsing/g_minicoq.ml4 create mode 100644 test-suite/failure/evarclear1.v create mode 100644 test-suite/failure/evarclear2.v delete mode 100644 toplevel/fhimsg.ml delete mode 100644 toplevel/minicoq.ml diff --git a/CHANGES b/CHANGES index 1c6a1e0369..fb092f50ce 100644 --- a/CHANGES +++ b/CHANGES @@ -214,6 +214,7 @@ Tactic Language - A bound variable whose name is not used elsewhere now serves as metavariable in "match" and it gets instantiated by an identifier (allow e.g. to extract the name of a statement like "exists x, P x"). +- New printing of Ltac call trace for better debugging. Tactics @@ -259,6 +260,9 @@ Tactics * "rewrite 3?A" means rewriting A at most three times. * "rewrite ?A" means rewriting A as long as possible (possibly never). * many of the above extensions can be combined with each other. +- Introduction patterns better respect the structure of context in presence of + missing or extra names in nested disjunction-conjunction patterns [possible + source of rare incompatibilities]. - New syntax "rename a into b, c into d" for "rename a into b; rename c into d" - New tactics "dependent induction/destruction H [ generalizing id_1 .. id_n ]" to do induction-inversion on instantiated inductive families à la BasicElim. @@ -270,6 +274,7 @@ Tactics - Tactic "apply" now able to traverse conjunctions and to select the first matching lemma among the components of the conjunction; tactic apply also able to apply lemmas of conclusion an empty type. +- Tactic "apply" now supports application of several lemmas in a row. - Tactics "set" and "pose" can set functions using notation "(f x1..xn := c)". - New tactic "instantiate" (without argument). - Tactic firstorder "with" and "using" options have their meaning swapped for @@ -288,6 +293,7 @@ Tactics now obsolete. - Tactics f_equal is now done in ML instead of Ltac: it now works on any equality of functions, regardless of the arity of the function. +- New options "before id", "at top", "at bottom" for tactics "move"/"intro". - Some more debug of reflexive omega (romega), and internal clarifications. Moreover, romega now has a variant "romega with *" that can be also used on non-Z goals (nat, N, positive) via a call to a translation tactic named @@ -295,6 +301,8 @@ Tactics independantly of romega. - Tactic "remember" now supports an "in" clause to remember only selected occurrences of a term. +- Tactic "pose proof" supports name overwriting in case of specialization of an + hypothesis. Program diff --git a/Makefile b/Makefile index d751682724..8a12bc1136 100644 --- a/Makefile +++ b/Makefile @@ -180,7 +180,6 @@ archclean: clean-ide cleantheories rm -f bin/parser.opt$(EXE) bin/coq-interface.opt$(EXE) find . -name '*.cmx' -or -name '*.cmxa' -or -name '*.[soa]' | xargs rm -f rm -f $(TOOLS) - rm -f $(MINICOQ) clean-ide: rm -f $(COQIDECMO) $(COQIDECMX) $(COQIDECMO:.cmo=.cmi) $(COQIDEBYTE) $(COQIDEOPT) $(COQIDE) diff --git a/Makefile.build b/Makefile.build index 206c62c7b0..7c20876348 100644 --- a/Makefile.build +++ b/Makefile.build @@ -605,14 +605,6 @@ $(COQDOC): $(COQDOCCMO) $(SHOW)'OCAMLC -o $@' $(HIDE)$(OCAMLC) $(BYTEFLAGS) -custom -o $@ str.cma unix.cma $(COQDOCCMO) -########################################################################### -# minicoq -########################################################################### - -$(MINICOQ): $(MINICOQCMO) - $(SHOW)'OCAMLC -o $@' - $(HIDE)$(OCAMLC) $(BYTEFLAGS) -custom -o $@ $(CMA) $(MINICOQCMO) $(OSDEPLIBS) - ########################################################################### # Installation ########################################################################### diff --git a/Makefile.common b/Makefile.common index ef909f615a..af380dd63a 100644 --- a/Makefile.common +++ b/Makefile.common @@ -46,8 +46,6 @@ COQBINARIES:= $(COQMKTOP) $(COQC) \ endif OTHERBINARIES:=$(COQMKTOPBYTE) $(COQCBYTE) -MINICOQ:=bin/minicoq$(EXE) - CSDPCERT:=bin/csdpcert$(EXE) ########################################################################### @@ -123,8 +121,8 @@ CONFIG:=\ config/coq_config.cmo LIBREP:=\ - lib/pp_control.cmo lib/pp.cmo lib/compat.cmo lib/util.cmo lib/bigint.cmo \ - lib/hashcons.cmo lib/dyn.cmo lib/system.cmo lib/flags.cmo \ + lib/pp_control.cmo lib/pp.cmo lib/compat.cmo lib/flags.cmo \ + lib/util.cmo lib/bigint.cmo lib/hashcons.cmo lib/dyn.cmo lib/system.cmo \ lib/bstack.cmo lib/edit.cmo lib/gset.cmo lib/gmap.cmo \ lib/tlm.cmo lib/gmapl.cmo lib/profile.cmo lib/explore.cmo \ lib/predicate.cmo lib/rtree.cmo lib/heap.cmo lib/option.cmo @@ -411,8 +409,8 @@ COQDOCCMO:=$(CONFIG) tools/coqdoc/cdglobals.cmo tools/coqdoc/alpha.cmo \ MCHECKER:=\ config/coq_config.cmo \ lib/pp_control.cmo lib/pp.cmo lib/compat.cmo \ - lib/util.cmo lib/option.cmo lib/hashcons.cmo \ - lib/system.cmo lib/flags.cmo \ + lib/flags.cmo lib/util.cmo lib/option.cmo lib/hashcons.cmo \ + lib/system.cmo \ lib/predicate.cmo lib/rtree.cmo \ kernel/names.cmo kernel/univ.cmo \ kernel/esubst.cmo checker/term.cmo \ @@ -426,17 +424,11 @@ MCHECKER:=\ checker/safe_typing.cmo checker/check.cmo \ checker/check_stat.cmo checker/checker.cmo -# minicoq - -MINICOQCMO:=$(CONFIG) $(LIBREP) $(KERNEL) \ - parsing/lexer.cmo parsing/g_minicoq.cmo \ - toplevel/fhimsg.cmo toplevel/minicoq.cmo - # grammar modules with camlp4 GRAMMARNEEDEDCMO:=\ - lib/pp_control.cmo lib/pp.cmo lib/compat.cmo lib/util.cmo lib/bigint.cmo \ - lib/dyn.cmo lib/flags.cmo lib/hashcons.cmo lib/predicate.cmo \ + lib/pp_control.cmo lib/pp.cmo lib/compat.cmo lib/flags.cmo \ + lib/util.cmo lib/bigint.cmo lib/dyn.cmo lib/hashcons.cmo lib/predicate.cmo \ lib/rtree.cmo lib/option.cmo \ kernel/names.cmo kernel/univ.cmo \ kernel/esubst.cmo kernel/term.cmo kernel/mod_subst.cmo kernel/sign.cmo \ @@ -511,9 +503,9 @@ PRINTERSCMO:=\ parsing/lexer.cmo interp/ppextend.cmo interp/genarg.cmo \ interp/topconstr.cmo interp/notation.cmo interp/dumpglob.cmo interp/reserve.cmo \ library/impargs.cmo interp/constrextern.cmo \ - interp/syntax_def.cmo interp/implicit_quantifiers.cmo interp/constrintern.cmo \ - proofs/proof_trees.cmo proofs/logic.cmo proofs/refiner.cmo \ - proofs/tacexpr.cmo \ + interp/syntax_def.cmo interp/implicit_quantifiers.cmo \ + interp/constrintern.cmo proofs/proof_trees.cmo proofs/tacexpr.cmo \ + proofs/proof_type.cmo proofs/logic.cmo proofs/refiner.cmo \ proofs/evar_refiner.cmo proofs/pfedit.cmo proofs/tactic_debug.cmo \ proofs/decl_mode.cmo \ parsing/ppconstr.cmo parsing/extend.cmo parsing/pcoq.cmo \ @@ -871,7 +863,7 @@ STAGE2_TARGETS:=$(COQBINARIES) lib kernel byterun library proofs tactics \ interp parsing pretyping highparsing toplevel hightactics \ coqide-binaries coqide-byte coqide-opt $(COQIDEOPT) $(COQIDEBYTE) $(COQIDE) \ pcoq-binaries $(COQINTERFACE) $(CSDPCERT) coqbinaries pcoq $(TOOLS) tools \ - printers $(MINICOQ) debug + printers debug VO_TARGETS:=logic arith bool narith zarith qarith lists strings sets \ fsets allfsets relations wellfounded ints reals allreals \ setoids sorting natural integer rational numbers noreal \ diff --git a/contrib/funind/functional_principles_proofs.ml b/contrib/funind/functional_principles_proofs.ml index d7bcde69cb..bd335d3049 100644 --- a/contrib/funind/functional_principles_proofs.ml +++ b/contrib/funind/functional_principles_proofs.ml @@ -136,7 +136,7 @@ let change_hyp_with_using msg hyp_id t tac : tactic = fun g -> let prov_id = pf_get_new_id hyp_id g in tclTHENS - ((* observe_tac msg *) (forward (Some (tclCOMPLETE tac)) (Genarg.IntroIdentifier prov_id) t)) + ((* observe_tac msg *) (forward (Some (tclCOMPLETE tac)) (dummy_loc,Genarg.IntroIdentifier prov_id) t)) [tclTHENLIST [ (* observe_tac "change_hyp_with_using thin" *) (thin [hyp_id]); @@ -388,7 +388,7 @@ let clean_hyp_with_heq ptes_infos eq_hyps hyp_id env sigma = in (* observe_tac "rec hyp " *) (tclTHENS - (assert_as true (Genarg.IntroIdentifier rec_pte_id) t_x) + (assert_as true (dummy_loc, Genarg.IntroIdentifier rec_pte_id) t_x) [ (* observe_tac "prove rec hyp" *) (prove_rec_hyp eq_hyps); (* observe_tac "prove rec hyp" *) @@ -571,7 +571,7 @@ let instanciate_hyps_with_args (do_prove:identifier list -> tactic) hyps args_id fun g -> let prov_hid = pf_get_new_id hid g in tclTHENLIST[ - forward None (Genarg.IntroIdentifier prov_hid) (mkApp(mkVar hid,args)); + forward None (dummy_loc,Genarg.IntroIdentifier prov_hid) (mkApp(mkVar hid,args)); thin [hid]; h_rename [prov_hid,hid] ] g @@ -1497,7 +1497,7 @@ let prove_principle_for_gen (tclTHEN (forward (Some ((fun g -> (* observe_tac "prove wf" *) (tclCOMPLETE (wf_tac is_mes)) g))) - (Genarg.IntroIdentifier wf_thm_id) + (dummy_loc,Genarg.IntroIdentifier wf_thm_id) (mkApp (delayed_force well_founded,[|input_type;relation|]))) ( (* observe_tac *) @@ -1561,7 +1561,7 @@ let prove_principle_for_gen ); (* observe_tac "" *) (forward (Some (prove_rec_arg_acc)) - (Genarg.IntroIdentifier acc_rec_arg_id) + (dummy_loc,Genarg.IntroIdentifier acc_rec_arg_id) (mkApp (delayed_force acc_rel,[|input_type;relation;mkVar rec_arg_id|])) ); (* observe_tac "reverting" *) (revert (List.rev (acc_rec_arg_id::args_ids))); diff --git a/contrib/funind/g_indfun.ml4 b/contrib/funind/g_indfun.ml4 index dae76f2dd9..d435f51351 100644 --- a/contrib/funind/g_indfun.ml4 +++ b/contrib/funind/g_indfun.ml4 @@ -90,11 +90,6 @@ END TACTIC EXTEND newfunind ["functional" "induction" ne_constr_list(cl) fun_ind_using(princl) with_names(pat)] -> [ - let pat = - match pat with - | None -> IntroAnonymous - | Some pat -> pat - in let c = match cl with | [] -> assert false | [c] -> c @@ -106,11 +101,6 @@ END TACTIC EXTEND snewfunind ["soft" "functional" "induction" ne_constr_list(cl) fun_ind_using(princl) with_names(pat)] -> [ - let pat = - match pat with - | None -> IntroAnonymous - | Some pat -> pat - in let c = match cl with | [] -> assert false | [c] -> c @@ -319,7 +309,7 @@ let poseq_unsafe idunsafe cstr gl = tclTHEN (Tactics.letin_tac None (Name idunsafe) cstr allClauses) (tclTHENFIRST - (Tactics.assert_as true IntroAnonymous (mkEq typ (mkVar idunsafe) cstr)) + (Tactics.assert_as true (Util.dummy_loc,IntroAnonymous) (mkEq typ (mkVar idunsafe) cstr)) Tactics.reflexivity) gl @@ -396,7 +386,7 @@ let finduction (oid:identifier option) (heuristic: fapp_info list -> fapp_info l fun gl -> (functional_induction true (applist (info.fname, List.rev !list_constr_largs)) - None IntroAnonymous) gl)) + None None) gl)) nexttac)) ordered_info_list in (* we try each (f t u v) until one does not fail *) (* TODO: try also to mix functional schemes *) diff --git a/contrib/funind/indfun.ml b/contrib/funind/indfun.ml index a6cbb3211b..79ef009729 100644 --- a/contrib/funind/indfun.ml +++ b/contrib/funind/indfun.ml @@ -120,7 +120,7 @@ let functional_induction with_clean c princl pat = princ_infos args_as_induction_constr princ' - pat + (None,pat) None) subst_and_reduce g diff --git a/contrib/funind/invfun.ml b/contrib/funind/invfun.ml index 63d44916be..f62d70ab9a 100644 --- a/contrib/funind/invfun.ml +++ b/contrib/funind/invfun.ml @@ -280,13 +280,13 @@ let prove_fun_correct functional_induction funs_constr graphs_constr schemes lem List.map (fun (_,_,br_type) -> List.map - (fun id -> Genarg.IntroIdentifier id) + (fun id -> dummy_loc, Genarg.IntroIdentifier id) (generate_fresh_id (id_of_string "y") ids (List.length (fst (decompose_prod_assum br_type)))) ) branches in (* before building the full intro pattern for the principle *) - let pat = Genarg.IntroOrAndPattern intro_pats in + let pat = Some (dummy_loc,Genarg.IntroOrAndPattern intro_pats) in let eq_ind = Coqlib.build_coq_eq () in let eq_construct = mkConstruct((destInd eq_ind),1) in (* The next to referencies will be used to find out which constructor to apply in each branch *) @@ -297,7 +297,7 @@ let prove_fun_correct functional_induction funs_constr graphs_constr schemes lem (* We get the identifiers of this branch *) let this_branche_ids = List.fold_right - (fun pat acc -> + (fun (_,pat) acc -> match pat with | Genarg.IntroIdentifier id -> Idset.add id acc | _ -> anomaly "Not an identifier" @@ -447,7 +447,7 @@ let prove_fun_correct functional_induction funs_constr graphs_constr schemes lem [ observe_tac "intro args_names" (tclMAP h_intro args_names); observe_tac "principle" (forward (Some (h_exact f_principle)) - (Genarg.IntroIdentifier principle_id) + (dummy_loc,Genarg.IntroIdentifier principle_id) princ_type); tclTHEN_i (observe_tac "functional_induction" ( @@ -948,7 +948,7 @@ let functional_inversion kn hid fconst f_correct : tactic = h_generalize [applist(f_correct,(Array.to_list f_args)@[res;mkVar hid])]; thin [hid]; h_intro hid; - Inv.inv FullInversion Genarg.IntroAnonymous (Rawterm.NamedHyp hid); + Inv.inv FullInversion None (Rawterm.NamedHyp hid); (fun g -> let new_ids = List.filter (fun id -> not (Idset.mem id old_ids)) (pf_ids_of_hyps g) in tclMAP (revert_graph kn pre_tac) (hid::new_ids) g diff --git a/contrib/funind/recdef.ml b/contrib/funind/recdef.ml index 13989f03bc..6227f92d72 100644 --- a/contrib/funind/recdef.ml +++ b/contrib/funind/recdef.ml @@ -1157,7 +1157,7 @@ let rec introduce_all_values_eq cont_tac functional termine [] -> let heq2 = next_global_ident_away true heq_id ids in tclTHENLIST - [forward None (IntroIdentifier heq2) + [forward None (dummy_loc,IntroIdentifier heq2) (mkApp(mkVar heq1, [|f_S(f_S(mkVar pmax))|])); simpl_iter (onHyp heq2); unfold_in_hyp [((true,[1]), evaluable_of_global_reference diff --git a/contrib/interface/depends.ml b/contrib/interface/depends.ml index dd40c5cc36..bf1cf5e7b2 100644 --- a/contrib/interface/depends.ml +++ b/contrib/interface/depends.ml @@ -57,8 +57,7 @@ let explore_tree pfs = and explain_prim = function | Refine c -> "Refine " ^ (string_of_ppcmds (Printer.prterm c)) | Intro identifier -> "Intro" - | Intro_replacing identifier -> "Intro_replacing" - | Cut (bool, identifier, types) -> "Cut" + | Cut (bool, _, identifier, types) -> "Cut" | FixRule (identifier, int, l) -> "FixRule" | Cofix (identifier, l) -> "Cofix" | Convert_concl (types, cast_kind) -> "Convert_concl" @@ -281,7 +280,8 @@ let rec depends_of_gen_tactic_expr depends_of_'constr depends_of_'ind depends_of | TacExact c | TacExactNoCheck c | TacVmCastNoCheck c -> depends_of_'constr c acc - | TacApply (_, _, cb) -> depends_of_'constr_with_bindings cb acc + | TacApply (_, _, [cb]) -> depends_of_'constr_with_bindings cb acc + | TacApply (_, _, _) -> failwith "TODO" | TacElim (_, cwb, cwbo) -> depends_of_'constr_with_bindings cwb (Option.fold_right depends_of_'constr_with_bindings cwbo acc) @@ -302,14 +302,13 @@ let rec depends_of_gen_tactic_expr depends_of_'constr depends_of_'ind depends_of | TacLetTac (_,c,_,_) -> depends_of_'constr c acc (* Derived basic tactics *) - | TacSimpleInduction _ - | TacSimpleDestruct _ + | TacSimpleInductionDestruct _ | TacDoubleInduction _ -> acc - | TacNewInduction (_, cwbial, cwbo, _, _) - | TacNewDestruct (_, cwbial, cwbo, _, _) -> + | TacInductionDestruct (_, _, [cwbial, cwbo, _, _]) -> list_union_map (depends_of_'a_induction_arg depends_of_'constr_with_bindings) cwbial (Option.fold_right depends_of_'constr_with_bindings cwbo acc) + | TacInductionDestruct (_, _, _) -> failwith "TODO" | TacDecomposeAnd c | TacDecomposeOr c -> depends_of_'constr c acc | TacDecompose (il, c) -> depends_of_'constr c (list_union_map depends_of_'ind il acc) @@ -410,8 +409,7 @@ let depends_of_compound_rule cr acc = match cr with and depends_of_prim_rule pr acc = match pr with | Refine c -> depends_of_constr c acc | Intro id -> acc - | Intro_replacing id -> acc - | Cut (_, _, t) -> depends_of_constr t acc (* TODO: check what 2nd argument contains *) + | Cut (_, _, _, t) -> depends_of_constr t acc (* TODO: check what 3nd argument contains *) | FixRule (_, _, l) -> list_union_map (o depends_of_constr trd_of_3) l acc (* TODO: check what the arguments contain *) | Cofix (_, l) -> list_union_map (o depends_of_constr snd) l acc (* TODO: check what the arguments contain *) | Convert_concl (t, _) -> depends_of_constr t acc diff --git a/contrib/interface/pbp.ml b/contrib/interface/pbp.ml index 06b957d9c2..65eadf13db 100644 --- a/contrib/interface/pbp.ml +++ b/contrib/interface/pbp.ml @@ -48,7 +48,7 @@ type pbp_atom = | PbpTryClear of identifier list | PbpGeneralize of identifier * identifier list | PbpLApply of identifier (* = CutAndApply *) - | PbpIntros of intro_pattern_expr list + | PbpIntros of intro_pattern_expr located list | PbpSplit (* Existential *) | PbpExists of identifier @@ -93,7 +93,7 @@ type pbp_rule = (identifier list * pbp_sequence option;; -let make_named_intro id = PbpIntros [IntroIdentifier id];; +let make_named_intro id = PbpIntros [zz,IntroIdentifier id];; let make_clears str_list = PbpThen [PbpTryClear str_list] @@ -171,7 +171,7 @@ let make_pbp_atomic_tactic = function | PbpRight -> TacAtom (zz, TacRight (false,NoBindings)) | PbpIntros l -> TacAtom (zz, TacIntroPattern l) | PbpLApply h -> TacAtom (zz, TacLApply (make_var h)) - | PbpApply h -> TacAtom (zz, TacApply (true,false,(make_var h,NoBindings))) + | PbpApply h -> TacAtom (zz, TacApply (true,false,[make_var h,NoBindings])) | PbpElim (hyp_name, names) -> let bind = List.map (fun s ->(zz,NamedHyp s,make_pbp_pattern s)) names in TacAtom @@ -255,9 +255,9 @@ fun avoid c path -> match kind_of_term c, path with or_and_tree_to_intro_pattern (id2::avoid) cont_expr path in let patt_list = if a = 1 then - [cont_patt; IntroIdentifier id2] + [zz,cont_patt; zz,IntroIdentifier id2] else - [IntroIdentifier id2; cont_patt] in + [zz,IntroIdentifier id2; zz,cont_patt] in (IntroOrAndPattern[patt_list], avoid_names, id, c, path, rank, total_branches) | (App(oper, [|c1; c2|]), 2::3::path) @@ -268,7 +268,7 @@ fun avoid c path -> match kind_of_term c, path with let id1 = next_global_ident x avoid in let cont_patt, avoid_names, id, c, path, rank, total_branches = or_and_tree_to_intro_pattern (id1::avoid) body path in - (IntroOrAndPattern[[IntroIdentifier id1; cont_patt]], + (IntroOrAndPattern[[zz,IntroIdentifier id1; zz,cont_patt]], avoid_names, id, c, path, rank, total_branches) | _ -> assert false) | (App(oper, [|c1; c2|]), 2::a::path) @@ -282,9 +282,9 @@ fun avoid c path -> match kind_of_term c, path with let new_rank = if a = 1 then rank else rank+1 in let patt_list = if a = 1 then - [[cont_patt];[IntroIdentifier id2]] + [[zz,cont_patt];[zz,IntroIdentifier id2]] else - [[IntroIdentifier id2];[cont_patt]] in + [[zz,IntroIdentifier id2];[zz,cont_patt]] in (IntroOrAndPattern patt_list, avoid_names, id, c, path, new_rank, total_branches+1) | (_, path) -> let id = next_global_ident hyp_radix avoid in @@ -305,13 +305,13 @@ let (imply_intro3: pbp_rule) = function let intro_patt, avoid_names, id, c, p, rank, total_branches = or_and_tree_to_intro_pattern avoid prem path in if total_branches = 1 then - Some(chain_tactics [PbpIntros [intro_patt]] + Some(chain_tactics [PbpIntros [zz,intro_patt]] (f avoid_names clear_names clear_flag (Some id) (kind_of_term c) path)) else Some (PbpThens - ([PbpIntros [intro_patt]], + ([PbpIntros [zz,intro_patt]], auxiliary_goals clear_names clear_flag id (rank - 1) ((f avoid_names clear_names clear_flag (Some id) @@ -667,7 +667,7 @@ let rec cleanup_clears str_list = function let rec optim3_aux str_list = function (PbpGeneralize (h,l1)):: - (PbpIntros [IntroIdentifier s])::(PbpGeneralize (h',l2))::others + (PbpIntros [zz,IntroIdentifier s])::(PbpGeneralize (h',l2))::others when s=h' -> optim3_aux (s::str_list) (PbpGeneralize (h,l1@l2)::others) | (PbpTryClear names)::other -> diff --git a/contrib/interface/showproof.ml b/contrib/interface/showproof.ml index 953fb5e790..4b9c1332a4 100644 --- a/contrib/interface/showproof.ml +++ b/contrib/interface/showproof.ml @@ -1197,12 +1197,12 @@ let rec natural_ntree ig ntree = | TacAssumption -> natural_trivial ig lh g gs ltree | TacClear _ -> natural_clear ig lh g gs ltree (* Besoin de l'argument de la tactique *) - | TacSimpleInduction (NamedHyp id) -> + | TacSimpleInductionDestruct (true,NamedHyp id) -> natural_induction ig lh g gs ge id ltree false | TacExtend (_,"InductionIntro",[a]) -> let id=(out_gen wit_ident a) in natural_induction ig lh g gs ge id ltree true - | TacApply (_,false,(c,_)) -> natural_apply ig lh g gs (snd c) ltree + | TacApply (_,false,[c,_]) -> natural_apply ig lh g gs (snd c) ltree | TacExact c -> natural_exact ig lh g gs (snd c) ltree | TacCut c -> natural_cut ig lh g gs (snd c) ltree | TacExtend (_,"CutIntro",[a]) -> diff --git a/contrib/interface/xlate.ml b/contrib/interface/xlate.ml index 2e4ff80bb0..716f6da3b7 100644 --- a/contrib/interface/xlate.ml +++ b/contrib/interface/xlate.ml @@ -615,8 +615,7 @@ let get_flag r = (* Rem: EVAR flag obsolète *) conv_flags, red_ids -let rec xlate_intro_pattern = - function +let rec xlate_intro_pattern (loc,pat) = match pat with | IntroOrAndPattern [] -> assert false | IntroOrAndPattern (fp::ll) -> CT_disj_pattern @@ -625,7 +624,7 @@ let rec xlate_intro_pattern = (fun l -> CT_intro_patt_list(List.map xlate_intro_pattern l)) ll) - | IntroWildcard _ -> CT_coerce_ID_to_INTRO_PATT(CT_ident "_" ) + | IntroWildcard -> CT_coerce_ID_to_INTRO_PATT(CT_ident "_" ) | IntroIdentifier c -> CT_coerce_ID_to_INTRO_PATT(xlate_ident c) | IntroAnonymous -> xlate_error "TODO: IntroAnonymous" | IntroFresh _ -> xlate_error "TODO: IntroFresh" @@ -686,8 +685,8 @@ let xlate_one_unfold_block = function ;; let xlate_with_names = function - IntroAnonymous -> CT_coerce_ID_OPT_to_INTRO_PATT_OPT ctv_ID_OPT_NONE - | fp -> CT_coerce_INTRO_PATT_to_INTRO_PATT_OPT (xlate_intro_pattern fp) + None -> CT_coerce_ID_OPT_to_INTRO_PATT_OPT ctv_ID_OPT_NONE + | Some fp -> CT_coerce_INTRO_PATT_to_INTRO_PATT_OPT (xlate_intro_pattern fp) let rawwit_main_tactic = Pcoq.rawwit_tactic Pcoq.tactic_main_level @@ -972,19 +971,22 @@ and xlate_tac = CT_intros_until (CT_coerce_ID_to_ID_OR_INT (xlate_ident id)) | TacIntrosUntil (AnonHyp n) -> CT_intros_until (CT_coerce_INT_to_ID_OR_INT (CT_int n)) - | TacIntroMove (Some id1, Some (_,id2)) -> - CT_intro_after(CT_coerce_ID_to_ID_OPT (xlate_ident id1),xlate_ident id2) - | TacIntroMove (None, Some (_,id2)) -> - CT_intro_after(CT_coerce_NONE_to_ID_OPT CT_none, xlate_ident id2) - | TacMove (true, id1, id2) -> + | TacIntroMove (Some id1, MoveAfter id2) -> + CT_intro_after(CT_coerce_ID_to_ID_OPT (xlate_ident id1),xlate_hyp id2) + | TacIntroMove (None, MoveAfter id2) -> + CT_intro_after(CT_coerce_NONE_to_ID_OPT CT_none, xlate_hyp id2) + | TacMove (true, id1, MoveAfter id2) -> CT_move_after(xlate_hyp id1, xlate_hyp id2) | TacMove (false, id1, id2) -> xlate_error "Non dep Move is only internal" + | TacMove _ -> xlate_error "TODO: move before, at top, at bottom" | TacIntroPattern patt_list -> CT_intros (CT_intro_patt_list (List.map xlate_intro_pattern patt_list)) - | TacIntroMove (Some id, None) -> + | TacIntroMove (Some id, MoveToEnd true) -> CT_intros (CT_intro_patt_list[CT_coerce_ID_to_INTRO_PATT(xlate_ident id)]) - | TacIntroMove (None, None) -> CT_intro (CT_coerce_NONE_to_ID_OPT CT_none) + | TacIntroMove (None, MoveToEnd true) -> + CT_intro (CT_coerce_NONE_to_ID_OPT CT_none) + | TacIntroMove _ -> xlate_error "TODO" | TacLeft (false,bindl) -> CT_left (xlate_bindings bindl) | TacRight (false,bindl) -> CT_right (xlate_bindings bindl) | TacSplit (false,false,bindl) -> CT_split (xlate_bindings bindl) @@ -1155,11 +1157,12 @@ and xlate_tac = xlate_error "TODO: trivial using" | TacReduce (red, l) -> CT_reduce (xlate_red_tactic red, xlate_clause l) - | TacApply (true,false,(c,bindl)) -> + | TacApply (true,false,[c,bindl]) -> CT_apply (xlate_formula c, xlate_bindings bindl) - | TacApply (true,true,(c,bindl)) -> + | TacApply (true,true,[c,bindl]) -> CT_eapply (xlate_formula c, xlate_bindings bindl) - | TacApply (false,_,_) -> xlate_error "TODO: simple (e)apply" + | TacApply (_,_,_) -> + xlate_error "TODO: simple (e)apply and iterated apply" | TacConstructor (false,n_or_meta, bindl) -> let n = match n_or_meta with AI n -> n | MetaId _ -> xlate_error "" in CT_constructor (CT_int n, xlate_bindings bindl) @@ -1183,10 +1186,12 @@ and xlate_tac = | TacCase (false,(c1,sl)) -> CT_casetac (xlate_formula c1, xlate_bindings sl) | TacElim (true,_,_) | TacCase (true,_) - | TacNewDestruct (true,_,_,_,_) | TacNewInduction (true,_,_,_,_) -> + | TacInductionDestruct (_,true,_) -> xlate_error "TODO: eelim, ecase, edestruct, einduction" - | TacSimpleInduction h -> CT_induction (xlate_quantified_hypothesis h) - | TacSimpleDestruct h -> CT_destruct (xlate_quantified_hypothesis h) + | TacSimpleInductionDestruct (true,h) -> + CT_induction (xlate_quantified_hypothesis h) + | TacSimpleInductionDestruct (false,h) -> + CT_destruct (xlate_quantified_hypothesis h) | TacCut c -> CT_cut (xlate_formula c) | TacLApply c -> CT_use (xlate_formula c) | TacDecompose ([],c) -> @@ -1227,19 +1232,16 @@ and xlate_tac = CT_dauto(xlate_int_or_var_opt_to_int_opt a, xlate_int_opt b) | TacDAuto (a, b, _) -> xlate_error "TODO: dauto using" - | TacNewDestruct(false,a,b,c,None) -> + | TacInductionDestruct(true,false,[a,b,(None,c),None]) -> CT_new_destruct (List.map xlate_int_or_constr a, xlate_using b, xlate_with_names c) - | TacNewInduction(false,a,b,c,None) -> + | TacInductionDestruct(false,false,[a,b,(None,c),None]) -> CT_new_induction (List.map xlate_int_or_constr a, xlate_using b, xlate_with_names c) - | TacNewDestruct(false,a,b,c,_) -> xlate_error "TODO: destruct in" - | TacNewInduction(false,a,b,c,_) ->xlate_error "TODO: induction in" - (*| TacInstantiate (a, b, cl) -> - CT_instantiate(CT_int a, xlate_formula b, - assert false) *) + | TacInductionDestruct(_,false,_) -> + xlate_error "TODO: clause 'in' and full 'as' of destruct/induction" | TacLetTac (na, c, cl, true) when cl = nowhere -> CT_pose(xlate_id_opt_aux na, xlate_formula c) | TacLetTac (na, c, cl, true) -> @@ -1248,13 +1250,13 @@ and xlate_tac = but the structures are different *) xlate_clause cl) | TacLetTac (na, c, cl, false) -> xlate_error "TODO: remember" - | TacAssert (None, IntroIdentifier id, c) -> + | TacAssert (None, (_,IntroIdentifier id), c) -> CT_assert(xlate_id_opt ((0,0),Name id), xlate_formula c) - | TacAssert (None, IntroAnonymous, c) -> + | TacAssert (None, (_,IntroAnonymous), c) -> CT_assert(xlate_id_opt ((0,0),Anonymous), xlate_formula c) - | TacAssert (Some (TacId []), IntroIdentifier id, c) -> + | TacAssert (Some (TacId []), (_,IntroIdentifier id), c) -> CT_truecut(xlate_id_opt ((0,0),Name id), xlate_formula c) - | TacAssert (Some (TacId []), IntroAnonymous, c) -> + | TacAssert (Some (TacId []), (_,IntroAnonymous), c) -> CT_truecut(xlate_id_opt ((0,0),Anonymous), xlate_formula c) | TacAssert _ -> xlate_error "TODO: assert with 'as' and 'by' and pose proof with 'as'" diff --git a/contrib/subtac/subtac.ml b/contrib/subtac/subtac.ml index c36c6458db..baf565ab1f 100644 --- a/contrib/subtac/subtac.ml +++ b/contrib/subtac/subtac.ml @@ -231,7 +231,8 @@ let subtac (loc, command) = debug 2 (Himsg.explain_pretype_error env exn); raise e - | (Stdpp.Exc_located (loc, e')) as e -> + | (Stdpp.Exc_located (loc, Proof_type.LtacLocated (_,e')) | + Stdpp.Exc_located (loc, e') as e) -> debug 2 (str "Parsing exception: "); (match e' with | Type_errors.TypeError (env, exn) -> diff --git a/contrib/subtac/subtac_obligations.ml b/contrib/subtac/subtac_obligations.ml index 4e824921bd..a393e2c9b5 100644 --- a/contrib/subtac/subtac_obligations.ml +++ b/contrib/subtac/subtac_obligations.ml @@ -442,6 +442,7 @@ and solve_obligation_by_tac prg obls i tac = true else false with + | Stdpp.Exc_located(_, Proof_type.LtacLocated (_, Refiner.FailError (_, s))) | Stdpp.Exc_located(_, Refiner.FailError (_, s)) | Refiner.FailError (_, s) -> user_err_loc (obl.obl_location, "solve_obligation", s) diff --git a/contrib/xml/proofTree2Xml.ml4 b/contrib/xml/proofTree2Xml.ml4 index 9afd07a61a..05be01bc61 100644 --- a/contrib/xml/proofTree2Xml.ml4 +++ b/contrib/xml/proofTree2Xml.ml4 @@ -82,8 +82,7 @@ let first_word s = let string_of_prim_rule x = match x with | Proof_type.Intro _-> "Intro" - | Proof_type.Intro_replacing _-> "Intro_replacing" - | Proof_type.Cut (_,_,_) -> "Cut" + | Proof_type.Cut _ -> "Cut" | Proof_type.FixRule (_,_,_) -> "FixRule" | Proof_type.Cofix (_,_)-> "Cofix" | Proof_type.Refine _ -> "Refine" diff --git a/dev/doc/style.txt b/dev/doc/style.txt index 2e597dc45a..a8924ba65d 100644 --- a/dev/doc/style.txt +++ b/dev/doc/style.txt @@ -20,6 +20,32 @@ match expr with | A -> ... | B x -> ... +Remarque : à partir de la 8.2 environ, la tendance est à utiliser le +format suivant qui permet de limiter l'escalade d'indentation tout en +produisant un aspect visuel intéressant de bloc : + +type t = +| A +| B of machin + +match expr with +| A -> ... +| B x -> ... + +let f expr = match expr with +| A -> ... +| B x -> ... + +let f expr = function +| A -> ... +| B x -> ... + +Le deuxième cas est obtenu sous tuareg avec les réglages + + (setq tuareg-with-indent 0) + (setq tuareg-function-indent 0) + (setq tuareg-let-always-indent nil) /// notons que cette dernière est bien + /// pour les let mais pas pour les let-in Conditionnelles =============== diff --git a/doc/common/macros.tex b/doc/common/macros.tex index b464a96220..ef632371df 100755 --- a/doc/common/macros.tex +++ b/doc/common/macros.tex @@ -190,6 +190,8 @@ \newcommand{\pattern}{\textrm{\textsl{pattern}}} \newcommand{\orpattern}{\textrm{\textsl{or\_pattern}}} \newcommand{\intropattern}{\textrm{\textsl{intro\_pattern}}} +\newcommand{\disjconjintropattern}{\textrm{\textsl{disj\_conj\_intro\_pattern}}} +\newcommand{\namingintropattern}{\textrm{\textsl{naming\_intro\_pattern}}} \newcommand{\pat}{\textrm{\textsl{pat}}} \newcommand{\pgs}{\textrm{\textsl{pgms}}} \newcommand{\pg}{\textrm{\textsl{pgm}}} diff --git a/doc/refman/RefMan-tac.tex b/doc/refman/RefMan-tac.tex index 9f6fa8be14..54237d721a 100644 --- a/doc/refman/RefMan-tac.tex +++ b/doc/refman/RefMan-tac.tex @@ -174,7 +174,8 @@ usable in the proof development. \end{ErrMsgs} \subsection{\tt move {\ident$_1$} after {\ident$_2$} -\tacindex{move}} +\tacindex{move} +\label{move}} This moves the hypothesis named {\ident$_1$} in the local context after the hypothesis named {\ident$_2$}. @@ -187,6 +188,32 @@ If {\ident$_1$} comes after {\ident$_2$} in the order of dependences, then all hypotheses between {\ident$_1$} and {\ident$_2$} which (possibly indirectly) occur in {\ident$_1$} are moved also. +\begin{Variants} + +\item {\tt move {\ident$_1$} before {\ident$_2$}} + +This moves {\ident$_1$} towards and just before the hypothesis named {\ident$_2$}. + +\item {\tt move {\ident} at top} + +This moves {\ident} at the top of the local context (at the beginning of the context). + +\item {\tt move {\ident} at bottom} + +This moves {\ident} at the bottom of the local context (at the end of the context). + +\item {\tt move dependent {\ident$_1$} after {\ident$_2$}}\\ + {\tt move dependent {\ident$_1$} before {\ident$_2$}}\\ + {\tt move dependent {\ident$_1$} at top}\\ + {\tt move dependent {\ident$_1$} at bottom} + +This moves {\ident$_1$} towards the specified place. All the +hypotheses that recursively depend on, for a downwards move, or +in, for an upwards move, the hypothesis {\ident$_1$} are moved +too so as to respect the order of dependencies between hypotheses. + +\end{Variants} + \begin{ErrMsgs} \item \errindex{{\ident$_i$} not found} @@ -316,22 +343,32 @@ the tactic {\tt intro} applies the tactic {\tt red} until the tactic Happens when {\num} is 0 or is greater than the number of non-dependent products of the goal. -\item {\tt intro after \ident} \tacindex{intro after} +\item {\tt intro after \ident} \tacindex{intro after}\\ + {\tt intro before \ident} \tacindex{intro before}\\ + {\tt intro at top} \tacindex{intro at top}\\ + {\tt intro at bottom} \tacindex{intro at bottom} - Applies {\tt intro} but puts the introduced - hypothesis after the hypothesis \ident{} in the hypotheses. + Applies {\tt intro} and moves the freshly introduced hypothesis + respectively after the hypothesis \ident{}, before the hypothesis + \ident{}, at the top of the local context, or at the bottom of the + local context. All hypotheses on which the new hypothesis depends + are moved too so as to respect the order of dependencies between + hypotheses. Note that {\tt intro as bottom} is is a synonym for {\tt + intro} with no argument. \begin{ErrMsgs} \item \errindex{No product even after head-reduction} \item \errindex{No such hypothesis} : {\ident} \end{ErrMsgs} -\item {\tt intro \ident$_1$ after \ident$_2$} - \tacindex{intro ... after} +\item {\tt intro \ident$_1$ after \ident$_2$}\\ + {\tt intro \ident$_1$ before \ident$_2$}\\ + {\tt intro \ident$_1$ at top}\\ + {\tt intro \ident$_1$ at bottom} - Behaves as previously but \ident$_1$ is the name of the introduced - hypothesis. It is equivalent to {\tt intro \ident$_1$; move - \ident$_1$ after \ident$_2$}. + Behaves as previously but naming the introduced hypothesis + \ident$_1$. It is equivalent to {\tt intro \ident$_1$} followed by + the appropriate call to {\tt move}~(see Section~\ref{move}). \begin{ErrMsgs} \item \errindex{No product even after head-reduction} @@ -404,6 +441,14 @@ Section~\ref{pattern} to transform the goal so that it gets the form premises. Here, variables are referred by names and non-dependent products by increasing numbers (see syntax in Section~\ref{Binding-list}). +\item {\tt apply} {\term$_1$} {\tt ,} \ldots {\tt ,} {\term$_n$} + + This is a shortcut for {\tt apply} {\term$_1$} {\tt ; [ ..~|} + \ldots~{\tt ; [ ..~| {\tt apply} {\term$_n$} ]} \ldots~{\tt ]}, i.e. for the + successive applications of {\term$_{i+1}$} on the last subgoal + generated by {\tt apply} {\term$_i$}, starting from the application + of {\term$_1$}. + \item {\tt eapply \term}\tacindex{eapply}\label{eapply} The tactic {\tt eapply} behaves as {\tt apply} but does not fail @@ -417,6 +462,29 @@ Section~\ref{pattern} to transform the goal so that it gets the form An example of use of {\tt eapply} is given in Section~\ref{eapply-example}. +\item {\tt simple apply {\term}} \tacindex{simple apply} + + This behaves like {\tt apply} but it reasons modulo conversion only + on subterms that contain no variables to instantiate. For instance, + if {\tt id := fun x:nat => x} and {\tt H : forall y, id y = y} then + {\tt simple apply H} on goal {\tt O = O} does not succeed because it + would require the conversion of {\tt f ?y} and {\tt O} where {\tt + ?y} is a variable to instantiate. Tactic {\tt simple apply} does not + either traverse tuples as {\tt apply} does. + + Because it reasons modulo a limited amount of conversion, {\tt + simple apply} fails quicker than {\tt apply} and it is then + well-suited for uses in used-defined tactics that backtrack often. + +\item \zeroone{{\tt simple}} {\tt apply} {\term$_1$} \zeroone{{\tt with} + {\bindinglist$_1$}} {\tt ,} \ldots {\tt ,} {\term$_n$} \zeroone{{\tt with} + {\bindinglist$_n$}}\\ + \zeroone{{\tt simple}} {\tt eapply} {\term$_1$} \zeroone{{\tt with} + {\bindinglist$_1$}} {\tt ,} \ldots {\tt ,} {\term$_n$} \zeroone{{\tt with} + {\bindinglist$_n$}} + + This summarizes the difference syntaxes for {\tt apply}. + \item {\tt lapply {\term}} \tacindex{lapply} This tactic applies to any goal, say {\tt G}. The argument {\term} @@ -911,7 +979,7 @@ $\!\!\!$\begin{tabular}{lcl} & | & {\tt *}\\ {\atoccurrences} & ::= & {\tt at} {\occlist}\\ -{\occlist} & ::= & \zeroone{\tt -} {\num$_1$} \dots\ {\num$_n$} +{\occlist} & ::= & \zeroone{{\tt -}} {\num$_1$} \dots\ {\num$_n$} \end{tabular} The role of an occurrence clause is to select a set of occurrences of @@ -1483,24 +1551,35 @@ induction n. \end{ErrMsgs} \begin{Variants} -\item{\tt induction {\term} as {\intropattern}} +\item{\tt induction {\term} as {\disjconjintropattern}} This behaves as {\tt induction {\term}} but uses the names in - {\intropattern} to name the variables introduced in the context. - The {\intropattern} must have the form {\tt [} $p_{11}$ \ldots + {\disjconjintropattern} to name the variables introduced in the context. + The {\disjconjintropattern} must typically be of the form + {\tt [} $p_{11}$ \ldots $p_{1n_1}$ {\tt |} {\ldots} {\tt |} $p_{m1}$ \ldots $p_{mn_m}$ {\tt ]} with $m$ being the number of constructors of the type of {\term}. Each variable introduced by {\tt induction} in the context of the $i^{th}$ goal gets its name from the list $p_{i1}$ \ldots $p_{in_i}$ in order. If there are not enough names, {\tt induction} invents names for the remaining variables to introduce. More - generally, the $p_{ij}$ can be any introduction patterns (see - Section~\ref{intros-pattern}). This provides a concise notation for - nested induction. + generally, the $p_{ij}$ can be any disjunctive/conjunctive + introduction pattern (see Section~\ref{intros-pattern}). For instance, + for an inductive type with one constructor, the pattern notation + {\tt ($p_{1}$,\ldots,$p_{n}$)} can be used instead of + {\tt [} $p_{1}$ \ldots $p_{n}$ {\tt ]}. + +\item{\tt induction {\term} as {\namingintropattern}} + + This behaves as {\tt induction {\term}} but adds an equation between + {\term} and the value that {\term} takes in each of the induction + case. The name of the equation is built according to + {\namingintropattern} which can be an identifier, a ``?'', etc, as + indicated in Section~\ref{intros-pattern}. -\Rem for an inductive type with one constructor, the pattern notation -{\tt ($p_{1}$,\ldots,$p_{n}$)} can be used instead of -{\tt [} $p_{1}$ \ldots $p_{n}$ {\tt ]}. +\item{\tt induction {\term} as {\namingintropattern} {\disjconjintropattern}} + + This combines the two previous forms. \item{\tt induction {\term} with \bindinglist} @@ -1533,11 +1612,6 @@ induction n. with complex predicates as the induction principles generated by {\tt Function} or {\tt Functional Scheme} may be. -\item \texttt{induction {\term} in *} - - This syntax tells to keep an equation between {\term} and the value - it gets in each case of the induction. - \item \texttt{induction {\term} in {\occgoalset}} This syntax is used for selecting which occurrences of {\term} the @@ -1547,12 +1621,13 @@ induction n. When an occurrence clause is given, an equation between {\term} and the value it gets in each case of the induction is added to the - context of the subgoals corresponding to the induction cases. + context of the subgoals corresponding to the induction cases (even + if no clause {\tt as {\namingintropattern}} is given. -\item{\tt induction {\term$_1$} with {\bindinglist$_1$} as {\intropattern} using {\term$_2$} with {\bindinglist$_2$} in {\occgoalset}}\\ - {\tt einduction {\term$_1$} with {\bindinglist$_1$} as {\intropattern} using {\term$_2$} with {\bindinglist$_2$} in {\occgoalset}} +\item {\tt induction {\term$_1$} with {\bindinglist$_1$} as {\namingintropattern} {\disjconjintropattern} using {\term$_2$} with {\bindinglist$_2$} in {\occgoalset}}\\ + {\tt einduction {\term$_1$} with {\bindinglist$_1$} as {\namingintropattern} {\disjconjintropattern} using {\term$_2$} with {\bindinglist$_2$} in {\occgoalset}} - This is the most general form of {\tt induction} and {\tt + These are the most general forms of {\tt induction} and {\tt einduction}. It combines the effects of the {\tt with}, {\tt as}, {\tt using}, and {\tt in} clauses. @@ -1598,7 +1673,7 @@ instantiate premises of the type of {\term$_2$}. \item{\tt elim {\term$_1$} with {\bindinglist$_1$} using {\term$_2$} with {\bindinglist$_2$}}\\ {\tt eelim {\term$_1$} with {\bindinglist$_1$} using {\term$_2$} with {\bindinglist$_2$}} - This is the most general form of {\tt elim} and {\tt eelim}. It + These are the most general forms of {\tt elim} and {\tt eelim}. It combines the effects of the {\tt using} clause and of the two uses of the {\tt with} clause. @@ -1663,7 +1738,7 @@ last introduced hypothesis. \end{itemize} \begin{Variants} -\item{\tt destruct {\term} as {\intropattern}} +\item{\tt destruct {\term} as {\disjconjintropattern}} This behaves as {\tt destruct {\term}} but uses the names in {\intropattern} to name the variables introduced in the context. @@ -1674,16 +1749,24 @@ last introduced hypothesis. of the $i^{th}$ goal gets its name from the list $p_{i1}$ \ldots $p_{in_i}$ in order. If there are not enough names, {\tt destruct} invents names for the remaining variables to introduce. More - generally, the $p_{ij}$ can be any introduction patterns (see - Section~\ref{intros-pattern}). This provides a concise notation for - nested destruction. + generally, the $p_{ij}$ can be any disjunctive/conjunctive + introduction pattern (see Section~\ref{intros-pattern}). This + provides a concise notation for nested destruction. % It is recommended to use this variant of {\tt destruct} for % robust proof scripts. -\Rem for an inductive type with one constructor, the pattern notation -{\tt ($p_{1}$,\ldots,$p_{n}$)} can be used instead of -{\tt [} $p_{1} $\ldots $p_{n}$ {\tt ]}. +\item{\tt destruct {\term} as {\namingintropattern}} + + This behaves as {\tt destruct {\term}} but adds an equation between + {\term} and the value that {\term} takes in each of the possible + cases. The name of the equation is built according to + {\namingintropattern} which can be an identifier, a ``?'', etc, as + indicated in Section~\ref{intros-pattern}. + +\item{\tt destruct {\term} as {\namingintropattern} {\disjconjintropattern}} + + This combines the two previous forms. \item{\tt destruct {\term} with \bindinglist} @@ -1709,11 +1792,6 @@ last introduced hypothesis. These are synonyms of {\tt induction {\term$_1$} using {\term$_2$}} and {\tt induction {\term$_1$} using {\term$_2$} with {\bindinglist}}. -\item \texttt{destruct {\term} in *} - - This syntax tells to keep an equation between {\term} and the value - it gets in each cases of the analysis. - \item \texttt{destruct {\term} in {\occgoalset}} This syntax is used for selecting which occurrences of {\term} the @@ -1723,12 +1801,13 @@ last introduced hypothesis. When an occurrence clause is given, an equation between {\term} and the value it gets in each cases of the analysis is added to the - context of the subgoals corresponding to the cases. + context of the subgoals corresponding to the cases (even + if no clause {\tt as {\namingintropattern}} is given. -\item{\tt destruct {\term$_1$} with {\bindinglist$_1$} as {\intropattern} using {\term$_2$} with {\bindinglist$_2$} in {\occgoalset}}\\ - {\tt edestruct {\term$_1$} with {\bindinglist$_1$} as {\intropattern} using {\term$_2$} with {\bindinglist$_2$} in {\occgoalset}} +\item{\tt destruct {\term$_1$} with {\bindinglist$_1$} as {\namingintropattern} {\disjconjintropattern} using {\term$_2$} with {\bindinglist$_2$} in {\occgoalset}}\\ + {\tt edestruct {\term$_1$} with {\bindinglist$_1$} as {\namingintropattern} {\disjconjintropattern} using {\term$_2$} with {\bindinglist$_2$} in {\occgoalset}} - This is the most general form of {\tt destruct} and {\tt edestruct}. + These are the general forms of {\tt destruct} and {\tt edestruct}. It combines the effects of the {\tt with}, {\tt as}, {\tt using}, and {\tt in} clauses. @@ -1781,18 +1860,24 @@ last introduced hypothesis. \tacindex{intros \intropattern}} This extension of the tactic {\tt intros} combines introduction of -variables or hypotheses and case analysis. An introduction pattern is +variables or hypotheses and case analysis. An {\em introduction pattern} is either: \begin{itemize} -\item the wildcard: {\tt \_} -\item the pattern \texttt{?} -\item the pattern \texttt{?\ident} -\item an identifier -\item a disjunction of lists of patterns: +\item A {\em naming introduction pattern}, i.e. either one of: + \begin{itemize} + \item the pattern \texttt{?} + \item the pattern \texttt{?\ident} + \item an identifier + \end{itemize} +\item A {\em disjunctive/conjunctive introduction pattern}, i.e. either one of: + \begin{itemize} + \item a disjunction of lists of patterns: {\tt [$p_{11}$ {\ldots} $p_{1m_1}$ | {\ldots} | $p_{11}$ {\ldots} $p_{nm_n}$]} -\item a conjunction of patterns: {\tt (} $p_1$ {\tt ,} {\ldots} {\tt ,} $p_n$ {\tt )} -\item a list of patterns {\tt (} $p_1$\ {\tt \&}\ {\ldots}\ {\tt \&}\ $p_n$ {\tt )} - for sequence of right-associative binary constructs + \item a conjunction of patterns: {\tt (} $p_1$ {\tt ,} {\ldots} {\tt ,} $p_n$ {\tt )} + \item a list of patterns {\tt (} $p_1$\ {\tt \&}\ {\ldots}\ {\tt \&}\ $p_n$ {\tt )} + for sequence of right-associative binary constructs + \end{itemize} +\item the wildcard: {\tt \_} \item the rewriting orientations: {\tt ->} or {\tt <-} \end{itemize} @@ -1801,13 +1886,6 @@ of type {\tt forall $x$:$T$, $P$} (dependent product), the behavior of {\tt intros $p$} is defined inductively over the structure of the introduction pattern $p$: \begin{itemize} -\item introduction on the wildcard depends on whether the product is - dependent or not: in the non dependent case, it erases the - corresponding hypothesis (i.e. it behaves as an {\tt intro} followed - by a {\tt clear}, cf Section~\ref{clear}) while in the dependent - case, it succeeds and erases the variable only if the wildcard is - part of a more complex list of introduction patterns that also - erases the hypotheses depending on this variable; \item introduction on \texttt{?} performs the introduction, and let {\Coq} choose a fresh name for the variable; \item introduction on \texttt{?\ident} performs the introduction, and @@ -1843,6 +1921,13 @@ introduction pattern $p$: constructors such as {\tt conj} or {\tt ex\_intro}; for instance, an hypothesis with type {\tt A\verb|/\|exists x, B\verb|/\|C\verb|/\|D} can be introduced via pattern {\tt (a \& x \& b \& c \& d)}; +\item introduction on the wildcard depends on whether the product is + dependent or not: in the non dependent case, it erases the + corresponding hypothesis (i.e. it behaves as an {\tt intro} followed + by a {\tt clear}, cf Section~\ref{clear}) while in the dependent + case, it succeeds and erases the variable only if the wildcard is + part of a more complex list of introduction patterns that also + erases the hypotheses depending on this variable; \item introduction over {\tt ->} (respectively {\tt <-}) expects the hypothesis to be an equality and the right-hand-side (respectively the left-hand-side) is replaced by the left-hand-side (respectively diff --git a/interp/genarg.ml b/interp/genarg.ml index b371582a15..e962880978 100644 --- a/interp/genarg.ml +++ b/interp/genarg.ml @@ -75,24 +75,24 @@ let create_arg s = let exists_argtype s = List.mem s !dyntab type intro_pattern_expr = - | IntroOrAndPattern of case_intro_pattern_expr - | IntroWildcard of loc - | IntroIdentifier of identifier - | IntroAnonymous + | IntroOrAndPattern of or_and_intro_pattern_expr + | IntroWildcard | IntroRewrite of bool + | IntroIdentifier of identifier | IntroFresh of identifier -and case_intro_pattern_expr = intro_pattern_expr list list + | IntroAnonymous +and or_and_intro_pattern_expr = (loc * intro_pattern_expr) list list -let rec pr_intro_pattern = function - | IntroOrAndPattern pll -> pr_case_intro_pattern pll - | IntroWildcard _ -> str "_" - | IntroIdentifier id -> pr_id id - | IntroAnonymous -> str "?" +let rec pr_intro_pattern (_,pat) = match pat with + | IntroOrAndPattern pll -> pr_or_and_intro_pattern pll + | IntroWildcard -> str "_" | IntroRewrite true -> str "->" | IntroRewrite false -> str "<-" + | IntroIdentifier id -> pr_id id | IntroFresh id -> str "?" ++ pr_id id + | IntroAnonymous -> str "?" -and pr_case_intro_pattern = function +and pr_or_and_intro_pattern = function | [pl] -> str "(" ++ hv 0 (prlist_with_sep pr_coma pr_intro_pattern pl) ++ str ")" | pll -> diff --git a/interp/genarg.mli b/interp/genarg.mli index da03718999..bbdc7f7f0a 100644 --- a/interp/genarg.mli +++ b/interp/genarg.mli @@ -32,16 +32,16 @@ type open_rawconstr = unit * rawconstr_and_expr type 'a with_ebindings = 'a * open_constr bindings type intro_pattern_expr = - | IntroOrAndPattern of case_intro_pattern_expr - | IntroWildcard of loc - | IntroIdentifier of identifier - | IntroAnonymous + | IntroOrAndPattern of or_and_intro_pattern_expr + | IntroWildcard | IntroRewrite of bool + | IntroIdentifier of identifier | IntroFresh of identifier -and case_intro_pattern_expr = intro_pattern_expr list list + | IntroAnonymous +and or_and_intro_pattern_expr = (loc * intro_pattern_expr) list list -val pr_intro_pattern : intro_pattern_expr -> Pp.std_ppcmds -val pr_case_intro_pattern : case_intro_pattern_expr -> Pp.std_ppcmds +val pr_intro_pattern : intro_pattern_expr located -> Pp.std_ppcmds +val pr_or_and_intro_pattern : or_and_intro_pattern_expr -> Pp.std_ppcmds (* The route of a generic argument, from parsing to evaluation @@ -128,15 +128,16 @@ val wit_int_or_var : (int or_var,tlevel) abstract_argument_type val rawwit_string : (string,rlevel) abstract_argument_type val globwit_string : (string,glevel) abstract_argument_type + val wit_string : (string,tlevel) abstract_argument_type val rawwit_pre_ident : (string,rlevel) abstract_argument_type val globwit_pre_ident : (string,glevel) abstract_argument_type val wit_pre_ident : (string,tlevel) abstract_argument_type -val rawwit_intro_pattern : (intro_pattern_expr,rlevel) abstract_argument_type -val globwit_intro_pattern : (intro_pattern_expr,glevel) abstract_argument_type -val wit_intro_pattern : (intro_pattern_expr,tlevel) abstract_argument_type +val rawwit_intro_pattern : (intro_pattern_expr located,rlevel) abstract_argument_type +val globwit_intro_pattern : (intro_pattern_expr located,glevel) abstract_argument_type +val wit_intro_pattern : (intro_pattern_expr located,tlevel) abstract_argument_type val rawwit_ident : (identifier,rlevel) abstract_argument_type val globwit_ident : (identifier,glevel) abstract_argument_type diff --git a/kernel/environ.ml b/kernel/environ.ml index 30cec7ed94..80c24058ef 100644 --- a/kernel/environ.ml +++ b/kernel/environ.ml @@ -379,17 +379,14 @@ let insert_after_hyp (ctxt,vals) id d check = (* To be used in Logic.clear_hyps *) let remove_hyps ids check_context check_value (ctxt, vals) = - let ctxt,vals,rmv = - List.fold_right2 (fun (id,_,_ as d) (id',v) (ctxt,vals,rmv) -> + List.fold_right2 (fun (id,_,_ as d) (id',v) (ctxt,vals) -> if List.mem id ids then - (ctxt,vals,id::rmv) + (ctxt,vals) else let nd = check_context d in let nv = check_value v in - (nd::ctxt,(id',nv)::vals,rmv)) - ctxt vals ([],[],[]) - in ((ctxt,vals),rmv) - + (nd::ctxt,(id',nv)::vals)) + ctxt vals ([],[]) diff --git a/kernel/environ.mli b/kernel/environ.mli index ca41c2d7d9..b0dc2846f9 100644 --- a/kernel/environ.mli +++ b/kernel/environ.mli @@ -222,7 +222,7 @@ val insert_after_hyp : named_context_val -> variable -> named_declaration -> (named_context -> unit) -> named_context_val -val remove_hyps : identifier list -> (named_declaration -> named_declaration) -> (Pre_env.lazy_val -> Pre_env.lazy_val) -> named_context_val -> named_context_val * identifier list +val remove_hyps : identifier list -> (named_declaration -> named_declaration) -> (Pre_env.lazy_val -> Pre_env.lazy_val) -> named_context_val -> named_context_val (* spiwack: functions manipulating the retroknowledge *) diff --git a/kernel/term.ml b/kernel/term.ml index a15510158f..d274857af5 100644 --- a/kernel/term.ml +++ b/kernel/term.ml @@ -370,16 +370,22 @@ let destProd c = match kind_of_term c with | Prod (x,t1,t2) -> (x,t1,t2) | _ -> invalid_arg "destProd" +let isProd c = match kind_of_term c with | Prod _ -> true | _ -> false + (* Destructs the abstraction [x:t1]t2 *) let destLambda c = match kind_of_term c with | Lambda (x,t1,t2) -> (x,t1,t2) | _ -> invalid_arg "destLambda" +let isLambda c = match kind_of_term c with | Lambda _ -> true | _ -> false + (* Destructs the let [x:=b:t1]t2 *) let destLetIn c = match kind_of_term c with | LetIn (x,b,t1,t2) -> (x,b,t1,t2) | _ -> invalid_arg "destProd" +let isLetIn c = match kind_of_term c with LetIn _ -> true | _ -> false + (* Destructs an application *) let destApp c = match kind_of_term c with | App (f,a) -> (f, a) @@ -389,10 +395,6 @@ let destApplication = destApp let isApp c = match kind_of_term c with App _ -> true | _ -> false -let isProd c = match kind_of_term c with | Prod _ -> true | _ -> false - -let isLambda c = match kind_of_term c with | Lambda _ -> true | _ -> false - (* Destructs a constant *) let destConst c = match kind_of_term c with | Const kn -> kn @@ -419,22 +421,27 @@ let destConstruct c = match kind_of_term c with | Construct (kn, a as r) -> r | _ -> invalid_arg "dest" -let isConstruct c = match kind_of_term c with - Construct _ -> true | _ -> false +let isConstruct c = match kind_of_term c with Construct _ -> true | _ -> false (* Destructs a term
Case c of lc1 | lc2 .. | lcn end *)
let destCase c = match kind_of_term c with
| Case (ci,p,c,v) -> (ci,p,c,v)
| _ -> anomaly "destCase"
+let isCase c = match kind_of_term c with Case _ -> true | _ -> false
+
let destFix c = match kind_of_term c with
| Fix fix -> fix
| _ -> invalid_arg "destFix"
-
+
+let isFix c = match kind_of_term c with Fix _ -> true | _ -> false
+
let destCoFix c = match kind_of_term c with
| CoFix cofix -> cofix
| _ -> invalid_arg "destCoFix"
+let isCoFix c = match kind_of_term c with CoFix _ -> true | _ -> false
+
(******************************************************************)
(* Cast management *)
(******************************************************************)
diff --git a/kernel/term.mli b/kernel/term.mli
index 9254a6ff83..2ab03e50fe 100644
--- a/kernel/term.mli
+++ b/kernel/term.mli
@@ -230,9 +230,13 @@ val isSort : constr -> bool
val isCast : constr -> bool
val isApp : constr -> bool
val isLambda : constr -> bool
+val isLetIn : constr -> bool
val isProd : constr -> bool
val isConst : constr -> bool
val isConstruct : constr -> bool
+val isFix : constr -> bool
+val isCoFix : constr -> bool
+val isCase : constr -> bool
val is_Prop : constr -> bool
val is_Set : constr -> bool
diff --git a/lib/flags.ml b/lib/flags.ml
index 0378e11fb4..76ab9fe64b 100644
--- a/lib/flags.ml
+++ b/lib/flags.ml
@@ -8,8 +8,6 @@
(*i $Id$ i*)
-open Util
-
let with_option o f x =
let old = !o in o:=true;
try let r = f x in o := old; r
@@ -78,6 +76,8 @@ let print_hyps_limit () = !print_hyps_limit
(* A list of the areas of the system where "unsafe" operation
* has been requested *)
+module Stringset = Set.Make(struct type t = string let compare = compare end)
+
let unsafe_set = ref Stringset.empty
let add_unsafe s = unsafe_set := Stringset.add s !unsafe_set
let is_unsafe s = Stringset.mem s !unsafe_set
diff --git a/lib/util.ml b/lib/util.ml
index 549b79e786..94e812ff65 100644
--- a/lib/util.ml
+++ b/lib/util.ml
@@ -1210,6 +1210,8 @@ let pr_opt_no_spc pr = function None -> mt () | Some x -> pr x
let nth n = str (ordinal n)
+(* [prlist pr [a ; ... ; c]] outputs [pr a ++ ... ++ pr c] *)
+
let rec prlist elem l = match l with
| [] -> mt ()
| h::t -> Stream.lapp (fun () -> elem h) (prlist elem t)
@@ -1221,6 +1223,9 @@ let rec prlist_strict elem l = match l with
| [] -> mt ()
| h::t -> (elem h)++(prlist_strict elem t)
+(* [prlist_with_sep sep pr [a ; ... ; c]] outputs
+ [pr a ++ sep() ++ ... ++ sep() ++ pr c] *)
+
let rec prlist_with_sep sep elem l = match l with
| [] -> mt ()
| [h] -> elem h
@@ -1228,6 +1233,23 @@ let rec prlist_with_sep sep elem l = match l with
let e = elem h and s = sep() and r = prlist_with_sep sep elem t in
e ++ s ++ r
+(* Print sequence of objects separated by space (unless an element is empty) *)
+
+let rec pr_sequence elem = function
+ | [] -> mt ()
+ | [h] -> elem h
+ | h::t ->
+ let e = elem h and r = pr_sequence elem t in
+ if e = mt () then r else e ++ spc () ++ r
+
+(* [pr_enum pr [a ; b ; ... ; c]] outputs
+ [pr a ++ str "," ++ pr b ++ str "," ++ ... ++ str "and" ++ pr c] *)
+
+let pr_enum pr l =
+ let c,l' = list_sep_last l in
+ prlist_with_sep pr_coma pr l' ++
+ (if l'<>[] then str " and" ++ spc () else mt()) ++ pr c
+
let pr_vertical_list pr = function
| [] -> str "none" ++ fnl ()
| l -> fnl () ++ str " " ++ hov 0 (prlist_with_sep pr_fnl pr l) ++ fnl ()
@@ -1242,6 +1264,9 @@ let prvecti elem v =
in
if n = 0 then mt () else pr (n - 1)
+(* [prvect_with_sep sep pr [|a ; ... ; c|]] outputs
+ [pr a ++ sep() ++ ... ++ sep() ++ pr c] *)
+
let prvect_with_sep sep elem v =
let rec pr n =
if n = 0 then
@@ -1253,8 +1278,16 @@ let prvect_with_sep sep elem v =
let n = Array.length v in
if n = 0 then mt () else pr (n - 1)
+(* [prvect pr [|a ; ... ; c|]] outputs [pr a ++ ... ++ pr c] *)
+
let prvect elem v = prvect_with_sep mt elem v
+let pr_located pr (loc,x) =
+ if Flags.do_translate() && loc<>dummy_loc then
+ let (b,e) = unloc loc in
+ comment b ++ pr x ++ comment e
+ else pr x
+
let surround p = hov 1 (str"(" ++ p ++ str")")
(*s Size of ocaml values. *)
diff --git a/lib/util.mli b/lib/util.mli
index d845dd2ebf..40d6046d7d 100644
--- a/lib/util.mli
+++ b/lib/util.mli
@@ -282,6 +282,9 @@ val prvecti : (int -> 'a -> std_ppcmds) -> 'a array -> std_ppcmds
val prvect_with_sep :
(unit -> std_ppcmds) -> ('b -> std_ppcmds) -> 'b array -> std_ppcmds
val pr_vertical_list : ('b -> std_ppcmds) -> 'b list -> std_ppcmds
+val pr_enum : ('a -> std_ppcmds) -> 'a list -> std_ppcmds
+val pr_located : ('a -> std_ppcmds) -> 'a located -> std_ppcmds
+val pr_sequence : ('a -> std_ppcmds) -> 'a list -> std_ppcmds
val surround : std_ppcmds -> std_ppcmds
diff --git a/parsing/g_minicoq.ml4 b/parsing/g_minicoq.ml4
deleted file mode 100644
index fe7906f63d..0000000000
--- a/parsing/g_minicoq.ml4
+++ /dev/null
@@ -1,177 +0,0 @@
-(************************************************************************)
-(* v * The Coq Proof Assistant / The Coq Development Team *)
-(* "
-let rec interp_message ist = function
- | [] -> mt()
- | MsgString s :: l -> pr_arg str s ++ interp_message ist l
- | MsgInt n :: l -> pr_arg int n ++ interp_message ist l
- | MsgIdent (loc,id) :: l ->
+let rec interp_message_token ist = function
+ | MsgString s -> str s
+ | MsgInt n -> int n
+ | MsgIdent (loc,id) ->
let v =
try List.assoc id ist.lfun
with Not_found -> user_err_loc (loc,"",pr_id id ++ str" not found.") in
- pr_arg message_of_value v ++ interp_message ist l
+ message_of_value v
let rec interp_message_nl ist = function
| [] -> mt()
- | l -> interp_message ist l ++ fnl()
+ | l -> prlist_with_sep spc (interp_message_token ist) l ++ fnl()
-let rec interp_intro_pattern ist gl = function
- | IntroOrAndPattern l -> IntroOrAndPattern (interp_case_intro_pattern ist gl l)
- | IntroIdentifier id -> interp_intro_pattern_var ist (pf_env gl) id
- | IntroWildcard _ | IntroAnonymous | IntroFresh _ | IntroRewrite _ as x -> x
+let interp_message ist l =
+ (* Force evaluation of interp_message_token so that potential errors
+ are raised now and not at printing time *)
+ prlist (fun x -> spc () ++ x) (List.map (interp_message_token ist) l)
-and interp_case_intro_pattern ist gl =
+let rec interp_intro_pattern ist gl = function
+ | loc, IntroOrAndPattern l ->
+ loc, IntroOrAndPattern (interp_or_and_intro_pattern ist gl l)
+ | loc, IntroIdentifier id ->
+ loc, interp_intro_pattern_var loc ist (pf_env gl) id
+ | loc, (IntroWildcard | IntroAnonymous | IntroFresh _ | IntroRewrite _)
+ as x -> x
+
+and interp_or_and_intro_pattern ist gl =
List.map (List.map (interp_intro_pattern ist gl))
(* Quantified named or numbered hypothesis or hypothesis in context *)
@@ -1716,14 +1721,14 @@ let rec val_interp ist gl (tac:glob_tactic_expr) =
let value_interp ist = match tac with
(* Immediate evaluation *)
- | TacFun (it,body) -> VFun (ist.lfun,it,body)
+ | TacFun (it,body) -> VFun (ist.trace,ist.lfun,it,body)
| TacLetIn (true,l,u) -> interp_letrec ist gl l u
| TacLetIn (false,l,u) -> interp_letin ist gl l u
| TacMatchContext (lz,lr,lmr) -> interp_match_context ist gl lz lr lmr
| TacMatch (lz,c,lmr) -> interp_match ist gl lz c lmr
| TacArg a -> interp_tacarg ist gl a
(* Delayed evaluation *)
- | t -> VTactic (ist.last_loc,eval_tactic ist t)
+ | t -> VFun (ist.trace,ist.lfun,[],t)
in check_for_interrupt ();
match ist.debug with
@@ -1732,7 +1737,14 @@ let rec val_interp ist gl (tac:glob_tactic_expr) =
| _ -> value_interp ist
and eval_tactic ist = function
- | TacAtom (loc,t) -> fun gl -> catch_error loc (interp_atomic ist gl t) gl
+ | TacAtom (loc,t) ->
+ fun gl ->
+ let box = ref None in abstract_tactic_box := box;
+ let call = LtacAtomCall (t,box) in
+ let tac = (* catch error in the interpretation *)
+ catch_error ((dloc,call)::ist.trace) (interp_atomic ist gl) t in
+ (* catch error in the evaluation *)
+ catch_error ((loc,call)::ist.trace) tac gl
| TacFun _ | TacLetIn _ -> assert false
| TacMatchContext _ | TacMatch _ -> assert false
| TacId s -> tclIDTAC_MESSAGE (interp_message_nl ist s)
@@ -1767,31 +1779,33 @@ and force_vrec ist gl = function
| VRec (lfun,body) -> val_interp {ist with lfun = !lfun} gl body
| v -> v
-and interp_ltac_reference isapplied mustbetac ist gl = function
+and interp_ltac_reference loc' mustbetac ist gl = function
| ArgVar (loc,id) ->
let v = List.assoc id ist.lfun in
let v = force_vrec ist gl v in
+ let v = propagate_trace ist loc id v in
if mustbetac then coerce_to_tactic loc id v else v
| ArgArg (loc,r) ->
let ids = extract_ids [] ist.lfun in
+ let loc_info = ((if loc' = dloc then loc else loc'),LtacNameCall r) in
let ist =
{ lfun=[]; debug=ist.debug; avoid_ids=ids;
- last_loc = if isapplied then ist.last_loc else loc } in
+ trace = loc_info::ist.trace } in
val_interp ist gl (lookup r)
and interp_tacarg ist gl = function
| TacVoid -> VVoid
- | Reference r -> interp_ltac_reference false false ist gl r
+ | Reference r -> interp_ltac_reference dloc false ist gl r
| Integer n -> VInteger n
- | IntroPattern ipat -> VIntroPattern (interp_intro_pattern ist gl ipat)
+ | IntroPattern ipat -> VIntroPattern (snd (interp_intro_pattern ist gl ipat))
| ConstrMayEval c -> VConstr (interp_constr_may_eval ist gl c)
| MetaIdArg (loc,_,id) -> assert false
- | TacCall (loc,r,[]) -> interp_ltac_reference false true ist gl r
+ | TacCall (loc,r,[]) -> interp_ltac_reference loc true ist gl r
| TacCall (loc,f,l) ->
- let fv = interp_ltac_reference true true ist gl f
+ let fv = interp_ltac_reference loc true ist gl f
and largs = List.map (interp_tacarg ist gl) l in
List.iter check_is_value largs;
- interp_app ist gl fv largs loc
+ interp_app loc ist gl fv largs
| TacExternal (loc,com,req,la) ->
interp_external loc ist gl com req (List.map (interp_tacarg ist gl) la)
| TacFreshId l ->
@@ -1801,12 +1815,7 @@ and interp_tacarg ist gl = function
| TacDynamic(_,t) ->
let tg = (tag t) in
if tg = "tactic" then
- let f = (tactic_out t) in
- val_interp ist gl
- (intern_tactic {
- ltacvars = (List.map fst ist.lfun,[]); ltacrecvars = [];
- gsigma = project gl; genv = pf_env gl }
- (f ist))
+ val_interp ist gl (tactic_out t ist)
else if tg = "value" then
value_out t
else if tg = "constr" then
@@ -1816,32 +1825,34 @@ and interp_tacarg ist gl = function
(str "Unknown dynamic: <" ++ str (Dyn.tag t) ++ str ">"))
(* Interprets an application node *)
-and interp_app ist gl fv largs loc =
+and interp_app loc ist gl fv largs =
match fv with
- | VFun(olfun,var,body) ->
+ | VFun(trace,olfun,var,body) ->
let (newlfun,lvar,lval)=head_with_value (var,largs) in
if lvar=[] then
let v =
try
- let lloc = if lval=[] then loc else ist.last_loc in
- val_interp { ist with lfun=newlfun@olfun; last_loc=lloc } gl body
+ catch_error trace
+ (val_interp { ist with lfun=newlfun@olfun; trace=trace } gl) body
with e ->
debugging_exception_step ist false e (fun () -> str "evaluation");
raise e in
debugging_step ist (fun () ->
str "evaluation returns" ++ fnl() ++ pr_value (Some (pf_env gl)) v);
- if lval=[] then v else interp_app ist gl v lval loc
+ if lval=[] then v else interp_app loc ist gl v lval
else
- VFun(newlfun@olfun,lvar,body)
+ VFun(trace,newlfun@olfun,lvar,body)
| _ ->
user_err_loc (loc, "Tacinterp.interp_app",
(str"Illegal tactic application."))
(* Gives the tactic corresponding to the tactic value *)
-and tactic_of_value vle g =
+and tactic_of_value ist vle g =
match vle with
| VRTactic res -> res
- | VTactic (loc,tac) -> catch_error loc tac g
+ | VFun (trace,lfun,[],t) ->
+ let tac = eval_tactic {ist with lfun=lfun; trace=trace} t in
+ catch_error trace tac g
| VFun _ -> error "A fully applied tactic is expected."
| _ -> raise NotTactic
@@ -1849,15 +1860,19 @@ and tactic_of_value vle g =
and eval_with_fail ist is_lazy goal tac =
try
(match val_interp ist goal tac with
- | VTactic (loc,tac) when not is_lazy -> VRTactic (catch_error loc tac goal)
+ | VFun (trace,lfun,[],t) when not is_lazy ->
+ let tac = eval_tactic {ist with lfun=lfun; trace=trace} t in
+ VRTactic (catch_error trace tac goal)
| a -> a)
with
- | Stdpp.Exc_located (_,FailError (0,s)) | FailError (0,s) ->
+ | FailError (0,s) | Stdpp.Exc_located(_, FailError (0,s))
+ | Stdpp.Exc_located(_,LtacLocated (_,FailError (0,s))) ->
raise (Eval_fail s)
- | Stdpp.Exc_located (s',FailError (lvl,s)) ->
- raise (Stdpp.Exc_located (s',FailError (lvl - 1, s)))
- | FailError (lvl,s) ->
- raise (FailError (lvl - 1, s))
+ | FailError (lvl,s) -> raise (FailError (lvl - 1, s))
+ | Stdpp.Exc_located(s,FailError (lvl,s')) ->
+ raise (Stdpp.Exc_located(s,FailError (lvl - 1, s')))
+ | Stdpp.Exc_located(s,LtacLocated (s'',FailError (lvl,s'))) ->
+ raise (Stdpp.Exc_located(s,LtacLocated (s'',FailError (lvl - 1, s'))))
(* Interprets the clauses of a recursive LetIn *)
and interp_letrec ist gl llc u =
@@ -2119,9 +2134,8 @@ and interp_ltac_constr ist gl e =
str "offending expression: " ++ fnl() ++
Pptactic.pr_glob_tactic (pf_env gl) e ++ fnl() ++ str "this is a " ++
(match result with
- VTactic _ -> str "VTactic"
| VRTactic _ -> str "VRTactic"
- | VFun (il,ul,b) ->
+ | VFun (_,il,ul,b) ->
(str "VFun with body " ++ fnl() ++
Pptactic.pr_glob_tactic (pf_env gl) b ++ fnl() ++
str "instantiated arguments " ++ fnl() ++
@@ -2135,7 +2149,7 @@ and interp_ltac_constr ist gl e =
(match opt_id with
Some id -> str (string_of_id id)
| None -> str "_") ++ str ", " ++ s)
- ul (str ""))
+ ul (mt()))
| VVoid -> str "VVoid"
| VInteger _ -> str "VInteger"
| VConstr _ -> str "VConstr"
@@ -2146,9 +2160,8 @@ and interp_ltac_constr ist gl e =
(* Interprets tactic expressions : returns a "tactic" *)
and interp_tactic ist tac gl =
- try tactic_of_value (val_interp ist gl tac) gl
- with NotTactic ->
- errorlabstrm "" (str "Must be a command or must give a tactic value.")
+ try tactic_of_value ist (val_interp ist gl tac) gl
+ with NotTactic -> errorlabstrm "" (str "Not a tactic.")
(* Interprets a primitive tactic *)
and interp_atomic ist gl = function
@@ -2157,14 +2170,15 @@ and interp_atomic ist gl = function
h_intro_patterns (List.map (interp_intro_pattern ist gl) l)
| TacIntrosUntil hyp ->
h_intros_until (interp_quantified_hypothesis ist hyp)
- | TacIntroMove (ido,ido') ->
+ | TacIntroMove (ido,hto) ->
h_intro_move (Option.map (interp_fresh_ident ist gl) ido)
- (Option.map (interp_hyp ist gl) ido')
+ (interp_move_location ist gl hto)
| TacAssumption -> h_assumption
| TacExact c -> h_exact (pf_interp_casted_constr ist gl c)
| TacExactNoCheck c -> h_exact_no_check (pf_interp_constr ist gl c)
| TacVmCastNoCheck c -> h_vm_cast_no_check (pf_interp_constr ist gl c)
- | TacApply (a,ev,cb) -> h_apply a ev (interp_constr_with_bindings ist gl cb)
+ | TacApply (a,ev,cb) ->
+ h_apply a ev (List.map (interp_constr_with_bindings ist gl) cb)
| TacElim (ev,cb,cbo) ->
h_elim ev (interp_constr_with_bindings ist gl cb)
(Option.map (interp_constr_with_bindings ist gl) cbo)
@@ -2210,20 +2224,16 @@ and interp_atomic ist gl = function
(pf_interp_constr_list ist gl lems)
(* Derived basic tactics *)
- | TacSimpleInduction h ->
- h_simple_induction (interp_quantified_hypothesis ist h)
- | TacNewInduction (ev,lc,cbo,ids,cls) ->
- h_new_induction ev (List.map (interp_induction_arg ist gl) lc)
- (Option.map (interp_constr_with_bindings ist gl) cbo)
- (interp_intro_pattern ist gl ids)
- (Option.map (interp_clause ist gl) cls)
- | TacSimpleDestruct h ->
- h_simple_destruct (interp_quantified_hypothesis ist h)
- | TacNewDestruct (ev,c,cbo,ids,cls) ->
- h_new_destruct ev (List.map (interp_induction_arg ist gl) c)
- (Option.map (interp_constr_with_bindings ist gl) cbo)
- (interp_intro_pattern ist gl ids)
- (Option.map (interp_clause ist gl) cls)
+ | TacSimpleInductionDestruct (isrec,h) ->
+ h_simple_induction_destruct isrec (interp_quantified_hypothesis ist h)
+ | TacInductionDestruct (isrec,ev,l) ->
+ h_induction_destruct ev isrec
+ (List.map (fun (lc,cbo,(ipato,ipats),cls) ->
+ (List.map (interp_induction_arg ist gl) lc,
+ Option.map (interp_constr_with_bindings ist gl) cbo,
+ (Option.map (interp_intro_pattern ist gl) ipato,
+ Option.map (interp_intro_pattern ist gl) ipats),
+ Option.map (interp_clause ist gl) cls)) l)
| TacDoubleInduction (h1,h2) ->
let h1 = interp_quantified_hypothesis ist h1 in
let h2 = interp_quantified_hypothesis ist h2 in
@@ -2241,7 +2251,7 @@ and interp_atomic ist gl = function
| TacClear (b,l) -> h_clear b (interp_hyp_list ist gl l)
| TacClearBody l -> h_clear_body (interp_hyp_list ist gl l)
| TacMove (dep,id1,id2) ->
- h_move dep (interp_hyp ist gl id1) (interp_hyp ist gl id2)
+ h_move dep (interp_hyp ist gl id1) (interp_move_location ist gl id2)
| TacRename l ->
h_rename (List.map (fun (id1,id2) ->
interp_hyp ist gl id1,
@@ -2283,11 +2293,11 @@ and interp_atomic ist gl = function
(Option.map (interp_tactic ist) by)
| TacInversion (DepInversion (k,c,ids),hyp) ->
Inv.dinv k (Option.map (pf_interp_constr ist gl) c)
- (interp_intro_pattern ist gl ids)
+ (Option.map (interp_intro_pattern ist gl) ids)
(interp_declared_or_quantified_hypothesis ist gl hyp)
| TacInversion (NonDepInversion (k,idl,ids),hyp) ->
Inv.inv_clause k
- (interp_intro_pattern ist gl ids)
+ (Option.map (interp_intro_pattern ist gl) ids)
(interp_hyp_list ist gl idl)
(interp_declared_or_quantified_hypothesis ist gl hyp)
| TacInversion (InversionUsing (c,idl),hyp) ->
@@ -2298,10 +2308,9 @@ and interp_atomic ist gl = function
(* For extensions *)
| TacExtend (loc,opn,l) ->
let tac = lookup_tactic opn in
- fun gl ->
- let args = List.map (interp_genarg ist gl) l in
- abstract_extended_tactic opn args (tac args) gl
- | TacAlias (loc,_,l,(_,body)) -> fun gl ->
+ let args = List.map (interp_genarg ist gl) l in
+ abstract_extended_tactic opn args (tac args)
+ | TacAlias (loc,s,l,(_,body)) -> fun gl ->
let rec f x = match genarg_tag x with
| IntArgType ->
VInteger (out_gen globwit_int x)
@@ -2311,7 +2320,7 @@ and interp_atomic ist gl = function
failwith "pre-identifiers cannot be bound"
| IntroPatternArgType ->
VIntroPattern
- (interp_intro_pattern ist gl (out_gen globwit_intro_pattern x))
+ (snd (interp_intro_pattern ist gl (out_gen globwit_intro_pattern x)))
| IdentArgType ->
VIntroPattern
(IntroIdentifier
@@ -2366,10 +2375,8 @@ and interp_atomic ist gl = function
in
let lfun = (List.map (fun (x,c) -> (x,f c)) l)@ist.lfun in
- let v = locate_tactic_call loc (val_interp { ist with lfun=lfun } gl body)
- in
- try tactic_of_value v gl
- with NotTactic -> user_err_loc (loc,"",str "Not a tactic.")
+ let trace = (loc,LtacNotationCall s)::ist.trace in
+ interp_tactic { ist with lfun=lfun; trace=trace } body gl
let make_empty_glob_sign () =
{ ltacvars = ([],[]); ltacrecvars = [];
@@ -2377,20 +2384,20 @@ let make_empty_glob_sign () =
(* Initial call for interpretation *)
let interp_tac_gen lfun avoid_ids debug t gl =
- interp_tactic { lfun=lfun; avoid_ids=avoid_ids; debug=debug; last_loc=dloc }
+ interp_tactic { lfun=lfun; avoid_ids=avoid_ids; debug=debug; trace=[] }
(intern_tactic {
ltacvars = (List.map fst lfun, []); ltacrecvars = [];
gsigma = project gl; genv = pf_env gl } t) gl
let eval_tactic t gls =
- interp_tactic { lfun=[]; avoid_ids=[]; debug=get_debug(); last_loc=dloc }
+ interp_tactic { lfun=[]; avoid_ids=[]; debug=get_debug(); trace=[] }
t gls
let interp t = interp_tac_gen [] [] (get_debug()) t
let eval_ltac_constr gl t =
interp_ltac_constr
- { lfun=[]; avoid_ids=[]; debug=get_debug(); last_loc=dloc } gl
+ { lfun=[]; avoid_ids=[]; debug=get_debug(); trace=[] } gl
(intern_tactic (make_empty_glob_sign ()) t )
(* Hides interpretation for pretty-print *)
@@ -2453,7 +2460,7 @@ let subst_global_reference subst =
let subst_global ref =
let ref',t' = subst_global subst ref in
if not (eq_constr (constr_of_global ref') t') then
- ppnl (str "Warning: the reference " ++ pr_global ref ++ str " is not " ++
+ ppnl (str "Warning: The reference " ++ pr_global ref ++ str " is not " ++
str " expanded to \"" ++ pr_lconstr t' ++ str "\", but to " ++
pr_global ref') ;
ref'
@@ -2507,7 +2514,8 @@ let rec subst_atomic subst (t:glob_atomic_tactic_expr) = match t with
| TacExact c -> TacExact (subst_rawconstr subst c)
| TacExactNoCheck c -> TacExactNoCheck (subst_rawconstr subst c)
| TacVmCastNoCheck c -> TacVmCastNoCheck (subst_rawconstr subst c)
- | TacApply (a,ev,cb) -> TacApply (a,ev,subst_raw_with_bindings subst cb)
+ | TacApply (a,ev,cb) ->
+ TacApply (a,ev,List.map (subst_raw_with_bindings subst) cb)
| TacElim (ev,cb,cbo) ->
TacElim (ev,subst_raw_with_bindings subst cb,
Option.map (subst_raw_with_bindings subst) cbo)
@@ -2538,14 +2546,11 @@ let rec subst_atomic subst (t:glob_atomic_tactic_expr) = match t with
| TacDAuto (n,p,lems) -> TacDAuto (n,p,List.map (subst_rawconstr subst) lems)
(* Derived basic tactics *)
- | TacSimpleInduction h as x -> x
- | TacNewInduction (ev,lc,cbo,ids,cls) ->
- TacNewInduction (ev,List.map (subst_induction_arg subst) lc,
- Option.map (subst_raw_with_bindings subst) cbo, ids, cls)
- | TacSimpleDestruct h as x -> x
- | TacNewDestruct (ev,c,cbo,ids,cls) ->
- TacNewDestruct (ev,List.map (subst_induction_arg subst) c,
- Option.map (subst_raw_with_bindings subst) cbo, ids, cls)
+ | TacSimpleInductionDestruct (isrec,h) as x -> x
+ | TacInductionDestruct (isrec,ev,l) ->
+ TacInductionDestruct (isrec,ev,List.map (fun (lc,cbo,ids,cls) ->
+ List.map (subst_induction_arg subst) lc,
+ Option.map (subst_raw_with_bindings subst) cbo, ids, cls) l)
| TacDoubleInduction (h1,h2) as x -> x
| TacDecomposeAnd c -> TacDecomposeAnd (subst_rawconstr subst c)
| TacDecomposeOr c -> TacDecomposeOr (subst_rawconstr subst c)
@@ -2771,7 +2776,7 @@ let print_ltac id =
try
let kn = Nametab.locate_tactic id in
let t = lookup kn in
- str "Ltac" ++ spc() ++ pr_qualid id ++ str ":=" ++ spc() ++
+ str "Ltac" ++ spc() ++ pr_qualid id ++ str " :=" ++ spc() ++
Pptactic.pr_glob_tactic (Global.env ()) t
with
Not_found ->
@@ -2846,17 +2851,33 @@ let glob_tactic_env l env x =
x
let interp_redexp env sigma r =
- let ist = { lfun=[]; avoid_ids=[]; debug=get_debug (); last_loc=dloc } in
+ let ist = { lfun=[]; avoid_ids=[]; debug=get_debug (); trace=[] } in
let gist = {(make_empty_glob_sign ()) with genv = env; gsigma = sigma } in
interp_red_expr ist sigma env (intern_red_expr gist r)
+(***************************************************************************)
+(* Embed tactics in raw or glob tactic expr *)
+
+let globTacticIn t = TacArg (TacDynamic (dummy_loc,tactic_in t))
+let tacticIn t = globTacticIn (fun ist -> glob_tactic (t ist))
+
+let tacticOut = function
+ | TacArg (TacDynamic (_,d)) ->
+ if (tag d) = "tactic" then
+ tactic_out d
+ else
+ anomalylabstrm "tacticOut" (str "Dynamic tag should be tactic")
+ | ast ->
+ anomalylabstrm "tacticOut"
+ (str "Not a Dynamic ast: " (* ++ print_ast ast*) )
+
(***************************************************************************)
(* Backwarding recursive needs of tactic glob/interp/eval functions *)
let _ = Auto.set_extern_interp
(fun l ->
let l = List.map (fun (id,c) -> (id,VConstr c)) l in
- interp_tactic {lfun=l;avoid_ids=[];debug=get_debug(); last_loc=dloc})
+ interp_tactic {lfun=l;avoid_ids=[];debug=get_debug(); trace=[]})
let _ = Auto.set_extern_intern_tac
(fun l ->
Flags.with_option strict_check
diff --git a/tactics/tacinterp.mli b/tactics/tacinterp.mli
index 2a490fdace..5c040821b9 100644
--- a/tactics/tacinterp.mli
+++ b/tactics/tacinterp.mli
@@ -26,9 +26,9 @@ open Redexpr
(* Values for interpretation *)
type value =
- | VTactic of Util.loc * tactic (* For mixed ML/Ltac tactics (e.g. Tauto) *)
| VRTactic of (goal list sigma * validation)
- | VFun of (identifier * value) list * identifier option list * glob_tactic_expr
+ | VFun of ltac_trace * (identifier*value) list *
+ identifier option list * glob_tactic_expr
| VVoid
| VInteger of int
| VIntroPattern of intro_pattern_expr
@@ -42,18 +42,16 @@ and interp_sign =
{ lfun : (identifier * value) list;
avoid_ids : identifier list;
debug : debug_info;
- last_loc : loc }
+ trace : ltac_trace }
(* Transforms an id into a constr if possible *)
val constr_of_id : Environ.env -> identifier -> constr
(* To embed several objects in Coqast.t *)
val tacticIn : (interp_sign -> raw_tactic_expr) -> raw_tactic_expr
-val tacticOut : raw_tactic_expr -> (interp_sign -> raw_tactic_expr)
+val globTacticIn : (interp_sign -> glob_tactic_expr) -> raw_tactic_expr
val valueIn : value -> raw_tactic_arg
-val valueOut: raw_tactic_arg -> value
val constrIn : constr -> constr_expr
-val constrOut : constr_expr -> constr
(* Sets the debugger mode *)
val set_debug : debug_info -> unit
diff --git a/tactics/tacticals.ml b/tactics/tacticals.ml
index 13ce334447..bbd9112d49 100644
--- a/tactics/tacticals.ml
+++ b/tactics/tacticals.ml
@@ -270,19 +270,28 @@ type branch_args = {
nassums : int; (* the number of assumptions to be introduced *)
branchsign : bool list; (* the signature of the branch.
true=recursive argument, false=constant *)
- branchnames : intro_pattern_expr list}
+ branchnames : intro_pattern_expr located list}
type branch_assumptions = {
ba : branch_args; (* the branch args *)
assums : named_context} (* the list of assumptions introduced *)
+let check_or_and_pattern_size loc names n =
+ if List.length names <> n then
+ if n = 1 then
+ user_err_loc (loc,"",str "Expects a conjunctive pattern.")
+ else
+ user_err_loc (loc,"",str "Expects a disjunctive pattern with " ++ int n
+ ++ str " branches.")
+
let compute_induction_names n = function
- | IntroAnonymous ->
+ | None ->
Array.make n []
- | IntroOrAndPattern names when List.length names = n ->
+ | Some (loc,IntroOrAndPattern names) ->
+ check_or_and_pattern_size loc names n;
Array.of_list names
| _ ->
- errorlabstrm "" (str "Expects " ++ int n ++ str " lists of names.")
+ error "Unexpected introduction pattern."
let compute_construtor_signatures isrec (_,k as ity) =
let rec analrec c recargs =
@@ -393,7 +402,7 @@ let elimination_then_using tac predicate bindings c gl =
let (ind,t) = pf_reduce_to_quantified_ind gl (pf_type_of gl c) in
let indclause = mk_clenv_from gl (c,t) in
general_elim_then_using gl_make_elim
- true IntroAnonymous tac predicate bindings ind indclause gl
+ true None tac predicate bindings ind indclause gl
let case_then_using =
general_elim_then_using gl_make_case_dep false
diff --git a/tactics/tacticals.mli b/tactics/tacticals.mli
index d7620acf2d..8cc556c62a 100644
--- a/tactics/tacticals.mli
+++ b/tactics/tacticals.mli
@@ -10,6 +10,7 @@
(*i*)
open Pp
+open Util
open Names
open Term
open Sign
@@ -124,23 +125,30 @@ type branch_args = {
nassums : int; (* the number of assumptions to be introduced *)
branchsign : bool list; (* the signature of the branch.
true=recursive argument, false=constant *)
- branchnames : intro_pattern_expr list}
+ branchnames : intro_pattern_expr located list}
type branch_assumptions = {
ba : branch_args; (* the branch args *)
assums : named_context} (* the list of assumptions introduced *)
+(* [check_disjunctive_pattern_size loc pats n] returns an appropriate *)
+(* error message if |pats| <> n *)
+val check_or_and_pattern_size :
+ Util.loc -> or_and_intro_pattern_expr -> int -> unit
+
(* Useful for [as intro_pattern] modifier *)
val compute_induction_names :
- int -> intro_pattern_expr -> intro_pattern_expr list array
+ int -> intro_pattern_expr located option ->
+ intro_pattern_expr located list array
val elimination_sort_of_goal : goal sigma -> sorts_family
val elimination_sort_of_hyp : identifier -> goal sigma -> sorts_family
val general_elim_then_using :
- (inductive -> goal sigma -> constr) -> rec_flag -> intro_pattern_expr ->
- (branch_args -> tactic) -> constr option ->
- (arg_bindings * arg_bindings) -> inductive -> clausenv -> tactic
+ (inductive -> goal sigma -> constr) -> rec_flag ->
+ intro_pattern_expr located option -> (branch_args -> tactic) ->
+ constr option -> (arg_bindings * arg_bindings) -> inductive -> clausenv ->
+ tactic
val elimination_then_using :
(branch_args -> tactic) -> constr option ->
@@ -151,12 +159,12 @@ val elimination_then :
(arg_bindings * arg_bindings) -> constr -> tactic
val case_then_using :
- intro_pattern_expr -> (branch_args -> tactic) ->
+ intro_pattern_expr located option -> (branch_args -> tactic) ->
constr option -> (arg_bindings * arg_bindings) ->
inductive -> clausenv -> tactic
val case_nodep_then_using :
- intro_pattern_expr -> (branch_args -> tactic) ->
+ intro_pattern_expr located option -> (branch_args -> tactic) ->
constr option -> (arg_bindings * arg_bindings) ->
inductive -> clausenv -> tactic
diff --git a/tactics/tactics.ml b/tactics/tactics.ml
index cb2acc9bd5..23524e8500 100644
--- a/tactics/tactics.ml
+++ b/tactics/tactics.ml
@@ -75,6 +75,8 @@ let inj_ebindings = function
| ExplicitBindings l ->
ExplicitBindings (List.map (fun (l,id,c) -> (l,id,inj_open c)) l)
+let dloc = dummy_loc
+
(*********************************************)
(* Tactics *)
(*********************************************)
@@ -126,15 +128,44 @@ let bad_tactic_args s l =
(******************************************)
let introduction = Tacmach.introduction
-let intro_replacing = Tacmach.intro_replacing
-let internal_cut = Tacmach.internal_cut
-let internal_cut_rev = Tacmach.internal_cut_rev
let refine = Tacmach.refine
let convert_concl = Tacmach.convert_concl
let convert_hyp = Tacmach.convert_hyp
-let thin = Tacmach.thin
let thin_body = Tacmach.thin_body
+let error_clear_dependency env id = function
+ | Evarutil.OccurHypInSimpleClause None ->
+ errorlabstrm "" (pr_id id ++ str " is used in conclusion.")
+ | Evarutil.OccurHypInSimpleClause (Some id') ->
+ errorlabstrm ""
+ (pr_id id ++ strbrk " is used in hypothesis " ++ pr_id id' ++ str".")
+ | Evarutil.EvarTypingBreak ev ->
+ errorlabstrm ""
+ (str "Cannot remove " ++ pr_id id ++
+ strbrk " without breaking the typing of " ++
+ Printer.pr_existential env ev ++ str".")
+
+let thin l gl =
+ try thin l gl
+ with Evarutil.ClearDependencyError (id,err) ->
+ error_clear_dependency (pf_env gl) id err
+
+let internal_cut_gen b d t gl =
+ try internal_cut b d t gl
+ with Evarutil.ClearDependencyError (id,err) ->
+ error_clear_dependency (pf_env gl) id err
+
+let internal_cut = internal_cut_gen false
+let internal_cut_replace = internal_cut_gen true
+
+let internal_cut_rev_gen b d t gl =
+ try internal_cut_rev b d t gl
+ with Evarutil.ClearDependencyError (id,err) ->
+ error_clear_dependency (pf_env gl) id err
+
+let internal_cut_rev = internal_cut_rev_gen false
+let internal_cut_rev_replace = internal_cut_rev_gen true
+
(* Moving hypotheses *)
let move_hyp = Tacmach.move_hyp
@@ -273,15 +304,19 @@ let fresh_id_avoid avoid id =
let fresh_id avoid id gl =
fresh_id_avoid (avoid@(pf_ids_of_hyps gl)) id
-let id_of_name_with_default s = function
- | Anonymous -> id_of_string s
+let id_of_name_with_default id = function
+ | Anonymous -> id
| Name id -> id
+let hid = id_of_string "H"
+let xid = id_of_string "X"
+
+let default_id_of_sort = function Prop _ -> hid | Type _ -> xid
+
let default_id env sigma = function
| (name,None,t) ->
- (match Typing.sort_of env sigma t with
- | Prop _ -> (id_of_name_with_default "H" name)
- | Type _ -> (id_of_name_with_default "X" name))
+ let dft = default_id_of_sort (Typing.sort_of env sigma t) in
+ id_of_name_with_default dft name
| (name,Some b,_) -> id_of_name_using_hdchar env b name
(* Non primitive introduction tactics are treated by central_intro
@@ -293,14 +328,14 @@ type intro_name_flag =
| IntroBasedOn of identifier * identifier list
| IntroMustBe of identifier
-let find_name decl gl = function
+let find_name loc decl gl = function
| IntroAvoid idl ->
(* this case must be compatible with [find_intro_names] below. *)
let id = fresh_id idl (default_id (pf_env gl) gl.sigma decl) gl in id
| IntroBasedOn (id,idl) -> fresh_id idl id gl
- | IntroMustBe id ->
+ | IntroMustBe id ->
let id' = fresh_id [] id gl in
- if id' <> id then error ((string_of_id id)^" is already used.");
+ if id'<>id then user_err_loc (loc,"",pr_id id ++ str" is already used.");
id'
(* Returns the names that would be created by intros, without doing
@@ -319,65 +354,72 @@ let find_intro_names ctxt gl =
ctxt (pf_env gl , []) in
List.rev res
-
let build_intro_tac id = function
- | None -> introduction id
- | Some dest -> tclTHEN (introduction id) (move_hyp true id dest)
+ | MoveToEnd true -> introduction id
+ | dest -> tclTHEN (introduction id) (move_hyp true id dest)
-let rec intro_gen name_flag move_flag force_flag gl =
+let rec intro_gen loc name_flag move_flag force_flag gl =
match kind_of_term (pf_concl gl) with
| Prod (name,t,_) ->
- build_intro_tac (find_name (name,None,t) gl name_flag) move_flag gl
+ build_intro_tac (find_name loc (name,None,t) gl name_flag) move_flag gl
| LetIn (name,b,t,_) ->
- build_intro_tac (find_name (name,Some b,t) gl name_flag) move_flag gl
+ build_intro_tac (find_name loc (name,Some b,t) gl name_flag) move_flag
+ gl
| _ ->
if not force_flag then raise (RefinerError IntroNeedsProduct);
try
tclTHEN
(reduce (Red true) onConcl)
- (intro_gen name_flag move_flag force_flag) gl
+ (intro_gen loc name_flag move_flag force_flag) gl
with Redelimination ->
- errorlabstrm "Intro" (str "No product even after head-reduction.")
+ user_err_loc(loc,"Intro",str "No product even after head-reduction.")
-let intro_mustbe_force id = intro_gen (IntroMustBe id) None true
-let intro_using id = intro_gen (IntroBasedOn (id,[])) None false
-let intro_force force_flag = intro_gen (IntroAvoid []) None force_flag
+let intro_mustbe_force id = intro_gen dloc (IntroMustBe id) no_move true
+let intro_using id = intro_gen dloc (IntroBasedOn (id,[])) no_move false
+let intro_force force_flag = intro_gen dloc (IntroAvoid []) no_move force_flag
let intro = intro_force false
let introf = intro_force true
-let intro_avoiding l = intro_gen (IntroAvoid l) None false
-
-let introf_move_name destopt = intro_gen (IntroAvoid []) destopt true
+let intro_avoiding l = intro_gen dloc (IntroAvoid l) no_move false
-(* For backwards compatibility *)
-let central_intro = intro_gen
+let introf_move_name destopt = intro_gen dloc (IntroAvoid []) destopt true
(**** Multiple introduction tactics ****)
let rec intros_using = function
- [] -> tclIDTAC
- | str::l -> tclTHEN (intro_using str) (intros_using l)
+ | [] -> tclIDTAC
+ | str::l -> tclTHEN (intro_using str) (intros_using l)
let intros = tclREPEAT (intro_force false)
let intro_erasing id = tclTHEN (thin [id]) (introduction id)
+let rec get_next_hyp_position id = function
+ | [] -> error ("No such hypothesis: " ^ string_of_id id)
+ | (hyp,_,_) :: right ->
+ if hyp = id then
+ match right with (id,_,_)::_ -> MoveBefore id | [] -> MoveToEnd true
+ else
+ get_next_hyp_position id right
+
+let intro_replacing id gl =
+ let next_hyp = get_next_hyp_position id (pf_hyps gl) in
+ tclTHENLIST [thin [id]; introduction id; move_hyp true id next_hyp] gl
+
let intros_replacing ids gl =
let rec introrec = function
| [] -> tclIDTAC
| id::tl ->
- (tclTHEN (tclORELSE (intro_replacing id)
- (tclORELSE (intro_erasing id) (* ?? *)
- (intro_using id)))
- (introrec tl))
+ tclTHEN (tclORELSE (intro_replacing id) (intro_using id))
+ (introrec tl)
in
introrec ids gl
(* User-level introduction tactics *)
-let intro_move idopt idopt' = match idopt with
- | None -> intro_gen (IntroAvoid []) idopt' true
- | Some id -> intro_gen (IntroMustBe id) idopt' true
+let intro_move idopt hto = match idopt with
+ | None -> intro_gen dloc (IntroAvoid []) hto true
+ | Some id -> intro_gen dloc (IntroMustBe id) hto true
let pf_lookup_hypothesis_as_renamed env ccl = function
| AnonHyp n -> pf_lookup_index_as_renamed env ccl n
@@ -435,7 +477,7 @@ let try_intros_until tac = function
let rec intros_move = function
| [] -> tclIDTAC
| (hyp,destopt) :: rest ->
- tclTHEN (intro_gen (IntroMustBe hyp) destopt false)
+ tclTHEN (intro_gen dloc (IntroMustBe hyp) destopt false)
(intros_move rest)
let dependent_in_decl a (_,c,t) =
@@ -443,33 +485,6 @@ let dependent_in_decl a (_,c,t) =
| None -> dependent a t
| Some body -> dependent a body || dependent a t
-let move_to_rhyp rhyp gl =
- let rec get_lhyp lastfixed depdecls = function
- | [] ->
- (match rhyp with
- | None -> lastfixed
- | Some h -> anomaly ("Hypothesis should occur: "^ (string_of_id h)))
- | (hyp,c,typ) as ht :: rest ->
- if Some hyp = rhyp then
- lastfixed
- else if List.exists (occur_var_in_decl (pf_env gl) hyp) depdecls then
- get_lhyp lastfixed (ht::depdecls) rest
- else
- get_lhyp (Some hyp) depdecls rest
- in
- let sign = pf_hyps gl in
- let (hyp,c,typ as decl) = List.hd sign in
- match get_lhyp None [decl] (List.tl sign) with
- | None -> tclIDTAC gl
- | Some hypto -> move_hyp true hyp hypto gl
-
-let rec intros_rmove = function
- | [] -> tclIDTAC
- | (hyp,destopt) :: rest ->
- tclTHENLIST [ introduction hyp;
- move_to_rhyp destopt;
- intros_rmove rest ]
-
(* Apply a tactic on a quantified hypothesis, an hypothesis in context
or a term with bindings *)
@@ -530,9 +545,7 @@ let cut_intro t = tclTHENFIRST (cut t) intro
(* cut_replacing échoue si l'hypothèse à remplacer apparaît dans le
but, ou dans une autre hypothèse *)
let cut_replacing id t tac =
- tclTHENS (cut t) [
- tclORELSE (intro_replacing id) (intro_erasing id);
- tac (refine_no_check (mkVar id)) ]
+ tclTHENS (cut t) [ intro_replacing id; tac (refine_no_check (mkVar id)) ]
let cut_in_parallel l =
let rec prec = function
@@ -644,6 +657,12 @@ let simplest_elim c = default_elim false (c,NoBindings)
(e.g. it could replace id:A->B->C by id:C, knowing A/\B)
*)
+let clenv_fchain_in id elim_flags mv elimclause hypclause =
+ try clenv_fchain ~allow_K:false ~flags:elim_flags mv elimclause hypclause
+ with PretypeError (env,NoOccurrenceFound (op,_)) ->
+ (* Set the hypothesis name in the message *)
+ raise (PretypeError (env,NoOccurrenceFound (op,Some id)))
+
let elimination_in_clause_scheme with_evars id elimclause indclause gl =
let (hypmv,indmv) =
match clenv_independent elimclause with
@@ -654,8 +673,8 @@ let elimination_in_clause_scheme with_evars id elimclause indclause gl =
let hyp = mkVar id in
let hyp_typ = pf_type_of gl hyp in
let hypclause = mk_clenv_from_n gl (Some 0) (hyp, hyp_typ) in
- let elimclause'' =
- clenv_fchain ~allow_K:false ~flags:elim_flags hypmv elimclause' hypclause in
+ let elimclause'' =
+ clenv_fchain_in id elim_flags hypmv elimclause' hypclause in
let new_hyp_typ = clenv_type elimclause'' in
if eq_constr hyp_typ new_hyp_typ then
errorlabstrm "general_rewrite_in"
@@ -752,16 +771,22 @@ let general_apply with_delta with_destruct with_evars (c,lbind) gl =
try_red_apply thm_ty0 in
try_main_apply c gl
-let apply_with_ebindings_gen b = general_apply b b
+let rec apply_with_ebindings_gen b e = function
+ | [] ->
+ tclIDTAC
+ | [cb] ->
+ general_apply b b e cb
+ | cb::cbl ->
+ tclTHENLAST (general_apply b b e cb) (apply_with_ebindings_gen b e cbl)
-let apply_with_ebindings = apply_with_ebindings_gen false false
-let eapply_with_ebindings = apply_with_ebindings_gen false true
+let apply_with_ebindings cb = apply_with_ebindings_gen false false [cb]
+let eapply_with_ebindings cb = apply_with_ebindings_gen false true [cb]
let apply_with_bindings (c,bl) =
apply_with_ebindings (c,inj_ebindings bl)
let eapply_with_bindings (c,bl) =
- apply_with_ebindings_gen false true (c,inj_ebindings bl)
+ apply_with_ebindings_gen false true [c,inj_ebindings bl]
let apply c =
apply_with_ebindings (c,NoBindings)
@@ -897,14 +922,10 @@ let clear_body = thin_body
let clear_wildcards ids =
tclMAP (fun (loc,id) gl ->
try with_check (Tacmach.thin_no_check [id]) gl
- with OccurHypInSimpleClause (id,ido) ->
+ with ClearDependencyError (id,err) ->
(* Intercept standard [thin] error message *)
- match ido with
- | None ->
- user_err_loc (loc,"",str "_ is used in conclusion.")
- | Some id ->
- user_err_loc
- (loc,"",str "_ is used in hypothesis " ++ pr_id id ++ str "."))
+ Stdpp.raise_with_loc loc
+ (error_clear_dependency (pf_env gl) (id_of_string "_") err))
ids
(* Takes a list of booleans, and introduces all the variables
@@ -946,12 +967,11 @@ let specialize mopt (c,lbind) g =
in
tclTHEN
(match evars with Some e -> tclEVARS e | _ -> tclIDTAC)
- (match kind_of_term (fst (decompose_app c)) with
- | Var id when List.exists (fun (i,_,_)-> i=id) (pf_hyps g) ->
- let id' = fresh_id [] id g in
- tclTHENS (fun g -> internal_cut id' (pf_type_of g term) g)
- [ exact_no_check term;
- tclTHEN (clear [id]) (rename_hyp [id',id]) ]
+ (match kind_of_term (fst(decompose_app (snd(decompose_lam_assum c)))) with
+ | Var id when List.mem id (pf_ids_of_hyps g) ->
+ tclTHENFIRST
+ (fun g -> internal_cut_replace id (pf_type_of g term) g)
+ (exact_no_check term)
| _ -> tclTHENLAST
(fun g -> cut (pf_type_of g term) g)
(exact_no_check term))
@@ -1047,22 +1067,33 @@ let fix_empty_case nv l =
and "[ ]" for no clause at all; so we are a bit liberal here *)
if Array.length nv = 0 & l = [[]] then [] else l
-let intro_or_and_pattern ll l' tac =
+let error_unexpected_extra_pattern loc nb pat =
+ let s1,s2,s3 = match pat with
+ | IntroIdentifier _ -> "name", (plural nb " introduction pattern"), "no"
+ | _ -> "introduction pattern", "", "none" in
+ user_err_loc (loc,"",str "Unexpected " ++ str s1 ++ str " (" ++
+ (if nb = 0 then (str s3 ++ str s2) else
+ (str "at most " ++ int nb ++ str s2)) ++ spc () ++
+ str (if nb = 1 then "was" else "were") ++
+ strbrk " expected in the branch).")
+
+let intro_or_and_pattern loc b ll l' tac =
tclLAST_HYP (fun c gl ->
let ind,_ = pf_reduce_to_quantified_ind gl (pf_type_of gl c) in
let nv = mis_constr_nargs ind in
- let rec adjust_names_length tail n = function
- | [] when n = 0 or tail -> []
- | [] -> IntroAnonymous :: adjust_names_length tail (n-1) []
- | _ :: _ as l when n = 0 ->
- if tail then l else error "Too many names in some branch."
- | ip :: l -> ip :: adjust_names_length tail (n-1) l in
+ let bracketed = b or not (l'=[]) in
+ let rec adjust_names_length nb n = function
+ | [] when n = 0 or not bracketed -> []
+ | [] -> (dloc,IntroAnonymous) :: adjust_names_length nb (n-1) []
+ | (loc',pat) :: _ as l when n = 0 ->
+ if bracketed then error_unexpected_extra_pattern loc' nb pat;
+ l
+ | ip :: l -> ip :: adjust_names_length nb (n-1) l in
let ll = fix_empty_case nv ll in
- if List.length ll <> Array.length nv then
- error "Not the right number of patterns.";
+ check_or_and_pattern_size loc ll (Array.length nv);
tclTHENLASTn
(tclTHEN case_last clear_last)
- (array_map2 (fun n l -> tac ((adjust_names_length (l'=[]) n l)@l'))
+ (array_map2 (fun n l -> tac ((adjust_names_length n n l)@l'))
nv (Array.of_list ll))
gl)
@@ -1074,11 +1105,11 @@ let clear_if_atomic l2r id gl =
else tclIDTAC gl
let rec explicit_intro_names = function
-| IntroIdentifier id :: l ->
+| (_, IntroIdentifier id) :: l ->
id :: explicit_intro_names l
-| (IntroWildcard _ | IntroAnonymous | IntroFresh _ | IntroRewrite _) :: l ->
+| (_, (IntroWildcard | IntroAnonymous | IntroFresh _ | IntroRewrite _)) :: l ->
explicit_intro_names l
-| IntroOrAndPattern ll :: l' ->
+| (_, IntroOrAndPattern ll) :: l' ->
List.flatten (List.map (fun l -> explicit_intro_names (l@l')) ll)
| [] ->
[]
@@ -1087,84 +1118,90 @@ let rec explicit_intro_names = function
to ensure that dependent hypotheses are cleared in the right
dependency order (see bug #1000); we use fresh names, not used in
the tactic, for the hyps to clear *)
-let rec intros_patterns avoid thin destopt = function
- | IntroWildcard loc :: l ->
+let rec intros_patterns b avoid thin destopt = function
+ | (loc, IntroWildcard) :: l ->
tclTHEN
- (intro_gen (IntroAvoid (avoid@explicit_intro_names l)) None true)
+ (intro_gen loc (IntroAvoid(avoid@explicit_intro_names l)) no_move true)
(onLastHyp (fun id ->
tclORELSE
- (tclTHEN (clear [id]) (intros_patterns avoid thin destopt l))
- (intros_patterns avoid ((loc,id)::thin) destopt l)))
- | IntroIdentifier id :: l ->
+ (tclTHEN (clear [id]) (intros_patterns b avoid thin destopt l))
+ (intros_patterns b avoid ((loc,id)::thin) destopt l)))
+ | (loc, IntroIdentifier id) :: l ->
tclTHEN
- (intro_gen (IntroMustBe id) destopt true)
- (intros_patterns avoid thin destopt l)
- | IntroAnonymous :: l ->
+ (intro_gen loc (IntroMustBe id) destopt true)
+ (intros_patterns b avoid thin destopt l)
+ | (loc, IntroAnonymous) :: l ->
tclTHEN
- (intro_gen (IntroAvoid (avoid@explicit_intro_names l)) destopt true)
- (intros_patterns avoid thin destopt l)
- | IntroFresh id :: l ->
+ (intro_gen loc (IntroAvoid (avoid@explicit_intro_names l))
+ destopt true)
+ (intros_patterns b avoid thin destopt l)
+ | (loc, IntroFresh id) :: l ->
tclTHEN
- (intro_gen (IntroBasedOn (id, avoid@explicit_intro_names l)) destopt true)
- (intros_patterns avoid thin destopt l)
- | IntroOrAndPattern ll :: l' ->
+ (intro_gen loc (IntroBasedOn (id, avoid@explicit_intro_names l))
+ destopt true)
+ (intros_patterns b avoid thin destopt l)
+ | (loc, IntroOrAndPattern ll) :: l' ->
tclTHEN
introf
- (intro_or_and_pattern ll l' (intros_patterns avoid thin destopt))
- | IntroRewrite l2r :: l ->
+ (intro_or_and_pattern loc b ll l'
+ (intros_patterns b avoid thin destopt))
+ | (loc, IntroRewrite l2r) :: l ->
tclTHEN
- (intro_gen (IntroAvoid (avoid@explicit_intro_names l)) None true)
+ (intro_gen loc (IntroAvoid(avoid@explicit_intro_names l)) no_move true)
(onLastHyp (fun id ->
tclTHENLIST [
!forward_general_multi_rewrite l2r false (mkVar id,NoBindings)
allClauses;
clear_if_atomic l2r id;
- intros_patterns avoid thin destopt l ]))
+ intros_patterns b avoid thin destopt l ]))
| [] -> clear_wildcards thin
-let intros_pattern = intros_patterns [] []
+let intros_pattern = intros_patterns false [] []
-let intro_pattern destopt pat = intros_patterns [] [] destopt [pat]
+let intro_pattern destopt pat = intros_patterns false [] [] destopt [dloc,pat]
let intro_patterns = function
| [] -> tclREPEAT intro
- | l -> intros_pattern None l
+ | l -> intros_pattern no_move l
(**************************)
(* Other cut tactics *)
(**************************)
-let hid = id_of_string "H"
-let xid = id_of_string "X"
-
-let make_id s = fresh_id [] (match s with Prop _ -> hid | Type _ -> xid)
+let make_id s = fresh_id [] (default_id_of_sort s)
-let prepare_intros s ipat gl = match ipat with
+let prepare_intros s (loc,ipat) gl = match ipat with
+ | IntroIdentifier id -> id, tclIDTAC
| IntroAnonymous -> make_id s gl, tclIDTAC
| IntroFresh id -> fresh_id [] id gl, tclIDTAC
- | IntroWildcard loc -> let id = make_id s gl in id, clear_wildcards [loc,id]
- | IntroIdentifier id -> id, tclIDTAC
+ | IntroWildcard -> let id = make_id s gl in id, clear_wildcards [dloc,id]
| IntroRewrite l2r ->
let id = make_id s gl in
id, !forward_general_multi_rewrite l2r false (mkVar id,NoBindings) allClauses
| IntroOrAndPattern ll -> make_id s gl,
- (tclTHENS
- (tclTHEN case_last clear_last)
- (List.map (intros_pattern None) ll))
+ intro_or_and_pattern loc true ll [] (intros_patterns true [] [] no_move)
let ipat_of_name = function
| Anonymous -> IntroAnonymous
| Name id -> IntroIdentifier id
+let allow_replace c gl = function (* A rather arbitrary condition... *)
+ | _, IntroIdentifier id ->
+ fst (decompose_app (snd (decompose_lam_assum c))) = mkVar id
+ | _ ->
+ false
+
let assert_as first ipat c gl =
match kind_of_term (hnf_type_of gl c) with
| Sort s ->
let id,tac = prepare_intros s ipat gl in
- tclTHENS ((if first then internal_cut else internal_cut_rev) id c)
+ let repl = allow_replace c gl ipat in
+ tclTHENS
+ ((if first then internal_cut_gen else internal_cut_rev_gen) repl id c)
(if first then [tclIDTAC; tac] else [tac; tclIDTAC]) gl
| _ -> error "Not a proposition or a type."
-let assert_tac first na = assert_as first (ipat_of_name na)
+let assert_tac first na = assert_as first (dloc,ipat_of_name na)
let true_cut = assert_tac true
(**************************)
@@ -1363,7 +1400,8 @@ let letin_abstract id c occs gl =
let ccl = match occurrences_of_goal occs with
| None -> pf_concl gl
| Some occ -> subst1 (mkVar id) (subst_term_occ occ c (pf_concl gl)) in
- let lastlhyp = if depdecls = [] then None else Some(pi1(list_last depdecls)) in
+ let lastlhyp =
+ if depdecls = [] then no_move else MoveAfter(pi1(list_last depdecls)) in
(depdecls,lastlhyp,ccl)
let letin_tac with_eq name c occs gl =
@@ -1375,19 +1413,25 @@ let letin_tac with_eq name c occs gl =
let (depdecls,lastlhyp,ccl)= letin_abstract id c occs gl in
let t = pf_type_of gl c in
let newcl,eq_tac = match with_eq with
- | Some lr ->
- let heq = fresh_id [] (add_prefix "Heq" id) gl in
+ | Some (lr,(loc,ido)) ->
+ let heq = match ido with
+ | IntroAnonymous -> fresh_id [id] (add_prefix "Heq" id) gl
+ | IntroFresh heq_base -> fresh_id [id] heq_base gl
+ | IntroIdentifier id -> id
+ | _ -> error"Expect an introduction pattern naming one hypothesis." in
let eqdata = build_coq_eq_data () in
let args = if lr then [t;mkVar id;c] else [t;c;mkVar id]in
let eq = applist (eqdata.eq,args) in
let refl = applist (eqdata.refl, [t;mkVar id]) in
mkNamedLetIn id c t (mkLetIn (Name heq, refl, eq, ccl)),
- tclTHEN (intro_gen (IntroMustBe heq) lastlhyp true) (thin_body [heq;id])
+ tclTHEN
+ (intro_gen loc (IntroMustBe heq) lastlhyp true)
+ (thin_body [heq;id])
| None ->
mkNamedLetIn id c t ccl, tclIDTAC in
tclTHENLIST
[ convert_concl_no_check newcl DEFAULTcast;
- intro_gen (IntroMustBe id) lastlhyp true;
+ intro_gen dloc (IntroMustBe id) lastlhyp true;
eq_tac;
tclMAP convert_hyp_no_check depdecls ] gl
@@ -1467,76 +1511,85 @@ let unfold_all x gl =
let check_unused_names names =
if names <> [] & Flags.is_verbose () then
- let s = if List.tl names = [] then " " else "s " in
msg_warning
- (str"Unused introduction pattern" ++ str s ++
- str": " ++ prlist_with_sep spc pr_intro_pattern names)
-
-let rec first_name_buggy = function
- | IntroOrAndPattern [] -> None
- | IntroOrAndPattern ([]::l) -> first_name_buggy (IntroOrAndPattern l)
- | IntroOrAndPattern ((p::_)::_) -> first_name_buggy p
- | IntroWildcard _ -> None
- | IntroRewrite _ -> None
- | IntroIdentifier id -> Some id
+ (str"Unused introduction " ++ str (plural (List.length names) "pattern")
+ ++ str": " ++ prlist_with_sep spc pr_intro_pattern names)
+
+let rec first_name_buggy avoid gl (loc,pat) = match pat with
+ | IntroOrAndPattern [] -> no_move
+ | IntroOrAndPattern ([]::l) ->
+ first_name_buggy avoid gl (loc,IntroOrAndPattern l)
+ | IntroOrAndPattern ((p::_)::_) -> first_name_buggy avoid gl p
+ | IntroWildcard -> no_move
+ | IntroRewrite _ -> no_move
+ | IntroIdentifier id -> MoveAfter id
| IntroAnonymous | IntroFresh _ -> assert false
let consume_pattern avoid id gl = function
- | [] -> (IntroIdentifier (fresh_id avoid id gl), [])
- | IntroAnonymous::names ->
+ | [] -> ((dloc, IntroIdentifier (fresh_id avoid id gl)), [])
+ | (loc,IntroAnonymous)::names ->
let avoid = avoid@explicit_intro_names names in
- (IntroIdentifier (fresh_id avoid id gl), names)
+ ((loc,IntroIdentifier (fresh_id avoid id gl)), names)
+ | (loc,IntroFresh id')::names ->
+ let avoid = avoid@explicit_intro_names names in
+ ((loc,IntroIdentifier (fresh_id avoid id' gl)), names)
| pat::names -> (pat,names)
let re_intro_dependent_hypotheses tophyp (lstatus,rstatus) =
let newlstatus = (* if some IH has taken place at the top of hyps *)
- List.map (function (hyp,None) -> (hyp,tophyp) | x -> x) lstatus in
+ List.map (function (hyp,MoveToEnd true) -> (hyp,tophyp) | x -> x) lstatus
+ in
tclTHEN
- (intros_rmove rstatus)
+ (intros_move rstatus)
(intros_move newlstatus)
+let update destopt tophyp = if destopt = no_move then tophyp else destopt
+
type elim_arg_kind = RecArg | IndArg | OtherArg
let induct_discharge statuslists destopt avoid' (avoid,ra) names gl =
let avoid = avoid @ avoid' in
- let rec peel_tac ra names tophyp gl = match ra with
+ let rec peel_tac ra names tophyp gl =
+ match ra with
| (RecArg,recvarname) ::
(IndArg,hyprecname) :: ra' ->
let recpat,names = match names with
- | [IntroIdentifier id as pat] ->
- let id = next_ident_away (add_prefix "IH" id) avoid in
- (pat, [IntroIdentifier id])
+ | [loc,IntroIdentifier id as pat] ->
+ let id' = next_ident_away (add_prefix "IH" id) avoid in
+ (pat, [dloc, IntroIdentifier id'])
| _ -> consume_pattern avoid recvarname gl names in
let hyprec,names = consume_pattern avoid hyprecname gl names in
(* IH stays at top: we need to update tophyp *)
(* This is buggy for intro-or-patterns with different first hypnames *)
(* Would need to pass peel_tac as a continuation of intros_patterns *)
(* (or to have hypotheses classified by blocks...) *)
- let tophyp = if tophyp=None then first_name_buggy hyprec else tophyp in
+ let newtophyp =
+ if tophyp=no_move then first_name_buggy avoid gl hyprec else tophyp
+ in
tclTHENLIST
- [ intros_patterns avoid [] destopt [recpat];
- intros_patterns avoid [] None [hyprec];
- peel_tac ra' names tophyp] gl
+ [ intros_patterns true avoid [] (update destopt tophyp) [recpat];
+ intros_patterns true avoid [] no_move [hyprec];
+ peel_tac ra' names newtophyp] gl
| (IndArg,hyprecname) :: ra' ->
(* Rem: does not happen in Coq schemes, only in user-defined schemes *)
let pat,names = consume_pattern avoid hyprecname gl names in
- tclTHEN (intros_patterns avoid [] destopt [pat])
+ tclTHEN (intros_patterns true avoid [] (update destopt tophyp) [pat])
(peel_tac ra' names tophyp) gl
| (RecArg,recvarname) :: ra' ->
let pat,names = consume_pattern avoid recvarname gl names in
- tclTHEN (intros_patterns avoid [] destopt [pat])
+ tclTHEN (intros_patterns true avoid [] (update destopt tophyp) [pat])
(peel_tac ra' names tophyp) gl
| (OtherArg,_) :: ra' ->
let pat,names = match names with
- | [] -> IntroAnonymous, []
+ | [] -> (dloc, IntroAnonymous), []
| pat::names -> pat,names in
- tclTHEN (intros_patterns avoid [] destopt [pat])
+ tclTHEN (intros_patterns true avoid [] (update destopt tophyp) [pat])
(peel_tac ra' names tophyp) gl
| [] ->
check_unused_names names;
re_intro_dependent_hypotheses tophyp statuslists gl
in
- peel_tac ra names None gl
+ peel_tac ra names no_move gl
(* - le recalcul de indtyp à chaque itération de atomize_one est pour ne pas
s'embêter à regarder si un letin_tac ne fait pas des
@@ -1594,7 +1647,7 @@ let find_atomic_param_of_ind nparams indtyp =
Idset.elements !indvars;
- (* [cook_sign] builds the lists [indhyps] of hyps that must be
+(* [cook_sign] builds the lists [indhyps] of hyps that must be
erased, the lists of hyps to be generalize [(hdeps,tdeps)] on the
goal together with the places [(lstatus,rstatus)] where to re-intro
them after induction. To know where to re-intro the dep hyp, we
@@ -1605,7 +1658,7 @@ let find_atomic_param_of_ind nparams indtyp =
more ancient (on the right) to more recent hyp (on the left) but
the computation of [lhyp] progresses from the other way, [cook_hyp]
is in two passes (an alternative would have been to write an
- higher-order algorithm). We strongly use references to reduce
+ higher-order algorithm). We use references to reduce
the accumulation of arguments.
To summarize, the situation looks like this
@@ -1657,7 +1710,7 @@ let find_atomic_param_of_ind nparams indtyp =
*)
-exception Shunt of identifier option
+exception Shunt of identifier move_location
let cook_sign hyp0_opt indvars_init env =
let hyp0,indvars =
@@ -1679,7 +1732,7 @@ let cook_sign hyp0_opt indvars_init env =
(* If there was no main induction hypotheses, then hyp is one of
indvars too, so add it to indhyps. *)
(if hyp0_opt=None then indhyps := hyp::!indhyps);
- None (* fake value *)
+ MoveToEnd false (* fake value *)
end else if List.mem hyp indvars then begin
(* warning: hyp can still occur after induction *)
(* e.g. if the goal (t hyp hyp0) with other occs of hyp in t *)
@@ -1695,11 +1748,11 @@ let cook_sign hyp0_opt indvars_init env =
rstatus := (hyp,rhyp)::!rstatus
else
ldeps := hyp::!ldeps; (* status computed in 2nd phase *)
- Some hyp end
+ MoveBefore hyp end
else
- Some hyp
+ MoveBefore hyp
in
- let _ = fold_named_context seek_deps env ~init:None in
+ let _ = fold_named_context seek_deps env ~init:(MoveToEnd false) in
(* 2nd phase from R to L: get left hyp of [hyp0] and [lhyps] *)
let compute_lstatus lhyp (hyp,_,_) =
if hyp = hyp0 then raise (Shunt lhyp);
@@ -1707,15 +1760,16 @@ let cook_sign hyp0_opt indvars_init env =
lstatus := (hyp,lhyp)::!lstatus;
lhyp
end else
- if List.mem hyp !indhyps then lhyp else (Some hyp)
+ if List.mem hyp !indhyps then lhyp else MoveAfter hyp
in
try
- let _ = fold_named_context_reverse compute_lstatus ~init:None env in
-(* anomaly "hyp0 not found" *)
- raise (Shunt (None)) (* ?? FIXME *)
+ let _ =
+ fold_named_context_reverse compute_lstatus ~init:(MoveToEnd true) env in
+ raise (Shunt (MoveToEnd true)) (* ?? FIXME *)
with Shunt lhyp0 ->
let statuslists = (!lstatus,List.rev !rstatus) in
- (statuslists, (if hyp0_opt=None then None else lhyp0) , !indhyps, !decldeps)
+ (statuslists, (if hyp0_opt=None then MoveToEnd true else lhyp0),
+ !indhyps, !decldeps)
(*
@@ -1801,9 +1855,9 @@ let make_base n id =
(* digits *)
id_of_string (atompart_of_id (make_ident (string_of_id id) (Some 0)))
-(* Builds tw different names from an optional inductive type and a
+(* Builds two different names from an optional inductive type and a
number, also deals with a list of names to avoid. If the inductive
- type is None, then hyprecname is HIi where i is a number. *)
+ type is None, then hyprecname is IHi where i is a number. *)
let make_up_names n ind_opt cname =
let is_hyp = atompart_of_id cname = "H" in
let base = string_of_id (make_base n cname) in
@@ -2032,11 +2086,11 @@ let cut_list n l =
res
-(* This functions splits the products of the induction scheme [elimt] in three
+(* This function splits the products of the induction scheme [elimt] into four
parts:
- - branches, easily detectable (they are not referred by rels in the subterm)
- - what was found before branches (acc1) that is: parameters and predicates
- - what was found after branches (acc3) that is: args and indarg if any
+ - branches, easily detectable (they are not referred by rels in the subterm)
+ - what was found before branches (acc1) that is: parameters and predicates
+ - what was found after branches (acc3) that is: args and indarg if any
if there is no branch, we try to fill in acc3 with args/indargs.
We also return the conclusion.
*)
@@ -2079,7 +2133,7 @@ let exchange_hd_app subst_hd t =
(* [rebuild_elimtype_from_scheme scheme] rebuilds the type of an
eliminator from its [scheme_info]. The idea is to build variants of
- eliminator by modifying there scheme_info, then rebuild the
+ eliminator by modifying their scheme_info, then rebuild the
eliminator type, then prove it (with tactics). *)
let rebuild_elimtype_from_scheme (scheme:elim_scheme): types =
let hiconcl =
@@ -2096,7 +2150,7 @@ let rebuild_elimtype_from_scheme (scheme:elim_scheme): types =
exception NoLastArg
exception NoLastArgCcl
-(* Builds an elim_scheme frome its type and calling form (const+binding) We
+(* Builds an elim_scheme from its type and calling form (const+binding). We
first separate branches. We obtain branches, hyps before (params + preds),
hyps after (args <+ indarg if present>) and conclusion. Then we proceed as
follows:
@@ -2184,17 +2238,17 @@ let compute_elim_sig ?elimc elimt =
extra final argument of the form (f x y ...) in the conclusion. In
the non standard case, naming of generated hypos is slightly
different. *)
-let compute_elim_signature elimc elimt names_info =
+let compute_elim_signature elimc elimt names_info ind_type_guess =
let scheme = compute_elim_sig ~elimc:elimc elimt in
let f,l = decompose_app scheme.concl in
(* Vérifier que les arguments de Qi sont bien les xi. *)
match scheme.indarg with
| Some (_,Some _,_) -> error "Strange letin, cannot recognize an induction scheme."
| None -> (* Non standard scheme *)
- let npred = List.length scheme.predicates in
let is_pred n c =
let hd = fst (decompose_app c) in match kind_of_term hd with
- | Rel q when n < q & q <= n+npred -> IndArg
+ | Rel q when n < q & q <= n+scheme.npredicates -> IndArg
+ | _ when hd = ind_type_guess & not scheme.farg_in_concl -> RecArg
| _ -> OtherArg in
let rec check_branch p c =
match kind_of_term c with
@@ -2223,10 +2277,9 @@ let compute_elim_signature elimc elimt names_info =
| Some ( _,None,ind) -> (* Standard scheme from an inductive type *)
let indhd,indargs = decompose_app ind in
- let npred = List.length scheme.predicates in
let is_pred n c =
let hd = fst (decompose_app c) in match kind_of_term hd with
- | Rel q when n < q & q <= n+npred -> IndArg
+ | Rel q when n < q & q <= n+scheme.npredicates -> IndArg
| _ when hd = indhd -> RecArg
| _ -> OtherArg in
let rec check_branch p c = match kind_of_term c with
@@ -2266,7 +2319,7 @@ let compute_elim_signature elimc elimt names_info =
let find_elim_signature isrec elim hyp0 gl =
let tmptyp0 = pf_get_hyp_typ gl hyp0 in
- let (elimc,elimt) = match elim with
+ let (elimc,elimt),ind = match elim with
| None ->
let mind,_ = pf_reduce_to_quantified_ind gl tmptyp0 in
let s = elimination_sort_of_goal gl in
@@ -2274,21 +2327,15 @@ let find_elim_signature isrec elim hyp0 gl =
if isrec then lookup_eliminator mind s
else pf_apply make_case_gen gl mind s in
let elimt = pf_type_of gl elimc in
- ((elimc, NoBindings), elimt)
- | Some (elimc,lbind as e) ->
- (e, pf_type_of gl elimc) in
- let indsign,elim_scheme = compute_elim_signature elimc elimt hyp0 in
+ ((elimc, NoBindings), elimt), mkInd mind
+ | Some (elimc,lbind as e) ->
+ let ind_type_guess,_ = decompose_app (snd (decompose_prod tmptyp0)) in
+ (e, pf_type_of gl elimc), ind_type_guess in
+ let indsign,elim_scheme =
+ compute_elim_signature elimc elimt hyp0 ind in
(indsign,elim_scheme)
-let mapi f l =
- let rec mapi_aux f i l =
- match l with
- | [] -> []
- | e::l' -> f e i :: mapi_aux f (i+1) l' in
- mapi_aux f 0 l
-
-
(* Instantiate all meta variables of elimclause using lid, some elts
of lid are parameters (first ones), the other are
arguments. Returns the clause obtained. *)
@@ -2307,12 +2354,13 @@ let recolle_clenv scheme lid elimclause gl =
let nidargs = List.length lidargs in
(* parameters correspond to first elts of lid. *)
let clauses_params =
- mapi (fun id i -> mkVar id , pf_get_hyp_typ gl id , lindmv.(i)) lidparams in
+ list_map_i (fun i id -> mkVar id , pf_get_hyp_typ gl id , lindmv.(i))
+ 0 lidparams in
(* arguments correspond to last elts of lid. *)
let clauses_args =
- mapi
- (fun id i -> mkVar id , pf_get_hyp_typ gl id , lindmv.(nmv-nidargs+i))
- lidargs in
+ list_map_i
+ (fun i id -> mkVar id , pf_get_hyp_typ gl id , lindmv.(nmv-nidargs+i))
+ 0 lidargs in
let clause_indarg =
match scheme.indarg with
| None -> []
@@ -2336,7 +2384,7 @@ let recolle_clenv scheme lid elimclause gl =
(elimc ?i ?j ?k...?l). This solves partly meta variables (and may
produce new ones). Then refine with the resulting term with holes.
*)
-let induction_tac_felim with_evars indvars (* (elimc,lbindelimc) elimt *) scheme gl =
+let induction_tac_felim with_evars indvars scheme gl =
let elimt = scheme.elimt in
let elimc,lbindelimc =
match scheme.elimc with | Some x -> x | None -> error "No definition of the principle." in
@@ -2349,6 +2397,29 @@ let induction_tac_felim with_evars indvars (* (elimc,lbindelimc) elimt *) scheme
let resolved = clenv_unique_resolver true elimclause' gl in
clenv_refine with_evars resolved gl
+let apply_induction_in_context isrec hyp0 indsign indvars names induct_tac gl =
+ let env = pf_env gl in
+ let statlists,lhyp0,indhyps,deps = cook_sign hyp0 indvars env in
+ let tmpcl = it_mkNamedProd_or_LetIn (pf_concl gl) deps in
+ let names = compute_induction_names (Array.length indsign) names in
+ let dephyps = List.map (fun (id,_,_) -> id) deps in
+ let deps_cstr =
+ List.fold_left
+ (fun a (id,b,_) -> if b = None then (mkVar id)::a else a) [] deps in
+ tclTHENLIST
+ [
+ (* Generalize dependent hyps (but not args) *)
+ if deps = [] then tclIDTAC else apply_type tmpcl deps_cstr;
+ (* clear dependent hyps *)
+ thin dephyps;
+ (* side-conditions in elim (resp case) schemes come last (resp first) *)
+ (if isrec then tclTHENFIRSTn else tclTHENLASTn)
+ (tclTHEN induct_tac (tclTRY (thin (List.rev indhyps))))
+ (array_map2
+ (induct_discharge statlists lhyp0 (List.rev dephyps)) indsign names)
+ ]
+ gl
+
(* Induction with several induction arguments, main differences with
induction_from_context is that there is no main induction argument,
so we chose one to be the positioning reference. On the other hand,
@@ -2364,7 +2435,6 @@ let induction_from_context_l isrec with_evars elim_info lid names gl =
(* Number of given induction args must be exact. *)
if List.length lid <> nargs_indarg_farg + scheme.nparams then
error "Not the right number of arguments given to induction scheme.";
- let env = pf_env gl in
(* hyp0 is used for re-introducing hyps at the right place afterward.
We chose the first element of the list of variables on which to
induct. It is probably the first of them appearing in the
@@ -2376,12 +2446,6 @@ let induction_from_context_l isrec with_evars elim_info lid names gl =
let nargs_without_first = nargs_indarg_farg - 1 in
let ivs,lp = cut_list nargs_without_first l in
e, ivs, lp in
- let statlists,lhyp0,indhyps,deps = cook_sign None (hyp0::indvars) env in
- let tmpcl = it_mkNamedProd_or_LetIn (pf_concl gl) deps in
- let names = compute_induction_names (Array.length indsign) names in
- let dephyps = List.map (fun (id,_,_) -> id) deps in
- let deps_cstr =
- List.fold_left (fun a (id,b,_) -> if b = None then (mkVar id)::a else a) [] deps in
(* terms to patternify we must patternify indarg or farg if present in concl *)
let lid_in_pattern =
if scheme.indarg <> None & not scheme.indarg_in_concl then List.rev indvars
@@ -2390,68 +2454,32 @@ let induction_from_context_l isrec with_evars elim_info lid names gl =
let realindvars = (* hyp0 is a real induction arg if it is not the
farg in the conclusion of the induction scheme *)
List.rev ((if scheme.farg_in_concl then indvars else hyp0::indvars) @ lid_params) in
- (* Magistral effet de bord: comme dans induction_from_context. *)
- tclTHENLIST
- [
- (* Generalize dependent hyps (but not args) *)
- if deps = [] then tclIDTAC else apply_type tmpcl deps_cstr;
- thin dephyps; (* clear dependent hyps *)
- (* pattern to make the predicate appear. *)
- reduce (Pattern (List.map inj_with_occurrences lidcstr)) onConcl;
- (* FIXME: Tester ca avec un principe dependant et non-dependant *)
- (if isrec then tclTHENFIRSTn else tclTHENLASTn)
- (tclTHENLIST [
- (* Induction by "refine (indscheme ?i ?j ?k...)" + resolution of all
- possible holes using arguments given by the user (but the
- functional one). *)
- induction_tac_felim with_evars realindvars scheme;
- tclTRY (thin (List.rev (indhyps)));
- ])
- (array_map2
- (induct_discharge statlists lhyp0 (List.rev dephyps)) indsign names)
- ]
- gl
-
-
+ let induct_tac = tclTHENLIST [
+ (* pattern to make the predicate appear. *)
+ reduce (Pattern (List.map inj_with_occurrences lidcstr)) onConcl;
+ (* Induction by "refine (indscheme ?i ?j ?k...)" + resolution of all
+ possible holes using arguments given by the user (but the
+ functional one). *)
+ (* FIXME: Tester ca avec un principe dependant et non-dependant *)
+ induction_tac_felim with_evars realindvars scheme
+ ] in
+ apply_induction_in_context isrec
+ None indsign (hyp0::indvars) names induct_tac gl
let induction_from_context isrec with_evars elim_info (hyp0,lbind) names gl =
let indsign,scheme = elim_info in
let indref = match scheme.indref with | None -> assert false | Some x -> x in
let tmptyp0 = pf_get_hyp_typ gl hyp0 in
let typ0 = pf_apply reduce_to_quantified_ref gl indref tmptyp0 in
-
- let env = pf_env gl in
- let indvars = find_atomic_param_of_ind scheme.nparams (snd (decompose_prod typ0)) in
- (* induction_from_context_l isrec elim_info (hyp0::List.rev indvars) names gl *)
- let statlists,lhyp0,indhyps,deps = cook_sign (Some hyp0) indvars env in
- let tmpcl = it_mkNamedProd_or_LetIn (pf_concl gl) deps in
- let names = compute_induction_names (Array.length indsign) names in
- let dephyps = List.map (fun (id,_,_) -> id) deps in
- let deps_cstr =
- List.fold_left
- (fun a (id,b,_) -> if b = None then (mkVar id)::a else a) [] deps in
-
- (* Magistral effet de bord: si hyp0 a des arguments, ceux d'entre
- eux qui ouvrent de nouveaux buts arrivent en premier dans la
- liste des sous-buts du fait qu'ils sont le plus à gauche dans le
- combinateur engendré par make_case_gen (un "Cases (hyp0 ?) of
- ...") et il faut alors appliquer tclTHENLASTn; en revanche,
- comme lookup_eliminator renvoie un combinateur de la forme
- "ind_rec ... (hyp0 ?)", les buts correspondant à des arguments de
- hyp0 sont maintenant à la fin et c'est tclTHENFIRSTn qui marche !!! *)
- tclTHENLIST
- [ if deps = [] then tclIDTAC else apply_type tmpcl deps_cstr;
- thin dephyps;
- (if isrec then tclTHENFIRSTn else tclTHENLASTn)
- (tclTHENLIST
- [ induction_tac with_evars (hyp0,lbind) typ0 scheme;
- tclTHEN (tclTRY (unfold_body hyp0)) (thin [hyp0]);
- tclTRY (thin indhyps) ])
- (array_map2
- (induct_discharge statlists lhyp0 (List.rev dephyps)) indsign names)
- ]
- gl
-
+ let indvars =
+ find_atomic_param_of_ind scheme.nparams (snd (decompose_prod typ0)) in
+ let induct_tac = tclTHENLIST [
+ induction_tac with_evars (hyp0,lbind) typ0 scheme;
+ tclTRY (unfold_body hyp0);
+ thin [hyp0]
+ ] in
+ apply_induction_in_context isrec
+ (Some hyp0) indsign indvars names induct_tac gl
exception TryNewInduct of exn
@@ -2484,17 +2512,22 @@ let induction_without_atomization isrec with_evars elim names lid gl =
then error "Not the right number of induction arguments."
else induction_from_context_l isrec with_evars elim_info lid names gl
-let new_induct_gen isrec with_evars elim names (c,lbind) cls gl =
+let new_induct_gen isrec with_evars elim (eqname,names) (c,lbind) cls gl =
match kind_of_term c with
| Var id when not (mem_named_context id (Global.named_context()))
- & lbind = NoBindings & not with_evars & cls = None ->
+ & lbind = NoBindings & not with_evars & cls = None
+ & eqname = None ->
induction_with_atomization_of_ind_arg
isrec with_evars elim names (id,lbind) gl
| _ ->
let x = id_of_name_using_hdchar (Global.env()) (pf_type_of gl c)
Anonymous in
let id = fresh_id [] x gl in
- let with_eq = if cls <> None then Some (not (isVar c)) else None in
+ let with_eq =
+ match eqname with
+ | Some eq -> Some (false,eq)
+ | _ ->
+ if cls <> None then Some (false,(dloc,IntroAnonymous)) else None in
tclTHEN
(letin_tac with_eq (Name id) c (Option.default allClauses cls))
(induction_with_atomization_of_ind_arg
@@ -2505,7 +2538,10 @@ let new_induct_gen isrec with_evars elim names (c,lbind) cls gl =
that all arguments and parameters of the scheme are given
(mandatory for the moment), so we don't need to deal with
parameters of the inductive type as in new_induct_gen. *)
-let new_induct_gen_l isrec with_evars elim names lc gl =
+let new_induct_gen_l isrec with_evars elim (eqname,names) lc gl =
+ if eqname <> None then
+ errorlabstrm "" (str "Do not know what to do with " ++
+ pr_intro_pattern (Option.get eqname));
let newlc = ref [] in
let letids = ref [] in
let rec atomize_list l gl =
@@ -2566,7 +2602,7 @@ let induct_destruct_l isrec with_evars lc elim names cls =
principles).
TODO: really unify induction with one and induction with several
args *)
-let induct_destruct isrec with_evars lc elim names cls =
+let induct_destruct isrec with_evars (lc,elim,names,cls) =
assert (List.length lc > 0); (* ensured by syntax, but if called inside caml? *)
if List.length lc = 1 then (* induction on one arg: use old mechanism *)
try
@@ -2580,11 +2616,16 @@ let induct_destruct isrec with_evars lc elim names cls =
with _ -> raise x)
else induct_destruct_l isrec with_evars lc elim names cls
+let induction_destruct isrec with_evars = function
+ | [] -> tclIDTAC
+ | [a] -> induct_destruct isrec with_evars a
+ | a::l ->
+ tclTHEN
+ (induct_destruct isrec with_evars a)
+ (tclMAP (induct_destruct false with_evars) l)
-
-
-let new_induct = induct_destruct true
-let new_destruct = induct_destruct false
+let new_induct ev lc e idl cls = induct_destruct true ev (lc,e,idl,cls)
+let new_destruct ev lc e idl cls = induct_destruct false ev (lc,e,idl,cls)
(* The registered tactic, which calls the default elimination
* if no elimination constant is provided. *)
diff --git a/tactics/tactics.mli b/tactics/tactics.mli
index 9070e26179..56597f58e8 100644
--- a/tactics/tactics.mli
+++ b/tactics/tactics.mli
@@ -9,6 +9,7 @@
(*i $Id$ i*)
(*i*)
+open Util
open Names
open Term
open Environ
@@ -68,7 +69,8 @@ val find_intro_names : rel_context -> goal sigma -> identifier list
val intro : tactic
val introf : tactic
val intro_force : bool -> tactic
-val intro_move : identifier option -> identifier option -> tactic
+val intro_move : identifier option -> identifier move_location -> tactic
+
(* [intro_avoiding idl] acts as intro but prevents the new identifier
to belong to [idl] *)
val intro_avoiding : identifier list -> tactic
@@ -110,9 +112,10 @@ val onInductionArg :
(*s Introduction tactics with eliminations. *)
-val intro_pattern : identifier option -> intro_pattern_expr -> tactic
-val intro_patterns : intro_pattern_expr list -> tactic
-val intros_pattern : identifier option -> intro_pattern_expr list -> tactic
+val intro_pattern : identifier move_location -> intro_pattern_expr -> tactic
+val intro_patterns : intro_pattern_expr located list -> tactic
+val intros_pattern :
+ identifier move_location -> intro_pattern_expr located list -> tactic
(*s Exact tactics. *)
@@ -167,7 +170,7 @@ val keep : identifier list -> tactic
val specialize : int option -> constr with_ebindings -> tactic
-val move_hyp : bool -> identifier -> identifier -> tactic
+val move_hyp : bool -> identifier -> identifier move_location -> tactic
val rename_hyp : (identifier * identifier) list -> tactic
val revert : identifier list -> tactic
@@ -183,7 +186,7 @@ val apply_without_reduce : constr -> tactic
val apply_list : constr list -> tactic
val apply_with_ebindings_gen :
- advanced_flag -> evars_flag -> constr with_ebindings -> tactic
+ advanced_flag -> evars_flag -> constr with_ebindings list -> tactic
val apply_with_bindings : constr with_bindings -> tactic
val eapply_with_bindings : constr with_bindings -> tactic
@@ -260,7 +263,9 @@ val elim :
val simple_induct : quantified_hypothesis -> tactic
val new_induct : evars_flag -> constr with_ebindings induction_arg list ->
- constr with_ebindings option -> intro_pattern_expr -> clause option -> tactic
+ constr with_ebindings option ->
+ intro_pattern_expr located option * intro_pattern_expr located option ->
+ clause option -> tactic
(*s Case analysis tactics. *)
@@ -269,7 +274,18 @@ val simplest_case : constr -> tactic
val simple_destruct : quantified_hypothesis -> tactic
val new_destruct : evars_flag -> constr with_ebindings induction_arg list ->
- constr with_ebindings option -> intro_pattern_expr -> clause option -> tactic
+ constr with_ebindings option ->
+ intro_pattern_expr located option * intro_pattern_expr located option ->
+ clause option -> tactic
+
+(*s Generic case analysis / induction tactics. *)
+
+val induction_destruct : evars_flag -> rec_flag ->
+ (constr with_ebindings induction_arg list *
+ constr with_ebindings option *
+ (intro_pattern_expr located option * intro_pattern_expr located option) *
+ clause option) list ->
+ tactic
(*s Eliminations giving the type instead of the proof. *)
@@ -330,9 +346,10 @@ val cut_replacing :
identifier -> constr -> (tactic -> tactic) -> tactic
val cut_in_parallel : constr list -> tactic
-val assert_as : bool -> intro_pattern_expr -> constr -> tactic
-val forward : tactic option -> intro_pattern_expr -> constr -> tactic
-val letin_tac : bool option -> name -> constr -> clause -> tactic
+val assert_as : bool -> intro_pattern_expr located -> constr -> tactic
+val forward : tactic option -> intro_pattern_expr located -> constr -> tactic
+val letin_tac : (bool * intro_pattern_expr located) option -> name ->
+ constr -> clause -> tactic
val true_cut : name -> constr -> tactic
val assert_tac : bool -> name -> constr -> tactic
val generalize : constr list -> tactic
diff --git a/tactics/tauto.ml4 b/tactics/tauto.ml4
index 90705c8c9c..d3dd2959c3 100644
--- a/tactics/tauto.ml4
+++ b/tactics/tauto.ml4
@@ -142,7 +142,7 @@ let rec tauto_intuit t_reduce solver ist =
and t_simplif = tacticIn simplif
and t_is_disj = tacticIn is_disj
and t_tauto_intuit = tacticIn (tauto_intuit t_reduce solver) in
- let t_solver = Tacexpr.TacArg (valueIn (VTactic (dummy_loc,solver))) in
+ let t_solver = globTacticIn (fun _ist -> solver) in
<:tactic<
($t_simplif;$t_axioms
|| match reverse goal with
@@ -165,16 +165,14 @@ let rec tauto_intuit t_reduce solver ist =
$t_solver
) >>
-let reduction_not_iff=interp
+let reduction_not_iff _ist =
<:tactic