Skip to content
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

Compute Dependencies in the extractable monad #133

Draft
wants to merge 1 commit into
base: coq-8.8
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions template-coq/src/constr_denoter.ml
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,6 @@ struct
with Not_found ->
CErrors.user_err ~hdr:"unquote_level" (str ("Level "^s^" is not a declared level."))





let unquote_level evm trm (* of type level *) : Evd.evar_map * Univ.Level.t =
let (h,args) = app_full trm [] in
if Constr.equal h lProp then
Expand Down
4 changes: 4 additions & 0 deletions template-coq/src/constr_quoted.ml
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,10 @@ struct
else
not_supported_verb trm "unquote_list"

let rec quote_list ty = function
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is almost certainly duplicated.

[] -> Constr.mkApp (c_nil, [| ty |])
| l::ls -> Constr.mkApp (c_cons, [| ty ; l ; quote_list ty ls |])

(* Unquote Coq nat to OCaml int *)
let rec unquote_nat trm =
let (h,args) = app_full trm [] in
Expand Down
13 changes: 8 additions & 5 deletions template-coq/src/plugin_core.ml
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,11 @@ let tmLemma (nm : ident) ?poly:(poly=false)(ty : term) : kername tm =
| _ -> failwith "Evd.fresh_global did not return a Const") in
ignore (Obligations.add_definition nm ~term:c cty ctx ~kind ~hook obls)

let tmInductive (mi : mutual_inductive_entry) : unit tm =
fun env evd success _fail ->
ignore (ComInductive.declare_mutual_inductive_with_eliminations mi Names.Id.Map.empty []) ;
success (Global.env ()) evd ()

let tmFreshName (nm : ident) : ident tm =
fun env evd success _fail ->
let name' =
Expand All @@ -134,6 +139,9 @@ let tmAboutString (s : string) : global_reference option tm =
let q = Libnames.make_qualid dp nm in
tmAbout q env evd success fail

let tmDependencies (gr : global_reference) ?bypass : global_reference list tm =
failwith "not implemented"

let tmCurrentModPath : Names.ModPath.t tm =
fun env evd success _fail ->
let mp = Lib.current_mp () in success env evd mp
Expand Down Expand Up @@ -161,11 +169,6 @@ let tmQuoteConstant (kn : kername) (bypass : bool) : constant_entry tm =
with
Not_found -> fail Pp.(str "constant not found " ++ Names.KerName.print kn)

let tmInductive (mi : mutual_inductive_entry) : unit tm =
fun env evd success _fail ->
ignore (ComInductive.declare_mutual_inductive_with_eliminations mi Names.Id.Map.empty []) ;
success (Global.env ()) evd ()

let tmExistingInstance (kn : kername) : unit tm =
fun env evd success _fail ->
(* note(gmm): this seems wrong. *)
Expand Down
5 changes: 3 additions & 2 deletions template-coq/src/plugin_core.mli
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,19 @@ val tmEval : reduction_strategy -> term -> term tm
val tmDefinition : ident -> ?poly:bool -> term option -> term -> kername tm
val tmAxiom : ident -> ?poly:bool -> term -> kername tm
val tmLemma : ident -> ?poly:bool -> term -> kername tm
val tmInductive : mutual_inductive_entry -> unit tm

val tmFreshName : ident -> ident tm

val tmAbout : qualid -> global_reference option tm
val tmAboutString : string -> global_reference option tm
val tmDependencies : global_reference -> ?bypass:bool -> global_reference list tm

val tmCurrentModPath : Names.ModPath.t tm

val tmQuoteInductive : kername -> (Names.MutInd.t * mutual_inductive_body) option tm
val tmQuoteUniverses : UGraph.t tm
val tmQuoteConstant : kername -> bool -> constant_entry tm

val tmInductive : mutual_inductive_entry -> unit tm

