Debian Codegraph @

tests/test_API_elaborate.v

raw
1 From elpi Require Import elpi.
2
3 Elpi Command elaborate.
4
5 (****** elaborate *******************************)
6 Axiom T1 : Type.
7 Axiom T2 : nat -> Type.
8 Axiom T3 : nat -> Type.
9
10 Axiom f1 : T1 -> Type.
11 Axiom f3 : forall b, T3 b -> Type.
12
13 Axiom g1 : T1 -> nat -> nat.
14 Axiom g3 : forall b, T3 b -> nat -> nat.
15
16 Axiom h : forall n , T2 n -> T3 n.
17
18 Coercion f1 : T1 >-> Sortclass.
19 Coercion f3 : T3 >-> Sortclass.
20 Coercion g1 : T1 >-> Funclass.
21 Coercion g3 : T3 >-> Funclass.
22 Coercion h : T2 >-> T3.
23
24 Elpi Query lp:{{
25
26 std.assert-ok! (coq.elaborate-skeleton {{ fun n (t : T2 n) (x : t) => t 3 }} TY E) "that was easy",
27 coq.env.add-const "elab_1" E TY tt _
28
29 }}.
30
31 Class foo (n : nat).
32 Definition bar n {f : foo n} := n = n.
33 #[local] Instance xxx : foo 3. Defined.
34
35 Elpi Query lp:{{
36
37 std.assert-ok! (coq.elaborate-ty-skeleton {{ bar _ }} TY E) "that was easy",
38 coq.env.add-const "elab_2" E (sort TY) tt _
39
40 }}.
41
42 Structure s := { field : Type; #[canonical=no] op : field -> field; }.
43 Canonical c := {| field := nat; op := (fun x => x) |}.
44
45 Elpi Query lp:{{
46
47 std.assert-ok! (coq.elaborate-skeleton {{ op _ 3 }} TY E) "that was easy",
48 coq.env.add-const "elab_3" E TY tt _
49
50 }}.
51
52 (* #[arguments(raw)] *)
53 Elpi Command test.API2.
54
55 Elpi Accumulate lp:{{
56 main [indt-decl D] :- coq.say "raw:" D,
57 std.assert-ok! (coq.elaborate-indt-decl-skeleton D D1) "illtyped",
58 coq.say "elab1:" D1,
59 coq.env.add-indt D1 I,
60 coq.env.indt-decl I D2,
61 coq.say "elab2:" D2.
62 main [const-decl N (some BO) TYA] :- std.do! [
63 coq.arity->term TYA TY,
64 std.assert-ok! (coq.elaborate-ty-skeleton TY _ TY1) "illtyped",
65 std.assert-ok! (coq.elaborate-skeleton BO TY1 BO1) "illtyped",
66 coq.env.add-const N BO1 TY1 @transparent! _,
67 ].
68 }}.
69
70
71 Elpi test.API2 Inductive ind1 (A : T1) | (B : Type) :=
72 K1 : ind1 B -> ind1 B | K2 : A -> ind1 B | K3 (a : A) : ind1 B.
73
74 (*
75
76 parameter A explicit (global (const «T1»)) c0 \
77 inductive ind1 tt
78 (parameter B explicit (sort (typ X0)) c1 \ arity (sort (typ X1))) c1 \
79 [constructor K1
80 (parameter B explicit (sort (typ X2)) c2 \
81 arity (prod `_` (app [c1, c2]) c3 \ app [c1, c2])),
82 constructor K2
83 (parameter B explicit (sort (typ X3)) c2 \
84 arity (prod `_` c0 c3 \ app [c1, c2])),
85 constructor K3
86 (parameter B explicit (sort (typ X4)) c2 \
87 arity (prod `a` c0 c3 \ app [c1, c2]))]
88 0 out of (_ : _UNBOUND_REL_3 _UNBOUND_REL_2 _UNBOUND_REL_1)
89 0 out of (_ : _UNBOUND_REL_2)
90 0 out of (_ : _UNBOUND_REL_2)
91 (A : T1) (B : Type) |- Type
92 |- (_UNBOUND_REL_3 _UNBOUND_REL_2 _UNBOUND_REL_1 ->
93 _UNBOUND_REL_4 _UNBOUND_REL_3 _UNBOUND_REL_2)
94 |- (_UNBOUND_REL_2 -> _UNBOUND_REL_4 _UNBOUND_REL_3 _UNBOUND_REL_2)
95 |- (_UNBOUND_REL_2 -> _UNBOUND_REL_4 _UNBOUND_REL_3 _UNBOUND_REL_2)
96 all params = 2, uniform params = 2
97 parameter A explicit (global (const «T1»)) c0 \
98 parameter B explicit (sort (typ «test_API.23)»)) c1 \
99 inductive ind1 tt (arity (sort (typ «test_API.25)»))) c2 \
100 [constructor K1 (arity (prod `_` c2 c3 \ c2)),
101 constructor K2
102 (arity (prod `_` (app [global (const «f1»), c0]) c3 \ c2)),
103 constructor K3
104 (arity (prod `_` (app [global (const «f1»), c0]) c3 \ c2))]
105
106
107
108 elab
109
110 (A : T1) (B : Type) |- Type
111 (_ : _UNBOUND_REL_3 _UNBOUND_REL_2 _UNBOUND_REL_1) |- (_UNBOUND_REL_4 _UNBOUND_REL_3 _UNBOUND_REL_2)
112 (_ : _UNBOUND_REL_2) |- (_UNBOUND_REL_4 _UNBOUND_REL_3 _UNBOUND_REL_2)
113 (a : _UNBOUND_REL_2) |- (_UNBOUND_REL_4 _UNBOUND_REL_3 _UNBOUND_REL_2)
114 all params = 2, uniform params = 1
115 parameter A explicit (global (const «T1»)) c0 \
116 inductive ind1 tt
117 (parameter B explicit (sort (typ «test_API.20)»)) c1 \
118 arity (sort (typ «test_API.4))»))) c1 \
119 [constructor K1
120 (parameter _ explicit (app [,, c0, c1]) c2 \
121 arity (app [c2, (fun `_` (sort prop) c3 \ c1), c0])),
122 constructor K2
123 (parameter _ explicit (app [global (const «f1»), c0]) c2 \
124 arity (app [c2, (fun `_` (sort prop) c3 \ c1), c0])),
125 constructor K3
126 (parameter a explicit (app [global (const «f1»), c0]) c2 \
127 arity (app [c2, (fun `_` (sort prop) c3 \ c1), c0]))]
128 File "./tests/test_API.v", line 123, characters 0-120:
129 Error:
130 wrong constant:,
131
132 *)
133
134 Elpi test.API2 Record ind2 (A : T1) := {
135 fld1 : A;
136 fld2 : fld1 = fld1;
137 }.
138
139 Elpi test.API2 Record ind3 := {
140 fld3 :> Type;
141 fld4 : forall x : fld3, x = x;
142 }.
143
144 Check (forall x : ind3, x -> Prop).
145
146 Elpi test.API2 Definition def1 A := fun x : A => x.
147
148 Elpi Query lp:{{
149
150 std.assert-ok! (coq.elaborate-skeleton {{ op lib:elpi.hole 3 }} TY E) "that was easy 2",
151 coq.env.add-const "elab_4" E TY tt _
152
153 }}.
154
155 Elpi Tactic test.
156 Elpi Accumulate lp:{{
157 solve _ _ :-
158 coq.term->string X S,
159 X = global (indc Y),
160 coq.say S.
161 }}.
162 Goal True.
163 Fail elpi test.
164 Abort.
165
166 Elpi Tactic test2.
167 Elpi Accumulate lp:{{
168 solve _ _ :-
169 coq.term->string (global (indc Y)) S,
170 coq.say S.
171 }}.
172 Goal True.
173 elpi test2.
174 Abort.
175
176 #[arguments(raw)] Elpi Command detype.
177 Elpi Accumulate lp:{{
178 main [upoly-const-decl _ _ (parameter _ _ (sort (typ U)) _ as A) (upoly-decl [UL] _ _ _)] :-
179 std.assert! (coq.univ.variable U UL) "wtf",
180 (@keepunivs! => std.assert-ok! (coq.elaborate-arity-skeleton A _ (parameter _ _ (sort (typ V)) _)) "wtf"),
181 std.assert! (U = V) "elaboration refreshes",
182 coq.say U V.
183 }}.
184
185
186 Elpi detype #[universes(polymorphic)] Definition f@{u|Set < u} (x : Type@{u}) := x.
187