-
Notifications
You must be signed in to change notification settings - Fork 70
Expand file tree
/
Copy pathrocq_elpi_HOAS.ml
More file actions
4120 lines (3666 loc) · 169 KB
/
rocq_elpi_HOAS.ml
File metadata and controls
4120 lines (3666 loc) · 169 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
(* rocq-elpi: Coq terms as the object language of elpi *)
(* license: GNU Lesser General Public License Version 2.1 or later *)
(* ------------------------------------------------------------------------- *)
module API = Elpi.API
module E = API.RawData
module CD = API.RawOpaqueData
module U = API.Utils
module P = API.RawPp
module S = API.State
module F = API.FlexibleData
module A = API.Ast.Term
module C = Constr
module EC = EConstr
open Names
module G = GlobRef
open Rocq_elpi_utils
(* ************************************************************************ *)
(* ****************** HOAS of Coq terms and goals ************************* *)
(* See also coq-HOAS.elpi (terms) *)
(* ************************************************************************ *)
(* {{{ CData ************************************************************** *)
(* names *)
let namein, naminc, isname, nameout, name =
let { CD.cin; cino; isc; cout }, name = CD.declare {
CD.name = "name";
doc = "Name.Name.t: Name hints (in binders), can be input writing a name between backticks, e.g. `x` or `_` for anonymous. Important: these are just printing hints with no meaning, hence in elpi two name are always related: `x` = `y`";
pp = (fun fmt x ->
Format.fprintf fmt "`%a`" Pp.pp_with (Name.print x));
compare = (fun _ _ -> 0);
hash = (fun _ -> 0);
hconsed = false;
constants = [];
} in
cin, cino, isc, cout, name
;;
let in_elpi_name x = namein x
let in_elpiast_name ~loc x = A.mkOpaque ~loc @@ naminc x
let coq_language = ref API.Quotation.elpi_language
let set_coq coq = coq_language := coq
let name_of_name ~loc = function
| Names.Name.Anonymous -> None
| Names.Name.Name id -> Some (API.Ast.Name.from_string @@ Names.Id.to_string id, loc, !coq_language)
let is_coq_name ~depth t =
match E.look ~depth t with
| E.CData n -> isname n || (CD.is_string n && Id.is_valid (CD.to_string n))
| _ -> false
let in_coq_name ~depth t =
match E.look ~depth t with
| E.CData n when isname n -> nameout n
| E.CData n when CD.is_string n ->
let s = CD.to_string n in
if s = "_" then Name.Anonymous
else Name.Name (Id.of_string s)
| E.UnifVar _ -> Name.Anonymous
| _ -> err Pp.(str"Not a name: " ++ str (API.RawPp.Debug.show_term t))
(* engine prologue, to break ciclicity *)
type coq_engine = {
global_env : Environ.env;
sigma : Evd.evar_map; (* includes universe constraints *)
}
let pre_engine : coq_engine S.component option ref = ref None
(* universes *)
module UnivOrd = struct
type t = Univ.Universe.t
let compare = Univ.Universe.compare
let show x = Pp.string_of_ppcmds (Univ.Universe.pr UnivNames.pr_level_with_global_universes x)
let pp fmt x = Format.fprintf fmt "%s" (show x)
end
module UnivSet = U.Set.Make(UnivOrd)
module UnivMap = U.Map.Make(UnivOrd)
module UnivLevelOrd = struct
type t = Univ.Level.t
let compare = Univ.Level.compare
let show x = Pp.string_of_ppcmds (UnivNames.pr_level_with_global_universes x)
let pp fmt x = Format.fprintf fmt "%s" (show x)
end
module UnivLevelSet = U.Set.Make(UnivLevelOrd)
module UnivLevelMap = U.Map.Make(UnivLevelOrd)
(* map from Elpi evars and Coq's universe levels *)
module UM = F.Map(struct
type t = Univ.Universe.t
let compare = Univ.Universe.compare
let show x = Pp.string_of_ppcmds @@ Univ.Universe.pr UnivNames.pr_level_with_global_universes x
let pp fmt x = Format.fprintf fmt "%a" Pp.pp_with (Univ.Universe.pr UnivNames.pr_level_with_global_universes x)
end)
let um = S.declare_component ~name:"rocq-elpi:evar-univ-map" ~descriptor:interp_state
~pp:UM.pp ~init:(fun () -> UM.empty) ~start:(fun x -> x) ()
let constraint_leq u1 u2 =
let open UnivProblem in
ULe (u1, u2)
let constraint_eq u1 u2 =
let open UnivProblem in
ULe (u1, u2)
[%%if coq = "9.0" || coq = "9.1"]
let add_constraints state c = S.update (Option.get !pre_engine) state (fun ({ sigma } as x) ->
{ x with sigma = Evd.add_universe_constraints sigma c })
[%%else]
let add_constraints state c = S.update (Option.get !pre_engine) state (fun ({ sigma } as x) ->
{ x with sigma = Evd.add_constraints sigma c })
[%%endif]
[%%if coq = "9.0" || coq = "9.1"]
let add_universe_constraint state c =
let open UnivProblem in
try add_constraints state (Set.singleton c)
with
| UGraph.UniverseInconsistency p ->
let sigma = (S.get (Option.get !pre_engine) state).sigma in
Feedback.msg_debug
(UGraph.explain_universe_inconsistency
(Termops.pr_evd_qvar sigma)
(Termops.pr_evd_level sigma)
p);
raise API.BuiltInPredicate.No_clause
| Evd.UniversesDiffer | UState.UniversesDiffer ->
Feedback.msg_debug Pp.(str"UniversesDiffer");
raise API.BuiltInPredicate.No_clause
[%%elif coq = "9.2"]
let add_universe_constraint state c =
let open UnivProblem in
try add_constraints state (Set.singleton c)
with
| QGraph.(EliminationError (QualityInconsistency (Some printer, (k, q, q', e)))) ->
Feedback.msg_debug
(QGraph.explain_quality_inconsistency printer e);
raise API.BuiltInPredicate.No_clause
| UGraph.UniverseInconsistency p ->
let sigma = (S.get (Option.get !pre_engine) state).sigma in
Feedback.msg_debug
(UGraph.explain_universe_inconsistency
(Termops.pr_evd_qvar sigma)
(Termops.pr_evd_level sigma)
p);
raise API.BuiltInPredicate.No_clause
| Evd.UniversesDiffer | UState.UniversesDiffer ->
Feedback.msg_debug Pp.(str"UniversesDiffer");
raise API.BuiltInPredicate.No_clause
[%%else]
let add_universe_constraint state c =
let open UnivProblem in
try add_constraints state (Set.singleton c)
with
| QGraph.(EliminationError (QualityInconsistency (Some printer, (k, q, q', e)))) ->
Feedback.msg_debug
(QGraph.explain_quality_inconsistency printer e);
raise API.BuiltInPredicate.No_clause
| UGraph.UniverseInconsistency p ->
let sigma = (S.get (Option.get !pre_engine) state).sigma in
Feedback.msg_debug
(UGraph.explain_universe_inconsistency
(Evd.sort_printer sigma)
p);
raise API.BuiltInPredicate.No_clause
| Evd.UniversesDiffer | UState.UniversesDiffer ->
Feedback.msg_debug Pp.(str"UniversesDiffer");
raise API.BuiltInPredicate.No_clause
[%%endif]
let new_univ_level_variable ?(flexible=false) state =
S.update_return (Option.get !pre_engine) state (fun ({ sigma } as e) ->
(* ~name: really mean the universe level is a binder as in Definition f@{x} *)
let rigidity = if flexible then UState.univ_flexible_alg else UState.univ_rigid in
let sigma, v = Evd.new_univ_level_variable ?name:None rigidity sigma in
let u = Univ.Universe.make v in
(*
let sigma = Evd.add_universe_constraints sigma
(UnivProblem.Set.singleton (UnivProblem.ULe (Sorts.set,Sorts.sort_of_univ u))) in
*)
{ e with sigma }, (v, u))
(* We patch data_of_cdata by forcing all output universes that
* are unification variables to be a Coq universe variable, so that
* we can always call Coq's API *)
let isuniv, univout, univino, (univ : Univ.Universe.t API.Conversion.t) =
let { CD.cin = univin; cino = univino; isc = isuniv; cout = univout }, univ_to_be_patched = CD.declare {
CD.name = "univ";
doc = "universe level (algebraic: max, +1, univ.variable)";
pp = (fun fmt x ->
let s = Pp.string_of_ppcmds (Univ.Universe.pr UnivNames.pr_level_with_global_universes x) in
Format.fprintf fmt "«%s»" s);
compare = Univ.Universe.compare;
hash = Univ.Universe.hash;
hconsed = false;
constants = [];
} in
(* turn UVars into fresh universes *)
isuniv, univout, univino, { univ_to_be_patched with
API.Conversion.readback = begin fun ~depth state t ->
match E.look ~depth t with
| E.UnifVar (b,args) ->
let m = S.get um state in
begin try
let u = UM.host b m in
state, u, []
with Not_found ->
(* flexible makes {{ Type }} = {{ Set }} also true when coq.unify-eq {{ Type }} {{ Set }} *)
let state, (_,u) = new_univ_level_variable ~flexible:true state in
let state = S.update um state (UM.add b u) in
state, u, [ API.Conversion.Unify(E.mkUnifVar b ~args state,univin u) ]
end
| _ -> univ_to_be_patched.API.Conversion.readback ~depth state t
end
}
let universe_level_variable =
let { CD.cin = levelin }, universe_level_variable_to_patch = CD.declare {
CD.name = "univ.variable";
doc = "universe level variable";
pp = (fun fmt x ->
let s = Pp.string_of_ppcmds (UnivNames.pr_level_with_global_universes x) in
Format.fprintf fmt "«%s»" s);
compare = Univ.Level.compare;
hash = Univ.Level.hash;
hconsed = false;
constants = [];
} in
{ universe_level_variable_to_patch with
API.Conversion.readback = begin fun ~depth state t ->
match E.look ~depth t with
| E.UnifVar (b,args) ->
let m = S.get um state in
begin try
let u = UM.host b m in
state, Option.get @@ Univ.Universe.level u, []
with Not_found ->
let state, (l,u) = new_univ_level_variable state in
let state = S.update um state (UM.add b u) in
state, l, [ API.Conversion.Unify(E.mkUnifVar b ~args state,levelin l) ]
end
| _ -> universe_level_variable_to_patch.API.Conversion.readback ~depth state t
end
}
[%%if coq = "9.0" || coq = "9.1"]
type univ_cst = Univ.univ_constraint
type univ_csts = Univ.Constraints.t
let univ_lt = Univ.Lt
let univ_le = Univ.Le
let univ_eq = Univ.Eq
let univ_csts_of_list = Univ.Constraints.of_list
let univ_csts_to_list = Univ.Constraints.elements
let evd_merge_ctx_set rigid = Evd.merge_sort_context_set rigid
let subst_univs_constraints = Univ.subst_univs_level_constraints
let univs_of_csts = UVars.UContext.constraints
let mk_universe_decl univdecl_extensible_instance univdecl_extensible_constraints univdecl_constraints univdecl_instance =
let open UState in
{ univdecl_qualities = [];
univdecl_extensible_instance;
univdecl_extensible_qualities = false;
univdecl_extensible_constraints;
univdecl_constraints;
univdecl_instance}
let default_univ_decl = UState.default_univ_decl
let dest_udecl ({ UState.univdecl_instance ; univdecl_constraints } : UState.universe_decl) =
univdecl_instance, univdecl_constraints
let universe_constraint : univ_cst API.Conversion.t =
let open API.Conversion in let open API.AlgebraicData in declare {
ty = TyName "univ-constraint";
doc = "Constraint between two universes level variables";
pp = (fun fmt _ -> Format.fprintf fmt "<todo>");
constructors = [
K("lt","",A(universe_level_variable,A(universe_level_variable,N)),
B (fun u1 u2 -> (u1,univ_lt,u2)),
M (fun ~ok ~ko -> function (l1,Univ.Lt,l2) -> ok l1 l2 | _ -> ko ()));
K("le","",A(universe_level_variable,A(universe_level_variable,N)),
B (fun u1 u2 -> (u1,univ_le,u2)),
M (fun ~ok ~ko -> function (l1,Univ.Le,l2) -> ok l1 l2 | _ -> ko ()));
K("eq","",A(universe_level_variable,A(universe_level_variable,N)),
B (fun u1 u2 -> (u1,univ_eq,u2)),
M (fun ~ok ~ko -> function (l1,Univ.Eq,l2) -> ok l1 l2 | _ -> ko ()))
]
} |> API.ContextualConversion.(!<)
[%%else]
type univ_cst = Univ.UnivConstraint.t
type univ_csts = Univ.UnivConstraints.t
let univ_lt = Univ.UnivConstraint.Lt
let univ_le = Univ.UnivConstraint.Le
let univ_eq = Univ.UnivConstraint.Eq
let univ_csts_of_list = Univ.UnivConstraints.of_list
let univ_csts_to_list = Univ.UnivConstraints.elements
let evd_merge_ctx_set rigid = Evd.merge_sort_context_set rigid
let subst_univs_constraints x = UVars.subst_univs_constraints x
let univs_of_csts x = PConstraints.univs @@ UVars.UContext.constraints x
let mk_universe_decl univdecl_extensible_instance univdecl_extensible_constraints univdecl_univ_constraints univdecl_instance =
let open UState in
{ univdecl_qualities = [];
univdecl_extensible_instance;
univdecl_elim_constraints = Sorts.ElimConstraints.empty;
univdecl_extensible_qualities = false;
univdecl_extensible_constraints;
univdecl_univ_constraints;
univdecl_instance}
let default_univ_decl = UState.default_univ_decl
let dest_udecl ({ UState.univdecl_instance ; univdecl_univ_constraints } : UState.universe_decl) =
univdecl_instance, univdecl_univ_constraints
let universe_constraint : univ_cst API.Conversion.t =
let open API.Conversion in let open API.AlgebraicData in declare {
ty = TyName "univ-constraint";
doc = "Constraint between two universes level variables";
pp = (fun fmt _ -> Format.fprintf fmt "<todo>");
constructors = [
K("lt","",A(universe_level_variable,A(universe_level_variable,N)),
B (fun u1 u2 -> (u1,univ_lt,u2)),
M (fun ~ok ~ko -> function (l1,Univ.UnivConstraint.Lt,l2) -> ok l1 l2 | _ -> ko ()));
K("le","",A(universe_level_variable,A(universe_level_variable,N)),
B (fun u1 u2 -> (u1,univ_le,u2)),
M (fun ~ok ~ko -> function (l1,Univ.UnivConstraint.Le,l2) -> ok l1 l2 | _ -> ko ()));
K("eq","",A(universe_level_variable,A(universe_level_variable,N)),
B (fun u1 u2 -> (u1,univ_eq,u2)),
M (fun ~ok ~ko -> function (l1,Univ.UnivConstraint.Eq,l2) -> ok l1 l2 | _ -> ko ()))
]
} |> API.ContextualConversion.(!<)
[%%endif]
let universe_variance : (Univ.Level.t * UVars.Variance.t option) API.Conversion.t =
let open API.Conversion in let open API.AlgebraicData in declare {
ty = TyName "univ-variance";
doc = "Variance of a universe level variable";
pp = (fun fmt _ -> Format.fprintf fmt "<todo>");
constructors = [
K("auto","",A(universe_level_variable,N),
B (fun u -> u,None),
M (fun ~ok ~ko -> function (u,None) -> ok u | _ -> ko ()));
K("covariant","",A(universe_level_variable,N),
B (fun u -> u,Some UVars.Variance.Covariant),
M (fun ~ok ~ko -> function (u,Some UVars.Variance.Covariant) -> ok u | _ -> ko ()));
K("invariant","",A(universe_level_variable,N),
B (fun u -> u,Some UVars.Variance.Invariant),
M (fun ~ok ~ko -> function (u,Some UVars.Variance.Invariant) -> ok u | _ -> ko ()));
K("irrelevant","",A(universe_level_variable,N),
B (fun u -> u,Some UVars.Variance.Invariant),
M (fun ~ok ~ko -> function (u,Some UVars.Variance.Irrelevant) -> ok u | _ -> ko ()));
]
} |> API.ContextualConversion.(!<)
type universe_decl = (Univ.Level.t list * bool) * (univ_csts * bool)
type universe_decl_cumul = ((Univ.Level.t * UVars.Variance.t option) list * bool) * (univ_csts * bool)
type any_universe_decl =
| NonCumul of universe_decl
| Cumul of universe_decl_cumul
let universe_decl : any_universe_decl API.Conversion.t =
let open API.Conversion in let open API.BuiltInData in let open API.AlgebraicData in let open Elpi.Builtin in declare {
ty = TyName "upoly-decl";
doc = "Constraints for a non-cumulative declaration. Boolean tt means loose (e.g. the '+' in f@{u v + | u < v +})";
pp = (fun fmt _ -> Format.fprintf fmt "<todo>");
constructors = [
K("upoly-decl","",A(list universe_level_variable,A(bool,A(list universe_constraint,A(bool,N)))),
B (fun x sx y sy-> NonCumul ((x,sx),(univ_csts_of_list y,sy))),
M (fun ~ok ~ko -> function NonCumul ((x,sx),(y,sy)) -> ok x sx (univ_csts_to_list y) sy | Cumul _ -> ko ()));
K("upoly-decl-cumul","",A(list universe_variance,A(bool,A(list universe_constraint,A(bool,N)))),
B (fun x sx y sy -> Cumul ((x,sx),(univ_csts_of_list y,sy))),
M (fun ~ok ~ko -> function Cumul ((x,sx),(y,sy)) -> ok x sx (univ_csts_to_list y) sy | NonCumul _ -> ko ()))
]
} |> API.ContextualConversion.(!<)
(* All in one data structure to represent the Coq context and its link with
the elpi one:
- section is not part of the elpi context, but Coq's evars are applied
also to that part
- proof is the named_context with proof variables only (no section part)
- local is the rel_context
- db2rel stores how many locally bound (rel) variables were there when
the binder for the given dbl is crossed: see lp2term
- env is a Coq environment corresponding to section + proof + local *)
type empty = [ `Options ]
type full = [ `Options | `Context ]
(* Readback of UVars into ... *)
type ppoption = All | Most | Normal
type hole_mapping =
| Verbatim (* 1:1 correspondence between UVar and Evar *)
| Heuristic (* new UVar outside Llam is pruned before being linked to Evar *)
| Implicit (* No link, UVar is intepreted as a "hole" constant *)
type uinstanceoption =
| NoInstance
(* the elpi command involved has to generate a fresh instance *)
| ConcreteInstance of UVars.Instance.t
(* a concrete instance was provided, the command will use it *)
| VarInstance of (F.Elpi.t * E.term list * inv_rel_key)
(* a variable was provided, the command will compute the instance to unify with it *)
type universe_decl_option =
| NotUniversePolymorphic
| Cumulative of universe_decl_cumul
| NonCumulative of universe_decl
type options = {
hoas_holes : hole_mapping option;
local : bool option;
user_warns : UserWarn.t option;
primitive : bool option;
failsafe : bool; (* readback is resilient to illformed terms *)
ppwidth : int;
pp : ppoption;
pplevel : Constrexpr.entry_relative_level;
using : string option;
inline : Declaremods.inline;
uinstance : uinstanceoption;
universe_decl : universe_decl_option;
reversible : bool option;
keepunivs : bool option;
redflags : RedFlags.reds option;
no_tc: bool option;
algunivs : bool option;
}
let default_options () = {
hoas_holes = Some Verbatim;
local = None;
user_warns = None;
primitive = None;
failsafe = false;
ppwidth = Option.default 80 (Topfmt.get_margin ());
pp = Normal;
pplevel = Constrexpr.LevelSome;
using = None;
inline = Declaremods.NoInline;
uinstance = NoInstance;
universe_decl = NotUniversePolymorphic;
reversible = None;
keepunivs = None;
redflags = None;
no_tc = None;
algunivs = None;
}
let make_options ~hoas_holes ~local ~warn ~depr ~primitive ~failsafe ~ppwidth
~pp ~pplevel ~using ~inline ~uinstance ~universe_decl ~reversible ~keepunivs
~redflags ~no_tc ~algunivs =
let user_warns = Some UserWarn.{ depr; warn } in
{ hoas_holes; local; user_warns; primitive; failsafe; ppwidth; pp;
pplevel; using; inline; uinstance; universe_decl; reversible; keepunivs;
redflags; no_tc; algunivs; }
let make_warn = UserWarn.make_warn
type 'a conv_context = {
section : Names.Id.t list;
section_len : int;
proof : EConstr.named_context;
proof_len : int;
local : (int * EConstr.rel_declaration) list;
local_len : int;
env : Environ.env;
db2name : Names.Id.t Int.Map.t;
name2db : int Names.Id.Map.t;
db2rel : int Int.Map.t;
names : Id.Set.t;
options : options;
hyps : E.hyp list;
}
let upcast (x : [> `Options ] conv_context) : full conv_context = (x :> full conv_context)
let pr_coq_ctx { env; db2name; db2rel } sigma =
let open Pp in
v 0 (
str "Mapping from DBL:"++ cut () ++ str " " ++
v 0 (prlist_with_sep cut (fun (i,n) -> str(E.Constants.show i) ++ str " |-> " ++ Id.print n)
(Int.Map.bindings db2name)) ++ cut () ++
v 0 (prlist_with_sep cut (fun (i,n) -> str(E.Constants.show i) ++ str " |-> " ++ int n)
(Int.Map.bindings db2rel)) ++ cut () ++
str "Named:" ++ cut () ++ str " " ++
v 0 (Printer.pr_named_context_of env sigma) ++ cut () ++
str "Rel:" ++ cut () ++ str " " ++
v 0 (Printer.pr_rel_context_of env sigma) ++ cut ()
)
let propc = E.Constants.declare_global_symbol "prop"
let spropc = E.Constants.declare_global_symbol "sprop"
let typc = E.Constants.declare_global_symbol "typ"
[%%if coq = "9.0" || coq = "9.1" || coq = "9.2"]
let ppsort fmt = function
| Sorts.Type _ -> Format.fprintf fmt "Type"
| Sorts.Set -> Format.fprintf fmt "Set"
| Sorts.Prop -> Format.fprintf fmt "Prop"
| Sorts.SProp -> Format.fprintf fmt "SProp"
| Sorts.QSort _ -> Format.fprintf fmt "QSort"
[%%else]
let ppsort fmt = function
| Sorts.Type _ -> Format.fprintf fmt "Type"
| Sorts.Set -> Format.fprintf fmt "Set"
| Sorts.Prop -> Format.fprintf fmt "Prop"
| Sorts.SProp -> Format.fprintf fmt "SProp"
| Sorts.GSort _ -> Format.fprintf fmt "GSort"
| Sorts.VSort _ -> Format.fprintf fmt "VSort"
[%%endif]
let sort : (Sorts.t, _ conv_context, API.Data.constraints) API.ContextualConversion.t =
let open API.ContextualConversion in
{
ty = API.Conversion.TyName "sort";
pp_doc = (fun fmt () ->
Format.fprintf fmt "%% Sorts (kinds of types)\n";
Format.fprintf fmt "kind sort type.\n";
Format.fprintf fmt "external symbol prop : sort. %% impredicative sort of propositions\n";
Format.fprintf fmt "external symbol sprop : sort. %% impredicative sort of propositions with definitional proof irrelevance\n";
Format.fprintf fmt "external symbol typ : univ -> sort. %% predicative sort of data (carries a universe level)\n";
);
pp = ppsort;
embed = (fun ~depth { options } _ state s ->
match s with
| Sorts.Prop -> state, E.mkConst propc, []
| Sorts.SProp -> state, E.mkConst spropc, []
| Sorts.Set ->
let state, u, gls = univ.embed ~depth state Univ.Universe.type0 in
state, E.mkApp typc u [], gls
| Sorts.Type u ->
let state, u, gls = univ.embed ~depth state u in
state, E.mkApp typc u [], gls
| _ -> nYI "sort polymorphism");
readback = (fun ~depth { options } _ state t ->
match E.look ~depth t with
| E.Const c when c == propc -> state, Sorts.prop, []
| E.Const c when c == spropc -> state, Sorts.sprop, []
| E.App(c,u,[]) when c == typc ->
let state, u, gls = univ.readback ~depth state u in
state, Sorts.sort_of_univ u ,gls
| E.UnifVar(k,_) -> begin
let m = S.get um state in
try
let u = UM.host k m in
state, Sorts.sort_of_univ u, []
with Not_found ->
let state, (_,u) = new_univ_level_variable state in
let state = S.update um state (UM.add k u) in
state, Sorts.sort_of_univ u, []
end
| _ -> raise API.Conversion.(TypeErr(TyName"sort",depth,t)));
}
let ast_sort ~loc = function
| Sorts.Prop -> A.mkGlobal ~loc propc
| Sorts.SProp -> A.mkGlobal ~loc spropc
| Sorts.Set -> A.mkAppGlobal ~loc ~hdloc:loc typc (A.mkOpaque ~loc @@ univino Univ.Universe.type0) []
| Sorts.Type u -> A.mkAppGlobal ~loc ~hdloc:loc typc (A.mkOpaque ~loc @@ univino u) []
| _ -> assert false
let in_coq_fresh ~id_only =
let mk_fresh dbl =
Id.of_string_soft
(Printf.sprintf "elpi_ctx_entry_%d_" dbl) in
fun ~depth dbl name ~names ->
match in_coq_name ~depth name with
| Name.Anonymous when id_only -> Name.Name (mk_fresh dbl)
| Name.Anonymous as x -> x
| Name.Name id when Id.Set.mem id names -> Name.Name (mk_fresh dbl)
| Name.Name id as x -> x
let relevant = EConstr.ERelevance.relevant
let anonR = Context.make_annot Names.Name.Anonymous EConstr.ERelevance.irrelevant
let nameR x = Context.make_annot (Names.Name.Name x) EConstr.ERelevance.irrelevant
let annotR x = Context.make_annot x EConstr.ERelevance.irrelevant
let in_coq_annot ~depth t = Context.make_annot (in_coq_name ~depth t) relevant
let in_coq_fresh_annot_name ~depth ~coq_ctx dbl t =
Context.make_annot (in_coq_fresh ~id_only:false ~depth ~names:coq_ctx.names dbl t) relevant
let in_coq_fresh_annot_id ~depth ~names dbl t =
let get_name = function Name.Name x -> x | Name.Anonymous -> assert false in
Context.make_annot (in_coq_fresh ~id_only:true ~depth ~names dbl t |> get_name) relevant
let unspec2opt = function Elpi.Builtin.Given x -> Some x | Elpi.Builtin.Unspec -> None
let opt2unspec = function Some x -> Elpi.Builtin.Given x | None -> Elpi.Builtin.Unspec
(* constants *)
type global_constant = Variable of Names.Id.t | Constant of Names.Constant.t
let hash_global_constant = function
| Variable id -> Names.Id.hash id
| Constant c -> Names.Constant.CanOrd.hash c
let compare_global_constant x y = match x,y with
| Variable v1, Variable v2 -> Names.Id.compare v1 v2
| Constant c1, Constant c2 -> Names.Constant.CanOrd.compare c1 c2
| Variable _, _ -> -1
| _ -> 1
let global_constant_of_globref = function
| GlobRef.VarRef x -> Variable x
| GlobRef.ConstRef x -> Constant x
| x -> CErrors.anomaly Pp.(str"not a global constant: " ++ (Printer.pr_global x))
let ({ CD.isc = isconstant; cout = constantout; cin = constantin; cino = constantino },constant),
({ CD.isc = isinductive; cout = inductiveout; cin = inductivein; cino = inductiveino },inductive),
({ CD.isc = isconstructor; cout = constructorout; cin = constructorin; cino = constructorino },constructor) =
let open API.RawOpaqueData in
declare {
name = "constant";
doc = "Global constant name";
pp = (fun fmt x ->
let x = match x with
| Variable x -> GlobRef.VarRef x
| Constant c -> GlobRef.ConstRef c in
Format.fprintf fmt "«%a»" Pp.pp_with (Printer.pr_global x));
compare = compare_global_constant;
hash = hash_global_constant;
hconsed = false;
constants = [];
},
declare {
name = "inductive";
doc = "Inductive type name";
pp = (fun fmt x -> Format.fprintf fmt "«%a»" Pp.pp_with (Printer.pr_global (GlobRef.IndRef x)));
compare = Names.Ind.CanOrd.compare;
hash = Names.Ind.CanOrd.hash;
hconsed = false;
constants = [];
},
declare {
name = "constructor";
doc = "Inductive constructor name";
pp = (fun fmt x -> Format.fprintf fmt "«%a»" Pp.pp_with (Printer.pr_global (GlobRef.ConstructRef x)));
compare = Names.Construct.CanOrd.compare;
hash = Names.Construct.CanOrd.hash;
hconsed = false;
constants = [];
}
;;
let inductiveina ~loc x = A.mkOpaque ~loc (inductiveino x)
let constantina ~loc x = A.mkOpaque ~loc (constantino x)
let constructorina ~loc x = A.mkOpaque ~loc (constructorino x)
let compare_instances x y =
let qx, ux = UVars.Instance.to_array x
and qy, uy = UVars.Instance.to_array y in
Util.Compare.(compare [(CArray.compare Sorts.Quality.compare, qx, qy); (CArray.compare Univ.Level.compare, ux, uy)])
[%%if coq = "9.0" || coq = "9.1" || coq = "9.2"]
let ppinst u = UVars.Instance.pr Sorts.QVar.raw_pr UnivNames.pr_level_with_global_universes u
[%%else]
let ppinst u = UVars.Instance.pr Sorts.raw_printer u
[%%endif]
let uinstancein, uinstanceino, isuinstance, uinstanceout, uinstance =
let { CD.cin; cino; isc; cout }, uinstance = CD.declare {
CD.name = "univ-instance";
doc = "Universes level instance for a universe-polymorphic constant";
pp = (fun fmt x ->
let s = Pp.string_of_ppcmds (ppinst x) in
Format.fprintf fmt "«%s»" s);
compare = compare_instances;
hash = UVars.Instance.hash;
hconsed = false;
constants = [];
} in
cin, cino, isc, cout, uinstance
;;
let uinstanceina ~loc x = A.mkOpaque ~loc (uinstanceino x)
let collect_term_variables ~depth t =
let rec aux ~depth acc t =
match E.look ~depth t with
| E.CData c when isconstant c ->
begin match constantout c with
| Variable id -> id :: acc
| _ -> acc
end
| x -> fold_elpi_term aux acc ~depth x
in
aux ~depth [] t
let constc = E.Constants.declare_global_symbol "const"
let indcc = E.Constants.declare_global_symbol "indc"
let indtc = E.Constants.declare_global_symbol "indt"
let gref : Names.GlobRef.t API.Conversion.t = {
API.Conversion.ty = API.Conversion.TyName "gref";
pp_doc = (fun fmt () ->
Format.fprintf fmt "%% Global objects: inductive types, inductive constructors, definitions@\n";
Format.fprintf fmt "kind gref type.@\n";
Format.fprintf fmt "external symbol const : constant -> gref. %% Nat.add, List.append, ...@\n";
Format.fprintf fmt "external symbol indt : inductive -> gref. %% nat, list, ...@\n";
Format.fprintf fmt "external symbol indc : constructor -> gref. %% O, S, nil, cons, ...@\n";
);
pp = (fun fmt x ->
Format.fprintf fmt "«%a»" Pp.pp_with (Printer.pr_global x));
embed = (fun ~depth state -> function
| GlobRef.IndRef i -> state, E.mkApp indtc (inductivein i) [], []
| GlobRef.ConstructRef c -> state, E.mkApp indcc (constructorin c) [], []
| GlobRef.VarRef v -> state, E.mkApp constc (constantin (Variable v)) [], []
| GlobRef.ConstRef c -> state, E.mkApp constc (constantin (Constant c)) [], []
);
readback = (fun ~depth state t ->
match E.look ~depth t with
| E.App(c,t,[]) when c == indtc ->
begin match E.look ~depth t with
| E.CData d when isinductive d -> state, GlobRef.IndRef (inductiveout d), []
| _ -> raise API.Conversion.(TypeErr(TyName"inductive",depth,t)); end
| E.App(c,t,[]) when c == indcc ->
begin match E.look ~depth t with
| E.CData d when isconstructor d -> state, GlobRef.ConstructRef (constructorout d), []
| _ -> raise API.Conversion.(TypeErr(TyName"constructor",depth,t)); end
| E.App(c,t,[]) when c == constc ->
begin match E.look ~depth t with
| E.CData d when isconstant d ->
begin match constantout d with
| Variable v -> state, GlobRef.VarRef v, []
| Constant v -> state, GlobRef.ConstRef v, [] end
| _ -> raise API.Conversion.(TypeErr(TyName"constant",depth,t)); end
| _ -> raise API.Conversion.(TypeErr(TyName"gref",depth,t));
);
}
let abbreviation =
let open API.OpaqueData in
declare {
name = "abbreviation";
doc = "Name of an abbreviation";
pp = (fun fmt x -> Format.fprintf fmt "«%s»" (KerName.to_string x));
compare = KerName.compare;
hash = KerName.hash;
hconsed = false;
constants = [];
}
module GROrd = struct
include Names.GlobRef.CanOrd
let show x = Pp.string_of_ppcmds (Printer.pr_global x)
let pp fmt x = Format.fprintf fmt "%a" Pp.pp_with (Printer.pr_global x)
end
module GRMap = U.Map.Make(GROrd)
module GRSet = U.Set.Make(GROrd)
let globalc = E.Constants.declare_global_symbol "global"
let pglobalc = E.Constants.declare_global_symbol "pglobal"
module GrefCache = Hashtbl.Make(GlobRef.UserOrd)
let cache = GrefCache.create 13
let assert_in_coq_gref_consistent ~poly gr =
match Global.is_polymorphic gr, poly with
| true, true -> ()
| false, false -> ()
| true, false ->
U.type_error Printf.(sprintf "Universe polymorphic gref %s used with the 'global' term constructor" (GROrd.show gr))
| false, true ->
U.type_error Printf.(sprintf "Non universe polymorphic gref %s used with the 'pglobal' term constructor" (GROrd.show gr))
;;
let assert_in_elpi_gref_consistent ~poly gr =
match Global.is_polymorphic gr, poly with
| true, true -> ()
| false, false -> ()
| true, false ->
U.anomaly Printf.(sprintf "Universe polymorphic gref %s used with the 'global' term constructor" (GROrd.show gr))
| false, true ->
U.anomaly Printf.(sprintf "Non universe polymorphic gref %s used with the 'pglobal' term constructor" (GROrd.show gr))
;;
let in_elpi_gr ~depth s r =
assert_in_elpi_gref_consistent ~poly:false r;
try
GrefCache.find cache r
with Not_found ->
let s, t, gl = gref.API.Conversion.embed ~depth s r in
assert (gl = []);
let x = E.mkAppGlobal globalc t [] in
GrefCache.add cache r x;
x
let in_elpiast_gref ~loc r =
match r with
| GlobRef.IndRef i -> A.mkAppGlobal ~loc ~hdloc:loc indtc (inductiveina ~loc i) []
| GlobRef.ConstructRef c -> A.mkAppGlobal ~loc ~hdloc:loc indcc (constructorina ~loc c) []
| GlobRef.VarRef v -> A.mkAppGlobal ~loc ~hdloc:loc constc (constantina ~loc (Variable v)) []
| GlobRef.ConstRef c -> A.mkAppGlobal ~loc ~hdloc:loc constc (constantina ~loc (Constant c)) []
let in_elpiast_gr ~loc r =
assert_in_elpi_gref_consistent ~poly:false r;
A.mkAppGlobal ~loc ~hdloc:loc globalc (in_elpiast_gref ~loc r) []
let in_elpi_poly_gr ~depth s r i =
assert_in_elpi_gref_consistent ~poly:true r;
let open API.Conversion in
let s, t, gl = gref.embed ~depth s r in
assert (gl = []);
E.mkApp pglobalc t [i]
let in_elpiast_poly_gr ~loc r i =
assert_in_elpi_gref_consistent ~poly:true r;
let t = in_elpiast_gref ~loc r in
A.mkAppGlobal ~loc ~hdloc:loc pglobalc t [i]
let in_elpi_poly_gr_instance ~depth s r i =
assert_in_elpi_gref_consistent ~poly:true r;
let open API.Conversion in
let s, i, gl = uinstance.embed ~depth s i in
assert (gl = []);
in_elpi_poly_gr ~depth s r i
let in_elpiast_poly_gr_instance ~loc r i =
assert_in_elpi_gref_consistent ~poly:true r;
let i = uinstanceina ~loc i in
in_elpiast_poly_gr ~loc r i
let in_coq_gref ~depth ~origin ~failsafe s t =
try
let s, t, gls = gref.API.Conversion.readback ~depth s t in
assert_in_coq_gref_consistent ~poly:false t;
assert(gls = []);
s, t
with API.Conversion.TypeErr _ ->
if failsafe then
s, Rocqlib.lib_ref "elpi.unknown_gref"
else
err Pp.(str "The term " ++ str(pp2string (P.term depth) origin) ++
str " cannot be represented in Coq since its gref part is illformed")
let mpin, ismp, mpout, modpath =
let { CD.cin; isc; cout }, x = CD.declare {
CD.name = "modpath";
doc = "Name of a module /*E*/";
pp = (fun fmt x ->
Format.fprintf fmt "«%s»" (Names.ModPath.to_string x));
compare = Names.ModPath.compare;
hash = Names.ModPath.hash;
hconsed = false;
constants = [];
} in
cin, isc, cout, x
;;
let mptyin, istymp, mptyout, modtypath =
let { CD.cin; isc; cout }, x = CD.declare {
CD.name = "modtypath";
doc = "Name of a module type /*E*/";
pp = (fun fmt x ->
Format.fprintf fmt "«%s»" (Names.ModPath.to_string x));
compare = Names.ModPath.compare;
hash = Names.ModPath.hash;
hconsed = false;
constants =[];
} in
cin, isc, cout, x
;;
let in_elpi_modpath ~ty mp = if ty then mptyin mp else mpin mp
let is_modpath ~depth t =
match E.look ~depth t with E.CData x -> ismp x | _ -> false
let is_modtypath ~depth t =
match E.look ~depth t with E.CData x -> istymp x | _ -> false
let in_coq_modpath ~depth t =
match E.look ~depth t with
| E.CData x when ismp x -> mpout x
| E.CData x when istymp x -> mptyout x
| _ -> assert false
(* ********************************* }}} ********************************** *)
(* {{{ constants (app, fun, ...) ****************************************** *)
(* binders *)
let lamc = E.Constants.declare_global_symbol "fun"
let in_elpi_lam n s t = E.mkApp lamc (in_elpi_name n) [s;E.mkLam t]
let in_elpiast_lam ~loc n s t =
A.mkAppGlobal ~loc ~hdloc:loc lamc (in_elpiast_name ~loc n) [s;A.mkLam ~loc (name_of_name ~loc n) t]
let prodc = E.Constants.declare_global_symbol "prod"
let in_elpi_prod n s t = E.mkApp prodc (in_elpi_name n) [s;E.mkLam t]
let in_elpiast_prod ~loc n s t =
A.mkAppGlobal ~loc~hdloc:loc prodc (in_elpiast_name ~loc n) [s;A.mkLam ~loc (name_of_name ~loc n) t]
let letc = E.Constants.declare_global_symbol "let"
let in_elpi_let n b s t = E.mkApp letc (in_elpi_name n) [s;b;E.mkLam t]
let in_elpiast_let ~loc n ~ty:s ~bo:b t =
A.mkAppGlobal ~loc ~hdloc:loc letc (in_elpiast_name ~loc n) [s;b;A.mkLam ~loc (name_of_name ~loc n) t]
(* other *)
let appc = E.Constants.declare_global_symbol "app"
let in_elpi_app_Arg ~depth hd args = E.mkAppMoreArgs ~depth hd args
let flatten_appc ~depth hd (args : E.term list) =
if E.isApp ~depth hd then
match E.look ~depth hd with
| E.App(c,x,[]) when c == appc ->
E.mkApp appc (U.list_to_lp_list (U.lp_list_to_list ~depth x @ args)) []
| _ ->
E.mkApp appc (U.list_to_lp_list (hd :: args)) []
else
E.mkApp appc (U.list_to_lp_list (hd :: args)) []
let in_elpi_appl ~depth hd (args : E.term list) =
if args = [] then hd
else flatten_appc ~depth hd args
let flatten_appc_ast ~loc hd args =
match hd with
| { A.it = A.App(g,c,_,x,[]); loc } when API.Ast.Name.is_global c appc ->
A.mkAppGlobal ~loc ~hdloc:loc appc (A.ne_list_to_lp_list (A.lp_list_to_list x @ args)) []
| { loc } -> A.mkAppGlobal ~loc ~hdloc:loc appc (A.ne_list_to_lp_list (hd :: args)) []
let in_elpiast_appl ~loc hd args =
if args = [] then hd
else flatten_appc_ast ~loc hd args
let in_elpi_app ~depth hd (args : E.term array) =
in_elpi_appl ~depth hd (Array.to_list args)
let matchc = E.Constants.declare_global_symbol "match"
let in_elpi_match (*ci_ind ci_npar ci_cstr_ndecls ci_cstr_nargs*) t rt bs =
E.mkApp matchc t [rt; U.list_to_lp_list bs]
let in_elpiast_match ~loc t rt bs =
A.mkAppGlobal ~loc ~hdloc:loc matchc t [rt;A.list_to_lp_list ~loc bs]
let fixc = E.Constants.declare_global_symbol "fix"
let in_elpi_fix name rno ty bo =
E.mkApp fixc (in_elpi_name name) [CD.of_int rno; ty; E.mkLam bo]
let in_elpiast_fix ~loc n rno ty bo =
A.mkAppGlobal ~loc ~hdloc:loc fixc (in_elpiast_name ~loc n) [A.mkOpaque ~loc @@ CD.int.cino rno; ty; A.mkLam ~loc (name_of_name ~loc n) bo]
let primitivec = E.Constants.declare_global_symbol "primitive"
type pstring = Pstring.t
let pp_pstring = Pstring.to_string
let eC_mkString = EC.mkString
type primitive_value =
| Uint63 of Uint63.t
| Float64 of Float64.t
| Pstring of pstring
| Projection of Projection.t
let ui63c = E.Constants.declare_global_symbol "uint63"
let fl64c = E.Constants.declare_global_symbol "float64"
let pstrc = E.Constants.declare_global_symbol "pstring"
let projc = E.Constants.declare_global_symbol "proj"
let uint63ina ~loc x = A.mkAppGlobal ~loc ~hdloc:loc primitivec (A.mkAppGlobal ~loc ~hdloc:loc ui63c (A.mkOpaque ~loc (uint63c.cino x)) []) []
let float64ina ~loc x = A.mkAppGlobal ~loc ~hdloc:loc primitivec (A.mkAppGlobal ~loc ~hdloc:loc fl64c (A.mkOpaque ~loc (float64c.cino x)) []) []
let projectionina ~loc p =
let n = Names.Projection.(arg p + npars p) in
A.mkAppGlobal ~loc ~hdloc:loc primitivec (A.mkAppGlobal ~loc ~hdloc:loc projc
(A.mkOpaque ~loc (projectionc.cino p)) [A.mkOpaque ~loc @@ CD.int.cino n]) []
let pstringina ~loc x = A.mkAppGlobal ~loc~hdloc:loc primitivec (A.mkAppGlobal ~loc ~hdloc:loc pstrc (A.mkOpaque ~loc (pstringc.cino x)) []) []
let primitive_value : primitive_value API.Conversion.t =
let module B = Rocq_elpi_utils in
let open API.AlgebraicData in declare {
ty = API.Conversion.TyName "primitive-value";
doc = "Primitive values";
pp = (fun fmt -> function
| Uint63 i -> Format.fprintf fmt "%s" (Uint63.to_string i)
| Float64 f -> Format.fprintf fmt "%s" (Float64.to_string f)
| Pstring s -> Format.fprintf fmt "%s" (pp_pstring s)
| Projection p -> Format.fprintf fmt "%s" (Projection.to_string p));
constructors = [
K("uint63","unsigned integers over 63 bits",A(B.uint63,N),
B (fun x -> Uint63 x),
M (fun ~ok ~ko -> function Uint63 x -> ok x | _ -> ko ()));
K("float64","double precision foalting points",A(B.float64,N),
B (fun x -> Float64 x),
M (fun ~ok ~ko -> function Float64 x -> ok x | _ -> ko ()));
K("pstring","primitive string",A(B.pstring,N),
B (fun x -> Pstring x),
M (fun ~ok ~ko -> function Pstring x -> ok x | _ -> ko ()));
K("proj","primitive projection",A(B.projection,A(API.BuiltInData.int,N)),
B (fun p n -> Projection p),
M (fun ~ok ~ko -> function Projection p -> ok p Names.Projection.(arg p + npars p) | _ -> ko ()));
]
} |> API.ContextualConversion.(!<)
let in_elpi_primitive ~depth state i =
let state, i, _ = primitive_value.API.Conversion.embed ~depth state i in
state, E.mkApp primitivec i []
let in_elpiast_primitive ~loc = function
| Uint63 i -> uint63ina ~loc i
| Float64 f -> float64ina ~loc f