Skip to content

Commit d86e160

Browse files
committed
feat: Add Symbol to TemplateMonad
1 parent a789bdb commit d86e160

File tree

5 files changed

+21
-0
lines changed

5 files changed

+21
-0
lines changed

template-rocq/src/run_template_monad.ml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,17 @@ let rec run_template_program_rec ~poly ?(intactic=false) (k : Constr.t Plugin_co
365365
Declare.declare_variable ~typing_flags:None ~name ~kind (SectionLocalAssum { typ; impl=Glob_term.Explicit; univs=empty_mono_univ_entry });
366366
let env = Global.env () in
367367
k ~st env evm (Lazy.force unit_tt)
368+
| TmSymbol (name, typ) ->
369+
if intactic then not_in_tactic "tmSymbol"
370+
else
371+
let name = unquote_ident (reduce_all env evm name) in
372+
let udecl = UState.default_univ_decl in
373+
let univs = Evd.check_univ_decl ~poly evm udecl in
374+
let entry = Declare.symbol_entry ~univs ~unfold_fix:false typ in
375+
let kn = Declare.declare_constant ~name ~kind:Decls.IsSymbol (Declare.SymbolEntry entry) in
376+
let () = Declare.assumption_message name in
377+
let env = Global.env () in
378+
k ~st env evm (Constr.mkConstU (kn, UVars.Instance.empty))
368379
| TmDefinition (opaque,name,s,typ,body) ->
369380
if intactic
370381
then not_in_tactic "tmDefinition"

template-rocq/src/template_monad.ml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ let (ptmReturn,
2424
ptmMkDefinition,
2525
ptmMkInductive,
2626
ptmVariable,
27+
ptmSymbol,
2728

2829
ptmFreshName,
2930

@@ -67,6 +68,7 @@ let (ptmReturn,
6768
r_template_monad_prop_p "tmMkDefinition",
6869
r_template_monad_prop_p "tmMkInductive",
6970
r_template_monad_prop_p "tmVariable",
71+
r_template_monad_prop_p "tmSymbol",
7072

7173
r_template_monad_prop_p "tmFreshName",
7274

@@ -179,6 +181,7 @@ type template_monad =
179181
| TmAxiomTerm of Constr.t * Constr.t
180182
| TmMkInductive of Constr.t * Constr.t
181183
| TmVariable of Constr.t * Constr.t
184+
| TmSymbol of Constr.t * Constr.t
182185

183186
| TmFreshName of Constr.t
184187

@@ -400,6 +403,10 @@ let next_action env evd (pgm : constr) : template_monad * _ =
400403
match args with
401404
| name::ty::[] -> (TmVariable (name,ty) , universes)
402405
| _ -> monad_failure "tmVariable" 2
406+
else if eq_gr ptmSymbol then
407+
match args with
408+
| name :: ty :: [] -> (TmSymbol (name, ty), universes)
409+
| _ -> monad_failure "tmSymbol" 2
403410
else if eq_gr ttmInductive then
404411
match args with
405412
| inferu :: mind::[] -> (TmMkInductive (inferu, mind), universes)

template-rocq/src/template_monad.mli

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ type template_monad =
3030
| TmAxiomTerm of Constr.t * Constr.t
3131
| TmMkInductive of Constr.t * Constr.t
3232
| TmVariable of Constr.t * Constr.t
33+
| TmSymbol of Constr.t * Constr.t
3334

3435
| TmFreshName of Constr.t
3536

template-rocq/theories/Constants.v

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,7 @@ Register MetaRocq.Template.TemplateMonad.Core.tmMsg as metarocq.templatemonad.pr
245245
Register MetaRocq.Template.TemplateMonad.Core.tmFail as metarocq.templatemonad.prop.tmFail.
246246
Register MetaRocq.Template.TemplateMonad.Core.tmEval as metarocq.templatemonad.prop.tmEval.
247247
Register MetaRocq.Template.TemplateMonad.Core.tmVariable as metarocq.templatemonad.prop.tmVariable.
248+
Register MetaRocq.Template.TemplateMonad.Core.tmSymbol as metarocq.templatemonad.prop.tmSymbol.
248249
Register MetaRocq.Template.TemplateMonad.Core.tmLemma as metarocq.templatemonad.prop.tmLemma.
249250
Register MetaRocq.Template.TemplateMonad.Core.tmDefinitionRed_ as metarocq.templatemonad.prop.tmDefinitionRed_.
250251
Register MetaRocq.Template.TemplateMonad.Core.tmAxiomRed as metarocq.templatemonad.prop.tmAxiomRed.

template-rocq/theories/TemplateMonad/Core.v

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ Cumulative Inductive TemplateMonad@{t u} : Type@{t} -> Prop :=
3333
| tmDefinitionRed_ : forall (opaque : bool), ident -> option reductionStrategy -> forall {A:Type@{t}}, A -> TemplateMonad A
3434
| tmAxiomRed : ident -> option reductionStrategy -> forall A : Type@{t}, TemplateMonad A
3535
| tmVariable : ident -> Type@{t} -> TemplateMonad unit
36+
| tmSymbol : ident -> Type@{t} -> TemplateMonad unit
3637

3738
(* Guaranteed to not cause "... already declared" error *)
3839
| tmFreshName : ident -> TemplateMonad ident

0 commit comments

Comments
 (0)