Skip to content

Commit

Permalink
Merge PR #12241: [declare] Merge DeclareDef into Declare
Browse files Browse the repository at this point in the history
Reviewed-by: Matafou
Reviewed-by: SkySkimmer
  • Loading branch information
SkySkimmer committed May 9, 2020
2 parents 5681ea2 + 6675e7c commit 34e2e79
Show file tree
Hide file tree
Showing 40 changed files with 491 additions and 523 deletions.
4 changes: 2 additions & 2 deletions doc/plugin_tutorial/tuto1/src/simple_declare.ml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
let declare_definition ~poly name sigma body =
let udecl = UState.default_univ_decl in
let scope = DeclareDef.Global Declare.ImportDefaultBehavior in
let scope = Declare.Global Declare.ImportDefaultBehavior in
let kind = Decls.(IsDefinition Definition) in
DeclareDef.declare_definition ~name ~scope ~kind ~impargs:[] ~udecl
Declare.declare_definition ~name ~scope ~kind ~impargs:[] ~udecl
~opaque:false ~poly ~types:None ~body sigma
10 changes: 5 additions & 5 deletions plugins/funind/gen_principle.ml
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ let build_functional_principle (sigma : Evd.evar_map) old_princ_type sorts funs
Declare.build_by_tactic env ~uctx ~poly:false ~typ ftac
in
(* uctx was ignored before *)
let hook = DeclareDef.Hook.make (hook new_principle_type) in
let hook = Declare.Hook.make (hook new_principle_type) in
(body, typ, univs, hook, sigma)

