Skip to content

Commit 92de5c8

Browse files
authored
Merge pull request #634 from rlepigre/br/prim-string
Adapt to rocq-prover/rocq#18973.
2 parents f3ca994 + 35dcf71 commit 92de5c8

File tree

9 files changed

+56
-1
lines changed

9 files changed

+56
-1
lines changed

coq-builtin.elpi

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1080,6 +1080,9 @@ typeabbrev uint63 (ctype "uint63").
10801080
typeabbrev float64 (ctype "float64").
10811081

10821082

1083+
typeabbrev pstring (ctype "pstring").
1084+
1085+
10831086
typeabbrev projection (ctype "projection").
10841087

10851088

@@ -1088,6 +1091,7 @@ kind primitive-value type.
10881091
type uint63 uint63 -> primitive-value. % unsigned integers over 63 bits
10891092
type float64 float64 ->
10901093
primitive-value. % double precision foalting points
1094+
type pstring pstring -> primitive-value. % primitive string
10911095
type proj projection -> int -> primitive-value. % primitive projection
10921096

10931097
% [coq.uint63->int U I] Transforms a primitive unsigned integer U into an
@@ -1106,6 +1110,15 @@ external pred coq.float64->float i:float64, o:float.
11061110
% on 64 bits. Currently, it should not fail.
11071111
external pred coq.float->float64 i:float, o:float64.
11081112

1113+
% [coq.pstring->string PS S] Transforms a Coq primitive string to an elpi
1114+
% string. It does not fail.
1115+
external pred coq.pstring->string i:pstring, o:string.
1116+
1117+
% [coq.string->pstring S PS] Transforms an elpi string into a Coq primitive
1118+
% string. It fails if the lenght of S is greater than the maximal primitive
1119+
% string length.
1120+
external pred coq.string->pstring i:string, o:pstring.
1121+
11091122

11101123
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
11111124
% API for extra logical objects

elpi/elpi_elaborator.elpi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,7 @@ of (pglobal GR I as X) T X :-
310310

311311
of (primitive (uint63 _) as X) T X :- unify-leq {{ lib:elpi.uint63 }} T.
312312
of (primitive (float64 _) as X) T X :- unify-leq {{ lib:elpi.float64 }} T.
313+
of (primitive (pstring _) as X) T X :- unify-leq {{ lib:elpi.pstring }} T.
313314

314315
of (uvar as X) T Y :- !, evar X T Y.
315316

src/coq_elpi_HOAS.ml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -728,6 +728,7 @@ let primitivec = E.Constants.declare_global_symbol "primitive"
728728
type primitive_value =
729729
| Uint63 of Uint63.t
730730
| Float64 of Float64.t
731+
| Pstring of Pstring.t
731732
| Projection of Projection.t
732733

