Skip to content

Commit 150527f

Browse files
committed
fix: Make quoting consider sort polymorphic types
This is a hacky fix that removes the commands from the inductive and instead declares tmQuote as an axiom, just to avoid having to update the complete inductive type to be sort polymorphic.
1 parent 7b09130 commit 150527f

File tree

3 files changed

+34
-7
lines changed

3 files changed

+34
-7
lines changed

template-rocq/theories/TemplateMonad/Core.v

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,6 @@ Cumulative Inductive TemplateMonad@{t u} : Type@{t} -> Prop :=
4646
| tmCurrentModPath : unit -> TemplateMonad modpath
4747

4848
(* Quoting and unquoting commands *)
49-
(* Similar to MetaRocq Quote Definition ... := ... *)
50-
| tmQuote : forall {A:Type@{t}}, A -> TemplateMonad Ast.term
51-
(* Similar to MetaRocq Quote Recursively Definition but takes a boolean "bypass opacity" flag.
52-
([true] - quote bodies of all dependencies (transparent and opaque);
53-
[false] -quote bodies of transparent definitions only) *)
54-
| tmQuoteRecTransp : forall {A:Type@{t}}, A -> bool(* bypass opacity? *) -> TemplateMonad program
5549
(* Quote the body of a definition or inductive. Its name need not be fully qualified *)
5650
| tmQuoteInductive : kername -> TemplateMonad mutual_inductive_body
5751
| tmQuoteUniverses : TemplateMonad ConstraintSet.t
@@ -70,6 +64,20 @@ Cumulative Inductive TemplateMonad@{t u} : Type@{t} -> Prop :=
7064
| tmInferInstance : option reductionStrategy -> forall A : Type@{t}, TemplateMonad (option_instance A)
7165
.
7266

67+
(* Moving outside of the inductive definition only to make it sort polymorphic but
68+
avoid having to update all of the TemplateMonad definition to be sort poylmorphic *)
69+
(* Similar to MetaRocq Quote Definition ... := ... *)
70+
Polymorphic Axiom tmQuote@{s; t u}
71+
: forall {A : Type@{s;t}}, A -> TemplateMonad@{t u} Ast.term.
72+
73+
(* Moving outside of the inductive definition only to make it sort polymorphic but
74+
avoid having to update all of the TemplateMonad definition to be sort poylmorphic *)
75+
(* Similar to MetaRocq Quote Recursively Definition but takes a boolean "bypass opacity" flag.
76+
([true] - quote bodies of all dependencies (transparent and opaque);
77+
[false] -quote bodies of transparent definitions only) *)
78+
Polymorphic Axiom tmQuoteRecTransp@{s; t u}
79+
: forall {A : Type@{s;t}}, A -> bool(* bypass opacity? *) -> TemplateMonad@{t u} program.
80+
7381
(** This version of [tmBind] flattens nesting structure; using it in deeply recursive template programs can speed things up drastically *)
7482
(** We use [tmBind] in the recursive position to avoid quadratic blowup in the number of [tmOptimizedBind]s *)
7583
Fixpoint tmOptimizedBind@{t u} {A B : Type@{t}} (v : TemplateMonad@{t u} A) : (A -> TemplateMonad@{t u} B) -> TemplateMonad@{t u} B

test-suite/_RocqProject.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ order_rec.v
4141
# primitive.v
4242
proj.v
4343
quotation_notations.v
44+
quote_global_sort.v
4445
reduction_test.v
4546
run_in_tactic.v
4647
safechecker_test.v
@@ -56,4 +57,3 @@ unfold.v
5657
univ.v
5758
vs.v
5859
ind_fresh_univ.v
59-

test-suite/quote_global_sort.v

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
From MetaRocq.Utils Require Import utils.
2+
From MetaRocq.Template Require Import All.
3+
Import MRMonadNotation.
4+
5+
Set Universe Polymorphism.
6+
#[universes(polymorphic=no)]
7+
Sort Exc.
8+
9+
MetaRocq Run (tmQuote Type@{Exc;Set} >>= tmPrint).
10+
11+
Axiom ax_raise@{u} : forall (A : Type@{Exc;u}), A.
12+
13+
MetaRocq Run (tmQuote ax_raise >>= tmPrint).
14+
15+
(* This one requires -allow-rewrite-rules enabled
16+
Symbol raise@{u} : forall (A : Type@{Exc;u}), A.
17+
18+
MetaRocq Run (tmQuote raise >>= tmPrint).
19+
*)

0 commit comments

Comments
 (0)