let change_property_sort evd toSort princ princName =
Expand Down Expand Up @@ -318,8 +318,8 @@ let generate_functional_principle (evd : Evd.evar_map ref) old_princ_type sorts
let uctx = Evd.evar_universe_context sigma in
let entry = Declare.definition_entry ~univs ?types body in
let (_ : Names.GlobRef.t) =
DeclareDef.declare_entry ~name:new_princ_name ~hook
~scope:(DeclareDef.Global Declare.ImportDefaultBehavior)
Declare.declare_entry ~name:new_princ_name ~hook
~scope:(Declare.Global Declare.ImportDefaultBehavior)
~kind:Decls.(IsProof Theorem)
~impargs:[] ~uctx entry
in
Expand Down Expand Up @@ -400,7 +400,7 @@ let register_struct is_rec fixpoint_exprl =
Pp.(str "Body of Function must be given")
in
ComDefinition.do_definition ~name:fname.CAst.v ~poly:false
~scope:(DeclareDef.Global Declare.ImportDefaultBehavior)
~scope:(Declare.Global Declare.ImportDefaultBehavior)
~kind:Decls.Definition univs binders None body (Some rtype);
let evd, rev_pconstants =
List.fold_left
Expand All @@ -419,7 +419,7 @@ let register_struct is_rec fixpoint_exprl =
(None, evd, List.rev rev_pconstants)
| _ ->
ComFixpoint.do_fixpoint
~scope:(DeclareDef.Global Declare.ImportDefaultBehavior) ~poly:false
~scope:(Declare.Global Declare.ImportDefaultBehavior) ~poly:false
fixpoint_exprl;
let evd, rev_pconstants =
List.fold_left
Expand Down
6 changes: 3 additions & 3 deletions plugins/funind/recdef.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1483,7 +1483,7 @@ let open_new_goal ~lemma build_proof sigma using_lemmas ref_ goal_name
let lemma = build_proof env (Evd.from_env env) start_tac end_tac in
Lemmas.save_lemma_proved ~lemma ~opaque:opacity ~idopt:None
in
let info = Lemmas.Info.make ~hook:(DeclareDef.Hook.make hook) () in
let info = Lemmas.Info.make ~hook:(Declare.Hook.make hook) () in
let lemma =
Lemmas.start_lemma ~name:na ~poly:false (* FIXME *) ~info sigma gls_type
in
Expand Down Expand Up @@ -1721,7 +1721,7 @@ let recursive_definition ~interactive_proof ~is_mes function_name rec_impls
let tcc_lemma_name = add_suffix function_name "_tcc" in
let tcc_lemma_constr = ref Undefined in
(* let _ = Pp.msgnl (fun _ _ -> str "relation := " ++ Printer.pr_lconstr_env env_with_pre_rec_args relation) in *)
let hook {DeclareDef.Hook.S.uctx; _} =
let hook {Declare.Hook.S.uctx; _} =
let term_ref = Nametab.locate (qualid_of_ident term_id) in
let f_ref =
declare_f function_name Decls.(IsProof Lemma) arg_types term_ref
Expand Down Expand Up @@ -1767,5 +1767,5 @@ let recursive_definition ~interactive_proof ~is_mes function_name rec_impls
functional_ref
(EConstr.of_constr rec_arg_type)
relation rec_arg_num term_id using_lemmas (List.length res_vars) evd
(DeclareDef.Hook.make hook))
(Declare.Hook.make hook))
()
2 changes: 1 addition & 1 deletion plugins/ltac/g_ltac.mlg
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ GRAMMAR EXTEND Gram
hint:
[ [ IDENT "Extern"; n = natural; c = OPT Constr.constr_pattern ; "=>";
tac = Pltac.tactic ->
{ ComHints.HintsExtern (n,c, in_tac tac) } ] ]
{ Vernacexpr.HintsExtern (n,c, in_tac tac) } ] ]
;
operconstr: LEVEL "0"
[ [ IDENT "ltac"; ":"; "("; tac = Pltac.tactic_expr; ")" ->
Expand Down
12 changes: 6 additions & 6 deletions plugins/ltac/rewrite.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1894,10 +1894,10 @@ let declare_projection name instance_id r =
in it_mkProd_or_LetIn ccl ctx
in
let types = Some (it_mkProd_or_LetIn typ ctx) in
let kind, opaque, scope = Decls.(IsDefinition Definition), false, DeclareDef.Global Declare.ImportDefaultBehavior in
let kind, opaque, scope = Decls.(IsDefinition Definition), false, Declare.Global Declare.ImportDefaultBehavior in
let impargs, udecl = [], UState.default_univ_decl in
let _r : GlobRef.t =
DeclareDef.declare_definition ~name ~scope ~kind ~opaque ~impargs ~udecl ~poly ~types ~body sigma
Declare.declare_definition ~name ~scope ~kind ~opaque ~impargs ~udecl ~poly ~types ~body sigma
in ()

let build_morphism_signature env sigma m =
Expand Down Expand Up @@ -1961,10 +1961,10 @@ let add_morphism_as_parameter atts m n : unit =
let env = Global.env () in
let evd = Evd.from_env env in
let poly = atts.polymorphic in
let kind, opaque, scope = Decls.(IsAssumption Logical), false, DeclareDef.Global Declare.ImportDefaultBehavior in
let kind, opaque, scope = Decls.(IsAssumption Logical), false, Declare.Global Declare.ImportDefaultBehavior in
let impargs, udecl = [], UState.default_univ_decl in
let evd, types = build_morphism_signature env evd m in
let evd, pe = DeclareDef.prepare_parameter ~poly ~udecl ~types evd in
let evd, pe = Declare.prepare_parameter ~poly ~udecl ~types evd in
let cst = Declare.declare_constant ~name:instance_id ~kind (Declare.ParameterEntry pe) in
let cst = GlobRef.ConstRef cst in
Classes.add_instance
Expand All @@ -1981,15 +1981,15 @@ let add_morphism_interactive atts m n : Lemmas.t =
let poly = atts.polymorphic in
let kind = Decls.(IsDefinition Instance) in
let tac = make_tactic "Coq.Classes.SetoidTactics.add_morphism_tactic" in
let hook { DeclareDef.Hook.S.dref; _ } = dref |> function
let hook { Declare.Hook.S.dref; _ } = dref |> function
| GlobRef.ConstRef cst ->
Classes.add_instance (Classes.mk_instance
(PropGlobal.proper_class env evd) Hints.empty_hint_info
atts.global (GlobRef.ConstRef cst));
declare_projection n instance_id (GlobRef.ConstRef cst)
| _ -> assert false
in
let hook = DeclareDef.Hook.make hook in
let hook = Declare.Hook.make hook in
let info = Lemmas.Info.make ~hook ~kind () in
Flags.silently
(fun () ->
Expand Down
14 changes: 7 additions & 7 deletions vernac/classes.ml
Original file line number Diff line number Diff line change
Expand Up @@ -313,8 +313,8 @@ let instance_hook info global ?hook cst =

let declare_instance_constant info global impargs ?hook name udecl poly sigma term termtype =
let kind = Decls.(IsDefinition Instance) in
let scope = DeclareDef.Global Declare.ImportDefaultBehavior in
let kn = DeclareDef.declare_definition ~name ~kind ~scope ~impargs
let scope = Declare.Global Declare.ImportDefaultBehavior in
let kn = Declare.declare_definition ~name ~kind ~scope ~impargs
~opaque:false ~poly sigma ~udecl ~types:(Some termtype) ~body:term in
instance_hook info global ?hook kn

Expand All @@ -325,7 +325,7 @@ let do_declare_instance sigma ~global ~poly k u ctx ctx' pri udecl impargs subst
in
let (_, ty_constr) = instance_constructor (k,u) subst in
let termtype = it_mkProd_or_LetIn ty_constr (ctx' @ ctx) in
let sigma, entry = DeclareDef.prepare_parameter ~poly sigma ~udecl ~types:termtype in
let sigma, entry = Declare.prepare_parameter ~poly sigma ~udecl ~types:termtype in
let cst = Declare.declare_constant ~name
~kind:Decls.(IsAssumption Logical) (Declare.ParameterEntry entry) in
DeclareUniv.declare_univ_binders (GlobRef.ConstRef cst) (Evd.universe_binders sigma);
Expand All @@ -334,17 +334,17 @@ let do_declare_instance sigma ~global ~poly k u ctx ctx' pri udecl impargs subst
instance_hook pri global cst

let declare_instance_program env sigma ~global ~poly name pri impargs udecl term termtype =
let hook { DeclareDef.Hook.S.scope; dref; _ } =
let hook { Declare.Hook.S.scope; dref; _ } =
let cst = match dref with GlobRef.ConstRef kn -> kn | _ -> assert false in
let pri = intern_info pri in
let env = Global.env () in
let sigma = Evd.from_env env in
declare_instance env sigma (Some pri) (not global) (GlobRef.ConstRef cst)
in
let obls, _, term, typ = RetrieveObl.retrieve_obligations env name sigma 0 term termtype in
let hook = DeclareDef.Hook.make hook in
let hook = Declare.Hook.make hook in
let uctx = Evd.evar_universe_context sigma in
let scope, kind = DeclareDef.Global Declare.ImportDefaultBehavior, Decls.Instance in
let scope, kind = Declare.Global Declare.ImportDefaultBehavior, Decls.Instance in
let _ : DeclareObl.progress =
Obligations.add_definition ~name ~term ~udecl ~scope ~poly ~kind ~hook ~impargs ~uctx typ obls
in ()
Expand All @@ -357,7 +357,7 @@ let declare_instance_open sigma ?hook ~tac ~global ~poly id pri impargs udecl id
let gls = List.rev (Evd.future_goals sigma) in
let sigma = Evd.reset_future_goals sigma in
let kind = Decls.(IsDefinition Instance) in
let hook = DeclareDef.Hook.(make (fun { S.dref ; _ } -> instance_hook pri global ?hook dref)) in
let hook = Declare.Hook.(make (fun { S.dref ; _ } -> instance_hook pri global ?hook dref)) in
let info = Lemmas.Info.make ~hook ~kind () in
(* XXX: We need to normalize the type, otherwise Admitted / Qed will fails!
This is due to a bug in proof_global :( *)
Expand Down
10 changes: 5 additions & 5 deletions vernac/classes.mli
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ val declare_instance : ?warn:bool -> env -> Evd.evar_map ->
Does nothing — or emit a “not-a-class” warning if the [warn] argument is set —
when said type is not a registered type class. *)

val existing_instance : bool -> qualid -> ComHints.hint_info_expr option -> unit
val existing_instance : bool -> qualid -> Vernacexpr.hint_info_expr option -> unit
(** globality, reference, optional priority and pattern information *)

val new_instance_interactive
Expand All @@ -34,7 +34,7 @@ val new_instance_interactive
-> ?generalize:bool
-> ?tac:unit Proofview.tactic
-> ?hook:(GlobRef.t -> unit)
-> ComHints.hint_info_expr
-> Vernacexpr.hint_info_expr
-> (bool * constr_expr) option
-> Id.t * Lemmas.t

Expand All @@ -47,7 +47,7 @@ val new_instance
-> (bool * constr_expr)
-> ?generalize:bool
-> ?hook:(GlobRef.t -> unit)
-> ComHints.hint_info_expr
-> Vernacexpr.hint_info_expr
-> Id.t

val new_instance_program
Expand All @@ -59,7 +59,7 @@ val new_instance_program
-> (bool * constr_expr) option
-> ?generalize:bool
-> ?hook:(GlobRef.t -> unit)
-> ComHints.hint_info_expr
-> Vernacexpr.hint_info_expr
-> Id.t

val declare_new_instance
Expand All @@ -69,7 +69,7 @@ val declare_new_instance
-> ident_decl
-> local_binder_expr list
-> constr_expr
-> ComHints.hint_info_expr
-> Vernacexpr.hint_info_expr
-> unit

(** {6 Low level interface used by Add Morphism, do not use } *)
Expand Down
11 changes: 5 additions & 6 deletions vernac/comAssumption.ml
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,7 @@ let context_set_of_entry = function
| Monomorphic_entry uctx -> uctx

let declare_assumptions ~poly ~scope ~kind univs nl l =
let open DeclareDef in
let () = match scope with
let () = let open Declare in match scope with
| Discharge ->
(* declare universes separately for variables *)
DeclareUctx.declare_universe_context ~poly (context_set_of_entry (fst univs))
Expand All @@ -100,10 +99,10 @@ let declare_assumptions ~poly ~scope ~kind univs nl l =
let univs,subst' =
List.fold_left_map (fun univs id ->
let refu = match scope with
| Discharge ->
| Declare.Discharge ->
declare_variable is_coe ~kind typ imps Glob_term.Explicit id;
GlobRef.VarRef id.CAst.v, Univ.Instance.empty
| Global local ->
| Declare.Global local ->
declare_axiom is_coe ~local ~poly ~kind typ univs imps nl id
in
next_univs univs, (id.CAst.v, Constr.mkRef refu))
Expand All @@ -130,7 +129,7 @@ let process_assumptions_udecls ~scope l =
udecl, id
| (_, ([], _))::_ | [] -> assert false
in
let open DeclareDef in
let open Declare in
let () = match scope, udecl with
| Discharge, Some _ ->
let loc = first_id.CAst.loc in
Expand Down Expand Up @@ -208,7 +207,7 @@ let context_insection sigma ~poly ctx =
let uctx = Evd.evar_universe_context sigma in
let kind = Decls.(IsDefinition Definition) in
let _ : GlobRef.t =
DeclareDef.declare_entry ~name ~scope:DeclareDef.Discharge
Declare.declare_entry ~name ~scope:Declare.Discharge
~kind ~impargs:[] ~uctx entry
in
()
Expand Down
2 changes: 1 addition & 1 deletion vernac/comAssumption.mli
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ open Constrexpr
val do_assumptions
: program_mode:bool
-> poly:bool
-> scope:DeclareDef.locality
-> scope:Declare.locality
-> kind:Decls.assumption_object_kind
-> Declaremods.inline
-> (ident_decl list * constr_expr) with_coercion list
Expand Down
12 changes: 6 additions & 6 deletions vernac/comCoercion.ml
Original file line number Diff line number Diff line change
Expand Up @@ -352,8 +352,8 @@ let try_add_new_identity_coercion id ~local ~poly ~source ~target =
let try_add_new_coercion_with_source ref ~local ~poly ~source =
try_add_new_coercion_core ref ~local poly (Some source) None false

let add_coercion_hook poly { DeclareDef.Hook.S.scope; dref; _ } =
let open DeclareDef in
let add_coercion_hook poly { Declare.Hook.S.scope; dref; _ } =
let open Declare in
let local = match scope with
| Discharge -> assert false (* Local Coercion in section behaves like Local Definition *)
| Global ImportNeedQualified -> true
Expand All @@ -363,10 +363,10 @@ let add_coercion_hook poly { DeclareDef.Hook.S.scope; dref; _ } =
let msg = Nametab.pr_global_env Id.Set.empty dref ++ str " is now a coercion" in
Flags.if_verbose Feedback.msg_info msg

let add_coercion_hook ~poly = DeclareDef.Hook.make (add_coercion_hook poly)
let add_coercion_hook ~poly = Declare.Hook.make (add_coercion_hook poly)

let add_subclass_hook ~poly { DeclareDef.Hook.S.scope; dref; _ } =
let open DeclareDef in
let add_subclass_hook ~poly { Declare.Hook.S.scope; dref; _ } =
let open Declare in
let stre = match scope with
| Discharge -> assert false (* Local Subclass in section behaves like Local Definition *)
| Global ImportNeedQualified -> true
Expand All @@ -375,4 +375,4 @@ let add_subclass_hook ~poly { DeclareDef.Hook.S.scope; dref; _ } =
let cl = class_of_global dref in
try_add_new_coercion_subclass cl ~local:stre ~poly

let add_subclass_hook ~poly = DeclareDef.Hook.make (add_subclass_hook ~poly)
let add_subclass_hook ~poly = Declare.Hook.make (add_subclass_hook ~poly)
4 changes: 2 additions & 2 deletions vernac/comCoercion.mli
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ val try_add_new_identity_coercion
-> local:bool
-> poly:bool -> source:cl_typ -> target:cl_typ -> unit

val add_coercion_hook : poly:bool -> DeclareDef.Hook.t
val add_coercion_hook : poly:bool -> Declare.Hook.t

val add_subclass_hook : poly:bool -> DeclareDef.Hook.t
val add_subclass_hook : poly:bool -> Declare.Hook.t

val class_of_global : GlobRef.t -> cl_typ
4 changes: 2 additions & 2 deletions vernac/comDefinition.ml
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ let do_definition ?hook ~name ~scope ~poly ~kind udecl bl red_option c ctypopt =
in
let kind = Decls.IsDefinition kind in
let _ : Names.GlobRef.t =
DeclareDef.declare_definition ~name ~scope ~kind ?hook ~impargs
Declare.declare_definition ~name ~scope ~kind ?hook ~impargs
~opaque:false ~poly evd ~udecl ~types ~body
in ()

Expand All @@ -126,7 +126,7 @@ let do_definition_program ?hook ~name ~scope ~poly ~kind udecl bl red_option c c
let (body, types), evd, udecl, impargs =
interp_definition ~program_mode udecl bl ~poly red_option c ctypopt
in
let term, ty, uctx, obls = DeclareDef.prepare_obligation ~name ~poly ~body ~types ~udecl evd in
let term, ty, uctx, obls = Declare.prepare_obligation ~name ~poly ~body ~types ~udecl evd in
let _ : DeclareObl.progress =
Obligations.add_definition
~name ~term ty ~uctx ~udecl ~impargs ~scope ~poly ~kind ?hook obls
Expand Down
8 changes: 4 additions & 4 deletions vernac/comDefinition.mli
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ open Constrexpr
(** {6 Definitions/Let} *)

val do_definition
: ?hook:DeclareDef.Hook.t
: ?hook:Declare.Hook.t
-> name:Id.t
-> scope:DeclareDef.locality
-> scope:Declare.locality
-> poly:bool
-> kind:Decls.definition_object_kind
-> universe_decl_expr option
Expand All @@ -28,9 +28,9 @@ val do_definition
-> unit

val do_definition_program
: ?hook:DeclareDef.Hook.t
: ?hook:Declare.Hook.t
-> name:Id.t
-> scope:DeclareDef.locality
-> scope:Declare.locality
-> poly:bool
-> kind:Decls.definition_object_kind
-> universe_decl_expr option
Expand Down
4 changes: 2 additions & 2 deletions vernac/comFixpoint.ml
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ let build_recthms ~indexes fixnames fixtypes fiximps =
in
let thms =
List.map3 (fun name typ (ctx,impargs,_) ->
{ DeclareDef.Recthm.name
{ Declare.Recthm.name
; typ
; args = List.map Context.Rel.Declaration.get_name ctx
; impargs})
Expand All @@ -284,7 +284,7 @@ let declare_fixpoint_generic ?indexes ~scope ~poly ((fixnames,fixrs,fixdefs,fixt
let rec_declaration = prepare_recursive_declaration fixnames fixrs fixtypes fixdefs in
let fix_kind = Decls.IsDefinition fix_kind in
let _ : GlobRef.t list =
DeclareDef.declare_mutually_recursive ~scope ~opaque:false ~kind:fix_kind ~poly ~uctx
Declare.declare_mutually_recursive ~scope ~opaque:false ~kind:fix_kind ~poly ~uctx
~possible_indexes:indexes ~restrict_ucontext:true ~udecl ~ntns ~rec_declaration
fixitems
in
Expand Down
8 changes: 4 additions & 4 deletions vernac/comFixpoint.mli
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,16 @@ open Vernacexpr
(** Entry points for the vernacular commands Fixpoint and CoFixpoint *)

val do_fixpoint_interactive :
scope:DeclareDef.locality -> poly:bool -> fixpoint_expr list -> Lemmas.t
scope:Declare.locality -> poly:bool -> fixpoint_expr list -> Lemmas.t

val do_fixpoint :
scope:DeclareDef.locality -> poly:bool -> fixpoint_expr list -> unit
scope:Declare.locality -> poly:bool -> fixpoint_expr list -> unit

val do_cofixpoint_interactive :
scope:DeclareDef.locality -> poly:bool -> cofixpoint_expr list -> Lemmas.t
scope:Declare.locality -> poly:bool -> cofixpoint_expr list -> Lemmas.t

val do_cofixpoint :
scope:DeclareDef.locality -> poly:bool -> cofixpoint_expr list -> unit
scope:Declare.locality -> poly:bool -> cofixpoint_expr list -> unit

(************************************************************************)
(** Internal API *)
Expand Down
Loading

0 comments on commit 34e2e79

Please sign in to comment.