ocaml-ppx-deriving/0009-Add-OCaml-5.00-support-to-the-tests-and-update-docum.patch
2023-07-10 22:22:19 -06:00

233 lines
10 KiB
Diff

From da4d0a0c55184b55c39fccb1d2379984770ddc04 Mon Sep 17 00:00:00 2001
From: Kate <kit.ty.kate@disroot.org>
Date: Wed, 16 Feb 2022 17:47:12 +0000
Subject: [PATCH 9/9] Add OCaml 5.00 support to the tests and update
documentation
---
CHANGELOG.md | 6 ++++++
README.md | 6 +++---
src/api/ppx_deriving.cppo.ml | 2 +-
src/api/ppx_deriving.cppo.mli | 4 ++--
src/runtime/ppx_deriving_runtime.cppo.mli | 2 ++
src_test/eq/test_deriving_eq.cppo.ml | 2 +-
src_test/fold/test_deriving_fold.cppo.ml | 3 +--
src_test/iter/test_deriving_iter.cppo.ml | 6 ++----
src_test/map/test_deriving_map.cppo.ml | 4 ++--
src_test/ord/test_deriving_ord.cppo.ml | 3 +--
src_test/runtime/test_runtime.cppo.ml | 2 +-
src_test/show/test_deriving_show.cppo.ml | 4 ++--
12 files changed, 24 insertions(+), 20 deletions(-)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index e177fb6..a3d885e 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,3 +1,9 @@
+(unreleased)
+------------
+
+* Introduce `Ppx_deriving_runtime.Stdlib` with OCaml >= 4.07. This module
+ already exists in OCaml < 4.07 but was missing otherwise.
+
5.2.1 (02/02/2021)
------------------
diff --git a/README.md b/README.md
index 1f02cca..9237e5e 100644
--- a/README.md
+++ b/README.md
@@ -90,7 +90,7 @@ The `[%derive.x:]` syntax can be shortened to `[%x:]`, given that the deriver `x
### Working with existing types
-At first, it may look like _deriving_ requires complete control of the type declaration. However, a lesser-known OCaml feature allows to derive functions for any existing type. Using `Pervasives.fpclass` as an example, _show_ can be derived as follows:
+At first, it may look like _deriving_ requires complete control of the type declaration. However, a lesser-known OCaml feature allows to derive functions for any existing type. Using `Stdlib.fpclass` as an example, _show_ can be derived as follows:
``` ocaml
# module M = struct
@@ -113,7 +113,7 @@ module M :
- : string = "FP_normal"
```
-The module is used to demonstrate that `show_myfpclass` really accepts `Pervasives.fpclass`, and not just `M.myfpclass`.
+The module is used to demonstrate that `show_myfpclass` really accepts `Stdlib.fpclass`, and not just `M.myfpclass`.
To avoid the need to repeat the type definition, it is possible to use [ppx_import](https://github.com/ocaml-ppx/ppx_import#usage) to automatically pull in the type definition. Attributes can be attached using its `[@with]` replacement feature.
@@ -184,7 +184,7 @@ This code will create printers which return the string `X.C`, `X` is a module pa
Plugins: eq and ord
-------------------
-_eq_ derives a function comparing values by semantic equality; structural or physical depending on context. _ord_ derives a function defining a total order for values, returning a negative value if lower, `0` if equal or a positive value if greater. They're similar to `Pervasives.(=)` and `Pervasives.compare`, but are faster, allow to customize the comparison rules, and never raise at runtime. _eq_ and _ord_ are short-circuiting.
+_eq_ derives a function comparing values by semantic equality; structural or physical depending on context. _ord_ derives a function defining a total order for values, returning a negative value if lower, `0` if equal or a positive value if greater. They're similar to `Stdlib.(=)` and `Stdlib.compare`, but are faster, allow to customize the comparison rules, and never raise at runtime. _eq_ and _ord_ are short-circuiting.
``` ocaml
# type t = [ `A | `B of int ] [@@deriving eq, ord];;
diff --git a/src/api/ppx_deriving.cppo.ml b/src/api/ppx_deriving.cppo.ml
index 6e6edec..b212fc9 100644
--- a/src/api/ppx_deriving.cppo.ml
+++ b/src/api/ppx_deriving.cppo.ml
@@ -180,7 +180,7 @@ let raise_errorf ?sub ?loc fmt =
#endif
let err = Location.error ?sub ?loc str in
raise (Location.Error err) in
- Printf.kprintf raise_msg fmt
+ Printf.ksprintf raise_msg fmt
let create =
let def_ext_str name ~options ~path typ_ext =
diff --git a/src/api/ppx_deriving.cppo.mli b/src/api/ppx_deriving.cppo.mli
index 81cb5b3..d31e998 100644
--- a/src/api/ppx_deriving.cppo.mli
+++ b/src/api/ppx_deriving.cppo.mli
@@ -184,7 +184,7 @@ val create_quoter : unit -> quoter
val quote : quoter:quoter -> expression -> expression
(** [sanitize module_ quoter expr] wraps [expr] in a way that ensures that the
- contents of [module_] and {!Pervasives}, as well as the identifiers in
+ contents of [module_] and {!Stdlib}, as well as the identifiers in
expressions returned by [quote] are in scope, and returns the wrapped
expression. [module_] defaults to {!Ppx_deriving_runtime} if it's not
provided*)
@@ -236,7 +236,7 @@ val attr_warning: expression -> attribute
val free_vars_in_core_type : core_type -> tyvar list
(** [remove_pervasives ~deriver typ] removes the leading "Pervasives."
- module name in longidents.
+ and "Stdlib." module name in longidents.
Type expressions marked with [\[\@nobuiltin\]] are ignored.
The name of the deriving plugin should be passed as [deriver]; it is used
diff --git a/src/runtime/ppx_deriving_runtime.cppo.mli b/src/runtime/ppx_deriving_runtime.cppo.mli
index 87674f5..01d8626 100644
--- a/src/runtime/ppx_deriving_runtime.cppo.mli
+++ b/src/runtime/ppx_deriving_runtime.cppo.mli
@@ -27,6 +27,8 @@ include module type of struct
include Stdlib
end
+module Stdlib = Stdlib
+
module Result : sig
type ('a, 'b) t = ('a, 'b) result =
| Ok of 'a
diff --git a/src_test/eq/test_deriving_eq.cppo.ml b/src_test/eq/test_deriving_eq.cppo.ml
index a2c4674..f8ff081 100644
--- a/src_test/eq/test_deriving_eq.cppo.ml
+++ b/src_test/eq/test_deriving_eq.cppo.ml
@@ -14,7 +14,7 @@ type a7 = char [@@deriving eq]
type a8 = string [@@deriving eq]
type a9 = bytes [@@deriving eq]
type r1 = int ref [@@deriving eq]
-type r2 = int Pervasives.ref [@@ocaml.warning "-3"][@@deriving eq]
+type r2 = int Stdlib.ref [@@deriving eq]
type l = int list [@@deriving eq]
type a = int array [@@deriving eq]
type o = int option [@@deriving eq]
diff --git a/src_test/fold/test_deriving_fold.cppo.ml b/src_test/fold/test_deriving_fold.cppo.ml
index e7ed05a..ec9060d 100644
--- a/src_test/fold/test_deriving_fold.cppo.ml
+++ b/src_test/fold/test_deriving_fold.cppo.ml
@@ -7,8 +7,7 @@ let test_btree ctxt =
let btree = (Node (Node (Leaf, 3, Leaf), 1, Node (Leaf, 2, Leaf))) in
assert_equal ~printer:string_of_int 6 (fold_btree (+) 0 btree)
-type 'a reflist = 'a Pervasives.ref list
-[@@ocaml.warning "-3"]
+type 'a reflist = 'a Stdlib.ref list
[@@deriving fold]
let test_reflist ctxt =
diff --git a/src_test/iter/test_deriving_iter.cppo.ml b/src_test/iter/test_deriving_iter.cppo.ml
index 581c6d1..bd4dd02 100644
--- a/src_test/iter/test_deriving_iter.cppo.ml
+++ b/src_test/iter/test_deriving_iter.cppo.ml
@@ -9,8 +9,7 @@ module T : sig
type ('a,'b) record = { a : 'a; b : 'b }
[@@deriving iter]
- type 'a reflist = 'a Pervasives.ref list
- [@@ocaml.warning "-3"]
+ type 'a reflist = 'a Stdlib.ref list
[@@deriving iter]
end = struct
@@ -21,8 +20,7 @@ end = struct
type ('a,'b) record = { a : 'a; b : 'b }
[@@deriving iter]
- type 'a reflist = 'a Pervasives.ref list
- [@@ocaml.warning "-3"]
+ type 'a reflist = 'a Stdlib.ref list
[@@deriving iter]
end
diff --git a/src_test/map/test_deriving_map.cppo.ml b/src_test/map/test_deriving_map.cppo.ml
index b688110..e152815 100644
--- a/src_test/map/test_deriving_map.cppo.ml
+++ b/src_test/map/test_deriving_map.cppo.ml
@@ -99,7 +99,7 @@ let test_var2 ctxt =
assert_equal ~printer:(show_var2 fmt_int) (A2 5) (map_var2 int_of_float (A2 5.))
let test_var3 ctxt =
- let show,map = show_var3 fmt_int fmt_str, map_var3 ((+)1) String.uppercase [@warning "-3"] in
+ let show,map = show_var3 fmt_int fmt_str, map_var3 ((+)1) String.uppercase_ascii in
assert_equal ~printer:show (A3 2) (map (A3 1));
assert_equal ~printer:show (B3 false) (map (B3 false));
assert_equal ~printer:show (C3("ABC", A3 3)) (map (C3("abc", A3 2)));
@@ -123,7 +123,7 @@ let test_record2 ctxt =
let test_record3 ctxt =
let show,map = show_record3 fmt_int fmt_str,
- map_record3 ((+)1) String.uppercase [@warning "-3"]
+ map_record3 ((+)1) String.uppercase_ascii
in
assert_equal ~printer:show {a3=5;b3=false;c3="ABC"} (map {a3=4;b3=false;c3="abc"});
let show,map = show_record3 fmt_int fmt_flt, map_record3 Char.code float_of_int in
diff --git a/src_test/ord/test_deriving_ord.cppo.ml b/src_test/ord/test_deriving_ord.cppo.ml
index fdd4d0d..271c1a6 100644
--- a/src_test/ord/test_deriving_ord.cppo.ml
+++ b/src_test/ord/test_deriving_ord.cppo.ml
@@ -118,8 +118,7 @@ let test_ref1 ctxt =
assert_equal ~printer (0) (compare_r1 (ref 0) (ref 0));
assert_equal ~printer (1) (compare_r1 (ref 1) (ref 0))
-type r2 = int Pervasives.ref
-[@@ocaml.warning "-3"]
+type r2 = int Stdlib.ref
[@@deriving ord]
let test_ref2 ctxt =
assert_equal ~printer (-1) (compare_r2 (ref 0) (ref 1));
diff --git a/src_test/runtime/test_runtime.cppo.ml b/src_test/runtime/test_runtime.cppo.ml
index aac3fcf..d4874ba 100644
--- a/src_test/runtime/test_runtime.cppo.ml
+++ b/src_test/runtime/test_runtime.cppo.ml
@@ -6,7 +6,7 @@ let test_ref_included
let test_ref_qualified
(x : 'a ref)
=
- (x : 'a Ppx_deriving_runtime.Pervasives.ref[@ocaml.warning "-3"])
+ (x : 'a Ppx_deriving_runtime.Stdlib.ref)
let test_backtrace
(x : Printexc.raw_backtrace)
diff --git a/src_test/show/test_deriving_show.cppo.ml b/src_test/show/test_deriving_show.cppo.ml
index 7a99db4..4a27818 100644
--- a/src_test/show/test_deriving_show.cppo.ml
+++ b/src_test/show/test_deriving_show.cppo.ml
@@ -12,8 +12,8 @@ type a7 = char [@@deriving show]
type a8 = string [@@deriving show]
type a9 = bytes [@@deriving show]
type r = int ref [@@deriving show]
-type r2 = int Pervasives.ref [@@ocaml.warning "-3"] [@@deriving show]
-type r3 = int Pervasives.ref ref [@@ocaml.warning "-3"] [@@deriving show]
+type r2 = int Stdlib.ref [@@deriving show]
+type r3 = int Stdlib.ref ref [@@deriving show]
type l = int list [@@deriving show]
type a = int array [@@deriving show]
type o = int option [@@deriving show]
--
2.41.0