val tmExistingInstance : kername -> unit tm
val tmInferInstance : term -> term option tm
11 changes: 11 additions & 0 deletions template-coq/src/run_template_monad.ml
Original file line number Diff line number Diff line change
Expand Up @@ -444,3 +444,14 @@ let rec run_template_program_rec ?(intactic=false) (k : Environ.env * Evd.evar_m
let evm,trm = denote_term evm (reduce_all env evm trm) in
Plugin_core.run (Plugin_core.tmPrint trm) env evm
(fun env evm _ -> k (env, evm, unit_tt))
| TmDependencies (trm, bypass) ->
let trm = Constr_denoter.CoqLiveDenoter.unquote_kn (reduce_all env evm trm) in
let bypass = Constr_quoted.ConstrQuoted.unquote_bool (reduce_all env evm bypass) in
Plugin_core.run Plugin_core.(tmBind (tmAbout trm) (function
None -> tmFail Pp.(str "Failed to resolve kernel name " ++ Libnames.pr_qualid trm)
| Some gr -> tmDependencies gr ~bypass)) env evm
(fun env evm result ->
let open Constr_quoted.ConstrQuoted in
let qresult = List.map quote_global_reference result in
let res = quote_list tglobal_reference qresult in
k (env, evm, res))
15 changes: 13 additions & 2 deletions template-coq/src/template_monad.ml
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,8 @@ let (ttmReturn,
ttmQuoteConstant,
ttmInductive,
ttmInferInstance,
ttmExistingInstance) =
ttmExistingInstance,
ttmDependencies) =
(r_template_monad_type_p "tmReturn",
r_template_monad_type_p "tmBind",

Expand All @@ -133,7 +134,8 @@ let (ttmReturn,
r_template_monad_type_p "tmInductive",

r_template_monad_type_p "tmInferInstance",
r_template_monad_type_p "tmExistingInstance")
r_template_monad_type_p "tmExistingInstance",
r_template_monad_type_p "tmDependencies")

type constr = Constr.t

Expand Down Expand Up @@ -179,6 +181,8 @@ type template_monad =
| TmInferInstance of Constr.t * Constr.t (* only Prop *)
| TmInferInstanceTerm of Constr.t (* only Extractable *)

| TmDependencies of Constr.t * Constr.t

(* todo: the recursive call is uneeded provided we call it on well formed terms *)
let rec app_full trm acc =
match Constr.kind trm with
Expand Down Expand Up @@ -370,4 +374,11 @@ let next_action env evd (pgm : constr) : template_monad * _ =
(TmInferInstanceTerm typ, universes)
| _ -> monad_failure "tmInferInstance" 2

else if Globnames.eq_gr glob_ref ttmDependencies then
match args with
| trm :: bypass :: [] ->
(TmDependencies (trm, bypass), universes)
| _ -> monad_failure "tmInferInstance" 2


else CErrors.user_err (str "Invalid argument or not yet implemented. The argument must be a TemplateProgram: " ++ pr_constr coConstr)
3 changes: 1 addition & 2 deletions template-coq/src/template_monad.mli
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

val ptmTestQuote : Names.global_reference
val ptmQuoteDefinition : Names.global_reference
val ptmQuoteDefinitionRed : Names.global_reference
Expand Down Expand Up @@ -48,7 +47,7 @@ type template_monad =
| TmExistingInstance of Constr.t
| TmInferInstance of Constr.t * Constr.t (* only Prop *)
| TmInferInstanceTerm of Constr.t (* only Extractable *)

| TmDependencies of Constr.t * Constr.t

val app_full
: Constr.constr -> Constr.constr list -> Constr.constr * Constr.constr list
Expand Down
2 changes: 2 additions & 0 deletions template-coq/theories/TemplateMonad/Extractable.v
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ Cumulative Inductive TM@{t} : Type@{t} -> Type :=
: TM constant_entry

| tmQuoteUniverses : TM uGraph.t
| tmDependencies (gr : global_reference) (bypass : bool)
: TM (list global_reference)

(* unquote before making the definition *)
(* FIXME take an optional universe context as well *)
Expand Down