-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added the ability to reflect Inductive definitions #32
Changes from 17 commits
7c2969d
4fac2ee
4a71321
6a07c23
3e025d6
1d75c3f
70bfe07
11e9c1c
7ba3c4e
7db60c9
c66334d
24cdc10
6506e45
03905b7
834cbb1
bdc1171
2fa5fdc
10f3993
596619d
fac3650
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,7 @@ let _ = Goptions.declare_bool_option { | |
Goptions.optwrite = (fun a -> cast_prop:=a); | ||
} | ||
|
||
(* whether Set Template Cast Propositions is on, as needed for erasure in Certicoq *) | ||
let is_cast_prop () = !cast_prop | ||
|
||
let pp_constr fmt x = Pp.pp_with fmt (Printer.pr_constr x) | ||
|
@@ -74,6 +75,8 @@ struct | |
let tS = resolve_symbol pkg_datatypes "S" | ||
let tnat = resolve_symbol pkg_datatypes "nat" | ||
let ttrue = resolve_symbol pkg_datatypes "true" | ||
let cSome = resolve_symbol pkg_datatypes "Some" | ||
let cNone = resolve_symbol pkg_datatypes "None" | ||
let tfalse = resolve_symbol pkg_datatypes "false" | ||
let tAscii = resolve_symbol ["Coq";"Strings";"Ascii"] "Ascii" | ||
let c_nil = resolve_symbol pkg_datatypes "nil" | ||
|
@@ -85,6 +88,7 @@ struct | |
let pair a b f s = | ||
Term.mkApp (c_pair, [| a ; b ; f ; s |]) | ||
|
||
(* reify the constructors in Template.Ast.v, which are the building blocks of reified terms *) | ||
let nAnon = r_reify "nAnon" | ||
let nNamed = r_reify "nNamed" | ||
let kVmCast = r_reify "VmCast" | ||
|
@@ -105,6 +109,7 @@ struct | |
r_reify "tConstruct", r_reify "tConst", r_reify "tInd", r_reify "tUnknown") | ||
|
||
let (tdef,tmkdef) = (r_reify "def", r_reify "mkdef") | ||
let (tLocalDef,tLocalAssum) = (r_reify "LocalDef", r_reify "LocalAssum") | ||
let (pConstr,pType,pAxiom,pIn) = | ||
(r_reify "PConstr", r_reify "PType", r_reify "PAxiom", r_reify "PIn") | ||
let tinductive_body = r_reify "inductive_body" | ||
|
@@ -564,6 +569,7 @@ struct | |
else | ||
not_supported trm | ||
|
||
|
||
let from_coq_pair trm = | ||
let (h,args) = app_full trm [] in | ||
if Term.eq_constr h c_pair then | ||
|
@@ -573,6 +579,7 @@ struct | |
else | ||
not_supported trm | ||
|
||
|
||
(** NOTE: Because the representation is lossy, I should probably | ||
** come back through elaboration. | ||
** - This would also allow writing terms with holes | ||
|
@@ -647,6 +654,59 @@ struct | |
else | ||
not_supported trm | ||
|
||
let denote_local_entry trm = | ||
let (h,args) = app_full trm [] in | ||
match args with | ||
x :: [] -> | ||
if Term.eq_constr h tLocalDef then Entries.LocalDef (denote_term x) | ||
else (if Term.eq_constr h tLocalAssum then Entries.LocalAssum (denote_term x) else bad_term trm) | ||
| _ -> bad_term trm | ||
|
||
let unquote_map_option f trm = | ||
let (h,args) = app_full trm [] in | ||
if Term.eq_constr h cSome then | ||
match args with | ||
_ :: x :: _ -> Some (f x) | ||
| _ -> bad_term trm | ||
else if Term.eq_constr h cNone then | ||
match args with | ||
_ :: [] -> None | ||
| _ -> bad_term trm | ||
else | ||
not_supported trm | ||
|
||
|
||
let declare_inductive (env: Environ.env) (evm: Evd.evar_map) (body: Constrexpr.constr_expr) : unit = | ||
let (body,_) = Constrintern.interp_constr env evm body in | ||
let (_,args) = app_full body [] in (* check that the first component is Build_mut_ind .. *) | ||
let one_ind b1 : Entries.one_inductive_entry = | ||
let (_,args) = app_full b1 [] in (* check that the first component is Build_one_ind .. *) | ||
match args with | ||
| mt::ma::mtemp::mcn::mct::[] -> | ||
{ | ||
mind_entry_typename = unquote_ident mt; | ||
mind_entry_arity = denote_term ma; | ||
mind_entry_template = from_bool mtemp; | ||
mind_entry_consnames = List.map unquote_ident (from_coq_list mcn); | ||
mind_entry_lc = List.map denote_term (from_coq_list mct) | ||
} | ||
| _ -> raise (Failure "ill-typed one_inductive_entry") | ||
in | ||
let mut_ind mr mf mp mi mpol mpr : Entries.mutual_inductive_entry = | ||
{ | ||
mind_entry_record = unquote_map_option (unquote_map_option unquote_ident) mr; | ||
mind_entry_finite = Decl_kinds.Finite; (* inductive *) | ||
mind_entry_params = List.map (fun p -> let (l,r) = (from_coq_pair p) in (unquote_ident l, (denote_local_entry r))) (from_coq_list mp); | ||
mind_entry_inds = List.map one_ind (from_coq_list mi); | ||
mind_entry_polymorphic = from_bool mpol; | ||
mind_entry_universes = Univ.UContext.empty; | ||
mind_entry_private = None (*mpr*) | ||
} in | ||
match args with | ||
mr::mf::mp::mi::mpol::mpr::[] -> | ||
Command.declare_mutual_inductive_with_eliminations (mut_ind mr mf mp mi mpol mpr) [] [];() | ||
| _ -> raise (Failure "ill-typed mutual_inductive_entry") | ||
|
||
end | ||
|
||
DECLARE PLUGIN "template_plugin" | ||
|
@@ -671,7 +731,7 @@ let to_ltac_val c = Tacexpr.TacDynamic(Loc.ghost,Pretyping.constr_in c) | |
|
||
(** From Containers **) | ||
let declare_definition | ||
id (loc, boxed_flag, def_obj_kind) | ||
(id : Names.Id.t) (loc, boxed_flag, def_obj_kind) | ||
(binder_list : Constrexpr.local_binder list) red_expr_opt constr_expr | ||
constr_expr_opt decl_hook = | ||
Command.do_definition | ||
|
@@ -766,6 +826,14 @@ VERNAC COMMAND EXTEND Unquote_vernac CLASSIFIED AS SIDEFF | |
[] None result None (Lemmas.mk_hook (fun _ _ -> ())) ] | ||
END;; | ||
|
||
(* get rid of the unused ident(name)? *) | ||
VERNAC COMMAND EXTEND Unquote_inductive CLASSIFIED AS SIDEFF | ||
| [ "Make" "Inductive" constr(def) ] -> | ||
[ check_inside_section () ; | ||
let (evm,env) = Lemmas.get_current_context () in | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it necessary to |
||
TermReify.declare_inductive env evm def ] | ||
END;; | ||
|
||
VERNAC COMMAND EXTEND Make_tests CLASSIFIED AS QUERY | ||
(* | ||
| [ "Make" "Definitions" tactic(t) ] -> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -63,3 +63,49 @@ Inductive program : Set := | |
list (ident * inductive_body) -> program -> program | ||
| PAxiom : ident -> term (* the type *) -> program -> program | ||
| PIn : term -> program. | ||
|
||
|
||
(** representation of mutual inductives. nearly copied from Coq/kernel/entries.mli | ||
*) | ||
|
||
Record one_inductive_entry : Set := { | ||
mind_entry_typename : ident; | ||
mind_entry_arity : term; | ||
mind_entry_template : bool; (* template polymorphism ? *) | ||
mind_entry_consnames : list ident; | ||
mind_entry_lc : list term}. | ||
|
||
|
||
Inductive local_entry : Set := | ||
| LocalDef : term -> local_entry (* local let binding *) | ||
| LocalAssum : term -> local_entry. | ||
|
||
(* | ||
type local_entry = | ||
| LocalDef of constr | ||
| LocalAssum of constr | ||
*) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Like the next comment. |
||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (** The kind of definition. See kerne/....mli **) |
||
Inductive recursivity_kind := | ||
| Finite (** = inductive *) | ||
| CoFinite (** = coinductive *) | ||
| BiFinite (** = non-recursive, like in "Record" definitions *). | ||
|
||
|
||
(* | ||
type recursivity_kind = | ||
| Finite | ||
| CoFinite | ||
| BiFinite | ||
*) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This seems like an out-of-place comment. |
||
|
||
(* kernel/entries.mli*) | ||
Record mutual_inductive_entry : Set := { | ||
mind_entry_record : option (option ident); | ||
mind_entry_finite : recursivity_kind; | ||
mind_entry_params : list (ident * local_entry); | ||
mind_entry_inds : list one_inductive_entry; | ||
mind_entry_polymorphic : bool; | ||
(* mind_entry_universes : Univ.universe_context; *) | ||
mind_entry_private : option bool | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Indeed private is for the HIT trick |
||
}. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What does this mean?