733734
let primitive_value : primitive_value API.Conversion.t =
@@ -738,6 +739,7 @@ let primitive_value : primitive_value API.Conversion.t =
738739
pp = (fun fmt -> function
739740
| Uint63 i -> Format.fprintf fmt "Type"
740741
| Float64 f -> Format.fprintf fmt "Set"
742+
| Pstring s -> Format.fprintf fmt "Set"
741743
| Projection p -> Format.fprintf fmt "");
742744
constructors = [
743745
K("uint63","unsigned integers over 63 bits",A(B.uint63,N),
@@ -746,6 +748,9 @@ let primitive_value : primitive_value API.Conversion.t =
746748
K("float64","double precision foalting points",A(B.float64,N),
747749
B (fun x -> Float64 x),
748750
M (fun ~ok ~ko -> function Float64 x -> ok x | _ -> ko ()));
751+
K("pstring","primitive string",A(B.pstring,N),
752+
B (fun x -> Pstring x),
753+
M (fun ~ok ~ko -> function Pstring x -> ok x | _ -> ko ()));
749754
K("proj","primitive projection",A(B.projection,A(API.BuiltInData.int,N)),
750755
B (fun p n -> Projection p),
751756
M (fun ~ok ~ko -> function Projection p -> ok p Names.Projection.(arg p + npars p) | _ -> ko ()));
@@ -1382,6 +1387,7 @@ let rec constr2lp coq_ctx ~calldepth ~depth state t =
13821387
| C.CoFix _ -> nYI "HOAS for cofix"
13831388
| C.Int i -> in_elpi_primitive ~depth state (Uint63 i)
13841389
| C.Float f -> in_elpi_primitive ~depth state (Float64 f)
1390+
| C.String s -> in_elpi_primitive ~depth state (Pstring s)
13851391
| C.Array _ -> nYI "HOAS for persistent arrays"
13861392
in
13871393
debug Pp.(fun () ->
@@ -1975,6 +1981,7 @@ and lp2constr ~calldepth syntactic_constraints coq_ctx ~depth state ?(on_ty=fals
19751981
begin match v with
19761982
| Uint63 i -> state, EC.mkInt i, gls
19771983
| Float64 f -> state, EC.mkFloat f, gls
1984+
| Pstring s -> state, EC.mkString s, gls
19781985
| Projection p -> state, EC.UnsafeMonomorphic.mkConst (Names.Projection.constant p), gls
19791986
end
19801987

src/coq_elpi_HOAS.mli

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ val collect_term_variables : depth:int -> term -> Names.Id.t list
180180
type primitive_value =
181181
| Uint63 of Uint63.t
182182
| Float64 of Float64.t
183+
| Pstring of Pstring.t
183184
| Projection of Projection.t
184185
val primitive_value : primitive_value Conversion.t
185186
val in_elpi_primitive : depth:int -> state -> primitive_value -> state * term

src/coq_elpi_builtins.ml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2513,6 +2513,7 @@ declared as cumulative.|};
25132513
25142514
MLData Coq_elpi_utils.uint63;
25152515
MLData Coq_elpi_utils.float64;
2516+
MLData Coq_elpi_utils.pstring;
25162517
MLData Coq_elpi_utils.projection;
25172518
MLData primitive_value;
25182519
@@ -2553,6 +2554,23 @@ declared as cumulative.|};
25532554
!: (Float64.of_float f))),
25542555
DocAbove);
25552556
2557+
MLCode(Pred("coq.pstring->string",
2558+
In(Coq_elpi_utils.pstring,"PS",
2559+
Out(B.string,"S",
2560+
Easy "Transforms a Coq primitive string to an elpi string. It does not fail.")),
2561+
(fun s _ ~depth:_ -> !: (Pstring.to_string s))),
2562+
DocAbove);
2563+
2564+
MLCode(Pred("coq.string->pstring",
2565+
In(B.string,"S",
2566+
Out(Coq_elpi_utils.pstring,"PS",
2567+
Easy "Transforms an elpi string into a Coq primitive string. It fails if the lenght of S is greater than the maximal primitive string length.")),
2568+
(fun s _ ~depth:_ ->
2569+
match Pstring.of_string s with
2570+
| Some s -> !: s
2571+
| None -> raise No_clause)),
2572+
DocAbove);
2573+
25562574
LPCode {|
25572575
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
25582576
% API for extra logical objects

src/coq_elpi_glob_quotation.ml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,7 @@ let rec gterm2lp ~depth state x =
379379
| GRec _ -> nYI "(glob)HOAS mutual/non-struct fix"
380380
| GInt i -> in_elpi_primitive ~depth state (Uint63 i)
381381
| GFloat f -> in_elpi_primitive ~depth state (Float64 f)
382+
| GString s -> in_elpi_primitive ~depth state (Pstring s)
382383
| GArray _ -> nYI "(glob)HOAS persistent arrays"
383384
;;
384385

src/coq_elpi_utils.ml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,18 @@ let float64 : Float64.t Elpi.API.Conversion.t =
190190
constants = [];
191191
}
192192

193+
let pstring : Pstring.t Elpi.API.Conversion.t =
194+
let open Elpi.API.OpaqueData in
195+
declare {
196+
name = "pstring";
197+
doc = "";
198+
pp = (fun fmt s -> Format.fprintf fmt "%S" (Pstring.to_string s));
199+
compare = Pstring.compare;
200+
hash = Pstring.hash;
201+
hconsed = false;
202+
constants = [];
203+
}
204+
193205
let debug = CDebug.create ~name:"elpi" ()
194206

195207
let projection : Names.Projection.t Elpi.API.Conversion.t =

src/coq_elpi_utils.mli

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ val fold_elpi_term :
4444

4545
val uint63 : Uint63.t Elpi.API.Conversion.t
4646
val float64 : Float64.t Elpi.API.Conversion.t
47+
val pstring : Pstring.t Elpi.API.Conversion.t
4748
val projection : Names.Projection.t Elpi.API.Conversion.t
4849

4950
val debug : CDebug.t

theories/elpi.v

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ Register Coq.Bool.Bool.reflect as elpi.reflect.
4646
Register Coq.Bool.Bool.ReflectF as elpi.ReflectF.
4747
Register Coq.Bool.Bool.ReflectT as elpi.ReflectT.
4848

49-
From Coq Require PrimFloat PrimInt63.
49+
From Coq Require PrimFloat PrimInt63 PrimString.
5050

5151
Register Coq.Floats.PrimFloat.float as elpi.float64.
5252
Register Coq.Numbers.Cyclic.Int63.PrimInt63.int as elpi.uint63.
53+
Register Coq.Strings.PrimString.string as elpi.pstring.

0 commit comments

Comments
 (0)